summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Toolkit/ModToolkit.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-13 17:22:45 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-13 17:22:45 -0400
commit125bcbee56bf40cf82abc7fdb502f8cbc18546cf (patch)
tree788997dd4683867b6e32e307c17c855bd7209d98 /src/StardewModdingAPI.Toolkit/ModToolkit.cs
parent56726073ba65a018312bcd9db7072381073de315 (diff)
downloadSMAPI-125bcbee56bf40cf82abc7fdb502f8cbc18546cf.tar.gz
SMAPI-125bcbee56bf40cf82abc7fdb502f8cbc18546cf.tar.bz2
SMAPI-125bcbee56bf40cf82abc7fdb502f8cbc18546cf.zip
migrate to new project file format
Diffstat (limited to 'src/StardewModdingAPI.Toolkit/ModToolkit.cs')
-rw-r--r--src/StardewModdingAPI.Toolkit/ModToolkit.cs89
1 files changed, 0 insertions, 89 deletions
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
-{
- /// <summary>A convenience wrapper for the various tools.</summary>
- public class ModToolkit
- {
- /*********
- ** Fields
- *********/
- /// <summary>The default HTTP user agent for the toolkit.</summary>
- private readonly string UserAgent;
-
- /// <summary>Maps vendor keys (like <c>Nexus</c>) to their mod URL template (where <c>{0}</c> is the mod ID). This doesn't affect update checks, which defer to the remote web API.</summary>
- private readonly IDictionary<string, string> VendorModUrls = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
- {
- ["Chucklefish"] = "https://community.playstarbound.com/resources/{0}",
- ["GitHub"] = "https://github.com/{0}/releases",
- ["Nexus"] = "https://www.nexusmods.com/stardewvalley/mods/{0}"
- };
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Encapsulates SMAPI's JSON parsing.</summary>
- public JsonHelper JsonHelper { get; } = new JsonHelper();
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Construct an instance.</summary>
- public ModToolkit()
- {
- ISemanticVersion version = new SemanticVersion(this.GetType().Assembly.GetName().Version);
- this.UserAgent = $"SMAPI Mod Handler Toolkit/{version}";
- }
-
- /// <summary>Extract mod metadata from the wiki compatibility list.</summary>
- public async Task<WikiModList> GetWikiCompatibilityListAsync()
- {
- var client = new WikiClient(this.UserAgent);
- return await client.FetchModsAsync();
- }
-
- /// <summary>Get SMAPI's internal mod database.</summary>
- /// <param name="metadataPath">The file path for the SMAPI metadata file.</param>
- public ModDatabase GetModDatabase(string metadataPath)
- {
- MetadataModel metadata = JsonConvert.DeserializeObject<MetadataModel>(File.ReadAllText(metadataPath));
- ModDataRecord[] records = metadata.ModData.Select(pair => new ModDataRecord(pair.Key, pair.Value)).ToArray();
- return new ModDatabase(records, this.GetUpdateUrl);
- }
-
- /// <summary>Extract information about all mods in the given folder.</summary>
- /// <param name="rootPath">The root folder containing mods.</param>
- public IEnumerable<ModFolder> GetModFolders(string rootPath)
- {
- return new ModScanner(this.JsonHelper).GetModFolders(rootPath);
- }
-
- /// <summary>Get an update URL for an update key (if valid).</summary>
- /// <param name="updateKey">The update key.</param>
- 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;
- }
- }
-}