Example #1
0
        private static async Task <AbsolutePath> DownloadMod(Game game, int mod)
        {
            var client = DownloadDispatcher.GetInstance <NexusDownloader>();
            await client.Prepare();

            var results = await client.Client !.GetModFiles(game, mod);
            var file    = results.files.FirstOrDefault(f => f.is_primary) ??
                          results.files.OrderByDescending(f => f.uploaded_timestamp).First();
            var src = _stagingFolder.Combine(file.file_name);

            if (src.Exists)
            {
                return(src);
            }

            var state = new NexusDownloader.State
            {
                ModID  = mod,
                Game   = game,
                FileID = file.file_id
            };
            await state.Download(src);

            return(src);
        }
Example #2
0
        public async Task LoversLabDownload()
        {
            await DownloadDispatcher.GetInstance <LoversLabDownloader>().Prepare();

            var ini = @"[General]
                        directURL=https://www.loverslab.com/files/file/11116-test-file-for-wabbajack-integration/?do=download&r=737123&confirm=1&t=1";

            var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());

            Assert.IsNotNull(state);

            /*var url_state = DownloadDispatcher.ResolveArchive("https://www.loverslab.com/files/file/11116-test-file-for-wabbajack-integration/?do=download&r=737123&confirm=1&t=1");
             * Assert.AreEqual("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt",
             *  ((HTTPDownloader.State)url_state).Url);
             */
            var converted = await state.RoundTripState();

            Assert.IsTrue(await converted.Verify(new Archive {
                Size = 20
            }));
            var filename = Guid.NewGuid().ToString();

            Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist {
                AllowedPrefixes = new List <string>()
            }));

            await converted.Download(new Archive { Name = "MEGA Test.txt" }, filename);

            Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));

            Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
        }
Example #3
0
        public async Task GameFileSourceDownload()
        {
            // Test mode off for this test
            Consts.TestMode = false;
            await DownloadDispatcher.GetInstance <LoversLabDownloader>().Prepare();

            var ini = $@"[General]
                        gameName={Game.SkyrimSpecialEdition.MetaData().MO2ArchiveName}
                        gameFile=Data/Update.esm";

            var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());

            Assert.IsNotNull(state);

            var converted = await state.RoundTripState();

            Assert.IsTrue(await converted.Verify(new Archive {
                Size = 20
            }));
            var filename = Guid.NewGuid().ToString();

            Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist {
                AllowedPrefixes = new List <string>()
            }));

            await converted.Download(new Archive { Name = "Update.esm" }, filename);

            Assert.AreEqual("/DLG/LjdGXI=", Utils.FileHash(filename));
            CollectionAssert.AreEqual(File.ReadAllBytes(Path.Combine(Game.SkyrimSpecialEdition.MetaData().GameLocation(), "Data/Update.esm")), File.ReadAllBytes(filename));
            Consts.TestMode = true;
        }
Example #4
0
        public async Task BethesdaNetDownload()
        {
            var downloader = DownloadDispatcher.GetInstance <BethesdaNetDownloader>();

            Assert.IsTrue(await downloader.IsLoggedIn.FirstAsync());

            var ini = $@"[General]
                              directURL=https://bethesda.net/en/mods/skyrim/mod-detail/4145641";

            var filename = Guid.NewGuid().ToString();
            var state    = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());

            Assert.IsNotNull(state);

            var converted = state.ViaJSON();

            Assert.IsTrue(await converted.Verify(new Archive {
                Name = "mod.ckm"
            }));

            Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist {
                AllowedPrefixes = new List <string>()
            }));

            await converted.Download(new Archive { Name = "mod.zip" }, filename);

            await using var fs = File.OpenRead(filename);
            using var archive  = new ZipArchive(fs);
            var entries = archive.Entries.Select(e => e.FullName).ToList();

            CollectionAssert.AreEqual(entries, new List <string> {
                @"Data\TestCK.esp", @"Data\TestCK.ini"
            });
        }
Example #5
0
        public async Task TESAllianceDownload()
        {
            await DownloadDispatcher.GetInstance <TESAllianceDownloader>().Prepare();

            const string ini = "[General]\n" +
                               "directURL=http://tesalliance.org/forums/index.php?/files/file/2035-wabbajack-test-file/";

            var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());

            Assert.IsNotNull(state);

            var converted = await state.RoundTripState();

            Assert.IsTrue(await converted.Verify(new Archive {
                Size = 20
            }));
            var filename = Guid.NewGuid().ToString();

            Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist {
                AllowedPrefixes = new List <string>()
            }));

            await converted.Download(new Archive { Name = "TESAlliance Test.zip" }, filename);

            Assert.AreEqual("eSIyd+KOG3s=", filename.FileHash());

            Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
        }
Example #6
0
        public async Task ServerGetsEdgeServerInfo()
        {
            var service = Fixture.GetService <CDNMirrorList>();

            Assert.True(await service.Execute() > 0);
            Assert.NotEmpty(service.Mirrors);
            Assert.True(DateTime.UtcNow - service.LastUpdate < TimeSpan.FromMinutes(1));

            var servers = await ClientAPI.GetCDNMirrorList();

            Assert.Equal(service.Mirrors, servers);

            var state = new WabbajackCDNDownloader.State(new Uri("https://wabbajack.b-cdn.net/this_file_doesn_t_exist"));
            await DownloadDispatcher.PrepareAll(new[] { state });

            await using var tmp = new TempFile();

            await Assert.ThrowsAsync <HttpException>(async() => await state.Download(new Archive(state)
            {
                Name = "test"
            }, tmp.Path));

            var downloader = DownloadDispatcher.GetInstance <WabbajackCDNDownloader>();

            Assert.Null(downloader.Mirrors); // Now works through a host remap
        }
Example #7
0
        public static async Task <AbsolutePath> DownloadMod(Game game, int mod, int fileId)
        {
            var client = DownloadDispatcher.GetInstance <NexusDownloader>();
            await client.Prepare();

            var results = await client.Client !.GetModFiles(game, mod);
            var file    = results.files.FirstOrDefault(f => f.file_id == fileId);

            return(await DownloadNexusFile(game, mod, file));
        }
Example #8
0
        private static async Task <AbsolutePath> DownloadMod(Game game, int mod)
        {
            var client = DownloadDispatcher.GetInstance <NexusDownloader>();
            await client.Prepare();

            var results = await client.Client !.GetModFiles(game, mod);
            var file    = results.files.FirstOrDefault(f => f.is_primary) ??
                          results.files.OrderByDescending(f => f.uploaded_timestamp).First();

            return(await DownloadNexusFile(game, mod, file));
        }
Example #9
0
        public async Task DownloadResume()
        {
            using (var server = new CrappyRandomServer())
            {
                var downloader = DownloadDispatcher.GetInstance <HTTPDownloader>();
                var state      = new HTTPDownloader.State {
                    Url = $"http://localhost:{server.Port}/foo"
                };

                await state.Download("test.resume_file");

                CollectionAssert.AreEqual(server.Data, File.ReadAllBytes("test.resume_file"));

                if (File.Exists("test.resume_file"))
                {
                    File.Delete("test.resume_file");
                }
            }
        }
Example #10
0
        public async Task AFKModsDownloadTest()
        {
            await DownloadDispatcher.GetInstance <AFKModsDownloader>().Prepare();

            const string ini = "[General]\n" +
                               "directURL=https://www.afkmods.com/index.php?/files/file/2120-skyrim-save-system-overhaul/&do=download&r=20112&confirm=1&t=1&csrfKey=840a4a373144097693171a79df77d521";

            var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());

            Assert.IsNotNull(state);

            var converted = await state.RoundTripState();

            Assert.IsTrue(await converted.Verify(new Archive {
                Size = 20
            }));
            var filename = Guid.NewGuid().ToString();

            Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist {
                AllowedPrefixes = new List <string>()
            }));

            await converted.Download(new Archive { Name = "AFKMods Test.zip" }, filename);
        }
Example #11
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <LoversLabOAuthDownloader>());
 }