add toolkit method to read compat list from local repo

This commit is contained in:
Jesse Plamondon-Willard
2024-12-29 16:15:51 -05:00
parent 66fecc71f3
commit 61a79ea91e
3 changed files with 32 additions and 0 deletions
+3
View File
@@ -5,6 +5,9 @@
* For players:
* Fixed `log_context` command not disabling the extra logs when run again.
* For external tools:
* Added toolkit method to read the compatibility list from a local copy of its Git repo.
## 4.1.10
Released 18 December 2024 for Stardew Valley 1.6.14 or later.
@@ -1,7 +1,9 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Markdig;
using Newtonsoft.Json;
using Pathoschild.Http.Client;
using StardewModdingAPI.Toolkit.Framework.Clients.CompatibilityRepo.Internal;
using StardewModdingAPI.Toolkit.Framework.Clients.CompatibilityRepo.RawDataModels;
@@ -53,6 +55,25 @@ public class CompatibilityRepoClient : IDisposable
.ToArray();
}
/// <summary>Fetch mods from the compatibility list by reading a local copy of the compatibility list repo.</summary>
/// <param name="gitRepoPath">The full path to the compatibility list repo folder.</param>
public async Task<ModCompatibilityEntry[]> FetchModsFromLocalGitFolderAsync(string gitRepoPath)
{
string modsJsonPath = Path.Combine(gitRepoPath, "data", "mods.jsonc");
string contentPacksJsonPath = Path.Combine(gitRepoPath, "data", "broken-content-packs.jsonc");
if (!File.Exists(modsJsonPath) || !File.Exists(contentPacksJsonPath))
throw new InvalidOperationException("The compatibility list repo folder doesn't contain the required JSON files.");
RawCompatibilityList? mods = JsonConvert.DeserializeObject<RawCompatibilityList>(File.ReadAllText(modsJsonPath));
RawCompatibilityList? brokenContentPacks = JsonConvert.DeserializeObject<RawCompatibilityList>(File.ReadAllText(contentPacksJsonPath));
return
(mods?.Mods ?? Array.Empty<RawModEntry>())
.Concat(brokenContentPacks?.BrokenContentPacks ?? Array.Empty<RawModEntry>())
.Select(this.ParseRawModEntry)
.ToArray();
}
/// <summary>Get the inline HTML produced by a Markdown string in a compatibility repo field.</summary>
/// <param name="markdown">The Markdown to parse.</param>
/// <remarks>This is a low-level method. Most code should use <see cref="FetchModsAsync"/> instead.</remarks>
+8
View File
@@ -70,6 +70,14 @@ public class ModToolkit
return await client.FetchModsAsync();
}
/// <summary>Extract mod metadata from the compatibility list repo by reading a local copy of the repo.</summary>
/// <param name="gitRepoPath">The full path to the compatibility list repo folder.</param>
public async Task<ModCompatibilityEntry[]> GetCompatibilityListFromLocalGitFolderAsync(string gitRepoPath)
{
using CompatibilityRepoClient client = new(this.UserAgent);
return await client.FetchModsFromLocalGitFolderAsync(gitRepoPath);
}
/// <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)