Exemple #1
0
        private static void CompressRom(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Invalid args");
            }
            CompressTask g0;

            using (StreamReader reader = new StreamReader(args[1]))
            {
                g0 = new CompressTask(reader);
            }

            using (BinaryReader reader = new BinaryReader(File.OpenRead(args[2])))
            {
                byte[]      file       = reader.ReadBytes((int)reader.BaseStream.Length);
                byte[]      compressed = new byte[0x400_0000];
Exemple #2
0
        public static int Compress(ReadOnlySpan <byte> read, Span <byte> w, CompressTask task, int cur = 0)
        {
            DmadataRecord dmadataRec = GetDmadataRec(read, task.Dmadata);
            var           dmadata    = GetDmadataRecords(read, task.Dmadata);

            for (int i = 0; i < dmadata.Count; i++)
            {
                if (i % 50 == 0)
                {
                    Console.WriteLine($"File {i}");
                }
                var         dmarec = dmadata[i];
                FileAddress vrom   = dmarec.VRom;
                FileAddress rom    = dmarec.Rom;
                if (rom.Start < 0)
                {
                    continue;
                }

                ReadOnlySpan <byte> file = read.Slice(rom.Start, vrom.Size);

                //if file should be compressed
                if (!task.Exclusions.Contains(i))
                {
                    int size = Yaz.Encode(file.ToArray(), vrom.Size, out byte[] comp);
                    if (size > 0)
                    {
                        Span <byte> c = new Span <byte>(comp, 0, size);
                        c.CopyTo(w.Slice(cur, size));
                        dmarec.Rom = new FileAddress(cur, cur + size);
                        cur       += size;
                        continue;
                    }
                }

                file.CopyTo(w.Slice(cur, vrom.Size));
                dmarec.Rom = new FileAddress(cur, 0);
                cur       += vrom.Size;
            }
            WriteDmadataRecords(w.Slice(dmadataRec.Rom.Start, dmadataRec.VRom.Size), dmadata);

            return(cur);
        }