From 59775e99c49790cf6632b0b6514f23c8209bece0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 May 2018 19:11:31 -0400 Subject: link smapi.io/install to install guide --- src/SMAPI.Web/Startup.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/SMAPI.Web/Startup.cs') diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 6c7ccecd..7f5b8e2b 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -153,9 +153,10 @@ namespace StardewModdingAPI.Web )); // shortcut redirects + redirects.Add(new RedirectToUrlRule(@"^/buildmsg(?:/?(.*))$", "https://github.com/Pathoschild/SMAPI/blob/develop/docs/mod-build-config.md#$1")); redirects.Add(new RedirectToUrlRule(@"^/compat\.?$", "https://stardewvalleywiki.com/Modding:SMAPI_compatibility")); redirects.Add(new RedirectToUrlRule(@"^/docs\.?$", "https://stardewvalleywiki.com/Modding:Index")); - redirects.Add(new RedirectToUrlRule(@"^/buildmsg(?:/?(.*))$", "https://github.com/Pathoschild/SMAPI/blob/develop/docs/mod-build-config.md#$1")); + redirects.Add(new RedirectToUrlRule(@"^/install\.?$", "https://stardewvalleywiki.com/Modding:Player_Guide/Getting_Started#Install_SMAPI")); // redirect legacy canimod.com URLs var wikiRedirects = new Dictionary -- cgit From 33db019c621a3f09fcfd5a79141831a63e14dedd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 2 Jun 2018 15:48:35 -0400 Subject: update various wiki links --- docs/release-notes.md | 10 +++++----- src/SMAPI.Web/Startup.cs | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/SMAPI.Web/Startup.cs') diff --git a/docs/release-notes.md b/docs/release-notes.md index e93c6bff..750fa37f 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -261,7 +261,7 @@ * **New features for modders** SMAPI 2.0 adds several features to enable new kinds of mods (see - [API documentation](https://stardewvalleywiki.com/Modding:SMAPI_APIs)). + [API documentation](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs)). The **content API** lets you edit, inject, and reload XNB data loaded by the game at any time. This lets SMAPI mods do anything previously only possible with XNB mods, and enables new mod scenarios not possible with XNB mods (e.g. @@ -384,8 +384,8 @@ For players: * Updated mod compatibility list. For modders: -* Added `SDate` utility for in-game date calculations (see [API reference](https://stardewvalleywiki.com/Modding:SMAPI_APIs#Dates)). -* Added support for minimum dependency versions in `manifest.json` (see [API reference](https://stardewvalleywiki.com/Modding:SMAPI_APIs#Manifest)). +* Added `SDate` utility for in-game date calculations (see [API reference](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Utilities#Dates)). +* Added support for minimum dependency versions in `manifest.json` (see [API reference](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Manifest)). * Added more useful logging when loading mods. * Added a `ModID` property to all mod helpers for extension methods. * Changed `manifest.MinimumApiVersion` from string to `ISemanticVersion`. This shouldn't affect mods unless they referenced that field in code. @@ -417,8 +417,8 @@ For players: * Updated mod compatibility list. For modders: -* You can now add dependencies to `manifest.json` (see [API reference](https://stardewvalleywiki.com/Modding:SMAPI_APIs#Manifest)). -* You can now translate your mod (see [API reference](https://stardewvalleywiki.com/Modding:SMAPI_APIs#Translation)). +* You can now add dependencies to `manifest.json` (see [API reference](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Manifest)). +* You can now translate your mod (see [API reference](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Translation)). * You can now load unpacked `.tbin` files from your mod folder through the content API. * SMAPI now automatically fixes tilesheet references for maps loaded from the mod folder. _When loading a map from the mod folder, SMAPI will automatically use tilesheets relative to the map file if they exists. Otherwise it will default to tilesheets in the game content._ diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 7f5b8e2b..82a0f4f6 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -161,16 +161,15 @@ namespace StardewModdingAPI.Web // redirect legacy canimod.com URLs var wikiRedirects = new Dictionary { - ["Modding:Creating_a_SMAPI_mod"] = new[] { "^/for-devs/creating-a-smapi-mod", "^/guides/creating-a-smapi-mod" }, + ["Modding:Index#Migration_guides"] = new[] { "^/for-devs/updating-a-smapi-mod", "^/guides/updating-a-smapi-mod" }, + ["Modding:Modder_Guide"] = new[] { "^/for-devs/creating-a-smapi-mod", "^/guides/creating-a-smapi-mod", "^/for-devs/creating-a-smapi-mod-advanced-config" }, + ["Modding:Player_Guide"] = new[] { "^/for-players/install-smapi", "^/guides/using-mods", "^/for-players/faqs", "^/for-players/intro", "^/for-players/use-mods", "^/guides/asking-for-help", "^/guides/smapi-faq" }, + ["Modding:Editing_XNB_files"] = new[] { "^/for-devs/creating-an-xnb-mod", "^/guides/creating-an-xnb-mod" }, ["Modding:Event_data"] = new[] { "^/for-devs/events", "^/guides/events" }, ["Modding:Gift_taste_data"] = new[] { "^/for-devs/npc-gift-tastes", "^/guides/npc-gift-tastes" }, ["Modding:IDE_reference"] = new[] { "^/for-devs/creating-a-smapi-mod-ide-primer" }, - ["Modding:Installing_SMAPI"] = new[] { "^/for-players/install-smapi", "^/guides/using-mods" }, ["Modding:Object_data"] = new[] { "^/for-devs/object-data", "^/guides/object-data" }, - ["Modding:Player_FAQs"] = new[] { "^/for-players/faqs", "^/for-players/intro", "^/for-players/use-mods", "^/guides/asking-for-help", "^/guides/smapi-faq" }, - ["Modding:SMAPI_APIs"] = new[] { "^/for-devs/creating-a-smapi-mod-advanced-config" }, - ["Modding:Updating_deprecated_SMAPI_code"] = new[] { "^/for-devs/updating-a-smapi-mod", "^/guides/updating-a-smapi-mod" }, ["Modding:Weather_data"] = new[] { "^/for-devs/weather", "^/guides/weather" } }; foreach (KeyValuePair pair in wikiRedirects) -- cgit From aee42562698ad3e84f781d51e8aa5017a1a589bc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Jun 2018 00:02:30 -0400 Subject: remove obsolete Nexus API client --- .../Framework/Clients/Nexus/NexusClient.cs | 48 ---------------------- .../Framework/ConfigModels/ApiClientsConfig.cs | 6 --- src/SMAPI.Web/Startup.cs | 5 --- src/SMAPI.Web/appsettings.json | 1 - 4 files changed, 60 deletions(-) delete mode 100644 src/SMAPI.Web/Framework/Clients/Nexus/NexusClient.cs (limited to 'src/SMAPI.Web/Startup.cs') diff --git a/src/SMAPI.Web/Framework/Clients/Nexus/NexusClient.cs b/src/SMAPI.Web/Framework/Clients/Nexus/NexusClient.cs deleted file mode 100644 index adec41be..00000000 --- a/src/SMAPI.Web/Framework/Clients/Nexus/NexusClient.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Threading.Tasks; -using Pathoschild.Http.Client; - -namespace StardewModdingAPI.Web.Framework.Clients.Nexus -{ - /// An HTTP client for fetching mod metadata from the Nexus Mods API. - internal class NexusClient : INexusClient - { - /********* - ** Properties - *********/ - /// The URL for a Nexus Mods API query excluding the base URL, where {0} is the mod ID. - private readonly string ModUrlFormat; - - /// The underlying HTTP client. - private readonly IClient Client; - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The user agent for the Nexus Mods API client. - /// The base URL for the Nexus Mods API. - /// The URL for a Nexus Mods API query excluding the , where {0} is the mod ID. - public NexusClient(string userAgent, string baseUrl, string modUrlFormat) - { - this.ModUrlFormat = modUrlFormat; - this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent); - } - - /// Get metadata about a mod. - /// The Nexus mod ID. - /// Returns the mod info if found, else null. - public async Task GetModAsync(uint id) - { - return await this.Client - .GetAsync(string.Format(this.ModUrlFormat, id)) - .As(); - } - - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - public void Dispose() - { - this.Client?.Dispose(); - } - } -} diff --git a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs index de6c024a..9452fdf9 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs @@ -47,9 +47,6 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /**** ** Nexus Mods ****/ - /// The user agent for the Nexus Mods API client. - public string NexusUserAgent { get; set; } - /// The base URL for the Nexus Mods API. public string NexusBaseUrl { get; set; } @@ -62,9 +59,6 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// The base URL for the Pastebin API. public string PastebinBaseUrl { get; set; } - /// The user agent for the Pastebin API client, where {0} is the SMAPI version. - public string PastebinUserAgent { get; set; } - /// The user key used to authenticate with the Pastebin API. public string PastebinUserKey { get; set; } diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 82a0f4f6..2019d6db 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -82,11 +82,6 @@ namespace StardewModdingAPI.Web password: api.GitHubPassword )); - //services.AddSingleton(new NexusClient( - // userAgent: api.NexusUserAgent, - // baseUrl: api.NexusBaseUrl, - // modUrlFormat: api.NexusModUrlFormat - //)); services.AddSingleton(new NexusWebScrapeClient( userAgent: userAgent, baseUrl: api.NexusBaseUrl, diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 09c7d1c2..fda77183 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -30,7 +30,6 @@ "GitHubUsername": null, // see top note "GitHubPassword": null, // see top note - "NexusUserAgent": "Nexus Client v0.63.15", "NexusBaseUrl": "https://www.nexusmods.com/stardewvalley/", "NexusModUrlFormat": "mods/{0}", -- cgit From 53a6833ab22fb41e909ed8ef50aa9262735818d9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Jun 2018 00:16:39 -0400 Subject: return file versions from Nexus in web API (#532) --- docs/release-notes.md | 1 + src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs | 4 ++ .../Clients/Nexus/NexusWebScrapeClient.cs | 44 ++++++++++++++++++++-- .../Framework/ConfigModels/ApiClientsConfig.cs | 5 ++- .../Framework/ModRepositories/NexusRepository.cs | 2 +- src/SMAPI.Web/Startup.cs | 3 +- src/SMAPI.Web/appsettings.json | 1 + .../Framework/Clients/WebApi/ModInfoModel.cs | 4 +- 8 files changed, 55 insertions(+), 9 deletions(-) (limited to 'src/SMAPI.Web/Startup.cs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 39b431cf..11a2a04c 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -59,6 +59,7 @@ * For SMAPI developers: * Added more consistent crossplatform handling using a new `EnvironmentUtility`, including MacOS detection. * Added beta update channel to SMAPI, the web API, and home page. + * Added latest mod file version (including optional files) to Nexus API results. * Added more stylish pufferchick on the home page. * Split mod DB out of `StardewModdingAPI.config.json` into its own file. * Rewrote input suppression using new SDV 1.3 APIs. diff --git a/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs b/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs index cd52c72b..4ecf2f76 100644 --- a/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs +++ b/src/SMAPI.Web/Framework/Clients/Nexus/NexusMod.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using StardewModdingAPI.Toolkit; namespace StardewModdingAPI.Web.Framework.Clients.Nexus { @@ -14,6 +15,9 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus /// The mod's semantic version number. public string Version { get; set; } + /// The latest file version. + public ISemanticVersion LatestFileVersion { get; set; } + /// The mod's web URL. [JsonProperty("mod_page_uri")] public string Url { get; set; } diff --git a/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs b/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs index d0597965..df5a437d 100644 --- a/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs +++ b/src/SMAPI.Web/Framework/Clients/Nexus/NexusWebScrapeClient.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Net; using System.Threading.Tasks; using HtmlAgilityPack; using Pathoschild.Http.Client; +using StardewModdingAPI.Toolkit; namespace StardewModdingAPI.Web.Framework.Clients.Nexus { @@ -12,9 +15,12 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus /********* ** Properties *********/ - /// The URL for a Nexus web page excluding the base URL, where {0} is the mod ID. + /// The URL for a Nexus mod page for the user, excluding the base URL, where {0} is the mod ID. private readonly string ModUrlFormat; + /// The URL for a Nexus mod page to scrape for versions, excluding the base URL, where {0} is the mod ID. + public string ModScrapeUrlFormat { get; set; } + /// The underlying HTTP client. private readonly IClient Client; @@ -25,10 +31,12 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus /// Construct an instance. /// The user agent for the Nexus Mods API client. /// The base URL for the Nexus Mods site. - /// The URL for a Nexus Mods web page excluding the , where {0} is the mod ID. - public NexusWebScrapeClient(string userAgent, string baseUrl, string modUrlFormat) + /// The URL for a Nexus Mods mod page for the user, excluding the , where {0} is the mod ID. + /// The URL for a Nexus mod page to scrape for versions, excluding the base URL, where {0} is the mod ID. + public NexusWebScrapeClient(string userAgent, string baseUrl, string modUrlFormat, string modScrapeUrlFormat) { this.ModUrlFormat = modUrlFormat; + this.ModScrapeUrlFormat = modScrapeUrlFormat; this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent); } @@ -42,7 +50,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus try { html = await this.Client - .GetAsync(string.Format(this.ModUrlFormat, id)) + .GetAsync(string.Format(this.ModScrapeUrlFormat, id)) .AsString(); } catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound) @@ -76,10 +84,38 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus string name = doc.DocumentNode.SelectSingleNode("//h1")?.InnerText.Trim(); string version = doc.DocumentNode.SelectSingleNode("//ul[contains(@class, 'stats')]//li[@class='stat-version']//div[@class='stat']")?.InnerText.Trim(); + // extract file versions + List rawVersions = new List(); + foreach (var fileSection in doc.DocumentNode.SelectNodes("//div[contains(@class, 'files-tabs')]")) + { + string sectionName = fileSection.Descendants("h2").First().InnerText; + if (sectionName != "Main files" && sectionName != "Optional files") + continue; + + rawVersions.AddRange( + from statBox in fileSection.Descendants().Where(p => p.HasClass("stat-version")) + from versionStat in statBox.Descendants().Where(p => p.HasClass("stat")) + select versionStat.InnerText.Trim() + ); + } + + // choose latest file version + ISemanticVersion latestFileVersion = null; + foreach (string rawVersion in rawVersions) + { + if (!SemanticVersion.TryParse(rawVersion, out ISemanticVersion cur)) + continue; + + if (latestFileVersion == null || cur.IsNewerThan(latestFileVersion)) + latestFileVersion = cur; + } + + // yield info return new NexusMod { Name = name, Version = version, + LatestFileVersion = latestFileVersion, Url = url }; } diff --git a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs index 9452fdf9..ae8f18d2 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ApiClientsConfig.cs @@ -50,9 +50,12 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /// The base URL for the Nexus Mods API. public string NexusBaseUrl { get; set; } - /// The URL for a Nexus Mods API query excluding the , where {0} is the mod ID. + /// The URL for a Nexus mod page for the user, excluding the , where {0} is the mod ID. public string NexusModUrlFormat { get; set; } + /// The URL for a Nexus mod page to scrape for versions, excluding the , where {0} is the mod ID. + public string NexusModScrapeUrlFormat { get; set; } + /**** ** Pastebin ****/ diff --git a/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs index 6cac6b8f..4afcda10 100644 --- a/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs +++ b/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs @@ -43,7 +43,7 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories return new ModInfoModel("Found no mod with this ID."); if (mod.Error != null) return new ModInfoModel(mod.Error); - return new ModInfoModel(name: mod.Name, version: this.NormaliseVersion(mod.Version), url: mod.Url); + return new ModInfoModel(name: mod.Name, version: this.NormaliseVersion(mod.Version), previewVersion: mod.LatestFileVersion?.ToString(), url: mod.Url); } catch (Exception ex) { diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 2019d6db..58584348 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -85,7 +85,8 @@ namespace StardewModdingAPI.Web services.AddSingleton(new NexusWebScrapeClient( userAgent: userAgent, baseUrl: api.NexusBaseUrl, - modUrlFormat: api.NexusModUrlFormat + modUrlFormat: api.NexusModUrlFormat, + modScrapeUrlFormat: api.NexusModScrapeUrlFormat )); services.AddSingleton(new PastebinClient( diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index fda77183..2f87dbe5 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -32,6 +32,7 @@ "NexusBaseUrl": "https://www.nexusmods.com/stardewvalley/", "NexusModUrlFormat": "mods/{0}", + "NexusModScrapeUrlFormat": "mods/{0}?tab=files", "PastebinBaseUrl": "https://pastebin.com/", "PastebinUserKey": null, // see top note diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs index e1a204c6..c8e296f0 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModInfoModel.cs @@ -9,10 +9,10 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi /// The mod name. public string Name { get; set; } - /// The semantic version for the mod's latest release. + /// The mod's latest release number. public string Version { get; set; } - /// The semantic version for the mod's latest preview release, if available and different from . + /// The mod's latest optional release, if newer than . public string PreviewVersion { get; set; } /// The mod's web URL. -- cgit From 89ad599561a058289d8ea44e0c345f1a30a3a6ac Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 28 Jun 2018 21:41:00 -0400 Subject: add support for writing versions to JSON --- docs/release-notes.md | 1 + src/SMAPI.Web/Startup.cs | 4 ++ .../Converters/SemanticVersionConverter.cs | 60 ++++++++++++++++++++-- 3 files changed, 60 insertions(+), 5 deletions(-) (limited to 'src/SMAPI.Web/Startup.cs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 062f902e..a8f6d851 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -44,6 +44,7 @@ * Added Harmony DLL for internal use by SMAPI. (Mods should still include their own copy for backwards compatibility, and in case it's removed later. SMAPI will always load its own version though.) * Added option to suppress update checks for a specific mod in `StardewModdingAPI.config.json`. * Added absolute pixels to `ICursorPosition`. + * Added support for reading/writing `ISemanticVersion` to JSON. * Update checks now use the update key order when deciding which to link to. * Fixed error if a mod loads a PNG while the game is loading (e.g. custom map tilesheets via `IAssetLoader`). * Fixed assets loaded by temporary content managers not being editable by mods. diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 58584348..ced6e1c7 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using StardewModdingAPI.Toolkit.Serialisation; using StardewModdingAPI.Web.Framework; using StardewModdingAPI.Web.Framework.Clients.Chucklefish; using StardewModdingAPI.Web.Framework.Clients.GitHub; @@ -56,6 +57,9 @@ namespace StardewModdingAPI.Web .ConfigureApplicationPartManager(manager => manager.FeatureProviders.Add(new InternalControllerFeatureProvider())) .AddJsonOptions(options => { + foreach (JsonConverter converter in new JsonHelper().JsonSettings.Converters) + options.SerializerSettings.Converters.Add(converter); + options.SerializerSettings.Formatting = Formatting.Indented; options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; }); diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs b/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs index 4f0949fa..9b2f5e7d 100644 --- a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs +++ b/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs @@ -1,17 +1,67 @@ +using System; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace StardewModdingAPI.Toolkit.Serialisation.Converters { /// Handles deserialisation of . - internal class SemanticVersionConverter : SimpleReadOnlyConverter + internal class SemanticVersionConverter : JsonConverter { /********* - ** Protected methods + ** Accessors + *********/ + /// Get whether this converter can read JSON. + public override bool CanRead => true; + + /// Get whether this converter can write JSON. + public override bool CanWrite => true; + + + /********* + ** Public methods + *********/ + /// Get whether this instance can convert the specified object type. + /// The object type. + public override bool CanConvert(Type objectType) + { + return typeof(ISemanticVersion).IsAssignableFrom(objectType); + } + + /// Reads the JSON representation of the object. + /// The JSON reader. + /// The object type. + /// The object being read. + /// The calling serializer. + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + string path = reader.Path; + switch (reader.TokenType) + { + case JsonToken.StartObject: + return this.ReadObject(JObject.Load(reader)); + case JsonToken.String: + return this.ReadString(JToken.Load(reader).Value(), path); + default: + throw new SParseException($"Can't parse {nameof(ISemanticVersion)} from {reader.TokenType} node (path: {reader.Path})."); + } + } + + /// Writes the JSON representation of the object. + /// The JSON writer. + /// The value. + /// The calling serializer. + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + writer.WriteValue(value?.ToString()); + } + + + /********* + ** Private methods *********/ /// Read a JSON object. /// The JSON object to read. - /// The path to the current JSON node. - protected override ISemanticVersion ReadObject(JObject obj, string path) + private ISemanticVersion ReadObject(JObject obj) { int major = obj.ValueIgnoreCase("MajorVersion"); int minor = obj.ValueIgnoreCase("MinorVersion"); @@ -26,7 +76,7 @@ namespace StardewModdingAPI.Toolkit.Serialisation.Converters /// Read a JSON string. /// The JSON string value. /// The path to the current JSON node. - protected override ISemanticVersion ReadString(string str, string path) + private ISemanticVersion ReadString(string str, string path) { if (string.IsNullOrWhiteSpace(str)) return null; -- cgit From 84d52b1735204550c6369270c03f61944c2c88bd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 29 Jul 2018 12:43:04 -0400 Subject: make beta version on smapi.io optional (#569) --- src/SMAPI.Web/Controllers/IndexController.cs | 11 +++++++++-- src/SMAPI.Web/Controllers/LogParserController.cs | 10 +++++----- src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs | 15 --------------- src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs | 18 ++++++++++++++++++ src/SMAPI.Web/Startup.cs | 2 +- src/SMAPI.Web/Views/Shared/_Layout.cshtml | 6 +++--- src/SMAPI.Web/appsettings.Development.json | 7 +++++-- src/SMAPI.Web/appsettings.json | 9 ++++++--- 8 files changed, 47 insertions(+), 31 deletions(-) delete mode 100644 src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs create mode 100644 src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs (limited to 'src/SMAPI.Web/Startup.cs') diff --git a/src/SMAPI.Web/Controllers/IndexController.cs b/src/SMAPI.Web/Controllers/IndexController.cs index 09bad112..8c4a0332 100644 --- a/src/SMAPI.Web/Controllers/IndexController.cs +++ b/src/SMAPI.Web/Controllers/IndexController.cs @@ -6,8 +6,10 @@ using System.Threading.Tasks; using HtmlAgilityPack; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Options; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Web.Framework.Clients.GitHub; +using StardewModdingAPI.Web.Framework.ConfigModels; using StardewModdingAPI.Web.ViewModels; namespace StardewModdingAPI.Web.Controllers @@ -20,6 +22,9 @@ namespace StardewModdingAPI.Web.Controllers /********* ** Properties *********/ + /// The site config settings. + private readonly SiteConfig SiteConfig; + /// The cache in which to store release data. private readonly IMemoryCache Cache; @@ -39,10 +44,12 @@ namespace StardewModdingAPI.Web.Controllers /// Construct an instance. /// The cache in which to store release data. /// The GitHub API client. - public IndexController(IMemoryCache cache, IGitHubClient github) + /// The context config settings. + public IndexController(IMemoryCache cache, IGitHubClient github, IOptions siteConfig) { this.Cache = cache; this.GitHub = github; + this.SiteConfig = siteConfig.Value; } /// Display the index page. @@ -60,7 +67,7 @@ namespace StardewModdingAPI.Web.Controllers IndexVersionModel stableVersionModel = stableVersion != null ? new IndexVersionModel(stableVersion.Version.ToString(), stableVersion.Release.Body, stableVersion.Asset.DownloadUrl, stableVersionForDevs?.Asset.DownloadUrl) : new IndexVersionModel("unknown", "", "https://github.com/Pathoschild/SMAPI/releases", null); // just in case something goes wrong) - IndexVersionModel betaVersionModel = betaVersion != null + IndexVersionModel betaVersionModel = betaVersion != null && this.SiteConfig.EnableSmapiBeta ? new IndexVersionModel(betaVersion.Version.ToString(), betaVersion.Release.Body, betaVersion.Asset.DownloadUrl, betaVersionForDevs?.Asset.DownloadUrl) : null; diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 354bdb06..17f8d3aa 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -21,8 +21,8 @@ namespace StardewModdingAPI.Web.Controllers /********* ** Properties *********/ - /// The log parser config settings. - private readonly ContextConfig Config; + /// The site config settings. + private readonly SiteConfig Config; /// The underlying Pastebin client. private readonly IPastebinClient Pastebin; @@ -39,11 +39,11 @@ namespace StardewModdingAPI.Web.Controllers ** Constructor ***/ /// Construct an instance. - /// The context config settings. + /// The context config settings. /// The Pastebin API client. - public LogParserController(IOptions contextProvider, IPastebinClient pastebin) + public LogParserController(IOptions siteConfig, IPastebinClient pastebin) { - this.Config = contextProvider.Value; + this.Config = siteConfig.Value; this.Pastebin = pastebin; } diff --git a/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs deleted file mode 100644 index 117462f4..00000000 --- a/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace StardewModdingAPI.Web.Framework.ConfigModels -{ - /// The config settings for the app context. - public class ContextConfig // must be public to pass into views - { - /********* - ** Accessors - *********/ - /// The root URL for the app. - public string RootUrl { get; set; } - - /// The root URL for the log parser. - public string LogParserUrl { get; set; } - } -} diff --git a/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs new file mode 100644 index 00000000..3d428015 --- /dev/null +++ b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs @@ -0,0 +1,18 @@ +namespace StardewModdingAPI.Web.Framework.ConfigModels +{ + /// The site config settings. + public class SiteConfig // must be public to pass into views + { + /********* + ** Accessors + *********/ + /// The root URL for the app. + public string RootUrl { get; set; } + + /// The root URL for the log parser. + public string LogParserUrl { get; set; } + + /// Whether to show SMAPI beta versions on the main page, if any. + public bool EnableSmapiBeta { get; set; } + } +} diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index ced6e1c7..bf3ec9a1 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -50,7 +50,7 @@ namespace StardewModdingAPI.Web // init configuration services .Configure(this.Configuration.GetSection("ModUpdateCheck")) - .Configure(this.Configuration.GetSection("Context")) + .Configure(this.Configuration.GetSection("Site")) .Configure(options => options.ConstraintMap.Add("semanticVersion", typeof(VersionConstraint))) .AddMemoryCache() .AddMvc() diff --git a/src/SMAPI.Web/Views/Shared/_Layout.cshtml b/src/SMAPI.Web/Views/Shared/_Layout.cshtml index d435e760..29da9100 100644 --- a/src/SMAPI.Web/Views/Shared/_Layout.cshtml +++ b/src/SMAPI.Web/Views/Shared/_Layout.cshtml @@ -1,6 +1,6 @@ @using Microsoft.Extensions.Options @using StardewModdingAPI.Web.Framework.ConfigModels -@inject IOptions ContextConfig +@inject IOptions SiteConfig @@ -15,8 +15,8 @@ diff --git a/src/SMAPI.Web/appsettings.Development.json b/src/SMAPI.Web/appsettings.Development.json index 495af120..67bb7748 100644 --- a/src/SMAPI.Web/appsettings.Development.json +++ b/src/SMAPI.Web/appsettings.Development.json @@ -16,10 +16,13 @@ "Microsoft": "Information" } }, - "Context": { + + "Site": { "RootUrl": "http://localhost:59482/", - "LogParserUrl": "http://localhost:59482/log/" + "LogParserUrl": "http://localhost:59482/log/", + "EnableSmapiBeta": false }, + "ApiClients": { "GitHubUsername": null, "GitHubPassword": null, diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 837ba536..9e3270ae 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -13,10 +13,13 @@ "Default": "Warning" } }, - "Context": { - "RootUrl": null, // see top note - "LogParserUrl": null // see top note + + "Site": { + "RootUrl": null, // see top note + "LogParserUrl": null, // see top note + "EnableSmapiBeta": null // see top note }, + "ApiClients": { "UserAgent": "SMAPI/{0} (+https://smapi.io)", -- cgit