Example #1
0
        public async Task InitializeAsync()
        {
            Queue  = new WorkQueue();
            _unsub = Utils.LogMessages.Subscribe(f => TestContext.WriteLine(f.ShortDescription));
            _stagingFolder.CreateDirectory();
            await _bsaFolder.DeleteDirectory();

            _bsaFolder.CreateDirectory();
        }
Example #2
0
 private static async Task ZipUpFolder(AbsolutePath folder, AbsolutePath output, bool deleteSource = true)
 {
     ZipFile.CreateFromDirectory((string)folder, (string)output);
     if (deleteSource)
     {
         await folder.DeleteDirectory();
     }
 }
Example #3
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 using var files = await FileExtractor.ExtractAll(Queue, filename);

            await files.MoveAllTo(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}");
                var tempFile = ((RelativePath)"tmp.bsa").RelativeToEntryPoint();
                var size     = bsa.Size;

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

                    absName.Parent.CreateDirectory();
                    using (var fs = absName.Create())
                    {
                        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 = ViaJson(a.State).MakeBuilder(size))
                {
                    var streams = await a.Files.PMap(Queue, async file =>
                    {
                        var absPath = _tempDir.Combine(file.Path);
                        var str     = absPath.OpenRead();
                        await w.AddFile(ViaJson(file.State), str);
                        return(str);
                    });

                    await w.Build(tempFile);

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

                TestContext.WriteLine($"Verifying {bsa}");
                await using var b = BSADispatch.OpenRead(tempFile);
                TestContext.WriteLine($"Performing A/B tests on {bsa}");
                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, 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);
                    Assert.Equal(GetData(pair.ai), GetData(pair.bi));
                });
            }
        }
Example #4
0
        public async Task InitializeAsync()
        {
            await VFS_TEST_DIR.DeleteDirectory();

            VFS_TEST_DIR.CreateDirectory();
        }
Example #5
0
 private static async Task ZipUpFolder(AbsolutePath folder, AbsolutePath output)
 {
     ZipFile.CreateFromDirectory((string)folder, (string)output);
     await folder.DeleteDirectory();
 }