コード例 #1
0
        public async Task <string> GetNexusDownloadLink(NexusDownloader.State archive)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var url = $"https://api.nexusmods.com/v1/games/{archive.Game.MetaData().NexusName}/mods/{archive.ModID}/files/{archive.FileID}/download_link.json";

            try
            {
                return((await Get <List <DownloadLink> >(url)).First().URI);
            }
            catch (HttpRequestException)
            {
                if (await IsPremium())
                {
                    throw;
                }
            }

            try
            {
                Utils.Log($"Requesting manual download for {archive.Name}");
                return((await Utils.Log(await ManuallyDownloadNexusFile.Create(archive)).Task).ToString());
            }
            catch (TaskCanceledException ex)
            {
                Utils.Error(ex, "Manual cancellation of download");
                throw;
            }
        }
コード例 #2
0
ファイル: NexusApi.cs プロジェクト: FrannyRed/wabbajack
        public async Task <string> GetNexusDownloadLink(NexusDownloader.State archive)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var info = await GetModInfo(archive.Game, archive.ModID);

            if (!info.available)
            {
                throw new Exception("Mod unavailable");
            }

            if (await IsPremium())
            {
                if (HourlyRemaining <= 0 && DailyRemaining <= 0)
                {
                    throw new NexusAPIQuotaExceeded();
                }

                var url =
                    $"https://api.nexusmods.com/v1/games/{archive.Game.MetaData().NexusName}/mods/{archive.ModID}/files/{archive.FileID}/download_link.json";
                return((await Get <List <DownloadLink> >(url)).First().URI);
            }

            try
            {
                Utils.Log($"Requesting manual download for {archive.Name} {archive.PrimaryKeyString}");
                return((await Utils.Log(await ManuallyDownloadNexusFile.Create(archive)).Task).ToString());
            }
            catch (TaskCanceledException ex)
            {
                Utils.Error(ex, "Manual cancellation of download");
                throw;
            }
        }
コード例 #3
0
        private async Task HandleManualNexusDownload(WebBrowserVM vm, CancellationTokenSource cancel, ManuallyDownloadNexusFile manuallyDownloadNexusFile)
        {
            var state = manuallyDownloadNexusFile.State;
            var game  = state.Game.MetaData();
            var hrefs = new[]
            {
                $"/Core/Libs/Common/Widgets/DownloadPopUp?id={state.FileID}&game_id={game.NexusGameId}",
                $"https://www.nexusmods.com/{game.NexusName}/mods/{state.ModID}?tab=files&file_id={state.FileID}",
                $"/Core/Libs/Common/Widgets/ModRequirementsPopUp?id={state.FileID}&game_id={game.NexusGameId}"
            };
            await vm.Driver.WaitForInitialized();

            IWebDriver browser = new CefSharpWrapper(vm.Browser);

            vm.Instructions         = $"Please Download {state.Name} - {state.ModID} - {state.FileID}";
            browser.DownloadHandler = uri =>
            {
                manuallyDownloadNexusFile.Resume(uri);
                browser.DownloadHandler = null;
            };
            await browser.NavigateTo(NexusApiClient.ManualDownloadUrl(manuallyDownloadNexusFile.State));

            var buttin_href = $"/Core/Libs/Common/Widgets/DownloadPopUp?id={manuallyDownloadNexusFile.State.FileID}&game_id={Game.SkyrimSpecialEdition}";

            while (!cancel.IsCancellationRequested && !manuallyDownloadNexusFile.Task.IsCompleted)
            {
                await browser.EvaluateJavaScript(
                    @"Array.from(document.getElementsByClassName('accordion')).forEach(e => Array.from(e.children).forEach(c => c.style=''))");

                foreach (var href in hrefs)
                {
                    const string style = "border-thickness: thick; border-color: #ff0000;border-width: medium;border-style: dashed;background-color: teal;padding: 7px";
                    await browser.EvaluateJavaScript($"Array.from(document.querySelectorAll('.accordion a[href=\"{href}\"]')).forEach(e => {{e.scrollIntoView({{behavior: 'smooth', block: 'center', inline: 'nearest'}}); e.setAttribute('style', '{style}');}});");
                }
                await Task.Delay(250);
            }
        }