Ejemplo n.º 1
0
        public async Task <AbstractDownloadState?> GetDownloaderState(dynamic archiveINI, bool quickMode)
        {
            var general = archiveINI.General;

            if (general.modID != null && general.fileID != null && general.gameName != null)
            {
                var game = GameRegistry.GetByFuzzyName((string)general.gameName).Game;

                if (quickMode)
                {
                    return(new State
                    {
                        Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                        ModID = long.Parse(general.modID),
                        FileID = long.Parse(general.fileID),
                    });
                }

                var client = DownloadDispatcher.GetInstance <NexusDownloader>().Client ?? await NexusApiClient.Get();

                ModInfo info;
                try
                {
                    info = await client.GetModInfo(game, long.Parse((string)general.modID));
                }
                catch (Exception)
                {
                    return(new State
                    {
                        Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                        ModID = long.Parse(general.modID),
                        FileID = long.Parse(general.fileID),
                    });
                }

                try
                {
                    return(new State
                    {
                        Name = NexusApiUtils.FixupSummary(info.name),
                        Author = NexusApiUtils.FixupSummary(info.author),
                        Version = general.version ?? "0.0.0.0",
                        ImageURL = info.picture_url,
                        IsNSFW = info.contains_adult_content,
                        Description = NexusApiUtils.FixupSummary(info.summary),
                        Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                        ModID = long.Parse(general.modID),
                        FileID = long.Parse(general.fileID)
                    });
                }
                catch (FormatException)
                {
                    Utils.Log(
                        $"Cannot parse ModID/FileID from {(string)general.gameName} {(string)general.modID} {(string)general.fileID}");
                    throw;
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
            private async Task <HttpResponseMessage> GetWithMirroredRetry(Http.Client client, string url)
            {
                int retries    = 0;
                var downloader = DownloadDispatcher.GetInstance <WabbajackCDNDownloader>();

                if (downloader.Mirrors != null)
                {
                    url = ReplaceHost(downloader.Mirrors, url);
                }

TOP:

                try
                {
                    return(await client.GetAsync(url, retry : false));
                }
                catch (Exception ex)
                {
                    if (retries > 5)
                    {
                        Utils.Log($"Tried to read from {retries} CDN servers, giving up");
                        throw;
                    }
                    Utils.Log($"Error reading {url} retying with a mirror");
                    Utils.Log(ex.ToString());
                    downloader.Mirrors ??= await ClientAPI.GetCDNMirrorList();

                    url      = ReplaceHost(downloader.Mirrors, url);
                    retries += 1;
                    Interlocked.Increment(ref downloader.TotalRetries);
                    goto TOP;
                }
            }
Ejemplo n.º 3
0
            public override async Task <bool> Verify(Archive a, CancellationToken?token = null)
            {
                try
                {
                    var nclient = DownloadDispatcher.GetInstance <NexusDownloader>();
                    await nclient.Prepare();

                    var client = nclient.Client !;

                    var modInfo = await client.GetModInfo(Game, ModID);

                    if (!modInfo.available)
                    {
                        return(false);
                    }
                    var modFiles = await client.GetModFiles(Game, ModID);

                    var found = modFiles.files
                                .FirstOrDefault(file => file.file_id == FileID && file.category_name != null);

                    return(found != null);
                }
                catch (Exception ex)
                {
                    Utils.Log($"{Name} - {Game} - {ModID} - {FileID} - Error getting Nexus download URL - {ex}");
                    return(false);
                }
            }
Ejemplo n.º 4
0
            private async Task <Stream> ResolveDownloadStream()
            {
                var downloader = (AbstractNeedsLoginDownloader)(object)DownloadDispatcher.GetInstance <TDownloader>();

TOP:
                var csrfurl = FileID == null
                    ? $"{Site}/files/file/{FileName}/?do=download"
                    : $"{Site}/files/file/{FileName}/?do=download&r={FileID}";
                var html = await downloader.AuthedClient.GetStringAsync(csrfurl);

                var pattern = new Regex("(?<=csrfKey=).*(?=[&\"\'])|(?<=csrfKey: \").*(?=[&\"\'])");
                var matches = pattern.Matches(html).Cast <Match>();

                var csrfKey = matches.Where(m => m.Length == 32).Select(m => m.ToString()).FirstOrDefault();

                if (csrfKey == null)
                {
                    return(null);
                }

                var sep = Site.EndsWith("?") ? "&" : "?";
                var url = FileID == null
                    ? $"{Site}/files/file/{FileName}/{sep}do=download&confirm=1&t=1&csrfKey={csrfKey}"
                    : $"{Site}/files/file/{FileName}/{sep}do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}";


                var streamResult = await downloader.AuthedClient.GetAsync(url);

                if (streamResult.StatusCode != HttpStatusCode.OK)
                {
                    Utils.Error(new InvalidOperationException(), $"{downloader.SiteName} servers reported an error for file: {FileID}");
                }

                var contentType = streamResult.Content.Headers.ContentType;

                if (contentType.MediaType != "application/json")
                {
                    return(await streamResult.Content.ReadAsStreamAsync());
                }

                // Sometimes LL hands back a json object telling us to wait until a certain time
                var times = (await streamResult.Content.ReadAsStringAsync()).FromJSONString <WaitResponse>();
                var secs  = times.Download - times.CurrentTime;

                for (int x = 0; x < secs; x++)
                {
                    Utils.Status($"Waiting for {secs} at the request of {downloader.SiteName}", Percent.FactoryPutInRange(x, secs));
                    await Task.Delay(1000);
                }
                Utils.Status("Retrying download");
                goto TOP;
            }
Ejemplo n.º 5
0
            public override async Task <(Archive?Archive, TempFile NewFile)> FindUpgrade(Archive a, Func <Archive, Task <AbsolutePath> > downloadResolver)
            {
                var client = DownloadDispatcher.GetInstance <NexusDownloader>().Client ?? await NexusApiClient.Get();

                await client.IsPremium();

                if (client.RemainingAPICalls <= 0)
                {
                    throw new NexusAPIQuotaExceeded();
                }

                var mod = await client.GetModInfo(Game, ModID);

                if (!mod.available)
                {
                    return(default);
Ejemplo n.º 6
0
            private async Task <Stream> ResolveDownloadStream()
            {
                var result = DownloadDispatcher.GetInstance <LoversLabDownloader>();

TOP:
                var html = await result._authedClient.GetStringAsync(
                    $"https://www.loverslab.com/files/file/{FileName}/?do=download&r={FileID}");

                var pattern = new Regex("(?<=csrfKey=).*(?=[&\"\'])");
                var csrfKey = pattern.Matches(html).Cast <Match>().Where(m => m.Length == 32).Select(m => m.ToString()).FirstOrDefault();

                if (csrfKey == null)
                {
                    return(null);
                }

                var url =
                    $"https://www.loverslab.com/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}";

                var streamResult = await result._authedClient.GetAsync(url);

                if (streamResult.StatusCode != HttpStatusCode.OK)
                {
                    Utils.Error(new InvalidOperationException(), $"LoversLab servers reported an error for file: {FileID}");
                }

                var content_type = streamResult.Content.Headers.ContentType;

                if (content_type.MediaType == "application/json")
                {
                    // Sometimes LL hands back a json object telling us to wait until a certain time
                    var times = (await streamResult.Content.ReadAsStringAsync()).FromJSONString <WaitResponse>();
                    var secs  = times.download - times.currentTime;
                    for (int x = 0; x < secs; x++)
                    {
                        Utils.Status($"Waiting for {secs} at the request of LoversLab", x * 100 / secs);
                        await Task.Delay(1000);
                    }
                    Utils.Status("Retrying download");
                    goto TOP;
                }

                return(await streamResult.Content.ReadAsStreamAsync());
            }
Ejemplo n.º 7
0
            public override async Task <bool> Verify(Archive a, CancellationToken?token = null)
            {
                try
                {
                    var nexusClient = DownloadDispatcher.GetInstance <NexusDownloader>();
                    await nexusClient.Prepare();

                    var client = nexusClient.Client !;

                    var file = await client.GetModFile(Game, ModID, FileID);

                    return(file?.category_name != null);
                }
                catch (Exception ex)
                {
                    Utils.Log($"{Name} - {Game} - {ModID} - {FileID} - Error getting Nexus download URL - {ex}");
                    return(false);
                }
            }
Ejemplo n.º 8
0
            public override async Task <bool> Download(Archive a, AbsolutePath destination)
            {
                string url;

                try
                {
                    url = await DownloadDispatcher.GetInstance <NexusDownloader>().Client !.GetNexusDownloadLink(this);
                }
                catch (NexusAPIQuotaExceeded ex)
                {
                    Utils.Log(ex.ExtendedDescription);
                    throw;
                }
                catch (Exception)
                {
                    return(false);
                }

                return(await new HTTPDownloader.State(url).Download(a, destination));
            }
Ejemplo n.º 9
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <NexusDownloader>());
 }
Ejemplo n.º 10
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <GoogleDriveDownloader>());
 }
Ejemplo n.º 11
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <WabbajackCDNDownloader>());
 }
Ejemplo n.º 12
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <SteamWorkshopDownloader>());
 }
Ejemplo n.º 13
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <MediaFireDownloader>());
 }
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <GameFileSourceDownloader>());
 }
Ejemplo n.º 15
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <VectorPlexusOAuthDownloader>());
 }
Ejemplo n.º 16
0
 public override IDownloader GetDownloader()
 {
     return(DownloadDispatcher.GetInstance <BethesdaNetDownloader>());
 }