From 125bcbee56bf40cf82abc7fdb502f8cbc18546cf Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 13 Sep 2019 17:22:45 -0400 Subject: migrate to new project file format --- src/StardewModdingAPI.Toolkit/ModToolkit.cs | 89 ----------------------------- 1 file changed, 89 deletions(-) delete mode 100644 src/StardewModdingAPI.Toolkit/ModToolkit.cs (limited to 'src/StardewModdingAPI.Toolkit/ModToolkit.cs') diff --git a/src/StardewModdingAPI.Toolkit/ModToolkit.cs b/src/StardewModdingAPI.Toolkit/ModToolkit.cs deleted file mode 100644 index 1b53e59e..00000000 --- a/src/StardewModdingAPI.Toolkit/ModToolkit.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Newtonsoft.Json; -using StardewModdingAPI.Toolkit.Framework.Clients.Wiki; -using StardewModdingAPI.Toolkit.Framework.ModData; -using StardewModdingAPI.Toolkit.Framework.ModScanning; -using StardewModdingAPI.Toolkit.Serialisation; - -namespace StardewModdingAPI.Toolkit -{ - /// A convenience wrapper for the various tools. - public class ModToolkit - { - /********* - ** Fields - *********/ - /// The default HTTP user agent for the toolkit. - private readonly string UserAgent; - - /// Maps vendor keys (like Nexus) to their mod URL template (where {0} is the mod ID). This doesn't affect update checks, which defer to the remote web API. - private readonly IDictionary VendorModUrls = new Dictionary(StringComparer.InvariantCultureIgnoreCase) - { - ["Chucklefish"] = "https://community.playstarbound.com/resources/{0}", - ["GitHub"] = "https://github.com/{0}/releases", - ["Nexus"] = "https://www.nexusmods.com/stardewvalley/mods/{0}" - }; - - - /********* - ** Accessors - *********/ - /// Encapsulates SMAPI's JSON parsing. - public JsonHelper JsonHelper { get; } = new JsonHelper(); - - - /********* - ** Public methods - *********/ - /// Construct an instance. - public ModToolkit() - { - ISemanticVersion version = new SemanticVersion(this.GetType().Assembly.GetName().Version); - this.UserAgent = $"SMAPI Mod Handler Toolkit/{version}"; - } - - /// Extract mod metadata from the wiki compatibility list. - public async Task GetWikiCompatibilityListAsync() - { - var client = new WikiClient(this.UserAgent); - return await client.FetchModsAsync(); - } - - /// Get SMAPI's internal mod database. - /// The file path for the SMAPI metadata file. - public ModDatabase GetModDatabase(string metadataPath) - { - MetadataModel metadata = JsonConvert.DeserializeObject(File.ReadAllText(metadataPath)); - ModDataRecord[] records = metadata.ModData.Select(pair => new ModDataRecord(pair.Key, pair.Value)).ToArray(); - return new ModDatabase(records, this.GetUpdateUrl); - } - - /// Extract information about all mods in the given folder. - /// The root folder containing mods. - public IEnumerable GetModFolders(string rootPath) - { - return new ModScanner(this.JsonHelper).GetModFolders(rootPath); - } - - /// Get an update URL for an update key (if valid). - /// The update key. - public string GetUpdateUrl(string updateKey) - { - string[] parts = updateKey.Split(new[] { ':' }, 2); - if (parts.Length != 2) - return null; - - string vendorKey = parts[0].Trim(); - string modID = parts[1].Trim(); - - if (this.VendorModUrls.TryGetValue(vendorKey, out string urlTemplate)) - return string.Format(urlTemplate, modID); - - return null; - } - } -} -- cgit