diff --git a/MinecraftLaunch/Components/Checker/ResourceChecker.cs b/MinecraftLaunch/Components/Checker/ResourceChecker.cs index b6bec0b..e13ec64 100644 --- a/MinecraftLaunch/Components/Checker/ResourceChecker.cs +++ b/MinecraftLaunch/Components/Checker/ResourceChecker.cs @@ -7,18 +7,26 @@ namespace MinecraftLaunch.Components.Checker; /// -/// Minecraft 游戏资源检查器 +/// A checker for Minecraft game resources. /// /// -/// 包含 Assets 和 Libraries +/// This includes both Assets and Libraries. /// public sealed class ResourceChecker(GameEntry entry) : IChecker { private AssetsResolver AssetsResolver => new(entry); - private LibrariesResolver LibraryResolver => new(entry); + /// + /// Gets the collection of missing resources. + /// public IReadOnlyCollection MissingResources { get; private set; } + /// + /// Checks the game resources asynchronously. + /// + /// + /// A ValueTask that represents the asynchronous operation. The task result contains a boolean value indicating whether all resources are present. + /// public async ValueTask CheckAsync() { var assetIndex = AssetsResolver.GetAssetIndexJson(); if (!assetIndex.Verify()) { @@ -35,4 +43,4 @@ public async ValueTask CheckAsync() { return !MissingResources.Any(); } -} \ No newline at end of file +} diff --git a/MinecraftLaunch/Components/Fetcher/CurseForgeFetcher.cs b/MinecraftLaunch/Components/Fetcher/CurseForgeFetcher.cs index e09adfc..da67a66 100644 --- a/MinecraftLaunch/Components/Fetcher/CurseForgeFetcher.cs +++ b/MinecraftLaunch/Components/Fetcher/CurseForgeFetcher.cs @@ -10,14 +10,34 @@ namespace MinecraftLaunch.Components.Fetcher; -public sealed class CurseForgeFetcher(string apiKey) : IFetcher> { - private readonly string _key = apiKey; - private readonly string _api = "https://api.curseforge.com/v1/mods"; - +/// +/// Fetches resources from CurseForge. +/// +public sealed class CurseForgeFetcher : IFetcher> { + private const string BASE_API = "https://api.curseforge.com/v1/mods"; + + private readonly string _key; + + /// + /// Initializes a new instance of the class. + /// + /// The API key for CurseForge. + public CurseForgeFetcher(string apiKey) { + _key = apiKey; + } + + /// + /// Fetches the CurseForge resources synchronously. + /// + /// An enumerable collection of CurseForge resources. public IEnumerable Fetch() { return FetchAsync().GetAwaiter().GetResult(); } + /// + /// Fetches the CurseForge resources asynchronously. + /// + /// A ValueTask that represents the asynchronous operation. The task result contains an enumerable collection of CurseForge resources. public async ValueTask> FetchAsync() { var result = new List(); var payload = new { @@ -26,7 +46,7 @@ public async ValueTask> FetchAsync() { gameVersionTypeId = null as string }; try { - using var responseMessage = await $"{_api}/featured" + using var responseMessage = await $"{BASE_API}/featured" .WithHeader("x-api-key", _key) .PostJsonAsync(payload); @@ -44,13 +64,22 @@ public async ValueTask> FetchAsync() { return result; } + /// + /// Searches for CurseForge resources asynchronously based on the provided search filter and other parameters. + /// + /// The search filter. + /// The class ID. Defaults to 6. + /// The category. Defaults to -1. + /// The game version. Defaults to null. + /// The mod loader type. Defaults to LoaderType.Any. + /// A ValueTask that represents the asynchronous operation. The task result contains an enumerable collection of CurseForge resources. public async ValueTask> SearchResourcesAsync( string searchFilter, int classId = 6, int category = -1, string gameVersion = null, LoaderType modLoaderType = LoaderType.Any) { - var stringBuilder = new StringBuilder(_api); + var stringBuilder = new StringBuilder(BASE_API); stringBuilder.Append("/search?gameId=432"); stringBuilder.Append("&sortField=Featured"); stringBuilder.Append("&sortOrder=desc"); diff --git a/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs b/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs index 50622c1..47ebaf7 100644 --- a/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs +++ b/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs @@ -10,6 +10,9 @@ namespace MinecraftLaunch.Components.Fetcher; +/// +/// Fetches Java installations on the system. +/// public sealed class JavaFetcher : IFetcher> { #region Fields [SupportedOSPlatform(nameof(OSPlatform.OSX))] @@ -66,10 +69,18 @@ public sealed class JavaFetcher : IFetcher> { #endregion + /// + /// Fetches the Java installations synchronously. + /// + /// An immutable array of Java entries. public ImmutableArray Fetch() { return FetchAsync().GetAwaiter().GetResult(); } + /// + /// Fetches the Java installations asynchronously. + /// + /// A ValueTask that represents the asynchronous operation. The task result contains an immutable array of Java entries. public async ValueTask> FetchAsync() { return EnvironmentUtil.GetPlatformName() switch { "windows" => FetchWindowJava(), diff --git a/MinecraftLaunch/Components/Fetcher/ModrinthFetcher.cs b/MinecraftLaunch/Components/Fetcher/ModrinthFetcher.cs index 3c394d3..97b684c 100644 --- a/MinecraftLaunch/Components/Fetcher/ModrinthFetcher.cs +++ b/MinecraftLaunch/Components/Fetcher/ModrinthFetcher.cs @@ -7,25 +7,44 @@ using MinecraftLaunch.Classes.Interfaces; using MinecraftLaunch.Classes.Models.Download; -namespace MinecraftLaunch.Components.Fetcher; +namespace MinecraftLaunch.Components.Fetcher; + +/// +/// Fetches resources from Modrinth. +/// public sealed class ModrinthFetcher : IFetcher> { - private readonly string _api = "https://api.modrinth.com/v2/"; - + private const string BASE_API = "https://api.modrinth.com/v2/"; + + /// + /// Fetches the Modrinth resources synchronously. + /// + /// An enumerable collection of Modrinth resources. public IEnumerable Fetch() { return FetchAsync().GetAwaiter().GetResult(); } + /// + /// Fetches the Modrinth resources asynchronously. + /// + /// A ValueTask that represents the asynchronous operation. The task result contains an enumerable collection of Modrinth resources. public async ValueTask> FetchAsync() { - var jNode = (await $"{_api}search".GetStringAsync()).AsNode(); + var jNode = (await $"{BASE_API}search".GetStringAsync()).AsNode(); return jNode?.Select("hits")?.GetEnumerable() .Deserialize>(JsonConverterUtil.DefaultJsonOptions); } - + + /// + /// Searches for Modrinth resources asynchronously based on the provided search filter and other parameters. + /// + /// The search filter. + /// The version. Defaults to null. + /// The resource type. Defaults to ModrinthResourceType.Mod. + /// A ValueTask that represents the asynchronous operation. The task result contains an enumerable collection of Modrinth resources. public async ValueTask> SearchResourcesAsync( string searchFilter, string version = default, ModrinthResourceType? resourceType = ModrinthResourceType.Mod) { - var stringBuilder = new StringBuilder(_api); + var stringBuilder = new StringBuilder(BASE_API); stringBuilder.Append($"search?query={searchFilter}"); var facets = new List(); diff --git a/MinecraftLaunch/Components/Launcher/Launcher.cs b/MinecraftLaunch/Components/Launcher/Launcher.cs index e857428..3445a98 100644 --- a/MinecraftLaunch/Components/Launcher/Launcher.cs +++ b/MinecraftLaunch/Components/Launcher/Launcher.cs @@ -10,25 +10,43 @@ namespace MinecraftLaunch.Components.Launcher; /// -/// 标准 Java版 Minecraft 启动器 +/// Launcher for the Java version of Minecraft. /// -public sealed class Launcher(IGameResolver resolver, LaunchConfig config) : ILauncher { +public sealed class Launcher : ILauncher { private ArgumentsBuilder _argumentsBuilder; - public LaunchConfig LaunchConfig => config; + /// + /// Gets the launch configuration. + /// + public LaunchConfig LaunchConfig { get; } - public IGameResolver GameResolver => resolver; + public IGameResolver GameResolver { get; } + /// + /// Initializes a new instance of the class. + /// + /// The game resolver. + /// The launch configuration. + public Launcher(IGameResolver resolver, LaunchConfig config) { + GameResolver = resolver; + LaunchConfig = config; + } + + /// + /// Launches the game asynchronously. + /// + /// The ID of the game to launch. + /// A ValueTask that represents the asynchronous operation. The task result contains a . public async ValueTask LaunchAsync(string id) { - var gameEntry = GameResolver.GetGameEntity(id); - var versionPath = gameEntry.OfVersionDirectoryPath(config.IsEnableIndependencyCore); - _argumentsBuilder = new(gameEntry, config); + var gameEntry = GameResolver.GetGameEntity(id); + var versionPath = gameEntry.OfVersionDirectoryPath(LaunchConfig.IsEnableIndependencyCore); + _argumentsBuilder = new(gameEntry, LaunchConfig); var arguments = _argumentsBuilder.Build(); var process = CreateProcess(arguments, versionPath); LibrariesResolver librariesResolver = new(gameEntry); - await ExtractNatives(versionPath, librariesResolver); + await Launcher.ExtractNatives(versionPath, librariesResolver); return new GameProcessWatcher(process, arguments); } @@ -46,7 +64,7 @@ private Process CreateProcess(IEnumerable arguments, string versionPath) }; } - private async Task ExtractNatives(string versionPath, LibrariesResolver librariesResolver) { + private static async Task ExtractNatives(string versionPath, LibrariesResolver librariesResolver) { var libraries = librariesResolver.GetLibraries() .Where(x => ((x as LibraryEntry)?.IsNative) != null) .Select(x => x.Path) diff --git a/MinecraftLaunch/MinecraftLaunch.csproj b/MinecraftLaunch/MinecraftLaunch.csproj index 3423d5b..d77b31a 100644 --- a/MinecraftLaunch/MinecraftLaunch.csproj +++ b/MinecraftLaunch/MinecraftLaunch.csproj @@ -15,6 +15,7 @@ latest MinecraftLaunch disable + False