Example #1
0
        public override async Task <int> ExecuteAsync(CommandContext context, Settings settings)
        {
            var config = settings.MergedConfiguration;

            _logger.LogInformation($"Attempting to retrieve game details for '{config.Game}'");
            var gameId = await _api.GetGameId(config.Game, config.ApiKey);

            _logger.LogDebug($"Game details loaded: {config.Game}/{gameId}");
            var game    = new GameRef(config.Game, gameId);
            var success = await _client.AddChangelog(game, config.ModId, settings.ModVersion, settings.ChangelogContent);

            if (success)
            {
                _logger.LogInformation($"[green]Success![/] Your changelog has been added for version [bold]'{settings.ModVersion}'[/]");
                return(0);
            }
            else
            {
                _logger.LogWarning("[bold orange3]Failed![/] There was an unknown error while updating the changelog!");
                _logger.LogWarning("Ensure that you have access to edit the requested mod and that it exists");
                return(1);
            }
        }
Example #2
0
        public override async Task <int> ExecuteAsync(CommandContext context, Settings settings)
        {
            var config   = settings.MergedConfiguration;
            var fileOpts = new FileOptions(config.FileName, settings.FileVersion)
            {
                Description = config.FileDescription
            };

            try
            {
                var compAction = Handlebars.Compile(fileOpts.Description);
                var result     = compAction?.Invoke(fileOpts);
                if (!string.IsNullOrWhiteSpace(result) && !string.Equals(fileOpts.Description, result))
                {
                    AnsiConsole.MarkupLine("Compiled description template using current file options.");
                    fileOpts.Description = result;
                }
            }
            catch (System.Exception ex)
            {
                AnsiConsole.MarkupLine($"[bold red]ERROR[/]: {ex.Message}");
            }
            if (settings.RemoveDownloadWithManager.IsSet)
            {
                _logger.LogInformation($"Remove Download with Manager option: {settings.RemoveDownloadWithManager.Value}");
                fileOpts.RemoveDownloadWithManager = settings.RemoveDownloadWithManager.Value;
            }
            if (settings.SkipMainVersionUpdate.IsSet && settings.SkipMainVersionUpdate.Value)
            {
                _logger.LogWarning("Skipping mod version update!");
                fileOpts.UpdateMainVersion = false;
            }
            if (settings.SetMainVortexFile.IsSet)
            {
                _logger.LogInformation($"Setting file as main Vortex file: {settings.SetMainVortexFile.Value}");
                fileOpts.SetAsMainVortex = settings.SetMainVortexFile.Value;
            }
            if (!IsConfigurationValid(settings) && !settings.AllowInteractive)
            {
                AnsiConsole.MarkupLine("[bold red]ERROR[/]: not all configuration is set correctly and unex is not running interactively. Exiting!");
                return(-1);
            }
            _logger.LogInformation($"Attempting to retrieve game details for '{config.Game}'");
            var gameId = await _apiClient.GetGameId(config.Game, config.ApiKey);

            _logger.LogInformation($"Game details loaded: {config.Game}/{gameId}");
            var game = new GameRef(config.Game, gameId);

            if (!string.IsNullOrWhiteSpace(config.PreviousFile))
            {
                if (config.PreviousFile == "auto")
                {
                    _logger.LogInformation("Automatic file update detection enabled! Retrieving previous file versions");
                    var fileId = await _apiClient.GetLatestFileId(config.Game, config.ModId, config.ApiKey);

                    if (fileId.HasValue)
                    {
                        _logger.LogInformation($"Uploaded file will replace existing file '{fileId.Value}");
                        fileOpts.PreviousFileId = fileId;
                    }
                }
                else
                {
                    if (int.TryParse(config.PreviousFile, out var previousId))
                    {
                        _logger.LogInformation($"Uploaded file will replace existing file '{previousId}");
                        fileOpts.PreviousFileId = previousId;
                    }
                    ;
                }
            }
            _logger.LogInformation($"Preparing to upload '{settings.ModFilePath}' to Nexus Mods upload API");
            var upload = await _uploader.UploadFile(game, config.ModId, new FileInfo(Path.GetFullPath(settings.ModFilePath)));

            _logger.LogInformation($"File successfully uploaded to Nexus Mods with ID '{upload.Id}'");
            var available = await _uploader.CheckStatus(upload);

            _logger.LogDebug($"File '{upload.Id}' confirmed as assembled: {available}");
            _logger.LogInformation($"Adding uploaded file to mod {config.ModId}");
            _logger.LogDebug($"Using file options: {fileOpts.ToString()}");
            var success = await _manager.AddFile(game, config.ModId, upload, fileOpts);

            if (success)
            {
                _logger.LogInformation($"{upload.OriginalFile} successfully uploaded and added to mod {config.ModId}!");
                _logger.LogInformation("Now go ask @Pickysaurus when a real API will be available! ;)");
                return(0);
            }
            else
            {
                _logger.LogWarning($"There was an error adding {upload.OriginalFile} to mod {config.ModId}!");
                return(1);
            }
        }