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); }
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; } }
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); } }
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; }
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);
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()); }
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); } }
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)); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <NexusDownloader>()); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <GoogleDriveDownloader>()); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <WabbajackCDNDownloader>()); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <SteamWorkshopDownloader>()); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <MediaFireDownloader>()); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <GameFileSourceDownloader>()); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <VectorPlexusOAuthDownloader>()); }
public override IDownloader GetDownloader() { return(DownloadDispatcher.GetInstance <BethesdaNetDownloader>()); }