Ejemplo n.º 1
0
        public async Task <IActionResult> IngestNexusFile()
        {
            long totalRows = 0;

            var dataPath = @"nexus_export.json".RelativeTo(_settings.TempPath);

            var data = JsonConvert.DeserializeObject <NexusIngestHeader>(await dataPath.ReadAllTextAsync());

            foreach (var record in data.ModInfos)
            {
                await SQL.AddNexusModInfo(GameRegistry.GetByFuzzyName(record.Game).Game, record.ModId,
                                          record.LastCheckedUTC, record.Data);

                totalRows += 1;
            }

            foreach (var record in data.FileInfos)
            {
                await SQL.AddNexusFileInfo(GameRegistry.GetByFuzzyName(record.Game).Game, record.ModId,
                                           long.Parse(record.FileId),
                                           record.LastCheckedUTC, record.Data);

                totalRows += 1;
            }

            foreach (var record in data.ModFiles)
            {
                await SQL.AddNexusModFiles(GameRegistry.GetByFuzzyName(record.Game).Game, record.ModId,
                                           record.LastCheckedUTC, record.Data);

                totalRows += 1;
            }

            return(Ok(totalRows));
        }
Ejemplo n.º 2
0
        public async Task <NexusApiClient.GetModFilesResponse> GetModFiles(string GameName, long ModId)
        {
            Utils.Log($"Nexus Mod Files {GameName} {ModId}");

            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await SQL.GetModFiles(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await NexusApiClient.Get(Request.Headers["apikey"].FirstOrDefault());

                result = await api.GetModFiles(game, ModId, false);

                await SQL.AddNexusModFiles(game, ModId, DateTime.UtcNow, result);

                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }
            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
Ejemplo n.º 3
0
        public async Task <ModInfo> GetModInfo(string GameName, long ModId)
        {
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetNexusModInfoString(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await GetClient();

                result = await api.GetModInfo(game, ModId, false);

                await _sql.AddNexusModInfo(game, ModId, result.updated_time, result);


                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }

            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
Ejemplo n.º 4
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.º 5
0
        public async Task <NexusApiClient.GetModFilesResponse> GetModFiles(string GameName, long ModId)
        {
            _logger.Log(LogLevel.Information, $"{GameName} {ModId}");
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetModFiles(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await NexusApiClient.Get(Request.Headers["apikey"].FirstOrDefault());

                result = await api.GetModFiles(game, ModId, false);

                var date = result.files.Select(f => f.uploaded_time).OrderByDescending(o => o).FirstOrDefault();
                date = date == default ? DateTime.UtcNow : date;
                await _sql.AddNexusModFiles(game, ModId, date, result);

                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }
            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
Ejemplo n.º 6
0
        public async Task <AbstractDownloadState> GetDownloaderState(dynamic archiveINI)
        {
            var gameName = (string)archiveINI?.General?.gameName;
            var gameFile = (string)archiveINI?.General?.gameFile;

            if (gameFile == null || gameFile == null)
            {
                return(null);
            }

            var game = GameRegistry.GetByFuzzyName(gameName);

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

            var path     = game.GameLocation();
            var filePath = Path.Combine(path, gameFile);

            if (!File.Exists(filePath))
            {
                return(null);
            }

            var hash = filePath.FileHashCached();

            return(new State
            {
                Game = game.Game,
                GameFile = gameFile,
                Hash = hash,
                GameVersion = game.InstalledVersion
            });
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <NexusFileInfo> > GetModFile(string GameName, long ModId, long FileId)
        {
            try
            {
                var game   = GameRegistry.GetByFuzzyName(GameName).Game;
                var result = await _sql.GetModFile(game, ModId, FileId);

                string method = "CACHED";
                if (result == null)
                {
                    var api = await GetClient();

                    result = await api.GetModFile(game, ModId, FileId, false);

                    var date = result.uploaded_time;
                    date = date == default ? DateTime.UtcNow : date;
                    await _sql.AddNexusModFile(game, ModId, FileId, date, result);

                    method = "NOT_CACHED";
                    Interlocked.Increment(ref ForwardCount);
                }
                else
                {
                    Interlocked.Increment(ref CachedCount);
                }

                Response.Headers.Add("x-cache-result", method);
                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogInformation("Unable to find mod file {GameName} {ModId}, {FileId}", GameName, ModId, FileId);
                return(NotFound());
            }
        }
Ejemplo n.º 8
0
        protected override async Task <ExitCode> Run()
        {
            var game = GameRegistry.GetByFuzzyName(GameName).Game;
            var p    = await HTMLInterface.GetUploadPermissions(game, ModId);

            Console.WriteLine($"Game: {game}");
            Console.WriteLine($"ModId: {ModId}");
            Console.WriteLine($"Permissions: {p}");
            return(ExitCode.Ok);
        }
Ejemplo n.º 9
0
        public async Task <NexusApiClient.GetModFilesResponse> GetModFiles(string GameName, long ModId)
        {
            //_logger.Log(LogLevel.Information, $"{GameName} {ModId}");
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetModFiles(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await GetClient();

                var permission = HTMLInterface.GetUploadPermissions(game, ModId);
                try
                {
                    result = await api.GetModFiles(game, ModId, false);
                }
                catch (HttpException ex)
                {
                    if (ex.Code == 403)
                    {
                        result = new NexusApiClient.GetModFilesResponse {
                            files = new List <NexusFileInfo>()
                        }
                    }
                    ;
                    else
                    {
                        throw;
                    }
                }

                var date = result.files.Select(f => f.uploaded_time).OrderByDescending(o => o).FirstOrDefault();
                date = date == default ? DateTime.UtcNow : date;
                await _sql.AddNexusModFiles(game, ModId, date, result);

                await _sql.SetNexusPermission(game, ModId, await permission);

                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }
            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
Ejemplo n.º 10
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 = await NexusApiClient.Get();

                ModInfo info;
                try
                {
                    info = await client.GetModInfo(game, long.Parse((string)general.modID));
                }
                catch (Exception)
                {
                    Utils.Error($"Error getting mod info for Nexus mod with {general.modID}");
                    throw;
                }

                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)
                });
            }

            return(null);
        }
Ejemplo n.º 11
0
        private async Task HandleManualNexusDownload(WebBrowserVM vm, CancellationTokenSource cancel, ManuallyDownloadNexusFile manuallyDownloadNexusFile)
        {
            var state = manuallyDownloadNexusFile.State;
            var game  = GameRegistry.GetByFuzzyName(state.GameName);
            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.ModName} - {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);
            }
        }
Ejemplo n.º 12
0
 public override Game Parse(object value)
 {
     return(GameRegistry.GetByFuzzyName((string)value).Game);
 }