示例#1
0
        public async Task SmallFilesShouldntCrash()
        {
            await using var temp = await TempFolder.Create();

            await using var archive = new TempFile();
            for (int i = 0; i < 1; i++)
            {
                await WriteRandomData(temp.Dir.Combine($"{i}.bin"), _rng.Next(10, 10));
            }

            await ZipUpFolder(temp.Dir, archive.Path, false);

            var results = await FileExtractor2.GatheringExtract(new NativeFileStreamFactory(archive.Path),
                                                                _ => true,
                                                                async (path, sfn) =>
            {
                await using var s = await sfn.GetStream();
                return(await s.xxHashAsync());
            });

            Assert.Equal(1, results.Count);
            foreach (var(path, hash) in results)
            {
                Assert.Equal(await temp.Dir.Combine(path).FileHashAsync(), hash);
            }
        }
示例#2
0
        public async Task SmallZipNoLongerCrashes()
        {
            var src = await DownloadMod(Game.Fallout4, 29596, 120918);

            await using var tmpFolder = await TempFolder.Create();

            await FileExtractor2.ExtractAll(src, tmpFolder.Dir);
        }
示例#3
0
        public async Task ExtractModlist()
        {
            ExtractedModlistFolder = await TempFolder.Create();

            await FileExtractor2.GatheringExtract(new NativeFileStreamFactory(ModListArchive), _ => true,
                                                  async (path, sfn) =>
            {
                await using var s = await sfn.GetStream();
                var fp            = ExtractedModlistFolder.Dir.Combine(path);
                fp.Parent.CreateDirectory();
                await fp.WriteAllAsync(s);
                return(0);
            });
        }
示例#4
0
        public async Task CanGatherDataFromOMODFiles()
        {
            var src = await DownloadMod(Game.Oblivion, 18498);

            await FileExtractor2.GatheringExtract(new NativeFileStreamFactory(src),
                                                  p => p.Extension == OMODExtension, async (path, sfn) =>
            {
                await FileExtractor2.GatheringExtract(sfn, _ => true, async(ipath, isfn) => {
                    // We shouldn't have any .crc files because this file should be recognized as a OMOD and extracted correctly
                    Assert.NotEqual(CRCExtension, ipath.Extension);
                    return(0);
                });
                return(0);
            });
        }
示例#5
0
        public async Task ExtractModlist()
        {
            ExtractedModlistFolder = await TempFolder.Create();

            await FileExtractor2.ExtractAll(Queue, ModListArchive, ExtractedModlistFolder.Dir);
        }
示例#6
0
        [InlineData(Game.Fallout4, 43474)]             // EM 2 Rifle
        public async Task BSACompressionRecompression(Game game, int modid)
        {
            var filename = await DownloadMod(game, modid);

            var folder = _bsaFolder.Combine(game.ToString(), modid.ToString());
            await folder.DeleteDirectory();

            folder.CreateDirectory();
            await FileExtractor2.ExtractAll(Queue, filename, folder);

            foreach (var bsa in folder.EnumerateFiles().Where(f => Consts.SupportedBSAs.Contains(f.Extension)))
            {
                TestContext.WriteLine($"From {bsa}");
                TestContext.WriteLine("Cleaning Output Dir");
                await _tempDir.DeleteDirectory();

                _tempDir.CreateDirectory();

                TestContext.WriteLine($"Reading {bsa}");
                await using var tempFolder = await TempFolder.Create();

                var tempFile = tempFolder.Dir.Combine("test.bsa");
                var size     = bsa.Size;

                var a = await BSADispatch.OpenRead(bsa);

                await a.Files.PMap(Queue, async file =>
                {
                    var absName = _tempDir.Combine(file.Path);
                    ViaJson(file.State);

                    absName.Parent.CreateDirectory();
                    await using (var fs = await absName.Create())
                    {
                        await file.CopyDataTo(fs);
                    }

                    Assert.Equal(file.Size, absName.Size);
                });


                // Check Files should be case insensitive
                Assert.Equal(a.Files.Count(), a.Files.Select(f => f.Path).ToHashSet().Count);
                Assert.Equal(a.Files.Count(), a.Files.Select(f => f.Path.ToString().ToLowerInvariant()).ToHashSet().Count);

                TestContext.WriteLine($"Building {bsa}");

                await using (var w = await ViaJson(a.State).MakeBuilder(size))
                {
                    var streams = await a.Files.PMap(Queue, async file =>
                    {
                        var absPath = _tempDir.Combine(file.Path);
                        var str     = await absPath.OpenRead();
                        await w.AddFile(ViaJson(file.State), str);
                        return(str);
                    });

                    await w.Build(tempFile);

                    streams.Do(s => s.Dispose());
                }

                TestContext.WriteLine($"Verifying {bsa}");
                var b = await BSADispatch.OpenRead(tempFile);

                TestContext.WriteLine($"Performing A/B tests on {bsa} and {tempFile}");
                Assert.Equal(a.State.ToJson(), b.State.ToJson());

                // Check same number of files
                Assert.Equal(a.Files.Count(), b.Files.Count());


                await a.Files.Zip(b.Files, (ai, bi) => (ai, bi))
                .PMap(Queue, async pair =>
                {
                    Assert.Equal(pair.ai.State.ToJson(), pair.bi.State.ToJson());
                    //Console.WriteLine($"   - {pair.ai.Path}");
                    Assert.Equal(pair.ai.Path, pair.bi.Path);
                    //Equal(pair.ai.Compressed, pair.bi.Compressed);
                    Assert.Equal(pair.ai.Size, pair.bi.Size);
                    Utils.Log($"Comparing {pair.ai.Path} to {pair.bi.Path}");
                    try
                    {
                        Assert.Equal(await GetData(pair.ai), await GetData(pair.bi));
                    }
                    catch (Exception)
                    {
                    }
                });
            }
        }