Example #1
0
        public void AlwaysCompressCorrectly()
        {
            using var imgStream = File.OpenRead("G:\\KH2.IMG");
            new Img(imgStream, File.OpenRead("G:\\KH2.IDX").Using(Idx.Read), true)
            .Entries.ToList()
            .Where(x => x.IsCompressed)
            .Where(x => !x.IsStreamed)
            .Select(x => new
            {
                Name  = IdxName.Lookup(x),
                Entry = x,
                Data  = imgStream
                        .SetPosition(x.Offset * 0x800)
                        .ReadBytes((x.BlockLength + 1) * 0x800)
            })
            .ToList()
            .AsParallel()
            .WithDegreeOfParallelism(16)
            .ForAll(x =>
            {
                new MemoryStream(Img.Decompress(x.Data)).Using(stream =>
                {
                    Helpers.AssertStream(stream, inStream =>
                    {
                        var compressedData   = Img.Compress(inStream.ReadAllBytes());
                        var decompressedData = Img.Decompress(compressedData);

                        return(new MemoryStream(decompressedData));
                    });
                });
            });
        }
Example #2
0
            public static List <string> ExtractIdx(Img img, IEnumerable <Idx.Entry> idxEntries, string basePath)
            {
                var idxs = new List <string>();

                foreach (var entry in idxEntries)
                {
                    var fileName = IdxName.Lookup(entry);
                    if (fileName == null)
                    {
                        fileName = $"@noname/{entry.Hash32:X08}-{entry.Hash16:X04}";
                    }

                    Console.WriteLine(fileName);

                    var outputFile = Path.Combine(basePath, fileName);
                    var outputDir  = Path.GetDirectoryName(outputFile);
                    if (Directory.Exists(outputDir) == false)
                    {
                        Directory.CreateDirectory(outputDir);
                    }

                    using (var file = File.Create(outputFile))
                    {
                        // TODO handle decompression
                        img.FileOpen(entry).CopyTo(file);
                    }

                    if (Path.GetExtension(fileName) == ".idx")
                    {
                        idxs.Add(outputFile);
                    }
                }

                return(idxs);
            }
Example #3
0
            protected int OnExecute(CommandLineApplication app)
            {
                var entries = OpenIdx(InputIdx);

                if (Sort)
                {
                    entries = entries.OrderBy(x => x.Offset);
                }

                foreach (var entry in entries)
                {
                    Console.WriteLine(IdxName.Lookup(entry) ?? $"@{entry.Hash32:X08}-{entry.Hash16:X04}");
                }

                return(0);
            }
Example #4
0
 public void GiveRealNames(uint hash32, ushort hash16, string name)
 {
     Assert.Equal(name, IdxName.Lookup(hash32, hash16));
 }
Example #5
0
 public static string GetFullName(this Idx.Entry entry) =>
 IdxName.Lookup(entry) ?? $"@{entry.Hash32:X08}_{entry.Hash16}";