From b8fb8ed391fde389128ad825c41ee5330b78bb0c Mon Sep 17 00:00:00 2001 From: Digitalroot Date: Tue, 21 May 2024 22:17:27 -0700 Subject: [PATCH] Updated to use nexusmods_session, set via env var COOKIE_NEXUSMOD_SESSION Added -dfa, --disable-file-archive options. Skips archiving older versions of the existing file. [default: False] Process will now exit with an error code when running the check command on the api-key and cookies. Fixes #18, #19, #14, #15 --- docs/README.md | 24 +- src/Digitalroot.ModUploader.sln.DotSettings | 2 + .../Clients/AbstractRestClient.cs | 42 ++- .../EnvironmentConfigurationProvider.cs | 3 +- .../Digitalroot.ModUploader.csproj | 12 +- src/Digitalroot.ModUploader/Program.cs | 17 +- .../NexusMods/Clients/NexusModsRestClient.cs | 17 +- .../NexusMods/Commands/CheckCommand.cs | 21 +- .../NexusMods/Commands/UploadCommand.cs | 267 +++++++++--------- .../Models/AddFileToModRequestModel.cs | 4 +- .../Models/CheckFileStatusRequestModel.cs | 6 +- .../NexusMods/Models/CookieRequestModel.cs | 12 +- .../Models/SaveDocumentationRequestModel.cs | 4 +- .../Models/UploadChunkExistsRequestModel.cs | 28 +- .../Models/UploadFileChunkRequestModel.cs | 4 +- .../Models/UploadFileMetaDataRequestModel.cs | 4 +- .../NexusMods/Validators/ValidatorsFactory.cs | 21 +- .../Serialization/NewtonsoftJsonSerializer.cs | 8 +- .../packages.lock.json | 51 +++- src/UnitTests/UnitTests.csproj | 11 +- 20 files changed, 295 insertions(+), 263 deletions(-) diff --git a/docs/README.md b/docs/README.md index 767d049..d7ea2e3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,9 +2,7 @@ ## Introduction -This is a command-line tool that can be used to upload mod files to an existing mod on Thunderstore, ModVault and Nexus Mods. - -**Note:** _Thunderstore support will be in a future release._ +This is a command-line tool that can be used to upload mod files to an existing mod on Nexus Mods. ## Installation @@ -25,7 +23,7 @@ Please use environment variables for the sensitive information. ### Environment Variables - __NEXUSMOD_API_KEY__ -- __NEXUSMOD_COOKIE_SID_DEVELOP__ +- __COOKIE_NEXUSMOD_SESSION__ All Commands support the `-?, -h, --help` options to show help and usage information @@ -34,7 +32,7 @@ All Commands support the `-?, -h, --help` options to show help and usage informa ###### Digitalroot.ModUploader.exe -h ```bat Description: - Uploads mods to Thunderstore, ModVault, or NexusMods + Uploads mods to NexusMods Usage: Digitalroot.ModUploader.exe [command] [options] @@ -44,9 +42,7 @@ Options: -?, -h, --help Show help and usage information Commands: - modvault, mv modvault.xyz commands. nexusmods, nx nexusmods.com commands. - thunderstore, ts thunderstore.io commands. ``` --- @@ -76,9 +72,9 @@ Usage: Digitalroot.ModUploader.exe nexusmods check [options] Options: - -k, --key Api Key, ENV: NEXUSMOD_API_KEY - -csid, --cookie_sid_develop Session Cookie, ENV: NEXUSMOD_COOKIE_SID_DEVELOP - -?, -h, --help Show help and usage information + -k, --key Api Key, ENV: NEXUSMOD_API_KEY + -cnms, --cookie_nexusmods_session Session Cookie, ENV: COOKIE_NEXUSMOD_SESSION + -?, -h, --help Show help and usage information ``` --- @@ -101,18 +97,19 @@ Options: -d, --description description -g, --game Game mod is for. [default: valheim] -dmfu, --disable-main-file-update Skips replacing an existing file in the 'Main' category with the new one. [default: False] + -dfa, --disable-file-archive Skips archiving older versions of the existing file. [default: False] -ddwm, --disable-download-with-manager Removes the 'Download With Manager' button. [default: False] -dvu, --disable-version-update Skips updating mod's main version to match this file's version. [default: False] -dmv, --disable-main-vortex Skips setting file as the main Vortex file. [default: False] -drpu, --disable-requirements-pop-up Skips informing downloaders of this mod's requirements before they attempt to download this file [default: False] -k, --key Api Key, ENV: NEXUSMOD_API_KEY - -csid, --cookie_sid_develop Session Cookie, ENV: NEXUSMOD_COOKIE_SID_DEVELOP + -cnms, --cookie_nexusmods_session Session Cookie, ENV: COOKIE_NEXUSMOD_SESSION -?, -h, --help Show help and usage information ``` #### Examples ```bash -nexusmods check -k "MyVeryLongNexusApiKey" -csid "%7B%22mechanism--MyVeryLongNexusSessionCookieSessIdValue--%22%7D" +nexusmods check -k "MyVeryLongNexusApiKey" -cnms "6c1ae4818867700000XX804f1f55ae72" ``` --- ```bash @@ -136,8 +133,7 @@ nexusmods upload 1303 "Digitalroot.Valheim.JVL.BT.Fix.v1.0.6.zip" -v "1.0.6" -f ##### Q4: Where do I get my Nexus Mods' Session Cookies? > From your browser. This [site](https://www.cookieyes.com/how-to-check-cookies-on-your-website-manually/) covers how to do it in most browers. -> The cookie you are looking for is called `sid_develop`. It starts with `%7B%22mechanism`. This is the html encoded value for `{"mechanism`. -> If your browser displays a cookie value starting with `{"mechanism` then you will need to html encode the value before using this tool. +> The cookie you are looking for is called `nexusmods_session`. It is a hex value that looks like `6c1ae4818867700000XX804f1f55ae72`.
diff --git a/src/Digitalroot.ModUploader.sln.DotSettings b/src/Digitalroot.ModUploader.sln.DotSettings index ff9282f..9f91488 100644 --- a/src/Digitalroot.ModUploader.sln.DotSettings +++ b/src/Digitalroot.ModUploader.sln.DotSettings @@ -1,6 +1,8 @@  + True True True + True True True True diff --git a/src/Digitalroot.ModUploader/Clients/AbstractRestClient.cs b/src/Digitalroot.ModUploader/Clients/AbstractRestClient.cs index 6100a89..0b86cfa 100644 --- a/src/Digitalroot.ModUploader/Clients/AbstractRestClient.cs +++ b/src/Digitalroot.ModUploader/Clients/AbstractRestClient.cs @@ -33,29 +33,20 @@ public class AbstractRestClient private protected AbstractRestClient(AbstractHostProviderConfiguration modsHostProviderConfiguration) { _configuration = modsHostProviderConfiguration; - ModHostProviderClient = new RestClient(_configuration.ServiceUri); - SetNewtonsoftJsonSerializerAsHandler(ModHostProviderClient); + var options = new RestClientOptions(_configuration.ServiceUri); + var jsonSerializerSettings = new JsonSerializerSettings + { + MissingMemberHandling = MissingMemberHandling.Ignore + , NullValueHandling = NullValueHandling.Ignore + }; + + ModHostProviderClient = new RestClient(options, configureSerialization: s => s.UseNewtonsoftJson(jsonSerializerSettings)); } #region Helper Methods internal string GetDefaultConfigValue(string value) => _configuration.GetDefaultConfigValue(value); - /// - /// Configures the client to use NewtonsoftJsonSerializer so that - /// The JsonProperty Attribute can be used. - /// e.g. [JsonProperty(PropertyName = "country")] - /// - /// - private protected static void SetNewtonsoftJsonSerializerAsHandler(RestClient restClient) - { - restClient.UseNewtonsoftJson(new JsonSerializerSettings - { - MissingMemberHandling = MissingMemberHandling.Ignore - , NullValueHandling = NullValueHandling.Ignore - }); - } - internal static ErrorResponseModel GetErrorMessage(RestResponse response) { return new ErrorResponseModel(response); @@ -75,7 +66,7 @@ private static void TraceResponse(RestResponse response) { Trace.WriteLine($"** Response ** - IsSuccessful: {response.IsSuccessful}, StatusCode: {response.StatusCode}"); Trace.WriteLine("[Headers:]"); - Trace.WriteLine(NewtonsoftJsonSerializer.Default.Serialize(response.Headers)); + Trace.WriteLine(NewtonsoftJsonSerializer.Default.Serialize(response.Headers ?? throw new InvalidOperationException())); Trace.WriteLine(string.Empty); switch (response.ContentType) @@ -91,7 +82,7 @@ private static void TraceResponse(RestResponse response) default: Trace.WriteLine("[Content]:"); - Trace.WriteLine(NewtonsoftJsonSerializer.Default.Serialize(response.Content)); + Trace.WriteLine(NewtonsoftJsonSerializer.Default.Serialize(response.Content ?? throw new InvalidOperationException())); break; } @@ -127,14 +118,14 @@ private static void TraceResponse(RestResponse response, TRe #region Obsolete - [Obsolete("Use Async Version")] + [Obsolete("Use Async Version", true)] protected static TRestResponse Get(RestClient restClient, RestRequest request) { var response = restClient.Get(request); return (TRestResponse)Activator.CreateInstance(typeof(TRestResponse), response); } - [Obsolete("Use Async Version")] + [Obsolete("Use Async Version", true)] protected static TRestResponse Get(RestClient restClient, RestRequest request) where TRestResponse : AbstractResponse { @@ -162,7 +153,8 @@ protected static async Task GetAsync(RestClient re if (request is AbstractAuthorizedRequest { Model: CookieRequestModel model }) { - restClient.AddCookie("sid_develop", model.CookieSidDevelop, "/", ".nexusmods.com"); + request.AddCookie("nexusmods_session", model.NexusmodsSession, "/", ".nexusmods.com"); + // request.AddCookie("nexusmods_session_refresh", model.NexusmodsSessionRefresh, "/", ".nexusmods.com"); } var response = await restClient.ExecuteGetAsync(request); @@ -177,7 +169,8 @@ protected static async Task GetAsync(request); @@ -197,7 +190,8 @@ protected static async Task PostAsync(request); diff --git a/src/Digitalroot.ModUploader/Configuration/EnvironmentConfigurationProvider.cs b/src/Digitalroot.ModUploader/Configuration/EnvironmentConfigurationProvider.cs index c5136a2..0fa2ff5 100644 --- a/src/Digitalroot.ModUploader/Configuration/EnvironmentConfigurationProvider.cs +++ b/src/Digitalroot.ModUploader/Configuration/EnvironmentConfigurationProvider.cs @@ -10,7 +10,8 @@ internal class EnvironmentConfigurationProvider : IConfigs /// string IConfigs.GetConfig(string keyName) { - return Environment.GetEnvironmentVariable(keyName); + var value = Environment.GetEnvironmentVariable(keyName); + return value; } #endregion diff --git a/src/Digitalroot.ModUploader/Digitalroot.ModUploader.csproj b/src/Digitalroot.ModUploader/Digitalroot.ModUploader.csproj index 5f93f37..099e1dc 100644 --- a/src/Digitalroot.ModUploader/Digitalroot.ModUploader.csproj +++ b/src/Digitalroot.ModUploader/Digitalroot.ModUploader.csproj @@ -11,14 +11,14 @@ drmu true MIT - Copyright © Digitalroot Technologies 2021 - 2023 + Copyright © Digitalroot Technologies 2021 - 2024 https://github.com/Digitalroot-Valheim/Digitalroot.ModUploader https://github.com/Digitalroot-Valheim/Digitalroot.ModUploader git ValheimRcon_color.png README.md - valheim, digitalroot, mods, cli, tool, nexusmods, thunderstore + valheim, digitalroot, mods, cli, tool, nexusmods Digitalroot Digitalroot Technologies Digitalroot Mod Uploader @@ -29,7 +29,7 @@ true False False - 1.3.1 + 1.4.0 https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json; https://digitalroot-valheim-nuget.s3.us-west-2.amazonaws.com/index.json @@ -52,9 +52,9 @@ - - - + + + diff --git a/src/Digitalroot.ModUploader/Program.cs b/src/Digitalroot.ModUploader/Program.cs index 7630cda..431c191 100644 --- a/src/Digitalroot.ModUploader/Program.cs +++ b/src/Digitalroot.ModUploader/Program.cs @@ -21,18 +21,18 @@ public static async Task Main(string[] args) Credits.PrintWelcome(); // Create a root command with some options - var rootCommand = new RootCommand("Uploads mods to Thunderstore, ModVault, or NexusMods") + var rootCommand = new RootCommand("Uploads mods to NexusMods") { - Provider.ModVault.Commands.GetRootCommand() ?? throw new InvalidOperationException() - , Provider.NexusMods.Commands.CommandFactory.GetCommand(Provider.NexusMods.Enums.CommandName.Root) as Command ?? throw new InvalidOperationException() - , Provider.Thunderstore.Commands.GetRootCommand() ?? throw new InvalidOperationException() + // Provider.ModVault.Commands.GetRootCommand() ?? throw new InvalidOperationException() + Provider.NexusMods.Commands.CommandFactory.GetCommand(Provider.NexusMods.Enums.CommandName.Root) as Command ?? throw new InvalidOperationException() + // , Provider.Thunderstore.Commands.GetRootCommand() ?? throw new InvalidOperationException() }; var cmdBuilder = new CommandLineBuilder(rootCommand); cmdBuilder.AddMiddleware(async (context, next) => { // Trace Output of Command passed. Warning this outputs -k and -c values. - Trace.WriteLineIf(context?.ParseResult != null, context.ParseResult); + Trace.WriteLine(context.ParseResult); await next(context); }); @@ -56,6 +56,10 @@ public static async Task Main(string[] args) Credits.PrintCredits(); } + #if DEBUG + Console.ReadKey(); + #endif + return results; } @@ -78,10 +82,9 @@ private static IHelpBuilder GetHelpBuilder(int maxWidth) } // ReSharper disable once UnusedMember.Local + [System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Not implemented yet")] private static MaskingHelpBuilder GetMaskingHelpBuilder(int maxWidth) => new(LocalizationResources.Instance, maxWidth); - [System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Not implemented yet")] - // ReSharper disable once UnusedMember.Local private static HelpBuilder GetUnMaskingHelpBuilder(int maxWidth) => new(LocalizationResources.Instance, maxWidth); private static void AddHelpSubCommandsRecursively(Command command) diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Clients/NexusModsRestClient.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Clients/NexusModsRestClient.cs index c25a5b6..22f5952 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Clients/NexusModsRestClient.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Clients/NexusModsRestClient.cs @@ -4,7 +4,9 @@ using Digitalroot.ModUploader.Provider.NexusMods.Configuration; using Digitalroot.ModUploader.Provider.NexusMods.Models; using Digitalroot.ModUploader.Provider.NexusMods.Protocol; +using Newtonsoft.Json; using RestSharp; +using RestSharp.Serializers.NewtonsoftJson; using System.Threading.Tasks; namespace Digitalroot.ModUploader.Provider.NexusMods.Clients @@ -28,11 +30,18 @@ internal class NexusModsRestClient : AbstractRestClient public NexusModsRestClient(NexusModsHostProviderConfiguration modsHostProviderConfiguration) : base(modsHostProviderConfiguration) { - _modHostApiProviderClient = new RestClient(modsHostProviderConfiguration.ServiceApiUri); - SetNewtonsoftJsonSerializerAsHandler(_modHostApiProviderClient); + var apiOptions = new RestClientOptions(modsHostProviderConfiguration.ServiceApiUri); + var jsonSerializerSettings = new JsonSerializerSettings + { + MissingMemberHandling = MissingMemberHandling.Ignore + , NullValueHandling = NullValueHandling.Ignore + }; - _modHostUploadProviderClient = new RestClient(modsHostProviderConfiguration.ServiceUploadUri); - SetNewtonsoftJsonSerializerAsHandler(_modHostUploadProviderClient); + _modHostApiProviderClient = new RestClient(apiOptions, configureSerialization: s => s.UseNewtonsoftJson(jsonSerializerSettings)); + + var uploadOptions = new RestClientOptions(modsHostProviderConfiguration.ServiceUploadUri); + + _modHostUploadProviderClient = new RestClient(uploadOptions, configureSerialization: s => s.UseNewtonsoftJson(jsonSerializerSettings)); } public static ErrorResponseModel GetErrorMessage(AbstractResponse response) diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/CheckCommand.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/CheckCommand.cs index c3fc591..cfde30b 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/CheckCommand.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/CheckCommand.cs @@ -9,7 +9,6 @@ using System.CommandLine; using System.CommandLine.Invocation; using System.Diagnostics.CodeAnalysis; -using System.Drawing; using System.Threading.Tasks; // ReSharper disable UseObjectOrCollectionInitializer @@ -23,7 +22,7 @@ internal static ICommand GetCheckCommand() var command = new Command("check", "Check that an API Key and Cookie are valid.") { CommandHelper.GetOption(new[] { "--key", "-k" }, "Api Key, ENV: " + "NEXUSMOD_API_KEY".Pastel(ColorOptions.EmColor), CommandUtils.RestClient.GetDefaultConfigValue("NEXUSMOD_API_KEY"), optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() - , CommandHelper.GetOption(new[] { "--cookie_sid_develop", "-csid" }, "Session Cookie, ENV: " + "NEXUSMOD_COOKIE_SID_DEVELOP".Pastel(ColorOptions.EmColor), CommandUtils.RestClient.GetDefaultConfigValue("NEXUSMOD_COOKIE_SID_DEVELOP"), optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() + , CommandHelper.GetOption(new[] { "--cookie_nexusmods_session", "-cnms" }, "Session Cookie, ENV: " + "COOKIE_NEXUSMOD_SESSION".Pastel(ColorOptions.EmColor), CommandUtils.RestClient.GetDefaultConfigValue("COOKIE_NEXUSMOD_SESSION"), optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() }; command.Handler = GetCommandHandler(); @@ -34,13 +33,19 @@ internal static ICommand GetCheckCommand() private static ICommandHandler GetCommandHandler() { - return CommandHandler.Create(async (key, cookie_sid_develop) => + return CommandHandler.Create(async (key, cnms) => { var checkApiKeyMessage = await CheckApiKey(key); - Console.WriteLine(checkApiKeyMessage.Response.IsApiKeyValid ? "API key successfully validated!".Pastel(Color.Green) : "API key validation failed!".Pastel(Color.Orange)); + Console.WriteLine(checkApiKeyMessage.Response.IsApiKeyValid ? "API key successfully validated!".Pastel(ColorOptions.SuccessColor) : "API key validation failed!".Pastel(ColorOptions.WarningColor)); - var checkCookieMessage = await CheckCookie(cookie_sid_develop); - Console.WriteLine(checkCookieMessage.ResponseModel.IsCookieValid ? "Cookies successfully validated!".Pastel(Color.Green) : "Cookie validation failed!".Pastel(Color.Orange)); + var checkCookieMessage = await CheckCookie(cnms); + Console.WriteLine(checkCookieMessage.ResponseModel.IsCookieValid ? "Cookies successfully validated!".Pastel(ColorOptions.SuccessColor) : "Cookie validation failed!".Pastel(ColorOptions.WarningColor)); + + if (!(checkApiKeyMessage.Response.IsApiKeyValid && checkCookieMessage.ResponseModel.IsCookieValid)) + { + Console.WriteLine("Validation failed! Failing on error".Pastel(ColorOptions.ErrorColor)); + Environment.Exit(1); + } }); } @@ -62,10 +67,10 @@ private static async Task> CheckCookie(string cookieSidDevelop) + >> CheckCookie(string nexusmodsSession) { var message = new Message(); - message.RequestModel = new CookieRequestModel(cookieSidDevelop); + message.RequestModel = new CookieRequestModel(nexusmodsSession); message.Request = new CheckCookieRequest(message.RequestModel); message.Response = await CommandUtils.RestClient.ExecuteAsync(message.Request); message.ResponseModel = new CheckCookieResponseModel(message.Response); diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/UploadCommand.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/UploadCommand.cs index fd17178..75919fa 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/UploadCommand.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Commands/UploadCommand.cs @@ -29,6 +29,7 @@ namespace Digitalroot.ModUploader.Provider.NexusMods.Commands; internal static class UploadCommand { private static readonly AutoResetEvent _autoEvent = new(false); + // ReSharper disable once RedundantDefaultMemberInitializer // ReSharper disable once IdentifierTypo private static bool _isErrored = false; @@ -45,12 +46,13 @@ internal static ICommand GetUploadCommand() , CommandHelper.GetOption(new[] { "--description", "-d" }, "Description", null, optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() , CommandHelper.GetOption(new[] { "--game", "-g" }, "Game mod is for.", "valheim", optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() , CommandHelper.GetOption(new[] { "--disable-main-file-update", "-dmfu" }, "Skips replacing an existing file in the " + "'Main'".Pastel(ColorOptions.EmColor) + " category with the new one.", false, optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() + , CommandHelper.GetOption(new[] { "--disable-file-archive", "-dfa" }, "Skips archiving older versions of the existing file.", false, optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() , CommandHelper.GetOption(new[] { "--disable-download-with-manager", "-ddwm" }, "Removes the " + "'Download With Manager'".Pastel(ColorOptions.EmColor) + " button.", false, optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() , CommandHelper.GetOption(new[] { "--disable-version-update", "-dvu" }, "Skips updating mod's main version to match this file's version.", false, optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() , CommandHelper.GetOption(new[] { "--disable-main-vortex", "-dmv" }, "Skips setting file as the main Vortex file.", false, optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() , CommandHelper.GetOption(new[] { "--disable-requirements-pop-up", "-drpu" }, "Skips informing downloaders of this mod's requirements before they attempt to download this file", false, optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() , CommandHelper.GetOption(new[] { "--key", "-k" }, "Api Key, ENV: " + "NEXUSMOD_API_KEY".Pastel(ColorOptions.EmColor), CommandUtils.RestClient.GetDefaultConfigValue("NEXUSMOD_API_KEY"), optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() - , CommandHelper.GetOption(new[] { "--cookie_sid_develop", "-csid" }, "Session Cookie, ENV: " + "NEXUSMOD_COOKIE_SID_DEVELOP".Pastel(ColorOptions.EmColor), CommandUtils.RestClient.GetDefaultConfigValue("NEXUSMOD_COOKIE_SID_DEVELOP"), optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() + , CommandHelper.GetOption(new[] { "--cookie_nexusmods_session", "-cnms" }, "Session Cookie, ENV: " + "COOKIE_NEXUSMOD_SESSION".Pastel(ColorOptions.EmColor), CommandUtils.RestClient.GetDefaultConfigValue("COOKIE_NEXUSMOD_SESSION"), optionValidatorsFactory: ValidatorsFactory.Instance) as Option ?? throw new InvalidOperationException() }; command.Handler = GetCommandHandler(); @@ -69,12 +71,14 @@ private static ICommandHandler GetCommandHandler() , string // description , string // game , bool // disableMainFileUpdate + , bool // disableFileArchive , bool // disableDownloadWithManager , bool // disableVersionUpdate , bool // disableMainVortex , bool // enableRequirementsPopUp , string // key - , string // cookie_sid_develop + , string // nexusmodsSession + >( async (modId // uint? - Arg , archiveFile // FileInfo - Arg @@ -84,16 +88,17 @@ private static ICommandHandler GetCommandHandler() , description // string , game // string , disableMainFileUpdate // bool + , disableFileArchive // bool , disableDownloadWithManager // bool , disableVersionUpdate // bool , disableMainVortex // bool , disableRequirementsPopUp // bool , key // string - , cookie_sid_develop // string - ) => + , nexusmodsSession // string + ) => { // Get Game Info - var gameInfoMessage = await GameInfo(key, game); + var gameInfoMessage = await GameInfoAsync(key, game); Console.WriteLine($"Preparing to upload '{archiveFile.Name}' ({FileSizeFormatter.FormatSize(archiveFile.Length)}) as version {version} to Nexus Mods upload Api.".Pastel(ColorOptions.InfoColor)); // Replace Existing file @@ -103,7 +108,7 @@ private static ICommandHandler GetCommandHandler() if (category == CategoryName.Main) { // Get mods current files - var modFileInfoMessage = await ModFilesInfo(key, game, modId); + var modFileInfoMessage = await GetModFilesInfoAsync(key, game, modId); if (!modFileInfoMessage.Response.IsSuccessful) return; var lastUpload = modFileInfoMessage.ResponseModel.Files.FirstOrDefault(fileInfo => fileInfo.CategoryId == Convert.ToUInt32(CategoryName.Main)); @@ -120,14 +125,14 @@ private static ICommandHandler GetCommandHandler() var totalChunks = GetChunkCount(archiveFile); // Upload all chunks but the last one. - var r = Parallel.For(1, totalChunks, new ParallelOptions { MaxDegreeOfParallelism = 2 }, RunUploadWorkFlow); + var r = Parallel.For(1, totalChunks, new ParallelOptions { MaxDegreeOfParallelism = 2 }, RunUploadWorkFlowAsync); while (!r.IsCompleted) { await Task.Delay(1000); } - - RunUploadWorkFlow(totalChunks); // Upload the last file chunk + + RunUploadWorkFlowAsync(totalChunks); // Upload the last file chunk _autoEvent.WaitOne(); if (_isErrored) @@ -137,30 +142,22 @@ private static ICommandHandler GetCommandHandler() #region Run Workflow - async void RunUploadWorkFlow(int i) + async void RunUploadWorkFlowAsync(int i) { try { - var uploadFileChunk = await GetUploadWorkflow(i - , totalChunks - , archiveFile - , cookie_sid_develop - , modId - , fileName - , version - , game - , disableDownloadWithManager - , disableVersionUpdate - , disableMainVortex - , category - , description - , gameInfoMessage - , disableRequirementsPopUp - , disableMainFileUpdate - , oldFileId - , !disableMainFileUpdate - , !disableMainFileUpdate - ); + var uploadFileChunk = await GetUploadWorkflowAsync(i + , totalChunks + , archiveFile + , nexusmodsSession + , modId + , fileName + , version + , game + , disableDownloadWithManager + , disableVersionUpdate + , disableMainVortex + ); if (uploadFileChunk == null) return; // if (uploadFileChunk.RequestModel.ResumableChunkNumber != totalChunks) return; @@ -186,7 +183,8 @@ async void RunUploadWorkFlow(int i) CheckFileStatusRequestModel, CheckFileStatusResponse, CheckFileStatusResponseModel - > checkFileStatus = await CheckFileStatus(cookie_sid_develop, uploadFileChunk.ResponseModel); + > checkFileStatus = await CheckFileStatusAsync(nexusmodsSession + , uploadFileChunk.ResponseModel); // Attach file to Mod. if (checkFileStatus.Response.IsSuccessful && checkFileStatus.ResponseModel.FileChunksReassembled) @@ -199,25 +197,25 @@ async void RunUploadWorkFlow(int i) AddFileToModRequestModel, AddFileToModResponse, AddFileToModResponseModel - > addFileToMod = await AddFileToMod(cookie_sid_develop - , modId - , version - , disableVersionUpdate - , disableMainVortex - , fileName - , archiveFile - , category - , description - , disableDownloadWithManager - , disableRequirementsPopUp - , gameInfoMessage.ResponseModel.Id - , checkFileStatus.RequestModel.Uuid - , checkFileStatus.RequestModel.FileHash - , disableMainFileUpdate - , oldFileId - , !disableMainFileUpdate - , !disableMainFileUpdate - ); + > addFileToMod = await AddFileToModAsync(nexusmodsSession + , modId + , version + , disableVersionUpdate + , disableMainVortex + , fileName + , archiveFile + , category + , description + , disableDownloadWithManager + , disableRequirementsPopUp + , gameInfoMessage.ResponseModel.Id + , checkFileStatus.RequestModel.Uuid + , checkFileStatus.RequestModel.FileHash + , disableMainFileUpdate + , oldFileId + , !disableMainFileUpdate + , !disableFileArchive + ); if (addFileToMod.Response.IsSuccessful) { @@ -244,34 +242,23 @@ async void RunUploadWorkFlow(int i) #region Workflow - [SuppressMessage("ReSharper", "UnusedParameter.Local")] private static async Task> GetUploadWorkflow(int i - , int totalChunks - , FileInfo archiveFile - , string cookiesid_develop - , uint modId - , string fileName - , string version - , string game - , bool disableDownloadWithManager - , bool disableVersionUpdate - , bool disableMainVortex - #pragma warning disable IDE0060 - , CategoryName categoryName - , string description - , Message gameInfoMessage - , bool disableRequirementsPopUp - , bool disableMainFileUpdate - , int oldFileId - , bool newExisting - , bool removeOldVersion - #pragma warning restore IDE0060 - ) + >> GetUploadWorkflowAsync(int i + , int totalChunks + , FileInfo archiveFile + , string nexusmodsSession + , uint modId + , string fileName + , string version + , string game + , bool disableDownloadWithManager + , bool disableVersionUpdate + , bool disableMainVortex + ) { // Check if chunk already uploaded Message< @@ -279,14 +266,14 @@ private static async Task checkUploadChunkExists = await CheckUploadChunkExists(archiveFile - , cookiesid_develop - , Convert.ToUInt32(i) - , i != totalChunks - ? Convert.ToUInt32(NexusModsRestClient.ChunkSize) - : Convert.ToUInt32(Convert.ToUInt64(archiveFile.Length) % NexusModsRestClient.ChunkSize) - , Convert.ToUInt32(totalChunks) - ); + > checkUploadChunkExists = await CheckUploadChunkExistsAsync(archiveFile + , nexusmodsSession + , Convert.ToUInt32(i) + , i != totalChunks + ? Convert.ToUInt32(NexusModsRestClient.ChunkSize) + : Convert.ToUInt32(Convert.ToUInt64(archiveFile.Length) % NexusModsRestClient.ChunkSize) + , Convert.ToUInt32(totalChunks) + ); if (!checkUploadChunkExists.Response.IsSuccessful) return null; @@ -335,17 +322,17 @@ private static async Task uploadFileChunk = await UploadFileChunk(modId - , archiveFile - , cookiesid_develop - , fileName - , version - , game - , disableDownloadWithManager - , disableVersionUpdate - , disableMainVortex - , checkUploadChunkExists.RequestModel - , buffer); + > uploadFileChunk = await UploadFileChunkAsync(modId + , archiveFile + , nexusmodsSession + , fileName + , version + , game + , disableDownloadWithManager + , disableVersionUpdate + , disableMainVortex + , checkUploadChunkExists.RequestModel + , buffer); return !uploadFileChunk.Response.IsSuccessful ? null : uploadFileChunk; } @@ -357,7 +344,6 @@ private static async Task /// Add an assembled file to a mod. /// - /// /// /// /// @@ -375,6 +361,7 @@ private static async Task /// /// + /// /// [SuppressMessage("Style", "IDE0017:Simplify object initialization", Justification = "Consistent Pattern")] private static async Task> AddFileToMod(string cookiesid_develop - , uint modId - , string version - , bool disableVersionUpdate - , bool disableMainVortex - , string fileName - , FileInfo archiveFile - , CategoryName categoryName - , string description - , bool disableDownloadWithManager - , bool disableRequirementsPopUp - , int gameId - , string fileUuid - , string uploadedFileHash - , bool disableMainFileUpdate - , int oldFileId - , bool newExisting - , bool removeOldVersion) + >> AddFileToModAsync(string nexusmodsSession + , uint modId + , string version + , bool disableVersionUpdate + , bool disableMainVortex + , string fileName + , FileInfo archiveFile + , CategoryName categoryName + , string description + , bool disableDownloadWithManager + , bool disableRequirementsPopUp + , int gameId + , string fileUuid + , string uploadedFileHash + , bool disableMainFileUpdate + , int oldFileId + , bool newExisting + , bool removeOldVersion) { Console.WriteLine($"Adding uploaded file to mod {modId}".Pastel(ColorOptions.InfoColor)); var message = new Message(); - message.RequestModel = new AddFileToModRequestModel(cookiesid_develop + message.RequestModel = new AddFileToModRequestModel(nexusmodsSession , gameId , fileName , version @@ -448,6 +435,7 @@ private static async Task /// Check if chunks have already been assembled. /// - /// /// + /// /// [SuppressMessage("Style", "IDE0017:Simplify object initialization", Justification = "Consistent Pattern")] private static async Task> CheckFileStatus(string cookiesid_develop, UploadFileChunkResponseModel uploadFileChunkResponseModel) + >> CheckFileStatusAsync(string nexusmodsSession + , UploadFileChunkResponseModel uploadFileChunkResponseModel) { Console.WriteLine($"Validating file upload for '{uploadFileChunkResponseModel.Uuid}'".Pastel(ColorOptions.InfoColor)); var message = new Message(); - message.RequestModel = new CheckFileStatusRequestModel(cookiesid_develop, uploadFileChunkResponseModel.Uuid, uploadFileChunkResponseModel.UploadFileHash); + message.RequestModel = new CheckFileStatusRequestModel(nexusmodsSession, uploadFileChunkResponseModel.Uuid, uploadFileChunkResponseModel.UploadFileHash); message.Request = new CheckFileStatusRequest(message.RequestModel); var attempt = 1; @@ -501,27 +490,27 @@ private static async Task /// - /// /// /// /// + /// /// [SuppressMessage("Style", "IDE0017:Simplify object initialization", Justification = "Consistent Pattern")] private static async Task> CheckUploadChunkExists(FileInfo archiveFile - , string cookiesid_develop - , uint resumableChunkNumber - , uint resumableCurrentChunkSize - , uint resumableTotalChunks) + >> CheckUploadChunkExistsAsync(FileInfo archiveFile + , string nexusmodsSession + , uint resumableChunkNumber + , uint resumableCurrentChunkSize + , uint resumableTotalChunks) { var message = new Message< UploadChunkExistsRequest, UploadChunkExistsRequestModel, UploadChunkExistsResponse, UploadChunkExistsChunkResponseModel >(); - message.RequestModel = new UploadChunkExistsRequestModel(cookiesid_develop + message.RequestModel = new UploadChunkExistsRequestModel(nexusmodsSession , archiveFile.Name , archiveFile.Length , resumableChunkNumber @@ -550,7 +539,7 @@ private static async Task> GameInfo(string key, string game) + >> GameInfoAsync(string key, string game) { Console.WriteLine($"Attempting to retrieve game details for '{game}'".Pastel(ColorOptions.InfoColor)); var message = new Message(); @@ -588,7 +577,7 @@ private static async Task> ModFilesInfo(string key, string game, uint modId) + >> GetModFilesInfoAsync(string key, string game, uint modId) { Console.WriteLine($"Attempting to retrieve mod file details for mod '{modId}' of '{game}'".Pastel(ColorOptions.InfoColor)); var message = new Message(); @@ -627,7 +616,6 @@ private static async Task /// /// - /// /// /// /// @@ -636,25 +624,26 @@ private static async Task /// /// + /// /// [SuppressMessage("Style", "IDE0017:Simplify object initialization", Justification = "Consistent Pattern")] private static async Task> UploadFileChunk(uint modId - , FileInfo archiveFile - , string cookiesid_develop - , string fileName - , string version - , string game - , bool disableDownloadWithManager - , bool disableVersionUpdate - , bool disableMainVortex - , UploadFileMetaDataRequestModel uploadFileMetaDataRequestModel - , byte[] buffer) + >> UploadFileChunkAsync(uint modId + , FileInfo archiveFile + , string nexusmodsSession + , string fileName + , string version + , string game + , bool disableDownloadWithManager + , bool disableVersionUpdate + , bool disableMainVortex + , UploadFileMetaDataRequestModel uploadFileMetaDataRequestModel + , byte[] buffer) { var message = new Message(); - message.RequestModel = new UploadFileChunkRequestModel(cookiesid_develop + message.RequestModel = new UploadFileChunkRequestModel(nexusmodsSession , modId , archiveFile , fileName @@ -718,11 +707,11 @@ private static void PrintLastUploadedFileInfo(ModFileInfoResponseModel lastUploa { if (lastUpload == null) { - Console.WriteLine($"Unable to locate file to replace.".Pastel(ColorOptions.ErrorColor)); + Console.WriteLine("Unable to locate file to replace.".Pastel(ColorOptions.ErrorColor)); return; } - Console.WriteLine($"Last file uploaded info".Pastel(ColorOptions.WarningColor)); + Console.WriteLine("Last file uploaded info".Pastel(ColorOptions.WarningColor)); Console.WriteLine($"{lastUpload.Name}, ({lastUpload.ModVersion})".Pastel(ColorOptions.WarningColor)); Console.WriteLine($"{lastUpload.FileName}, ({lastUpload.FileId})".Pastel(ColorOptions.WarningColor)); } diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/AddFileToModRequestModel.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/AddFileToModRequestModel.cs index f224368..09d8f0a 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/AddFileToModRequestModel.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/AddFileToModRequestModel.cs @@ -28,7 +28,7 @@ internal class AddFileToModRequestModel : CookieRequestModel public readonly bool RemoveNmmButton; // 1 + /// - internal AddFileToModRequestModel(string cookiesid_develop + internal AddFileToModRequestModel(string nexusmodsSession , int gameId , string name , string fileVersion @@ -48,7 +48,7 @@ internal AddFileToModRequestModel(string cookiesid_develop , bool removeNmmButton , bool newExisting , bool removeOldVersion) - : base(cookiesid_develop) + : base(nexusmodsSession) { GameId = gameId; // Name = name; // diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CheckFileStatusRequestModel.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CheckFileStatusRequestModel.cs index 004ae97..1eb9354 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CheckFileStatusRequestModel.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CheckFileStatusRequestModel.cs @@ -8,8 +8,10 @@ internal class CheckFileStatusRequestModel : CookieRequestModel internal string Uuid { get; } internal string FileHash { get; } - internal CheckFileStatusRequestModel(string cookiesid_develop, string uuid, string fileHash) - : base(cookiesid_develop) + internal CheckFileStatusRequestModel(string nexusmodsSession + , string uuid + , string fileHash) + : base(nexusmodsSession) { Uuid = uuid; FileHash = fileHash; diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CookieRequestModel.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CookieRequestModel.cs index 8df3779..562007f 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CookieRequestModel.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/CookieRequestModel.cs @@ -1,19 +1,13 @@ using Digitalroot.ModUploader.Models; -using System; namespace Digitalroot.ModUploader.Provider.NexusMods.Models; internal class CookieRequestModel : AbstractRequestModel { - internal string CookieSidDevelop { get; } + internal string NexusmodsSession { get; } - internal CookieRequestModel(string cookieSidDevelop) - { - CookieSidDevelop = cookieSidDevelop; - } - - [Obsolete("Fix Me", true)] - internal CookieRequestModel(string cookieNexusId, string cookieSidDevelop) + internal CookieRequestModel(string nexusmodsSession) { + NexusmodsSession = nexusmodsSession; } } diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/SaveDocumentationRequestModel.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/SaveDocumentationRequestModel.cs index 76fd879..2e51f5b 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/SaveDocumentationRequestModel.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/SaveDocumentationRequestModel.cs @@ -12,7 +12,7 @@ internal class SaveDocumentationRequestModel : CookieRequestModel public readonly string Action; public readonly string ReadMeFile; - internal SaveDocumentationRequestModel(string cookiesid_develop + internal SaveDocumentationRequestModel(string nexusmodsSession , uint modId , uint gameId , string newVersion @@ -20,7 +20,7 @@ internal SaveDocumentationRequestModel(string cookiesid_develop , int inputMethod = 0 , string action = "save" , string readMeFile = "") - : base(cookiesid_develop) + : base(nexusmodsSession) { ModId = modId; GameId = gameId; diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadChunkExistsRequestModel.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadChunkExistsRequestModel.cs index 7e063ba..96e6796 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadChunkExistsRequestModel.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadChunkExistsRequestModel.cs @@ -6,26 +6,26 @@ internal class UploadChunkExistsRequestModel : UploadFileMetaDataRequestModel { /// // ReSharper disable once MemberCanBePrivate.Global - internal UploadChunkExistsRequestModel(string cookiesid_develop - , string resumableFilename - , ulong resumableTotalSize - , uint resumableChunkNumber - , uint resumableCurrentChunkSize - , uint resumableTotalChunks) - : base(cookiesid_develop + internal UploadChunkExistsRequestModel(string nexusmodsSession + , string resumableFilename + , ulong resumableTotalSize + , uint resumableChunkNumber + , uint resumableCurrentChunkSize + , uint resumableTotalChunks) + : base(nexusmodsSession , resumableFilename , resumableTotalSize , resumableChunkNumber , resumableCurrentChunkSize , resumableTotalChunks) { } - internal UploadChunkExistsRequestModel(string cookieCookiesid - , string resumableFilename - , long resumableTotalSize - , uint resumableChunkNumber - , uint resumableCurrentChunkSize - , uint resumableTotalChunks) - : this(cookieCookiesid + internal UploadChunkExistsRequestModel(string nexusmodsSession + , string resumableFilename + , long resumableTotalSize + , uint resumableChunkNumber + , uint resumableCurrentChunkSize + , uint resumableTotalChunks) + : this(nexusmodsSession , resumableFilename , Convert.ToUInt64(resumableTotalSize) , resumableChunkNumber diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileChunkRequestModel.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileChunkRequestModel.cs index 5945126..68dba50 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileChunkRequestModel.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileChunkRequestModel.cs @@ -19,7 +19,7 @@ internal class UploadFileChunkRequestModel : UploadFileMetaDataRequestModel public byte[] Buffer { get; } /// - internal UploadFileChunkRequestModel(string cookiesid_develop + internal UploadFileChunkRequestModel(string nexusmodsSession , uint modId , FileInfo archiveFile , string fileName @@ -32,7 +32,7 @@ internal UploadFileChunkRequestModel(string cookiesid_develop , uint resumableCurrentChunkSize , uint resumableTotalChunks , byte[] buffer) - : base(cookiesid_develop + : base(nexusmodsSession , archiveFile.Name , Convert.ToUInt64(archiveFile.Length) , resumableChunkNumber diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileMetaDataRequestModel.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileMetaDataRequestModel.cs index 49eadb1..41dd806 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileMetaDataRequestModel.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Models/UploadFileMetaDataRequestModel.cs @@ -16,13 +16,13 @@ internal class UploadFileMetaDataRequestModel : CookieRequestModel public readonly uint ResumableTotalChunks; /// - internal UploadFileMetaDataRequestModel(string cookiesid_develop + internal UploadFileMetaDataRequestModel(string nexusmodsSession , string resumableFilename , ulong resumableTotalSize , uint resumableChunkNumber , uint resumableCurrentChunkSize , uint resumableTotalChunks) - : base(cookiesid_develop) + : base(nexusmodsSession) { ResumableFilename = resumableFilename; ResumableTotalSize = resumableTotalSize; diff --git a/src/Digitalroot.ModUploader/Provider/NexusMods/Validators/ValidatorsFactory.cs b/src/Digitalroot.ModUploader/Provider/NexusMods/Validators/ValidatorsFactory.cs index bf21797..b06de3b 100644 --- a/src/Digitalroot.ModUploader/Provider/NexusMods/Validators/ValidatorsFactory.cs +++ b/src/Digitalroot.ModUploader/Provider/NexusMods/Validators/ValidatorsFactory.cs @@ -32,10 +32,6 @@ protected override void OnFileInfoValidation(ArgumentResult argumentResult) #endregion - #region Command - - #endregion - #region Option /// @@ -46,6 +42,7 @@ protected override void OnStringValidation(OptionResult optionResult) switch (optionResult.Symbol.Name) { case "key": + case "k": if ((optionResult.Tokens.Count != 1 || string.IsNullOrEmpty(optionResult.Tokens[0].Value)) && string.IsNullOrEmpty(CommandUtils.RestClient.GetDefaultConfigValue("NEXUSMOD_API_KEY"))) @@ -55,10 +52,22 @@ protected override void OnStringValidation(OptionResult optionResult) break; - case "cookie": + case "cookie_nexusmods_session": + case "cnms": + if ((optionResult.Tokens.Count != 1 + || string.IsNullOrEmpty(optionResult.Tokens[0].Value)) + && string.IsNullOrEmpty(CommandUtils.RestClient.GetDefaultConfigValue("COOKIE_NEXUSMOD_SESSION"))) + { + AddErrorMessage(optionResult, $"Error: --{optionResult.Symbol.Name} value is missing."); + } + + break; + + case "cookie_nexusmods_session_refresh": + case "cnmsr": if ((optionResult.Tokens.Count != 1 || string.IsNullOrEmpty(optionResult.Tokens[0].Value)) - && string.IsNullOrEmpty(CommandUtils.RestClient.GetDefaultConfigValue("NEXUSMOD_COOKIE"))) + && string.IsNullOrEmpty(CommandUtils.RestClient.GetDefaultConfigValue("COOKIE_NEXUSMOD_SESSION_REFRESH"))) { AddErrorMessage(optionResult, $"Error: --{optionResult.Symbol.Name} value is missing."); } diff --git a/src/Digitalroot.ModUploader/Serialization/NewtonsoftJsonSerializer.cs b/src/Digitalroot.ModUploader/Serialization/NewtonsoftJsonSerializer.cs index 2175ef9..18080ff 100644 --- a/src/Digitalroot.ModUploader/Serialization/NewtonsoftJsonSerializer.cs +++ b/src/Digitalroot.ModUploader/Serialization/NewtonsoftJsonSerializer.cs @@ -18,9 +18,9 @@ public NewtonsoftJsonSerializer(JsonSerializer serializer) _serializer = serializer; } - public string ContentType + public ContentType ContentType { - get => "application/json"; // Probably used for Serialization? + get => ContentType.Json; //"application/json"; // Probably used for Serialization? set { } } @@ -57,8 +57,8 @@ public T Deserialize(RestResponse response) , ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); - public static JsonSerializerSettings DefaultSettings => new JsonSerializerSettings - { + public static JsonSerializerSettings DefaultSettings => new() + { NullValueHandling = NullValueHandling.Ignore , MissingMemberHandling = MissingMemberHandling.Ignore , Formatting = Formatting.Indented diff --git a/src/Digitalroot.ModUploader/packages.lock.json b/src/Digitalroot.ModUploader/packages.lock.json index 18cbfc4..f9054fc 100644 --- a/src/Digitalroot.ModUploader/packages.lock.json +++ b/src/Digitalroot.ModUploader/packages.lock.json @@ -4,24 +4,27 @@ "net6.0": { "Pastel": { "type": "Direct", - "requested": "[4.0.2, )", - "resolved": "4.0.2", - "contentHash": "tNbthiPTiDA4wdz8UeYXaJVSV8P6attDFaFUd854f/0JT9N1U1CGO7AOd7fcb4IQexY69X2SuQjvGe+jmmbwcw==" + "requested": "[5.1.0, )", + "resolved": "5.1.0", + "contentHash": "jQ0fTkHZvgQsmbr5qU0IdCP1PWuUfmEmekIsTwysWK/iIwmT9Mbm0x5GpjYSTEwHTNVEpjYhBhyKVdzESgRCpg==" }, "RestSharp": { "type": "Direct", - "requested": "[108.0.3, )", - "resolved": "108.0.3", - "contentHash": "phq1AkVhqVXHZxvWDV4fJEJKCR5OHNFUGx2Ix8o5EFShS6654oZhth4X2RWvaU/W7UexIswW0T+lTirxfLU2Ow==" + "requested": "[110.2.0, )", + "resolved": "110.2.0", + "contentHash": "FXGw0IMcqY7yO/hzS9QrD3iNswNgb9UxJnxWmfOxmGs4kRlZWqdtBoGPLuhlbgsDzX1RFo4WKui8TGGKXWKalw==", + "dependencies": { + "System.Text.Json": "7.0.2" + } }, "RestSharp.Serializers.NewtonsoftJson": { "type": "Direct", - "requested": "[108.0.3, )", - "resolved": "108.0.3", - "contentHash": "OtL5CaGNA6sgBI4cTQMTLCcEtOqYJ0AuQG1ym1/oX5rRn4gJY3hdF89QLMjieCfEsxCrgqf29jJ3ydYuK8xTTA==", + "requested": "[110.2.0, )", + "resolved": "110.2.0", + "contentHash": "fcIBvya52kVo3gcRVULihj+N/S1UQTxmlRgZMfPX2h0r1U4EyTg0O+YDAiOFxkSDUyk8bgsHMEIRNBkLfv1ajw==", "dependencies": { - "Newtonsoft.Json": "13.0.1", - "RestSharp": "108.0.3" + "Newtonsoft.Json": "13.0.3", + "RestSharp": "110.2.0" } }, "System.CommandLine": { @@ -35,13 +38,35 @@ }, "Newtonsoft.Json": { "type": "Transitive", - "resolved": "13.0.1", - "contentHash": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==" + "resolved": "13.0.3", + "contentHash": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==" }, "System.Memory": { "type": "Transitive", "resolved": "4.5.4", "contentHash": "1MbJTHS1lZ4bS4FmsJjnuGJOu88ZzTT2rLvrhW7Ygic+pC0NWA+3hgAen0HRdsocuQXCkUTdFn9yHJJhsijDXw==" + }, + "System.Runtime.CompilerServices.Unsafe": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" + }, + "System.Text.Encodings.Web": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "OP6umVGxc0Z0MvZQBVigj4/U31Pw72ITihDWP9WiWDm+q5aoe0GaJivsfYGq53o6dxH7DcXWiCTl7+0o2CGdmg==", + "dependencies": { + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + } + }, + "System.Text.Json": { + "type": "Transitive", + "resolved": "7.0.2", + "contentHash": "/LZf/JrGyilojqwpaywb+sSz8Tew7ij4K/Sk+UW8AKfAK7KRhR6mKpKtTm06cYA7bCpGTWfYksIW+mVsdxPegQ==", + "dependencies": { + "System.Runtime.CompilerServices.Unsafe": "6.0.0", + "System.Text.Encodings.Web": "7.0.0" + } } } } diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index 210ccfa..72cbe11 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -7,10 +7,13 @@ - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +