Example #1
0
        public async Task FileStructureParseTest(string productCode, int expectedFileCount)
        {
            var searchResults = await Client.SearchAsync(productCode, CancellationToken.None).ConfigureAwait(false);

            Assert.That(searchResults?.Data?.Count, Is.EqualTo(1));

            var ird = await Client.DownloadAsync(searchResults.Data[0], "ird", CancellationToken.None).ConfigureAwait(false);

            Assert.That(ird, Is.Not.Null);
            Assert.That(ird.FileCount, Is.EqualTo(expectedFileCount));

            using (var decompressedStream = GetDecompressHeader(ird))
            {
                var reader = new CDReader(decompressedStream, true, true);
                var files  = reader.GetFilesystemStructure();
                Assert.That(files.Count, Is.EqualTo(expectedFileCount));
            }
        }
        public static DiscInfo ToDiscInfo(this Ird ird)
        {
            List <FileRecord> fsInfo;
            var sectorSize = 2048L;

            using (var stream = new MemoryStream())
            {
                using (var headerStream = new MemoryStream(ird.Header))
                    using (var gzipStream = new GZipStream(headerStream, CompressionMode.Decompress))
                    {
                        gzipStream.CopyTo(stream);
                    }
                stream.Seek(0, SeekOrigin.Begin);
                var reader = new CDReader(stream, true, true);
                fsInfo     = reader.GetFilesystemStructure();
                sectorSize = reader.ClusterSize;
            }
            var checksums = ird.Files.ToDictionary(f => f.Offset, f => f.Md5Checksum.ToHexString());

            return(new DiscInfo
            {
                ProductCode = ird.ProductCode,
                DiscVersion = ird.GameVersion,
                DiscKeyRawData = ird.Data1.ToHexString(),
                DiscKey = Decrypter.DecryptDiscKey(ird.Data1).ToHexString(),
                Files = fsInfo.ToDictionary(
                    f => f.Filename,
                    f => new FileInfo
                {
                    Offset = f.StartSector * sectorSize,
                    Size = f.Length,
                    Hashes = new Dictionary <string, string>
                    {
                        ["MD5"] = checksums[f.StartSector],
                    }
                })
            });
        }