From f81eee156221d2bd207e986fcc2c5ea34d9f3719 Mon Sep 17 00:00:00 2001 From: laolarou Date: Tue, 28 Nov 2023 17:46:20 -0800 Subject: [PATCH] fully migrated to NET8 --- .../Class/Helper/AuthPropertyHelper.cs | 12 +- .../Class/Helper/CurseForgeAPIHelper.cs | 9 +- .../Class/Helper/GameRegexHelper.cs | 12 +- .../ProjBobcat/Class/Helper/HttpHelper.cs | 54 +++--- .../ProjBobcat/Class/Helper/MavenHelper.cs | 13 +- .../ProjBobcat/Class/Helper/RandomHelper.cs | 9 +- .../ProjBobcat/Class/Helper/StringHelper.cs | 3 +- .../Class/Helper/TOMLParser/TomlParser.cs | 49 +---- .../Helper/TOMLParser/TommyExtensions.cs | 6 +- .../Class/LaunchArgumentParserBase.cs | 27 +-- ProjBobcat/ProjBobcat/Class/LaunchWrapper.cs | 29 +-- .../ProjBobcat/Class/LauncherParserBase.cs | 4 +- .../ProjBobcat/Class/Model/AppxPackageInfo.cs | 24 +-- .../Class/Model/AssetObjectModel.cs | 4 +- .../Class/Model/Auth/AuthResultBase.cs | 4 +- .../Class/Model/Auth/MicrosoftAuthResult.cs | 14 +- .../Class/Model/Auth/YggdrasilAuthResult.cs | 7 +- ProjBobcat/ProjBobcat/Class/Model/CPUInfo.cs | 6 +- .../CurseForge/API/FeaturedQueryOptions.cs | 10 +- .../CurseForge/CurseForgeAddonAuthorInfo.cs | 4 +- .../Model/CurseForge/CurseForgeAddonInfo.cs | 34 ++-- .../CurseForge/CurseForgeAttachmentInfo.cs | 8 +- .../CurseForge/CurseForgeCategoryInfo.cs | 6 +- .../CurseForgeCategorySectionInfo.cs | 6 +- .../CurseForgeFeaturedAddonModel.cs | 12 +- .../CurseForgeGameVersionLatestFiles.cs | 4 +- .../CurseForge/CurseForgeLatestFileModel.cs | 14 +- .../CurseForge/CurseForgeManifestModel.cs | 14 +- .../CurseForge/CurseForgeMineCraftModel.cs | 6 +- .../Model/CurseForge/CurseForgeModuleModel.cs | 2 +- .../CurseForgeSearchCategoryModel.cs | 8 +- .../CurseForgeSortableGameVersionModel.cs | 7 +- .../Class/Model/CurseForge/DataModel.cs | 4 +- .../Class/Model/DownloadCheckResult.cs | 2 +- .../ProjBobcat/Class/Model/DownloadFile.cs | 45 ++--- .../ProjBobcat/Class/Model/DownloadRange.cs | 6 +- .../Class/Model/DownloadSettings.cs | 18 +- .../Class/Model/Fabric/FabricArtifactModel.cs | 4 +- .../Class/Model/Fabric/FabricLauncherMeta.cs | 8 +- .../Model/Fabric/FabricLoaderArtifactModel.cs | 6 +- .../Class/Model/Fabric/FabricModInfoModel.cs | 30 +-- .../Model/Forge/ForgeInstallProcessorModel.cs | 6 +- .../Class/Model/Forge/ForgeInstallProfile.cs | 38 ++-- .../Model/Forge/LegacyForgeInstallProfile.cs | 62 +++--- .../Class/Model/ForgeInstallResult.cs | 2 +- .../Model/GameResource/AssetDownloadInfo.cs | 14 +- .../GameResource/GameLoggingDownloadInfo.cs | 14 +- .../Model/GameResource/LibraryDownloadInfo.cs | 14 +- .../GameResource/VersionJarDownloadInfo.cs | 14 +- .../ProjBobcat/Class/Model/GameRulesModel.cs | 5 +- .../ProjBobcat/Class/Model/InstallerBase.cs | 6 +- .../Class/Model/JavaVersionModel.cs | 2 +- .../ProjBobcat/Class/Model/JvmRulesModel.cs | 6 +- .../ProjBobcat/Class/Model/LaunchResult.cs | 10 +- .../ProjBobcat/Class/Model/LaunchSettings.cs | 30 +-- .../Model/LauncherAccount/AccountModel.cs | 14 +- .../LauncherAccount/AccountProfileModel.cs | 4 +- .../LauncherAccount/LauncherAccountModel.cs | 7 +- .../Model/LauncherProfile/AuthProfileModel.cs | 2 +- .../LauncherProfile/AuthPropertyModel.cs | 6 +- .../Model/LauncherProfile/GameProfileModel.cs | 14 +- .../LauncherProfile/LauncherProfileModel.cs | 8 +- .../LauncherProfile/LauncherVersionModel.cs | 2 +- .../LauncherProfile/SelectedUserModel.cs | 4 +- .../Model/LiteLoader/LiteLoaderBuildModel.cs | 18 +- .../LiteLoaderDownloadVersionModel.cs | 12 +- .../ProjBobcat/Class/Model/MavenInfo.cs | 14 +- .../ProjBobcat/Class/Model/MemoryInfo.cs | 10 +- .../Microsoft/Graph/DeviceIdResponseModel.cs | 8 +- .../Microsoft/Graph/GraphAuthResultModel.cs | 10 +- .../Graph/GraphResponseErrorModel.cs | 8 +- .../MicrosoftAuth/AuthMojangResponseModel.cs | 8 +- .../MicrosoftAuth/AuthTokenResponseModel.cs | 20 -- .../MicrosoftAuth/AuthXBLRequestModel.cs | 12 +- .../Model/MicrosoftAuth/AuthXSTSErrorModel.cs | 6 +- .../MicrosoftAuth/AuthXSTSRequestModel.cs | 10 +- .../MicrosoftAuth/AuthXSTSResponseModel.cs | 2 +- .../MicrosoftAuthenticatorAPISettings.cs | 6 +- .../MicrosoftAuth/MojangErrorResponseModel.cs | 10 +- .../MojangOwnershipResponseModel.cs | 10 +- .../MojangProfileResponseModel.cs | 22 +-- .../Model/Modrinth/ModrinthCategoryInfo.cs | 6 +- .../Modrinth/ModrinthModPackFileModel.cs | 5 +- .../Modrinth/ModrinthModPackIndexModel.cs | 5 +- .../Modrinth/ModrinthProjectDependencyInfo.cs | 4 +- .../Model/Modrinth/ModrinthProjectInfo.cs | 30 +-- .../Model/Modrinth/ModrinthProjectInfoBase.cs | 20 +- .../ModrinthProjectInfoSearchResult.cs | 8 +- .../Model/Modrinth/ModrinthSearchOptions.cs | 2 +- .../Model/Modrinth/ModrinthSearchResult.cs | 2 +- .../Model/Modrinth/ModrinthVersionInfo.cs | 36 ++-- .../Class/Model/Mojang/UserProfile.cs | 8 +- .../Model/Mojang/UserProfilePropertyValue.cs | 8 +- .../Class/Model/Mojang/VersionManifest.cs | 14 +- .../ProjBobcat/Class/Model/NativeFileInfo.cs | 4 +- .../Model/NeoForge/NeoForgeVersionsModel.cs | 4 +- .../ProjBobcat/Class/Model/OperatingSystem.cs | 10 - .../Optifine/OptifineDownloadVersionModel.cs | 18 +- .../ProjBobcat/Class/Model/PlayerUUID.cs | 8 +- .../Class/Model/ProgressReportBase.cs | 4 +- .../Class/Model/Quilt/QuiltLoaderModel.cs | 6 +- .../Model/Quilt/QuiltSupportGameModel.cs | 2 +- .../ProjBobcat/Class/Model/RawVersionModel.cs | 63 ++++--- .../Model/ResourceCompleterCheckResult.cs | 4 +- .../Class/Model/ServerPing/PingPayload.cs | 6 +- .../Class/Model/ServerPing/Player.cs | 4 +- .../Model/ServerPing/ServerPingModInfo.cs | 9 +- .../Model/ServerPing/ServerPingResult.cs | 4 +- .../Class/Model/ServerPing/VersionPayload.cs | 4 +- .../ProjBobcat/Class/Model/ServerSettings.cs | 2 +- .../ProjBobcat/Class/Model/TaskResult.cs | 15 +- .../Model/Version/Item/BigIntegerItem.cs | 13 +- .../Class/Model/Version/Item/ListItem.cs | 2 +- .../Class/Model/Version/Item/LongItem.cs | 9 +- .../ProjBobcat/Class/Model/VersionInfo.cs | 24 ++- .../YggdrasilAuth/AuthRefreshRequestModel.cs | 12 +- .../Model/YggdrasilAuth/AuthRequestModel.cs | 16 +- .../Model/YggdrasilAuth/AuthResponseModel.cs | 4 +- .../YggdrasilAuth/AuthTokenRequestModel.cs | 4 +- .../Class/Model/YggdrasilAuth/ErrorModel.cs | 8 +- .../YggdrasilAuth/PlayerTextureInfoModel.cs | 6 +- .../Model/YggdrasilAuth/ProfileInfoModel.cs | 6 +- .../Model/YggdrasilAuth/PropertyModel.cs | 6 +- .../YggdrasilAuth/SignOutRequestModel.cs | 4 +- .../Model/YggdrasilAuth/TextureInfoModel.cs | 2 +- .../Model/YggdrasilAuth/UserInfoModel.cs | 4 +- .../ProjBobcat/Class/VersionLocatorBase.cs | 8 +- .../Authenticator/MicrosoftAuthenticator.cs | 61 +++--- .../Authenticator/OfflineAuthenticator.cs | 4 +- .../Authenticator/YggdrasilAuthenticator.cs | 62 ++++-- .../Installer/FabricInstaller.cs | 5 +- .../HighVersionForgeInstaller.cs | 137 ++++++++------ .../ForgeInstaller/LegacyForgeInstaller.cs | 18 +- .../Installer/LiteLoaderInstaller.cs | 9 +- .../ModPackInstaller/CurseForgeInstaller.cs | 23 ++- .../ModPackInstaller/ModPackInstallerBase.cs | 2 +- .../ModPackInstaller/ModrinthInstaller.cs | 16 +- .../Installer/OptifineInstaller.cs | 7 +- .../Installer/QuiltInstaller.cs | 10 +- .../Launch/DefaultLaunchArgumentParser.cs | 45 +++-- .../Launch/DefaultLauncherAccountParser.cs | 60 +++--- .../Launch/DefaultLauncherProfileParser.cs | 80 +++++--- .../Launch/DefaultVersionLocator.cs | 54 +++--- .../Launch/GameCore/DefaultGameCore.cs | 26 ++- .../Launch/GameCore/GameCoreBase.cs | 12 +- .../LogAnalysis/DefaultLogAnalyzer.cs | 178 +----------------- .../Logging/DefaultGameLogResolver.cs | 59 +----- .../ResourceInfoResolver/AssetInfoResolver.cs | 19 +- .../GameLoggingInfoResolver.cs | 12 +- .../LibraryInfoResolver.cs | 43 ++--- .../ResourceInfoResolver/ResolverBase.cs | 4 +- .../VersionInfoResolver.cs | 12 +- .../Service/ServerPingService.cs | 10 +- .../Event/DownloadFileCompletedEventArgs.cs | 15 +- .../ForgeInstallStageChangedEventArgs.cs | 4 +- .../Event/GameResourceInfoResolveEventArgs.cs | 4 +- .../Event/InstallerStageChangedEventArgs.cs | 4 +- .../ProjBobcat/Event/LaunchLogEventArgs.cs | 4 +- .../Exceptions/UnknownGameNameException.cs | 23 +-- .../ProjBobcat/Interface/IAuthenticator.cs | 4 +- .../Interface/ICurseForgeInstaller.cs | 4 +- .../ProjBobcat/Interface/IFabricInstaller.cs | 2 +- .../ProjBobcat/Interface/IForgeInstaller.cs | 6 +- ProjBobcat/ProjBobcat/Interface/IGameCore.cs | 8 +- .../ProjBobcat/Interface/IGameResource.cs | 14 +- ProjBobcat/ProjBobcat/Interface/IInstaller.cs | 6 +- .../Interface/IModrinthInstaller.cs | 4 +- .../Interface/IOptifineInstaller.cs | 6 +- .../ProjBobcat/Interface/IQuiltInstaller.cs | 2 +- .../Interface/IResourceInfoResolver.cs | 4 +- .../ProjBobcat/Interface/IVersionLocator.cs | 4 +- .../Windows/DefaultMinecraftUWPCore.cs | 2 +- ProjBobcat/ProjBobcat/ProjBobcat.csproj | 5 +- 173 files changed, 1163 insertions(+), 1387 deletions(-) delete mode 100644 ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthTokenResponseModel.cs delete mode 100644 ProjBobcat/ProjBobcat/Class/Model/OperatingSystem.cs diff --git a/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs index f0a379ca..9a6083e9 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs @@ -42,7 +42,8 @@ public static string ResolveUserProperties(this IEnumerable? prop /// PropertyModel /// Profile集合 /// 转换好的UserProperty - public static AuthPropertyModel ToAuthProperty(this PropertyModel model, + public static AuthPropertyModel? ToAuthProperty( + this PropertyModel? model, IReadOnlyDictionary profiles) { return model is null @@ -61,11 +62,14 @@ public static AuthPropertyModel ToAuthProperty(this PropertyModel model, /// PropertyModel集合 /// Profile集合 /// 转换好的UserProperty - public static IEnumerable ToAuthProperties(this IEnumerable models, + public static IEnumerable ToAuthProperties( + this IEnumerable? models, IReadOnlyDictionary profiles) { return models == null - ? new List() - : models.Select(model => model.ToAuthProperty(profiles)); + ? [] + : models + .Select(model => model.ToAuthProperty(profiles)) + .OfType(); } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs index fbc5fa4b..53f8e1a7 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Json; using System.Text; @@ -14,7 +15,6 @@ namespace ProjBobcat.Class.Helper; #region Temp Models record AddonInfoReqModel(IEnumerable modIds); - record FileInfoReqModel(IEnumerable fileIds); [JsonSerializable(typeof(AddonInfoReqModel))] @@ -37,11 +37,14 @@ public static class CurseForgeAPIHelper { const string BaseUrl = "https://api.curseforge.com/v1"; - static string ApiKey { get; set; } + static string ApiKey { get; set; } = null!; static HttpClient Client => HttpClientHelper.DefaultClient; static HttpRequestMessage Req(HttpMethod method, string url) { + if (string.IsNullOrEmpty(ApiKey)) + throw new NullReferenceException("未设置 API KEY,请调用 SetApiKey(string apiKey) 来进行设置。"); + var req = new HttpRequestMessage(method, url); req.Headers.Add("x-api-key", ApiKey); diff --git a/ProjBobcat/ProjBobcat/Class/Helper/GameRegexHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/GameRegexHelper.cs index 500ff0aa..baf2ebea 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/GameRegexHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/GameRegexHelper.cs @@ -8,20 +8,10 @@ public static partial class GameRegexHelper const string ForgeLegacyJarRegexStr = "forge-[0-9]{1,}.[0-9]{1,}[.]?[0-9]{0,}-[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{4}-[0-9]{1,}.[0-9]{1,}[.]?[0-9]{0,}-universal.jar"; - - -#if NET8_0_OR_GREATER + [GeneratedRegex("[0-9]{1,}.[0-9]{1,}[.]?[0-9]{0,}")] public static partial Regex GameVersionRegex(); [GeneratedRegex("forge-[0-9]{1,}.[0-9]{1,}[.]?[0-9]{0,}-[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{4}-[0-9]{1,}.[0-9]{1,}[.]?[0-9]{0,}-universal.jar")] public static partial Regex ForgeLegacyJarRegex(); - -#else - - public static readonly Regex GameVersionRegex = new(GameVersionRegexStr, RegexOptions.Compiled); - - public static readonly Regex ForgeLegacyJarRegex = new(ForgeLegacyJarRegexStr, RegexOptions.Compiled); - -#endif } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs index 6cb6662c..947131ee 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs @@ -16,17 +16,10 @@ public static partial class HttpHelper { const string UriRegexStr = "((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+$,\\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww‌​w.|[-;:&=\\+$,\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?‌​(?:[\\w]*))?)"; - -#if NET8_0_OR_GREATER + [GeneratedRegex(UriRegexStr)] private static partial Regex UriRegex(); -#else - - static readonly Regex UriRegex = new(UriRegexStr, RegexOptions.Compiled); - -#endif - static HttpClient Client => HttpClientHelper.DefaultClient; /// @@ -34,14 +27,7 @@ public static partial class HttpHelper /// /// 待处理Uri /// 匹配的Uri - public static string RegexMatchUri(string uri) - { -#if NET8_0_OR_GREATER - return UriRegex().Match(uri).Value; -#else - return UriRegex.Match(uri).Value; -#endif - } + public static string RegexMatchUri(string uri) => UriRegex().Match(uri).Value; /// /// Http Delete方法 @@ -51,8 +37,11 @@ public static string RegexMatchUri(string uri) /// ContentType /// Auth 字段 /// - public static async Task Delete(string address, string data, - string contentType = "application/json", Tuple auth = default) + public static async Task Delete( + string address, + string data, + string contentType = "application/json", + ValueTuple auth = default) { using var req = new HttpRequestMessage(HttpMethod.Delete, new Uri(address)) { @@ -61,7 +50,9 @@ public static async Task Delete(string address, string data req.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); - if (!(auth?.Equals(default) ?? true)) + if (auth != default && + !string.IsNullOrEmpty(auth.Item1) && + !string.IsNullOrEmpty(auth.Item2)) req.Headers.Authorization = new AuthenticationHeaderValue(auth.Item1, auth.Item2); var acceptLanguage = new StringWithQualityHeaderValue(CultureInfo.CurrentCulture.Name); @@ -78,14 +69,18 @@ public static async Task Delete(string address, string data /// Get地址 /// Auth 字段 /// 获取到的字符串 - public static async Task Get(string address, Tuple auth = default) + public static async Task Get( + string address, + ValueTuple auth = default) { using var req = new HttpRequestMessage(HttpMethod.Get, new Uri(address)); var acceptLanguage = new StringWithQualityHeaderValue(CultureInfo.CurrentCulture.Name); req.Headers.AcceptLanguage.Add(acceptLanguage); - if (!(auth?.Equals(default) ?? true)) + if (auth != default && + !string.IsNullOrEmpty(auth.Item1) && + !string.IsNullOrEmpty(auth.Item2)) req.Headers.Authorization = new AuthenticationHeaderValue(auth.Item1, auth.Item2); var res = await Client.SendAsync(req); @@ -118,8 +113,11 @@ public static async Task PostFormData(string address, /// ContentType /// Auth 字段 /// - public static async Task Post(string address, string data, - string contentType = "application/json", Tuple auth = default) + public static async Task Post( + string address, + string data, + string contentType = "application/json", + ValueTuple auth = default) { using var req = new HttpRequestMessage(HttpMethod.Post, new Uri(address)) { @@ -128,7 +126,9 @@ public static async Task Post(string address, string data, req.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); - if (!(auth?.Equals(default) ?? true)) + if (auth != default && + !string.IsNullOrEmpty(auth.Item1) && + !string.IsNullOrEmpty(auth.Item2)) req.Headers.Authorization = new AuthenticationHeaderValue(auth.Item1, auth.Item2); var acceptLanguage = new StringWithQualityHeaderValue(CultureInfo.CurrentCulture.Name); @@ -146,8 +146,10 @@ public static async Task Post(string address, string data, /// 参数 /// ContentType /// - public static async Task PostWithParams(string address, - IEnumerable> param, string contentType = "application/json") + public static async Task PostWithParams( + string address, + IEnumerable> param, + string contentType = "application/json") { using var content = new FormUrlEncodedContent(param); content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(contentType); diff --git a/ProjBobcat/ProjBobcat/Class/Helper/MavenHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/MavenHelper.cs index 2178dd15..f49907fd 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/MavenHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/MavenHelper.cs @@ -9,12 +9,8 @@ namespace ProjBobcat.Class.Helper; /// public static partial class MavenHelper { -#if NET8_0_OR_GREATER [GeneratedRegex("\\.")] private static partial Regex GroupPathRegex(); -#else - static readonly Regex GroupPathRegex = new("\\.", RegexOptions.Compiled); -#endif /// /// 使用名字来解析Maven包信息。 @@ -69,14 +65,7 @@ public static partial class MavenHelper /// /// Maven Id /// 处理好的Group Path - public static string GetGroupPath(this string artifactId) - { -#if NET8_0_OR_GREATER - return GroupPathRegex().Replace(artifactId, "/"); -#else - return GroupPathRegex.Replace(artifactId, "/"); -#endif - } + public static string GetGroupPath(this string artifactId) => GroupPathRegex().Replace(artifactId, "/"); /// /// 获取Maven全名 diff --git a/ProjBobcat/ProjBobcat/Class/Helper/RandomHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/RandomHelper.cs index f3ebfa1b..82e36af1 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/RandomHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/RandomHelper.cs @@ -30,14 +30,7 @@ public static class RandomHelper /// /// /// - public static int RandomInteger(int min, int max) - { -#if NET8_0_OR_GREATER - return Random.Shared.Next(min, max + 1); -#else - return System.Security.Cryptography.RandomNumberGenerator.GetInt32(min, max + 1); -#endif - } + public static int RandomInteger(int min, int max) => Random.Shared.Next(min, max + 1); /// /// 随机打乱集合当中的元素 diff --git a/ProjBobcat/ProjBobcat/Class/Helper/StringHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/StringHelper.cs index b9261e5b..4a19dafa 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/StringHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/StringHelper.cs @@ -8,8 +8,9 @@ namespace ProjBobcat.Class.Helper; /// public static class StringHelper { - public static string FixPathArgument(string arg) + public static string? FixPathArgument(string? arg) { + if (string.IsNullOrEmpty(arg)) return null; if (!arg.Contains(' ')) return arg; return $"\"{arg}\""; diff --git a/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TomlParser.cs b/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TomlParser.cs index 696b9748..ea7d3873 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TomlParser.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TomlParser.cs @@ -1899,33 +1899,15 @@ public static bool IsNaN(string s) return s is NAN_VALUE or POS_NAN_VALUE or NEG_NAN_VALUE; } - public static bool IsInteger(string s) - { -#if NET8_0_OR_GREATER - return IntegerPattern().IsMatch(s); -#else - return IntegerPattern.IsMatch(s); -#endif - } + public static bool IsInteger(string s) => IntegerPattern().IsMatch(s); - public static bool IsFloat(string s) - { -#if NET8_0_OR_GREATER - return FloatPattern().IsMatch(s); -#else - return FloatPattern.IsMatch(s); -#endif - } + public static bool IsFloat(string s) => FloatPattern().IsMatch(s); public static bool IsIntegerWithBase(string s, out int numberBase) { numberBase = 10; - -#if NET8_0_OR_GREATER + var match = BasedIntegerPattern().Match(s); -#else - var match = BasedIntegerPattern.Match(s); -#endif if (!match.Success) return false; IntegerBases.TryGetValue(match.Groups["base"].Value, out numberBase); @@ -2051,8 +2033,7 @@ public static bool IsValueSeparator(char c) { return c is ITEM_SEPARATOR or ARRAY_END_SYMBOL or INLINE_TABLE_END_SYMBOL; } - -#if NET8_0_OR_GREATER + [GeneratedRegex("^(\\+|-)?(?!_)(0|(?!0)(_?\\d)*)$")] private static partial Regex IntegerPattern(); @@ -2062,28 +2043,6 @@ public static bool IsValueSeparator(char c) [GeneratedRegex("^(\\+|-)?0(?x|b|o)(?!_)(_?[0-9A-F])*$", RegexOptions.IgnoreCase)] private static partial Regex BasedIntegerPattern(); -#else - - /** - * A pattern to verify the integer value according to the TOML specification. - */ - static readonly Regex IntegerPattern = new("^(\\+|-)?(?!_)(0|(?!0)(_?\\d)*)$", RegexOptions.Compiled); - - /** - * A pattern to verify the float value according to the TOML specification. - */ - static readonly Regex FloatPattern = - new("^(\\+|-)?(?!_)(0|(?!0)(_?\\d)+)(((e(\\+|-)?(?!_)(_?\\d)+)?)|(\\.(?!_)(_?\\d)+(e(\\+|-)?(?!_)(_?\\d)+)?))$", - RegexOptions.IgnoreCase | RegexOptions.Compiled); - - /** - * A pattern to verify a special 0x, 0o and 0b forms of an integer according to the TOML specification. - */ - static readonly Regex BasedIntegerPattern = new("^(\\+|-)?0(?x|b|o)(?!_)(_?[0-9A-F])*$", - RegexOptions.IgnoreCase | RegexOptions.Compiled); - -#endif - #endregion } diff --git a/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TommyExtensions.cs b/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TommyExtensions.cs index 00946541..d662a3df 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TommyExtensions.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/TOMLParser/TommyExtensions.cs @@ -3,6 +3,8 @@ using System.IO; using System.Text; +#nullable disable + namespace ProjBobcat.Class.Helper.TOMLParser; /// @@ -225,4 +227,6 @@ public static TomlNode MergeWith(this TomlNode self, TomlNode with, bool mergeNe return self; } -} \ No newline at end of file +} + +#nullable restore \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/LaunchArgumentParserBase.cs b/ProjBobcat/ProjBobcat/Class/LaunchArgumentParserBase.cs index c15ddf11..e879cf0e 100644 --- a/ProjBobcat/ProjBobcat/Class/LaunchArgumentParserBase.cs +++ b/ProjBobcat/ProjBobcat/Class/LaunchArgumentParserBase.cs @@ -10,35 +10,38 @@ namespace ProjBobcat.Class; /// /// 提供了ProjBobcat启动参数解析器的底层实现和预设属性 /// -public abstract class LaunchArgumentParserBase : LauncherParserBase +public abstract class LaunchArgumentParserBase( + string rootPath, + LaunchSettings launchSettings, + ILauncherProfileParser launcherProfileParser, + IVersionLocator versionLocator, + AuthResultBase authResult) + : LauncherParserBase(rootPath) { /// /// 启动设置 /// - private protected LaunchSettings LaunchSettings { get; set; } + protected LaunchSettings LaunchSettings { get; init; } = launchSettings; /// /// launcher_profile 解析器 /// - private protected ILauncherProfileParser LauncherProfileParser { get; set; } + protected ILauncherProfileParser LauncherProfileParser { get; init; } = launcherProfileParser; /// /// 版本定位器 /// - - private protected IVersionLocator VersionLocator { get; set; } + protected IVersionLocator VersionLocator { get; init; } = versionLocator; /// /// 账户验证结果 /// - - private protected AuthResultBase AuthResult { get; set; } + protected AuthResultBase AuthResult { get; init; } = authResult; /// /// 游戏档案 /// - - private protected GameProfileModel GameProfile { get; set; } + protected GameProfileModel? GameProfile { get; init; } /// /// Native 根目录 @@ -54,15 +57,15 @@ public abstract class LaunchArgumentParserBase : LauncherParserBase /// /// Class 路径 /// - private protected string ClassPath { get; set; } + protected abstract string ClassPath { get; init; } /// /// 版本信息 /// - private protected VersionInfo VersionInfo { get; set; } + protected abstract VersionInfo VersionInfo { get; init; } /// /// 上一次的验证结果 /// - private protected AuthResultBase LastAuthResult { get; set; } + protected AuthResultBase? LastAuthResult { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/LaunchWrapper.cs b/ProjBobcat/ProjBobcat/Class/LaunchWrapper.cs index 38f52d6a..631b8a6e 100644 --- a/ProjBobcat/ProjBobcat/Class/LaunchWrapper.cs +++ b/ProjBobcat/ProjBobcat/Class/LaunchWrapper.cs @@ -12,23 +12,18 @@ namespace ProjBobcat.Class; /// /// 启动包装类 /// -public class LaunchWrapper : IDisposable +/// +/// 构造函数 +/// +/// 验证结果 +public class LaunchWrapper(AuthResultBase authResult) : IDisposable { bool _disposedValue; - /// - /// 构造函数 - /// - /// 验证结果 - public LaunchWrapper(AuthResultBase authResult) - { - AuthResult = authResult; - } - /// /// 验证结果 /// - public AuthResultBase AuthResult { get; } + public AuthResultBase AuthResult { get; } = authResult; /// /// 退出码 @@ -38,20 +33,13 @@ public LaunchWrapper(AuthResultBase authResult) /// /// 游戏核心 /// - public IGameCore GameCore { get; init; } + public required IGameCore GameCore { get; init; } /// /// 游戏进程 /// public Process? Process { get; init; } - // // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器 - // ~LaunchWrapper() - // { - // // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中 - // Dispose(disposing: false); - // } - public void Dispose() { // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中 @@ -106,6 +94,7 @@ void ProcessOnErrorDataReceived(object sender, DataReceivedEventArgs e) void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs e) { if (string.IsNullOrEmpty(e.Data)) return; + if (GameCore.GameLogResolver == null) return; var totalPrefix = GameCore.GameLogResolver.ResolveTotalPrefix(e.Data); var type = GameCore.GameLogResolver.ResolveLogType(string.IsNullOrEmpty(totalPrefix) @@ -144,7 +133,7 @@ void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs e) }); } - protected virtual void Dispose(bool disposing) + void Dispose(bool disposing) { if (!_disposedValue) { diff --git a/ProjBobcat/ProjBobcat/Class/LauncherParserBase.cs b/ProjBobcat/ProjBobcat/Class/LauncherParserBase.cs index 1008bc41..7988b819 100644 --- a/ProjBobcat/ProjBobcat/Class/LauncherParserBase.cs +++ b/ProjBobcat/ProjBobcat/Class/LauncherParserBase.cs @@ -3,7 +3,7 @@ /// /// 提供了ProjBobcat启动器配置解析器的底层实现和预设属性 /// -public abstract class LauncherParserBase +public abstract class LauncherParserBase(string rootPath) { - private protected string RootPath { get; init; } + protected string RootPath { get; init; } = rootPath; } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/AppxPackageInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/AppxPackageInfo.cs index e927c6bb..3574cc96 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/AppxPackageInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/AppxPackageInfo.cs @@ -6,43 +6,43 @@ public record AppxPackageInfo /// 应用程序的名称 /// 例如: Microsoft Minecraft UWP /// - public string Name { get; set; } + public string? Name { get; set; } /// /// 应用程序的发布者 /// 例如: Microsoft Corporation /// - public string Publisher { get; set; } + public string? Publisher { get; set; } /// /// 应用程序的架构 /// 例如: X64 /// - public string Architecture { get; set; } + public string? Architecture { get; set; } /// /// 应用程序的资源ID /// 例如: neutral /// - public string ResourceId { get; set; } + public string? ResourceId { get; set; } /// /// 应用程序的版本号 /// 例如: 1.19.8301.0 /// - public string Version { get; set; } + public string? Version { get; set; } /// /// 应用程序的完整包名称 /// 例如: Microsoft.MinecraftUWP_1.19.8301.0_x64__8wekyb3d8bbwe /// - public string PackageFullName { get; set; } + public string? PackageFullName { get; set; } /// /// 应用程序的安装位置 /// 例如: C:\Program Files\WindowsApps\Microsoft.MinecraftUWP_1.19.8301.0_x64__8wekyb3d8bbwe /// - public string InstallLocation { get; set; } + public string? InstallLocation { get; set; } /// /// 应用程序是否为框架 @@ -54,13 +54,13 @@ public record AppxPackageInfo /// 应用程序的包家族名称 /// 例如: Microsoft.MinecraftUWP_8wekyb3d8bbwe /// - public string PackageFamilyName { get; set; } + public string? PackageFamilyName { get; set; } /// /// 应用程序的发布者ID /// 例如: 8wekyb3d8bbwe /// - public string PublisherId { get; set; } + public string? PublisherId { get; set; } /// /// 应用程序是否为资源包 @@ -91,7 +91,7 @@ public record AppxPackageInfo /// 例如: {Microsoft.Services.Store.Engagement_10.0.19011.0_x64__8wekyb3d8bbwe, /// Microsoft.VCLibs.140.00_14.0.30704.0_x64__8wekyb3d8bbwe} /// - public string[] Dependencies { get; set; } + public string[]? Dependencies { get; set; } /// /// 应用程序是否为部分暂存的 @@ -103,11 +103,11 @@ public record AppxPackageInfo /// 应用程序的签名类型 /// 例如: Store /// - public string SignatureKind { get; set; } + public string? SignatureKind { get; set; } /// /// 应用程序的状态 /// 例如: Ok /// - public string Status { get; set; } + public string? Status { get; set; } } diff --git a/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs b/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs index bef41558..87f1a351 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs @@ -12,7 +12,7 @@ public class AssetFileInfo /// Hash检验码 /// [JsonPropertyName("hash")] - public string Hash { get; set; } + public required string Hash { get; init; } /// /// 文件大小 @@ -30,7 +30,7 @@ public class AssetObjectModel /// Asset Objects集合 /// [JsonPropertyName("objects")] - public IReadOnlyDictionary Objects { get; set; } + public required IReadOnlyDictionary Objects { get; init; } } [JsonSerializable(typeof(AssetObjectModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Auth/AuthResultBase.cs b/ProjBobcat/ProjBobcat/Class/Model/Auth/AuthResultBase.cs index e4c6f591..26cccd50 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Auth/AuthResultBase.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Auth/AuthResultBase.cs @@ -15,7 +15,7 @@ public class AuthResultBase /// /// 获取的AccessToken /// - public string AccessToken { get; set; } + public string? AccessToken { get; set; } /// /// 错误信息 @@ -30,5 +30,5 @@ public class AuthResultBase /// /// 用户信息 /// - public UserInfoModel User { get; set; } + public UserInfoModel? User { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Auth/MicrosoftAuthResult.cs b/ProjBobcat/ProjBobcat/Class/Model/Auth/MicrosoftAuthResult.cs index 03aa24c3..312ac8df 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Auth/MicrosoftAuthResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Auth/MicrosoftAuthResult.cs @@ -7,32 +7,32 @@ public class MicrosoftAuthResult : AuthResultBase /// /// 皮肤 /// - public string? Skin { get; set; } + public string? Skin { get; init; } /// /// 披风 /// - public string? Cape { get; set; } + public string? Cape { get; init; } /// /// 刷新用 Token /// - public string RefreshToken { get; set; } + public string? RefreshToken { get; init; } /// /// 验证时间 /// - public DateTime CurrentAuthTime { get; set; } + public DateTime CurrentAuthTime { get; init; } /// /// XBox UID /// - public string XBoxUid { get; set; } + public string? XBoxUid { get; init; } /// /// Token 失效时间 /// - public int ExpiresIn { get; set; } + public int ExpiresIn { get; init; } - public string Email { get; set; } + public string? Email { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Auth/YggdrasilAuthResult.cs b/ProjBobcat/ProjBobcat/Class/Model/Auth/YggdrasilAuthResult.cs index 037f3ae7..2ebaad70 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Auth/YggdrasilAuthResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Auth/YggdrasilAuthResult.cs @@ -10,8 +10,7 @@ public class YggdrasilAuthResult : AuthResultBase /// /// 可用的Profiles /// - public ProfileInfoModel[] Profiles { get; set; } - - public string LocalId { get; set; } - public string RemoteId { get; set; } + public ProfileInfoModel[]? Profiles { get; set; } + public string? LocalId { get; set; } + public string? RemoteId { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CPUInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/CPUInfo.cs index 58cc6de0..66ae5dc7 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CPUInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CPUInfo.cs @@ -1,7 +1,7 @@ namespace ProjBobcat.Class.Model; -public class CPUInfo +public readonly struct CPUInfo { - public double Usage { get; set; } - public string Name { get; set; } + public required double Usage { get; init; } + public required string Name { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs index 4fc09846..8b241870 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs @@ -7,17 +7,17 @@ public class FeaturedQueryOptions { public int GameId { get; set; } - [JsonPropertyName("addonIds")] public int[] AddonIds { get; set; } + [JsonPropertyName("addonIds")] public required int[] AddonIds { get; init; } - [JsonPropertyName("featuredCount")] public int FeaturedCount { get; set; } + [JsonPropertyName("featuredCount")] public required int FeaturedCount { get; init; } - [JsonPropertyName("popularCount")] public int PopularCount { get; set; } + [JsonPropertyName("popularCount")] public required int PopularCount { get; init; } - [JsonPropertyName("updatedCount")] public int UpdatedCount { get; set; } + [JsonPropertyName("updatedCount")] public required int UpdatedCount { get; init; } public static FeaturedQueryOptions Default => new() { - AddonIds = Array.Empty(), + AddonIds = [], FeaturedCount = 15, GameId = 432, PopularCount = 150, diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonAuthorInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonAuthorInfo.cs index fa29cacc..5d1af888 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonAuthorInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonAuthorInfo.cs @@ -5,9 +5,9 @@ namespace ProjBobcat.Class.Model.CurseForge; public class CurseForgeAddonAuthorInfo { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } [JsonPropertyName("projectId")] public int ProjectId { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonInfo.cs index 85605200..55a2059f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAddonInfo.cs @@ -8,53 +8,53 @@ public class CurseForgeAddonInfo { [JsonPropertyName("id")] public int Id { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } - [JsonPropertyName("authors")] public CurseForgeAddonAuthorInfo[] Authors { get; set; } - [JsonPropertyName("logo")] public CurseForgeAttachmentInfo Logo { get; set; } + [JsonPropertyName("authors")] public required CurseForgeAddonAuthorInfo[] Authors { get; init; } + [JsonPropertyName("logo")] public CurseForgeAttachmentInfo? Logo { get; set; } - [JsonPropertyName("screenshots")] public CurseForgeAttachmentInfo[] Screenshots { get; set; } + [JsonPropertyName("screenshots")] public CurseForgeAttachmentInfo[] Screenshots { get; set; } = []; - [JsonPropertyName("websiteUrl")] public string WebsiteUrl { get; set; } + [JsonPropertyName("websiteUrl")] public string? WebsiteUrl { get; set; } [JsonPropertyName("gameId")] public int GameId { get; set; } - [JsonPropertyName("summary")] public string Summary { get; set; } - [JsonPropertyName("links")] public IReadOnlyDictionary Links { get; set; } + [JsonPropertyName("summary")] public string? Summary { get; set; } + [JsonPropertyName("links")] public IReadOnlyDictionary Links { get; set; } = new Dictionary(); [JsonPropertyName("defaultFileId")] public int DefaultFileId { get; set; } [JsonPropertyName("releaseType")] public int ReleaseType { get; set; } [JsonPropertyName("downloadCount")] public double DownloadCount { get; set; } - [JsonPropertyName("latestFiles")] public CurseForgeLatestFileModel[] LatestFiles { get; set; } + [JsonPropertyName("latestFiles")] public CurseForgeLatestFileModel[] LatestFiles { get; set; } = []; - [JsonPropertyName("categories")] public CurseForgeCategoryInfo[] Categories { get; set; } + [JsonPropertyName("categories")] public CurseForgeCategoryInfo[] Categories { get; set; } = []; [JsonPropertyName("status")] public int Status { get; set; } [JsonPropertyName("primaryCategoryId")] public int PrimaryCategoryId { get; set; } - [JsonPropertyName("categorySection")] public CurseForgeCategorySectionInfo CategorySection { get; set; } + [JsonPropertyName("categorySection")] public CurseForgeCategorySectionInfo? CategorySection { get; set; } - [JsonPropertyName("slug")] public string Slug { get; set; } + [JsonPropertyName("slug")] public string? Slug { get; set; } [JsonPropertyName("gameVersionLatestFiles")] - public CurseForgeGameVersionLatestFiles[] GameVersionLatestFiles { get; set; } + public CurseForgeGameVersionLatestFiles[]? GameVersionLatestFiles { get; set; } [JsonPropertyName("isFeatured")] public bool IsFeatured { get; set; } [JsonPropertyName("gamePopularityRank")] public int GamePopularityRank { get; set; } - [JsonPropertyName("primaryLanguage")] public string PrimaryLanguage { get; set; } + [JsonPropertyName("primaryLanguage")] public string? PrimaryLanguage { get; set; } - [JsonPropertyName("gameSlug")] public string GameSlug { get; set; } + [JsonPropertyName("gameSlug")] public string? GameSlug { get; set; } - [JsonPropertyName("gameName")] public string GameName { get; set; } + [JsonPropertyName("gameName")] public string? GameName { get; set; } - [JsonPropertyName("portalName")] public string PortalName { get; set; } + [JsonPropertyName("portalName")] public string? PortalName { get; set; } [JsonPropertyName("dateModified")] public DateTime DateModified { get; set; } @@ -64,5 +64,5 @@ public class CurseForgeAddonInfo [JsonPropertyName("isAvailable")] public bool IsAvailable { get; set; } - [JsonPropertyName("isExperiemental")] public bool IsExperiemental { get; set; } + [JsonPropertyName("isExperiemental")] public bool IsExperimental { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAttachmentInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAttachmentInfo.cs index c0621c09..4e2eadf4 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAttachmentInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeAttachmentInfo.cs @@ -8,13 +8,13 @@ public class CurseForgeAttachmentInfo [JsonPropertyName("id")] public int Id { get; set; } - [JsonPropertyName("description")] public string Description { get; set; } + [JsonPropertyName("description")] public string? Description { get; set; } - [JsonPropertyName("thumbnailUrl")] public string ThumbnailUrl { get; set; } + [JsonPropertyName("thumbnailUrl")] public string? ThumbnailUrl { get; set; } - [JsonPropertyName("title")] public string Title { get; set; } + [JsonPropertyName("title")] public string? Title { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } [JsonPropertyName("status")] public int Status { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategoryInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategoryInfo.cs index 35e901a6..beb95397 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategoryInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategoryInfo.cs @@ -6,11 +6,11 @@ public class CurseForgeCategoryInfo { [JsonPropertyName("categoryId")] public int CategoryId { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } - [JsonPropertyName("avatarUrl")] public string AvatarUrl { get; set; } + [JsonPropertyName("avatarUrl")] public string? AvatarUrl { get; set; } [JsonPropertyName("parentId")] public int ParentId { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategorySectionInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategorySectionInfo.cs index c3ee004f..000982bd 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategorySectionInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeCategorySectionInfo.cs @@ -9,14 +9,14 @@ public class CurseForgeCategorySectionInfo [JsonPropertyName("gameId")] public int GameId { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } [JsonPropertyName("packageType")] public int PackageType { get; set; } - [JsonPropertyName("path")] public string Path { get; set; } + [JsonPropertyName("path")] public string? Path { get; set; } [JsonPropertyName("initialInclusionPattern")] - public string InitialInclusionPattern { get; set; } + public string? InitialInclusionPattern { get; set; } [JsonPropertyName("extraIncludePattern")] public JsonElement ExtraIncludePattern { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeFeaturedAddonModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeFeaturedAddonModel.cs index 1cae04e7..afbdb367 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeFeaturedAddonModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeFeaturedAddonModel.cs @@ -1,12 +1,16 @@ -using System.Text.Json.Serialization; +using System; +using System.Text.Json.Serialization; namespace ProjBobcat.Class.Model.CurseForge; public class CurseForgeFeaturedAddonModel { - [JsonPropertyName("featured")] public CurseForgeAddonInfo[] Featured { get; set; } + [JsonPropertyName("featured")] + public CurseForgeAddonInfo[] Featured { get; set; } = Array.Empty(); - [JsonPropertyName("popular")] public CurseForgeAddonInfo[] Popular { get; set; } + [JsonPropertyName("popular")] + public CurseForgeAddonInfo[] Popular { get; set; } = Array.Empty(); - [JsonPropertyName("recentlyUpdated")] public CurseForgeAddonInfo[] RecentlyUpdated { get; set; } + [JsonPropertyName("recentlyUpdated")] + public CurseForgeAddonInfo[] RecentlyUpdated { get; set; } = Array.Empty(); } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeGameVersionLatestFiles.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeGameVersionLatestFiles.cs index d16b14a3..3d1c74f4 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeGameVersionLatestFiles.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeGameVersionLatestFiles.cs @@ -5,11 +5,11 @@ namespace ProjBobcat.Class.Model.CurseForge; public class CurseForgeGameVersionLatestFiles { - [JsonPropertyName("gameVersion")] public string GameVersion { get; set; } + [JsonPropertyName("gameVersion")] public string? GameVersion { get; set; } [JsonPropertyName("projectFileId")] public int ProjectFileId { get; set; } - [JsonPropertyName("projectFileName")] public string ProjectFileName { get; set; } + [JsonPropertyName("projectFileName")] public string? ProjectFileName { get; set; } [JsonPropertyName("fileType")] public int FileType { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeLatestFileModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeLatestFileModel.cs index fc3caee6..3e7ceef7 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeLatestFileModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeLatestFileModel.cs @@ -8,9 +8,9 @@ public class CurseForgeLatestFileModel { [JsonPropertyName("id")] public int Id { get; set; } - [JsonPropertyName("displayName")] public string DisplayName { get; set; } + [JsonPropertyName("displayName")] public required string DisplayName { get; init; } - [JsonPropertyName("fileName")] public string FileName { get; set; } + [JsonPropertyName("fileName")] public required string FileName { get; init; } [JsonPropertyName("fileDate")] public DateTime FileDate { get; set; } @@ -20,25 +20,25 @@ public class CurseForgeLatestFileModel [JsonPropertyName("fileStatus")] public int FileStatus { get; set; } - [JsonPropertyName("downloadUrl")] public string DownloadUrl { get; set; } + [JsonPropertyName("downloadUrl")] public required string DownloadUrl { get; init; } [JsonPropertyName("isAlternate")] public bool IsAlternate { get; set; } [JsonPropertyName("alternateFileId")] public int AlternateFileId { get; set; } - [JsonPropertyName("dependencies")] public CurseForgeDependencyModel[] Dependencies { get; set; } + [JsonPropertyName("dependencies")] public CurseForgeDependencyModel[]? Dependencies { get; set; } [JsonPropertyName("isAvailable")] public bool IsAvailable { get; set; } - [JsonPropertyName("modules")] public CurseForgeModuleModel[] Modules { get; set; } + [JsonPropertyName("modules")] public CurseForgeModuleModel[]? Modules { get; set; } [JsonPropertyName("packageFingerprint")] public long PackageFingerprint { get; set; } - [JsonPropertyName("gameVersions")] public string[] GameVersions { get; set; } + [JsonPropertyName("gameVersions")] public required string[] GameVersions { get; init; } [JsonPropertyName("sortableGameVersion")] - public CurseForgeSortableGameVersionModel[] SortableGameVersion { get; set; } + public CurseForgeSortableGameVersionModel[]? SortableGameVersion { get; set; } [JsonPropertyName("installMetadata")] public JsonElement InstallMetadata { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs index 0b1a1fa2..1066d78a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs @@ -4,21 +4,21 @@ namespace ProjBobcat.Class.Model.CurseForge; public class CurseForgeManifestModel { - [JsonPropertyName("minecraft")] public CurseForgeMineCraftModel MineCraft { get; set; } + [JsonPropertyName("minecraft")] public required CurseForgeMineCraftModel MineCraft { get; init; } - [JsonPropertyName("manifestType")] public string ManifestType { get; set; } + [JsonPropertyName("manifestType")] public string? ManifestType { get; set; } [JsonPropertyName("manifestVersion")] public int ManifestVersion { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public required string Version { get; init; } - [JsonPropertyName("author")] public string Author { get; set; } + [JsonPropertyName("author")] public string? Author { get; set; } - [JsonPropertyName("files")] public CurseForgeFileModel[] Files { get; set; } + [JsonPropertyName("files")] public required CurseForgeFileModel[] Files { get; init; } - [JsonPropertyName("overrides")] public string Overrides { get; set; } + [JsonPropertyName("overrides")] public string? Overrides { get; set; } } [JsonSerializable(typeof(CurseForgeManifestModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeMineCraftModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeMineCraftModel.cs index bf38237f..0d538ec0 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeMineCraftModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeMineCraftModel.cs @@ -4,14 +4,14 @@ namespace ProjBobcat.Class.Model.CurseForge; public class CurseForgeModLoaderModel { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public string? Id { get; set; } [JsonPropertyName("primary")] public bool IsPrimary { get; set; } } public class CurseForgeMineCraftModel { - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public required string Version { get; init; } - [JsonPropertyName("modLoaders")] public CurseForgeModLoaderModel[] ModLoaders { get; set; } + [JsonPropertyName("modLoaders")] public CurseForgeModLoaderModel[]? ModLoaders { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeModuleModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeModuleModel.cs index 823ce514..8e4969b1 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeModuleModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeModuleModel.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.CurseForge; public class CurseForgeModuleModel { - [JsonPropertyName("foldername")] public string FolderName { get; set; } + [JsonPropertyName("foldername")] public string? FolderName { get; set; } [JsonPropertyName("fingerprint")] public long Fingerprint { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSearchCategoryModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSearchCategoryModel.cs index 463ee92d..f7cef8e4 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSearchCategoryModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSearchCategoryModel.cs @@ -7,13 +7,13 @@ public class CurseForgeSearchCategoryModel { [JsonPropertyName("id")] public int? Id { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("slug")] public string Slug { get; set; } + [JsonPropertyName("slug")] public string? Slug { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } - [JsonPropertyName("iconUrl")] public string IconUrl { get; set; } + [JsonPropertyName("iconUrl")] public string? IconUrl { get; set; } [JsonPropertyName("dateModified")] public DateTime? DateModified { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSortableGameVersionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSortableGameVersionModel.cs index c0fb7a31..9dd9fd37 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSortableGameVersionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeSortableGameVersionModel.cs @@ -6,12 +6,13 @@ namespace ProjBobcat.Class.Model.CurseForge; public class CurseForgeSortableGameVersionModel { [JsonPropertyName("gameVersionPadded")] - public string GameVersionPadded { get; set; } + public string? GameVersionPadded { get; set; } - [JsonPropertyName("gameVersion")] public string GameVersion { get; set; } + [JsonPropertyName("gameVersion")] + public string? GameVersion { get; set; } [JsonPropertyName("gameVersionReleaseDate")] public DateTime GameVersionReleaseDate { get; set; } - [JsonPropertyName("gameVersionName")] public string GameVersionName { get; set; } + [JsonPropertyName("gameVersionName")] public string? GameVersionName { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/DataModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/DataModel.cs index b691029f..eb2d9ca7 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/DataModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/DataModel.cs @@ -4,10 +4,10 @@ namespace ProjBobcat.Class.Model.CurseForge; public class DataModel { - [JsonPropertyName("data")] public T Data { get; set; } + [JsonPropertyName("data")] public T? Data { get; set; } } public class DataModelWithPagination : DataModel { - [JsonPropertyName("pagination")] public PaginationModel Pagination { get; set; } + [JsonPropertyName("pagination")] public PaginationModel? Pagination { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/DownloadCheckResult.cs b/ProjBobcat/ProjBobcat/Class/Model/DownloadCheckResult.cs index 53fd1e36..087778d0 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/DownloadCheckResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/DownloadCheckResult.cs @@ -8,5 +8,5 @@ public class DownloadCheckResult public long Size { get; set; } public int? StatusCode { get; set; } public bool SupportsResume { get; set; } - public Exception Exception { get; set; } + public Exception? Exception { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/DownloadFile.cs b/ProjBobcat/ProjBobcat/Class/Model/DownloadFile.cs index 78186c0b..380a617d 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/DownloadFile.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/DownloadFile.cs @@ -12,24 +12,23 @@ public class DownloadFile : IDisposable static readonly object CompletedEventKey = new(); static readonly object ChangedEventKey = new(); - protected readonly EventHandlerList ListEventDelegates = new(); - - bool disposedValue; + readonly EventHandlerList _listEventDelegates = new(); + bool _disposedValue; /// /// 下载Uri /// - public string DownloadUri { get; set; } + public required string DownloadUri { get; init; } /// /// 下载路径 /// - public string DownloadPath { get; set; } + public required string DownloadPath { get; init; } /// /// 保存的文件名 /// - public string FileName { get; set; } + public required string FileName { get; init; } /// /// 最大重试计数 @@ -39,24 +38,17 @@ public class DownloadFile : IDisposable /// /// 文件类型(仅在Lib/Asset补全时可用) /// - public ResourceType FileType { get; set; } + public ResourceType FileType { get; init; } /// /// 文件大小 /// - public long FileSize { get; set; } + public long FileSize { get; init; } /// /// 文件检验码 /// - public string CheckSum { get; set; } - - // // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器 - // ~DownloadFile() - // { - // // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中 - // Dispose(disposing: false); - // } + public string? CheckSum { get; init; } public void Dispose() { @@ -70,8 +62,8 @@ public void Dispose() /// public event EventHandler Completed { - add => ListEventDelegates.AddHandler(CompletedEventKey, value); - remove => ListEventDelegates.RemoveHandler(CompletedEventKey, value); + add => _listEventDelegates.AddHandler(CompletedEventKey, value); + remove => _listEventDelegates.RemoveHandler(CompletedEventKey, value); } /// @@ -79,14 +71,15 @@ public event EventHandler Completed /// public event EventHandler Changed { - add => ListEventDelegates.AddHandler(ChangedEventKey, value); - remove => ListEventDelegates.RemoveHandler(ChangedEventKey, value); + add => _listEventDelegates.AddHandler(ChangedEventKey, value); + remove => _listEventDelegates.RemoveHandler(ChangedEventKey, value); } public void OnChanged(double speed, double progress, long bytesReceived, long totalBytes) { - var eventList = ListEventDelegates; - var @event = (EventHandler)eventList[ChangedEventKey]; + var eventList = _listEventDelegates; + var @event = (EventHandler?)eventList[ChangedEventKey]; + @event?.Invoke(this, new DownloadFileChangedEventArgs { Speed = speed, @@ -98,22 +91,22 @@ public void OnChanged(double speed, double progress, long bytesReceived, long to public void OnCompleted(bool? success, Exception? ex, double averageSpeed) { - var eventList = ListEventDelegates; + var eventList = _listEventDelegates; var @event = (EventHandler?)eventList[CompletedEventKey]; @event?.Invoke(this, new DownloadFileCompletedEventArgs(success, ex, averageSpeed)); } protected virtual void Dispose(bool disposing) { - if (!disposedValue) + if (!_disposedValue) { if (disposing) // TODO: 释放托管状态(托管对象) - ListEventDelegates.Dispose(); + _listEventDelegates.Dispose(); // TODO: 释放未托管的资源(未托管的对象)并重写终结器 // TODO: 将大型字段设置为 null - disposedValue = true; + _disposedValue = true; } } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/DownloadRange.cs b/ProjBobcat/ProjBobcat/Class/Model/DownloadRange.cs index 38e38a85..a1756126 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/DownloadRange.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/DownloadRange.cs @@ -8,17 +8,17 @@ public class DownloadRange /// /// 开始字节 /// - public long Start { get; set; } + public required long Start { get; init; } /// /// 结束字节 /// - public long End { get; set; } + public required long End { get; init; } /// /// 临时文件名称 /// - public string TempFileName { get; set; } + public required string TempFileName { get; init; } public override string ToString() { diff --git a/ProjBobcat/ProjBobcat/Class/Model/DownloadSettings.cs b/ProjBobcat/ProjBobcat/Class/Model/DownloadSettings.cs index 441f918f..0f7fed40 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/DownloadSettings.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/DownloadSettings.cs @@ -40,7 +40,7 @@ public class DownloadSettings /// /// 请求源 /// - public string Host { get; set; } + public string? Host { get; init; } public HashAlgorithm GetHashAlgorithm() { @@ -58,8 +58,7 @@ public HashAlgorithm GetHashAlgorithm() public async Task HashDataAsync(string filePath, CancellationToken? token) { token ??= CancellationToken.None; - -#if NET8_0_OR_GREATER + await using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); return HashType switch @@ -71,18 +70,5 @@ public async Task HashDataAsync(string filePath, CancellationToken? toke HashType.SHA512 => await SHA512.HashDataAsync(fs, token.Value), _ => throw new NotSupportedException() }; -#else - var bytes = await File.ReadAllBytesAsync(filePath, token.Value); - - return HashType switch - { - HashType.MD5 => MD5.HashData(bytes), - HashType.SHA1 => SHA1.HashData(bytes), - HashType.SHA256 => SHA256.HashData(bytes), - HashType.SHA384 => SHA384.HashData(bytes), - HashType.SHA512 => SHA512.HashData(bytes), - _ => throw new NotSupportedException() - }; -#endif } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricArtifactModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricArtifactModel.cs index b11fc3c8..608807c0 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricArtifactModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricArtifactModel.cs @@ -7,7 +7,7 @@ public class FabricArtifactModel [JsonPropertyName("gameVersion")] public string? GameVersion { get; set; } [JsonPropertyName("separator")] public string? Separator { get; set; } [JsonPropertyName("build")] public int BuildNum { get; set; } - [JsonPropertyName("maven")] public string Maven { get; set; } - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("maven")] public required string Maven { get; init; } + [JsonPropertyName("version")] public required string Version { get; init; } [JsonPropertyName("stable")] public bool IsStable { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLauncherMeta.cs b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLauncherMeta.cs index e3c7914b..667025c8 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLauncherMeta.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLauncherMeta.cs @@ -5,14 +5,14 @@ namespace ProjBobcat.Class.Model.Fabric; public class FabricLibraries { - [JsonPropertyName("client")] public Library[] Client { get; set; } - [JsonPropertyName("common")] public Library[] Common { get; set; } - [JsonPropertyName("server")] public Library[] Server { get; set; } + [JsonPropertyName("client")] public Library[] Client { get; set; } = []; + [JsonPropertyName("common")] public Library[] Common { get; set; } = []; + [JsonPropertyName("server")] public Library[] Server { get; set; } = []; } public class FabricLauncherMeta { [JsonPropertyName("version")] public int Version { get; set; } - [JsonPropertyName("libraries")] public FabricLibraries Libraries { get; set; } + [JsonPropertyName("libraries")] public required FabricLibraries Libraries { get; init; } [JsonPropertyName("mainClass")] public JsonElement MainClass { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLoaderArtifactModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLoaderArtifactModel.cs index 228b3036..5f11433b 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLoaderArtifactModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricLoaderArtifactModel.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.Fabric; public class FabricLoaderArtifactModel { - [JsonPropertyName("loader")] public FabricArtifactModel Loader { get; set; } - [JsonPropertyName("intermediary")] public FabricArtifactModel Intermediary { get; set; } - [JsonPropertyName("launcherMeta")] public FabricLauncherMeta LauncherMeta { get; set; } + [JsonPropertyName("loader")] public required FabricArtifactModel Loader { get; init; } + [JsonPropertyName("intermediary")] public required FabricArtifactModel Intermediary { get; init; } + [JsonPropertyName("launcherMeta")] public required FabricLauncherMeta LauncherMeta { get; init; } } [JsonSerializable(typeof(FabricLoaderArtifactModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs index 37eb2cd5..9691e491 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs @@ -5,19 +5,19 @@ namespace ProjBobcat.Class.Model.Fabric; public class FabricFileInfo { - [JsonPropertyName("file")] public string File { get; set; } + [JsonPropertyName("file")] public string? File { get; set; } } public class ModUpdater { - [JsonPropertyName("strategy")] public string Strategy { get; set; } + [JsonPropertyName("strategy")] public string? Strategy { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } } public class Custom { - [JsonPropertyName("modUpdater")] public ModUpdater ModUpdater { get; set; } + [JsonPropertyName("modUpdater")] public ModUpdater? ModUpdater { get; set; } } public class FabricModInfoModel @@ -28,27 +28,27 @@ public class FabricModInfoModel [JsonPropertyName("version")] public string? Version { get; set; } - [JsonPropertyName("environment")] public string Environment { get; set; } + [JsonPropertyName("environment")] public string? Environment { get; set; } - [JsonPropertyName("entrypoints")] public IReadOnlyDictionary Entrypoints { get; set; } + [JsonPropertyName("entrypoints")] public IReadOnlyDictionary? Entrypoints { get; set; } - [JsonPropertyName("custom")] public Custom Custom { get; set; } + [JsonPropertyName("custom")] public Custom? Custom { get; set; } - [JsonPropertyName("depends")] public IReadOnlyDictionary Depends { get; set; } + [JsonPropertyName("depends")] public IReadOnlyDictionary? Depends { get; set; } - [JsonPropertyName("recommends")] public IReadOnlyDictionary Recommends { get; set; } + [JsonPropertyName("recommends")] public IReadOnlyDictionary? Recommends { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("description")] public string Description { get; set; } + [JsonPropertyName("description")] public string? Description { get; set; } - [JsonPropertyName("icon")] public string Icon { get; set; } + [JsonPropertyName("icon")] public string? Icon { get; set; } - [JsonPropertyName("authors")] public string[] Authors { get; set; } + [JsonPropertyName("authors")] public string[] Authors { get; set; } = []; - [JsonPropertyName("contacts")] public IReadOnlyDictionary Contacts { get; set; } + [JsonPropertyName("contacts")] public IReadOnlyDictionary? Contacts { get; set; } - [JsonPropertyName("jars")] public FabricFileInfo[] Jars { get; set; } + [JsonPropertyName("jars")] public FabricFileInfo[]? Jars { get; set; } } [JsonSerializable(typeof(FabricModInfoModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProcessorModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProcessorModel.cs index ed48df58..90394e38 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProcessorModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProcessorModel.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.Forge; public class ForgeInstallProcessorModel { - public ForgeInstallProfileProcessor Processor { get; set; } - public string[] Arguments { get; set; } - public Dictionary Outputs { get; set; } + public required ForgeInstallProfileProcessor Processor { get; init; } + public required string[] Arguments { get; init; } + public required IReadOnlyDictionary Outputs { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs b/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs index 17ca8e63..d44626af 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs @@ -5,51 +5,53 @@ namespace ProjBobcat.Class.Model.Forge; public class ForgeInstallProfileData { - [JsonPropertyName("client")] public string Client { get; set; } + [JsonPropertyName("client")] public string? Client { get; set; } - [JsonPropertyName("server")] public string Server { get; set; } + [JsonPropertyName("server")] public string? Server { get; set; } } public class ForgeInstallProfileProcessor { [JsonPropertyName("sides")] public string[]? Sides { get; set; } - [JsonPropertyName("jar")] public string Jar { get; set; } + [JsonPropertyName("jar")] public required string Jar { get; init; } - [JsonPropertyName("classpath")] public string[] ClassPath { get; set; } + [JsonPropertyName("classpath")] public required string[] ClassPath { get; init; } - [JsonPropertyName("args")] public string[] Arguments { get; set; } + [JsonPropertyName("args")] public required string[] Arguments { get; init; } - [JsonPropertyName("outputs")] public IReadOnlyDictionary Outputs { get; set; } + [JsonPropertyName("outputs")] public IReadOnlyDictionary? Outputs { get; set; } } public class ForgeInstallProfile { - [JsonPropertyName("_comment_")] public string[] Comments { get; set; } + [JsonPropertyName("_comment_")] public string[]? Comments { get; set; } [JsonPropertyName("spec")] public int Spec { get; set; } - [JsonPropertyName("profile")] public string Profile { get; set; } + [JsonPropertyName("profile")] public string? Profile { get; set; } - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public string? Version { get; set; } - [JsonPropertyName("icon")] public string Icon { get; set; } + [JsonPropertyName("icon")] public string? Icon { get; set; } - [JsonPropertyName("json")] public string Json { get; set; } + [JsonPropertyName("json")] public string? Json { get; set; } - [JsonPropertyName("path")] public string Path { get; set; } + [JsonPropertyName("path")] public string? Path { get; set; } - [JsonPropertyName("logo")] public string Logo { get; set; } + [JsonPropertyName("logo")] public string? Logo { get; set; } - [JsonPropertyName("minecraft")] public string MineCraft { get; set; } + [JsonPropertyName("minecraft")] public string? MineCraft { get; set; } - [JsonPropertyName("welcome")] public string Welcome { get; set; } + [JsonPropertyName("welcome")] public string? Welcome { get; set; } - [JsonPropertyName("data")] public IReadOnlyDictionary Data { get; set; } + [JsonPropertyName("data")] + public IReadOnlyDictionary Data { get; set; } = + new Dictionary(); - [JsonPropertyName("processors")] public ForgeInstallProfileProcessor[] Processors { get; set; } + [JsonPropertyName("processors")] public ForgeInstallProfileProcessor[] Processors { get; set; } = []; - [JsonPropertyName("libraries")] public Library[] Libraries { get; set; } + [JsonPropertyName("libraries")] public Library[] Libraries { get; set; } = []; } [JsonSerializable(typeof(ForgeInstallProfile))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs b/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs index ca10c26d..872119cf 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs @@ -8,34 +8,34 @@ namespace ProjBobcat.Class.Model.Forge; /// public class Install { - [JsonPropertyName("profileName")] public string ProfileName { get; set; } + [JsonPropertyName("profileName")] public string? ProfileName { get; set; } - [JsonPropertyName("target")] public string Target { get; set; } + [JsonPropertyName("target")] public string? Target { get; set; } - [JsonPropertyName("path")] public string Path { get; set; } + [JsonPropertyName("path")] public string? Path { get; set; } - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public string? Version { get; set; } - [JsonPropertyName("filePath")] public string FilePath { get; set; } + [JsonPropertyName("filePath")] public string? FilePath { get; set; } - [JsonPropertyName("welcome")] public string Welcome { get; set; } + [JsonPropertyName("welcome")] public string? Welcome { get; set; } - [JsonPropertyName("minecraft")] public string MineCraft { get; set; } + [JsonPropertyName("minecraft")] public string? MineCraft { get; set; } - [JsonPropertyName("mirrorList")] public string MirrorList { get; set; } + [JsonPropertyName("mirrorList")] public string? MirrorList { get; set; } - [JsonPropertyName("logo")] public string Logo { get; set; } + [JsonPropertyName("logo")] public string? Logo { get; set; } - [JsonPropertyName("modList")] public string ModList { get; set; } + [JsonPropertyName("modList")] public string? ModList { get; set; } } public class ForgeLibraries { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } - [JsonPropertyName("checksums")] public string[] CheckSums { get; set; } + [JsonPropertyName("checksums")] public string[]? CheckSums { get; set; } [JsonPropertyName("serverreq")] public bool ServerReq { get; set; } @@ -44,33 +44,33 @@ public class ForgeLibraries public class VersionInfo { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public required string Id { get; set; } - [JsonPropertyName("time")] public string Time { get; set; } + [JsonPropertyName("time")] public string? Time { get; set; } - [JsonPropertyName("releaseTime")] public string ReleaseTime { get; set; } + [JsonPropertyName("releaseTime")] public string? ReleaseTime { get; set; } - [JsonPropertyName("type")] public string Type { get; set; } + [JsonPropertyName("type")] public string? Type { get; set; } [JsonPropertyName("minecraftArguments")] - public string MinecraftArguments { get; set; } + public string? MinecraftArguments { get; set; } - [JsonPropertyName("mainClass")] public string MainClass { get; set; } + [JsonPropertyName("mainClass")] public string? MainClass { get; set; } - [JsonPropertyName("inheritsFrom")] public string InheritsFrom { get; set; } + [JsonPropertyName("inheritsFrom")] public required string InheritsFrom { get; set; } - [JsonPropertyName("jar")] public string Jar { get; set; } + [JsonPropertyName("jar")] public string? Jar { get; set; } - [JsonPropertyName("assets")] public string Assets { get; set; } + [JsonPropertyName("assets")] public string? Assets { get; set; } [JsonPropertyName("logging")] public JsonElement Logging { get; set; } - [JsonPropertyName("libraries")] public ForgeLibraries[] Libraries { get; set; } + [JsonPropertyName("libraries")] public ForgeLibraries[] Libraries { get; set; } = []; } public class Optional { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } [JsonPropertyName("client")] public bool Client { get; set; } @@ -78,13 +78,13 @@ public class Optional [JsonPropertyName("inject")] public bool Inject { get; set; } - [JsonPropertyName("desc")] public string Desc { get; set; } + [JsonPropertyName("desc")] public string? Desc { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } - [JsonPropertyName("artifact")] public string Artifact { get; set; } + [JsonPropertyName("artifact")] public string? Artifact { get; set; } - [JsonPropertyName("maven")] public string Maven { get; set; } + [JsonPropertyName("maven")] public string? Maven { get; set; } } /// @@ -92,11 +92,11 @@ public class Optional /// public class LegacyForgeInstallProfile { - [JsonPropertyName("install")] public Install Install { get; set; } + [JsonPropertyName("install")] public Install? Install { get; set; } - [JsonPropertyName("versionInfo")] public VersionInfo VersionInfo { get; set; } + [JsonPropertyName("versionInfo")] public required VersionInfo VersionInfo { get; set; } - [JsonPropertyName("optionals")] public Optional[] OptionalList { get; set; } + [JsonPropertyName("optionals")] public Optional[]? OptionalList { get; set; } } [JsonSerializable(typeof(VersionInfo))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/ForgeInstallResult.cs b/ProjBobcat/ProjBobcat/Class/Model/ForgeInstallResult.cs index c63b09c0..2abab52a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ForgeInstallResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ForgeInstallResult.cs @@ -15,5 +15,5 @@ public class ForgeInstallResult /// /// 错误信息 /// - public ErrorModel Error { get; set; } + public ErrorModel? Error { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameResource/AssetDownloadInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/GameResource/AssetDownloadInfo.cs index 32adb9cf..a96bfad0 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameResource/AssetDownloadInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameResource/AssetDownloadInfo.cs @@ -4,11 +4,11 @@ namespace ProjBobcat.Class.Model.GameResource; public class AssetDownloadInfo : IGameResource { - public string FileName { get; set; } - public string Path { get; set; } - public string Title { get; set; } - public ResourceType Type { get; set; } - public string Url { get; set; } - public long FileSize { get; set; } - public string CheckSum { get; set; } + public required string FileName { get; init; } + public required string Path { get; init; } + public required string Title { get; init; } + public required ResourceType Type { get; init; } + public required string Url { get; init; } + public required long FileSize { get; init; } + public required string? CheckSum { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameLoggingDownloadInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameLoggingDownloadInfo.cs index 36aec769..2018fe86 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameLoggingDownloadInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameLoggingDownloadInfo.cs @@ -4,11 +4,11 @@ namespace ProjBobcat.Class.Model.GameResource; public class GameLoggingDownloadInfo : IGameResource { - public string Path { get; set; } - public string Title { get; set; } - public ResourceType Type { get; set; } - public string? Url { get; set; } - public string FileName { get; set; } - public long FileSize { get; set; } - public string? CheckSum { get; set; } + public required string Path { get; init; } + public required string Title { get; init; } + public required ResourceType Type { get; init; } + public required string Url { get; init; } + public required string FileName { get; init; } + public required long FileSize { get; init; } + public required string? CheckSum { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameResource/LibraryDownloadInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/GameResource/LibraryDownloadInfo.cs index 3ce5dc3b..a7e94f54 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameResource/LibraryDownloadInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameResource/LibraryDownloadInfo.cs @@ -4,11 +4,11 @@ namespace ProjBobcat.Class.Model.GameResource; public class LibraryDownloadInfo : IGameResource { - public string FileName { get; set; } - public string Path { get; set; } - public string Title { get; set; } - public ResourceType Type { get; set; } - public string Url { get; set; } - public long FileSize { get; set; } - public string CheckSum { get; set; } + public required string FileName { get; init; } + public required string Path { get; init; } + public required string Title { get; init; } + public required ResourceType Type { get; init; } + public required string Url { get; init; } + public required long FileSize { get; init; } + public required string? CheckSum { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameResource/VersionJarDownloadInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/GameResource/VersionJarDownloadInfo.cs index 6fbf42d4..d429317a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameResource/VersionJarDownloadInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameResource/VersionJarDownloadInfo.cs @@ -4,11 +4,11 @@ namespace ProjBobcat.Class.Model.GameResource; public class VersionJarDownloadInfo : IGameResource { - public string Path { get; set; } - public string Title { get; set; } - public ResourceType Type { get; set; } - public string Url { get; set; } - public string FileName { get; set; } - public long FileSize { get; set; } - public string CheckSum { get; set; } + public required string Path { get; init; } + public required string Title { get; init; } + public required ResourceType Type { get; init; } + public required string Url { get; init; } + public required string FileName { get; init; } + public required long FileSize { get; init; } + public required string? CheckSum { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs b/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs index 984513c2..572b599a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs @@ -5,9 +5,10 @@ namespace ProjBobcat.Class.Model; public class GameRules { - [JsonPropertyName("action")] public string Action { get; set; } + [JsonPropertyName("action")] public required string Action { get; init; } - [JsonPropertyName("features")] public Dictionary Features { get; set; } + [JsonPropertyName("features")] + public IReadOnlyDictionary Features { get; set; } = new Dictionary(); } [JsonSerializable(typeof(GameRules))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/InstallerBase.cs b/ProjBobcat/ProjBobcat/Class/Model/InstallerBase.cs index 912e5475..99d0b3e1 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/InstallerBase.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/InstallerBase.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model; public abstract class InstallerBase : ProgressReportBase, IInstaller { - public string? RootPath { get; set; } - public string? CustomId { get; set; } - public string? InheritsFrom { get; set; } + public abstract string RootPath { get; init; } + public string? CustomId { get; init; } + public string? InheritsFrom { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/JavaVersionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/JavaVersionModel.cs index 774417b1..fe3e6d37 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/JavaVersionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/JavaVersionModel.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model; public class JavaVersionModel { - [JsonPropertyName("component")] public string Component { get; set; } + [JsonPropertyName("component")] public string? Component { get; set; } [JsonPropertyName("majorVersion")] public int MajorVersion { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs b/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs index 1ae23cb8..45816624 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs @@ -6,11 +6,11 @@ namespace ProjBobcat.Class.Model; public class OperatingSystemRules { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public string? Version { get; set; } - [JsonPropertyName("arch")] public string Arch { get; set; } + [JsonPropertyName("arch")] public string? Arch { get; set; } public bool IsAllow() { diff --git a/ProjBobcat/ProjBobcat/Class/Model/LaunchResult.cs b/ProjBobcat/ProjBobcat/Class/Model/LaunchResult.cs index 7edf078f..cbbd8242 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LaunchResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LaunchResult.cs @@ -6,9 +6,9 @@ namespace ProjBobcat.Class.Model; public class LaunchResult { - public LaunchErrorType ErrorType { get; set; } - public LaunchSettings LaunchSettings { get; set; } - public ErrorModel? Error { get; set; } - public TimeSpan RunTime { get; set; } - public Process? GameProcess { get; set; } + public LaunchErrorType ErrorType { get; init; } + public LaunchSettings? LaunchSettings { get; init; } + public ErrorModel? Error { get; init; } + public TimeSpan RunTime { get; init; } + public Process? GameProcess { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LaunchSettings.cs b/ProjBobcat/ProjBobcat/Class/Model/LaunchSettings.cs index 5b258725..d57685e4 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LaunchSettings.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LaunchSettings.cs @@ -11,12 +11,12 @@ public class GameArguments /// /// Java executable file /// - public string? JavaExecutable { get; set; } + public required string JavaExecutable { get; set; } public uint MinMemory { get; set; } - public uint MaxMemory { get; set; } + public required uint MaxMemory { get; init; } public ResolutionModel? Resolution { get; set; } - public GcType GcType { get; set; } + public required GcType GcType { get; init; } public IReadOnlyList? AdditionalJvmArguments { get; set; } public ServerSettings? ServerSettings { get; set; } public string? AdvanceArguments { get; set; } @@ -24,38 +24,38 @@ public class GameArguments public class LaunchSettings { - public string? GameName { get; set; } + public required string GameName { get; init; } /// /// Real game root, should be the root of /saves, /logs /// - public string GamePath { get; set; } + public required string GamePath { get; init; } /// /// The game resource path, should be the root of /libraries /// - public string GameResourcePath { get; set; } + public required string GameResourcePath { get; init; } /// /// Real version id, like 1.14, 1.14-forge-xxxx /// - public string Version { get; set; } + public required string Version { get; init; } /// /// 游戏窗口标题 /// - public string? WindowTitle { get; set; } + public string? WindowTitle { get; init; } - public IVersionLocator VersionLocator { get; set; } + public required IVersionLocator VersionLocator { get; init; } - public IAuthenticator? Authenticator { get; set; } - public ProfileInfoModel? SelectedProfile { get; set; } + public required IAuthenticator Authenticator { get; init; } + public ProfileInfoModel? SelectedProfile { get; init; } - public bool VersionInsulation { get; set; } - public string? LauncherName { get; set; } + public bool VersionInsulation { get; init; } + public string? LauncherName { get; init; } - public GameArguments? FallBackGameArguments { get; set; } - public GameArguments? GameArguments { get; set; } + public GameArguments? FallBackGameArguments { get; init; } + public required GameArguments GameArguments { get; init; } public override string ToString() { diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountModel.cs index 8416c0a3..a1e63424 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountModel.cs @@ -6,7 +6,7 @@ namespace ProjBobcat.Class.Model.LauncherAccount; public class AccountModel { - [JsonPropertyName("accessToken")] public string AccessToken { get; set; } + [JsonPropertyName("accessToken")] public required string AccessToken { get; set; } [JsonPropertyName("accessTokenExpiresAt")] public DateTime AccessTokenExpiresAt { get; set; } @@ -22,19 +22,19 @@ public class AccountModel [JsonPropertyName("legacy")] public bool Legacy { get; set; } - [JsonPropertyName("localId")] public string LocalId { get; set; } + [JsonPropertyName("localId")] public required string LocalId { get; set; } - [JsonPropertyName("minecraftProfile")] public AccountProfileModel MinecraftProfile { get; set; } + [JsonPropertyName("minecraftProfile")] public AccountProfileModel? MinecraftProfile { get; set; } [JsonPropertyName("persistent")] public bool Persistent { get; set; } - [JsonPropertyName("remoteId")] public string RemoteId { get; set; } + [JsonPropertyName("remoteId")] public required string RemoteId { get; set; } - [JsonPropertyName("type")] public string Type { get; set; } + [JsonPropertyName("type")] public required string Type { get; set; } - [JsonPropertyName("userProperites")] public AuthPropertyModel[] UserProperites { get; set; } + [JsonPropertyName("userProperites")] public AuthPropertyModel[]? UserProperites { get; set; } - [JsonPropertyName("username")] public string Username { get; set; } + [JsonPropertyName("username")] public required string Username { get; set; } [JsonPropertyName("__id")] public Guid Id { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountProfileModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountProfileModel.cs index 156704ab..5a8edbda 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountProfileModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/AccountProfileModel.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.LauncherAccount; public class AccountProfileModel { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public required string Id { get; init; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs index 3f4b8f66..d642e911 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs @@ -5,13 +5,14 @@ namespace ProjBobcat.Class.Model.LauncherAccount; public class LauncherAccountModel { - [JsonPropertyName("accounts")] public Dictionary? Accounts { get; set; } + [JsonPropertyName("accounts")] + public Dictionary? Accounts { get; set; } [JsonPropertyName("activeAccountLocalId")] - public string ActiveAccountLocalId { get; set; } + public string? ActiveAccountLocalId { get; set; } [JsonPropertyName("mojangClientToken")] - public string MojangClientToken { get; set; } + public required string MojangClientToken { get; init; } } [JsonSerializable(typeof(LauncherAccountModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthProfileModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthProfileModel.cs index 8f6c969a..6c82ad70 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthProfileModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthProfileModel.cs @@ -11,5 +11,5 @@ public class AuthProfileModel /// 显示名称 /// [JsonPropertyName("displayName")] - public string DisplayName { get; set; } + public required string DisplayName { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthPropertyModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthPropertyModel.cs index 18e14df6..71e5249c 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthPropertyModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/AuthPropertyModel.cs @@ -11,13 +11,13 @@ public class AuthPropertyModel /// 名称 /// [JsonPropertyName("name")] - public string Name { get; set; } + public required string Name { get; set; } /// /// Profile Id /// [JsonPropertyName("profileId")] - public string ProfileId { get; set; } + public string? ProfileId { get; set; } /// /// 用户Id @@ -29,5 +29,5 @@ public class AuthPropertyModel /// 值 /// [JsonPropertyName("value")] - public string Value { get; set; } + public required string Value { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/GameProfileModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/GameProfileModel.cs index d50f837a..edf7859e 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/GameProfileModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/GameProfileModel.cs @@ -12,13 +12,13 @@ public class GameProfileModel /// 名称 /// [JsonPropertyName("name")] - public string Name { get; set; } + public string? Name { get; set; } /// /// 游戏目录 /// [JsonPropertyName("gameDir")] - public string GameDir { get; set; } + public string? GameDir { get; set; } /// /// 创建时间 @@ -30,7 +30,7 @@ public class GameProfileModel /// Java虚拟机路径 /// [JsonPropertyName("javaDir")] - public string JavaDir { get; set; } + public string? JavaDir { get; set; } /// /// 游戏窗口分辨率 @@ -42,19 +42,19 @@ public class GameProfileModel /// 游戏图标 /// [JsonPropertyName("icon")] - public string Icon { get; set; } + public string? Icon { get; set; } /// /// Java虚拟机启动参数 /// [JsonPropertyName("javaArgs")] - public string JavaArgs { get; set; } + public string? JavaArgs { get; set; } /// /// 最后一次的版本Id /// [JsonPropertyName("lastVersionId")] - public string LastVersionId { get; set; } + public string? LastVersionId { get; set; } /// /// 最后一次启动 @@ -66,5 +66,5 @@ public class GameProfileModel /// 版本类型 /// [JsonPropertyName("type")] - public string Type { get; set; } + public string? Type { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs index aa028ac6..17e1aba2 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs @@ -5,13 +5,13 @@ namespace ProjBobcat.Class.Model.LauncherProfile; public class LauncherProfileModel { - [JsonPropertyName("profiles")] public Dictionary Profiles { get; set; } + [JsonPropertyName("profiles")] public Dictionary? Profiles { get; init; } - [JsonPropertyName("clientToken")] public string ClientToken { get; set; } + [JsonPropertyName("clientToken")] public string? ClientToken { get; init; } - [JsonPropertyName("selectedUser")] public SelectedUserModel SelectedUser { get; set; } + [JsonPropertyName("selectedUser")] public SelectedUserModel? SelectedUser { get; set; } - [JsonPropertyName("launcherVersion")] public LauncherVersionModel LauncherVersion { get; set; } + [JsonPropertyName("launcherVersion")] public LauncherVersionModel? LauncherVersion { get; init; } } [JsonSerializable(typeof(LauncherProfileModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherVersionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherVersionModel.cs index f4ad0949..ab295e08 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherVersionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherVersionModel.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.LauncherProfile; public class LauncherVersionModel { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } [JsonPropertyName("format")] public int Format { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/SelectedUserModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/SelectedUserModel.cs index 2796f5a8..2eebb781 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/SelectedUserModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/SelectedUserModel.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.LauncherProfile; public class SelectedUserModel { - [JsonPropertyName("account")] public string Account { get; set; } + [JsonPropertyName("account")] public string? Account { get; set; } - [JsonPropertyName("profile")] public string Profile { get; set; } + [JsonPropertyName("profile")] public string? Profile { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderBuildModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderBuildModel.cs index 328e842d..38f24138 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderBuildModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderBuildModel.cs @@ -4,13 +4,13 @@ namespace ProjBobcat.Class.Model.LiteLoader; public class LiteLoaderBuildModel { - [JsonPropertyName("tweakClass")] public string TweakClass { get; set; } - [JsonPropertyName("libraries")] public Library[] Libraries { get; set; } - [JsonPropertyName("stream")] public string Stream { get; set; } - [JsonPropertyName("file")] public string File { get; set; } - [JsonPropertyName("version")] public string Version { get; set; } - [JsonPropertyName("md5")] public string Md5 { get; set; } - [JsonPropertyName("timestamp")] public string Timestamp { get; set; } - [JsonPropertyName("srcJar")] public string SrcJar { get; set; } - [JsonPropertyName("mcpJar")] public string McpJar { get; set; } + [JsonPropertyName("tweakClass")] public required string TweakClass { get; set; } + [JsonPropertyName("libraries")] public Library[] Libraries { get; set; } = []; + [JsonPropertyName("stream")] public string? Stream { get; set; } + [JsonPropertyName("file")] public string? File { get; set; } + [JsonPropertyName("version")] public string? Version { get; set; } + [JsonPropertyName("md5")] public string? Md5 { get; set; } + [JsonPropertyName("timestamp")] public string? Timestamp { get; set; } + [JsonPropertyName("srcJar")] public string? SrcJar { get; set; } + [JsonPropertyName("mcpJar")] public string? McpJar { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderDownloadVersionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderDownloadVersionModel.cs index fd3d2f76..d2923dc5 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderDownloadVersionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LiteLoader/LiteLoaderDownloadVersionModel.cs @@ -4,12 +4,12 @@ namespace ProjBobcat.Class.Model.LiteLoader; public class LiteLoaderDownloadVersionModel { - [JsonPropertyName("_id")] public string Id { get; set; } - [JsonPropertyName("mcversion")] public string McVersion { get; set; } - [JsonPropertyName("build")] public LiteLoaderBuildModel Build { get; set; } - [JsonPropertyName("hash")] public string Hash { get; set; } - [JsonPropertyName("type")] public string Type { get; set; } - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("_id")] public string? Id { get; set; } + [JsonPropertyName("mcversion")] public required string McVersion { get; set; } + [JsonPropertyName("build")] public required LiteLoaderBuildModel Build { get; set; } + [JsonPropertyName("hash")] public string? Hash { get; set; } + [JsonPropertyName("type")] public required string Type { get; set; } + [JsonPropertyName("version")] public string? Version { get; set; } [JsonPropertyName("__v")] public int VersionLocker { get; set; } } diff --git a/ProjBobcat/ProjBobcat/Class/Model/MavenInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/MavenInfo.cs index 1fb0eda4..b481d915 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MavenInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MavenInfo.cs @@ -9,35 +9,35 @@ public class MavenInfo /// /// 组织名。 /// - public string OrganizationName { get; set; } + public required string OrganizationName { get; init; } /// /// 项目名。 /// - public string ArtifactId { get; set; } + public required string ArtifactId { get; init; } /// /// 版本号。 /// - public string Version { get; set; } + public required string Version { get; init; } /// /// 分类串。 /// - public string Classifier { get; set; } + public required string Classifier { get; init; } /// /// 类型。 /// - public string Type { get; set; } + public required string Type { get; init; } /// /// 是否为快照。 /// - public bool IsSnapshot { get; set; } + public required bool IsSnapshot { get; init; } /// /// 路径。 /// - public string Path { get; set; } + public required string Path { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MemoryInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/MemoryInfo.cs index 6903fb7c..d48d6366 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MemoryInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MemoryInfo.cs @@ -1,9 +1,9 @@ namespace ProjBobcat.Class.Model; -public class MemoryInfo +public readonly struct MemoryInfo { - public double Total { get; set; } - public double Used { get; set; } - public double Free { get; set; } - public double Percentage { get; set; } + public required double Total { get; init; } + public required double Used { get; init; } + public required double Free { get; init; } + public required double Percentage { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs index c43e7790..ad95bbd6 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs @@ -4,17 +4,17 @@ namespace ProjBobcat.Class.Model.Microsoft.Graph; public class DeviceIdResponseModel { - [JsonPropertyName("user_code")] public string UserCode { get; set; } + [JsonPropertyName("user_code")] public required string UserCode { get; set; } - [JsonPropertyName("device_code")] public string DeviceCode { get; set; } + [JsonPropertyName("device_code")] public required string DeviceCode { get; set; } - [JsonPropertyName("verification_uri")] public string VerificationUri { get; set; } + [JsonPropertyName("verification_uri")] public required string VerificationUri { get; set; } [JsonPropertyName("expires_in")] public int ExpiresIn { get; set; } [JsonPropertyName("interval")] public int Interval { get; set; } - [JsonPropertyName("message")] public string Message { get; set; } + [JsonPropertyName("message")] public string? Message { get; set; } } [JsonSerializable(typeof(DeviceIdResponseModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs index 4c4c6376..85a53438 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs @@ -4,17 +4,17 @@ namespace ProjBobcat.Class.Model.Microsoft.Graph; public class GraphAuthResultModel { - [JsonPropertyName("token_type")] public string TokenType { get; set; } + [JsonPropertyName("token_type")] public string? TokenType { get; set; } - [JsonPropertyName("scope")] public string Scope { get; set; } + [JsonPropertyName("scope")] public string? Scope { get; set; } [JsonPropertyName("expires_in")] public int ExpiresIn { get; set; } - [JsonPropertyName("access_token")] public string AccessToken { get; set; } + [JsonPropertyName("access_token")] public required string AccessToken { get; init; } - [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } + [JsonPropertyName("refresh_token")] public required string RefreshToken { get; init; } - [JsonPropertyName("id_token")] public string IdToken { get; set; } + [JsonPropertyName("id_token")] public string? IdToken { get; set; } } [JsonSerializable(typeof(GraphAuthResultModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs index a05ca03e..d6878415 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs @@ -5,12 +5,12 @@ namespace ProjBobcat.Class.Model.Microsoft.Graph; public class GraphResponseErrorModel { - [JsonPropertyName("error")] public string ErrorType { get; set; } + [JsonPropertyName("error")] public required string ErrorType { get; init; } [JsonPropertyName("error_description")] - public string ErrorDescription { get; set; } + public string? ErrorDescription { get; set; } - [JsonPropertyName("error_codes")] public int[] ErrorCodes { get; set; } + [JsonPropertyName("error_codes")] public int[]? ErrorCodes { get; set; } [JsonPropertyName("timestamp")] public DateTime TimeStamp { get; set; } @@ -18,7 +18,7 @@ public class GraphResponseErrorModel [JsonPropertyName("correlation_id")] public Guid CorrelationId { get; set; } - [JsonPropertyName("error_uri")] public string ErrorUri { get; set; } + [JsonPropertyName("error_uri")] public string? ErrorUri { get; set; } } [JsonSerializable(typeof(GraphResponseErrorModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs index 873dcb84..cc1416b5 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs @@ -5,13 +5,13 @@ namespace ProjBobcat.Class.Model.MicrosoftAuth; public class AuthMojangResponseModel { - [JsonPropertyName("username")] public string UserName { get; set; } + [JsonPropertyName("username")] public string? UserName { get; set; } - [JsonPropertyName("roles")] public JsonElement[] Roles { get; set; } + [JsonPropertyName("roles")] public JsonElement[]? Roles { get; set; } - [JsonPropertyName("access_token")] public string AccessToken { get; set; } + [JsonPropertyName("access_token")] public required string AccessToken { get; set; } - [JsonPropertyName("token_type")] public string TokenType { get; set; } + [JsonPropertyName("token_type")] public string? TokenType { get; set; } [JsonPropertyName("expires_in")] public long ExpiresIn { get; set; } } diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthTokenResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthTokenResponseModel.cs deleted file mode 100644 index 5c9a5081..00000000 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthTokenResponseModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Text.Json.Serialization; - -namespace ProjBobcat.Class.Model.MicrosoftAuth; - -public class AuthTokenResponseModel -{ - [JsonPropertyName("token_type")] public string TokenType { get; set; } - - [JsonPropertyName("expires_in")] public int ExpiresIn { get; set; } - - [JsonPropertyName("scope")] public string Scope { get; set; } - - [JsonPropertyName("access_token")] public string AccessToken { get; set; } - - [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } - - [JsonPropertyName("user_id")] public string UserId { get; set; } - - [JsonPropertyName("foci")] public string Foci { get; set; } -} \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs index d43c4e9b..9d91a357 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs @@ -4,16 +4,16 @@ namespace ProjBobcat.Class.Model.MicrosoftAuth; public class XBLProperties { - public string AuthMethod { get; set; } - public string SiteName { get; set; } - public string RpsTicket { get; set; } + public required string AuthMethod { get; init; } + public required string SiteName { get; init; } + public required string RpsTicket { get; init; } } public class AuthXBLRequestModel { - public XBLProperties Properties { get; set; } - public string RelyingParty { get; set; } - public string TokenType { get; set; } + public required XBLProperties Properties { get; init; } + public required string RelyingParty { get; init; } + public required string TokenType { get; init; } public static AuthXBLRequestModel Get(string accessToken) { diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs index 772e600c..378fdac9 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs @@ -4,10 +4,10 @@ namespace ProjBobcat.Class.Model.MicrosoftAuth; public class AuthXSTSErrorModel { - public string Identity { get; set; } + public string? Identity { get; set; } public uint XErr { get; set; } - public string Message { get; set; } - public string Redirect { get; set; } + public string? Message { get; set; } + public string? Redirect { get; set; } } [JsonSerializable(typeof(AuthXSTSErrorModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs index 178ea66a..950adc76 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs @@ -4,15 +4,15 @@ namespace ProjBobcat.Class.Model.MicrosoftAuth; public class XSTSProperties { - public string SandboxId { get; set; } - public string[] UserTokens { get; set; } + public required string SandboxId { get; init; } + public required string[] UserTokens { get; init; } } public class AuthXSTSRequestModel { - public XSTSProperties Properties { get; set; } - public string RelyingParty { get; set; } - public string TokenType { get; set; } + public required XSTSProperties Properties { get; init; } + public required string RelyingParty { get; init; } + public required string TokenType { get; init; } public static AuthXSTSRequestModel Get(string token, string relyingParty = "rp://api.minecraftservices.com/") { diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs index 4263be7f..26f1be20 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs @@ -8,7 +8,7 @@ public class AuthXSTSResponseModel { public DateTime IssueInstant { get; set; } public DateTime NotAfter { get; set; } - public string Token { get; set; } + public required string Token { get; set; } public JsonElement DisplayClaims { get; set; } } diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MicrosoftAuthenticatorAPISettings.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MicrosoftAuthenticatorAPISettings.cs index 0a5441c5..74ab7fe0 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MicrosoftAuthenticatorAPISettings.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MicrosoftAuthenticatorAPISettings.cs @@ -2,7 +2,7 @@ public class MicrosoftAuthenticatorAPISettings { - public string ClientId { get; set; } - public string TenentId { get; set; } - public string[] Scopes { get; set; } + public required string ClientId { get; init; } + public required string TenentId { get; init; } + public required string[] Scopes { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs index aa729e73..06301bc3 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs @@ -4,15 +4,15 @@ namespace ProjBobcat.Class.Model.MicrosoftAuth; public class MojangErrorResponseModel { - [JsonPropertyName("path")] public string Path { get; set; } + [JsonPropertyName("path")] public string? Path { get; set; } - [JsonPropertyName("errorType")] public string ErrorType { get; set; } + [JsonPropertyName("errorType")] public string? ErrorType { get; set; } - [JsonPropertyName("error")] public string Error { get; set; } + [JsonPropertyName("error")] public string? Error { get; set; } - [JsonPropertyName("errorMessage")] public string ErrorMessage { get; set; } + [JsonPropertyName("errorMessage")] public string? ErrorMessage { get; set; } - [JsonPropertyName("developerMessage")] public string DeveloperMessage { get; set; } + [JsonPropertyName("developerMessage")] public string? DeveloperMessage { get; set; } } [JsonSerializable(typeof(MojangErrorResponseModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs index 510bf7d8..326be84e 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs @@ -4,18 +4,18 @@ namespace ProjBobcat.Class.Model.MicrosoftAuth; public class OwnershipItem { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("signature")] public string Signature { get; set; } + [JsonPropertyName("signature")] public string? Signature { get; set; } } public class MojangOwnershipResponseModel { - [JsonPropertyName("items")] public OwnershipItem[] Items { get; set; } + [JsonPropertyName("items")] public OwnershipItem[]? Items { get; set; } - [JsonPropertyName("signature")] public string Signature { get; set; } + [JsonPropertyName("signature")] public string? Signature { get; set; } - [JsonPropertyName("keyId")] public string KeyId { get; set; } + [JsonPropertyName("keyId")] public string? KeyId { get; set; } } [JsonSerializable(typeof(MojangOwnershipResponseModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs index 9f76ac57..ea803a92 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs @@ -6,35 +6,35 @@ namespace ProjBobcat.Class.Model.MicrosoftAuth; public class MojangSkinProfile { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public string? Id { get; set; } - [JsonPropertyName("state")] public string State { get; set; } + [JsonPropertyName("state")] public string? State { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } - [JsonPropertyName("variant")] public string Variant { get; set; } + [JsonPropertyName("variant")] public string? Variant { get; set; } - [JsonPropertyName("alias")] public string Alias { get; set; } + [JsonPropertyName("alias")] public string? Alias { get; set; } } public class MojangProfileResponseModel { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public required string Id { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; set; } - [JsonPropertyName("skins")] public MojangSkinProfile[] Skins { get; set; } + [JsonPropertyName("skins")] public MojangSkinProfile[]? Skins { get; set; } - [JsonPropertyName("capes")] public MojangSkinProfile[] Capes { get; set; } + [JsonPropertyName("capes")] public MojangSkinProfile[]? Capes { get; set; } public MojangSkinProfile? GetActiveSkin() { - return Skins?.FirstOrDefault(x => x.State.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase)); + return Skins?.FirstOrDefault(x => x.State?.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase) ?? false); } public MojangSkinProfile? GetActiveCape() { - return Capes?.FirstOrDefault(x => x.State.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase)); + return Capes?.FirstOrDefault(x => x.State?.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase) ?? false); } } diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs index ebb359fe..d0db936d 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs @@ -4,11 +4,11 @@ namespace ProjBobcat.Class.Model.Modrinth; public class ModrinthCategoryInfo { - [JsonPropertyName("icon")] public string Icon { get; set; } + [JsonPropertyName("icon")] public string? Icon { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("project_type")] public string ProjectType { get; set; } + [JsonPropertyName("project_type")] public string? ProjectType { get; set; } } [JsonSerializable(typeof(ModrinthCategoryInfo))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackFileModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackFileModel.cs index e04f1fc9..d12844d8 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackFileModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackFileModel.cs @@ -7,9 +7,10 @@ public class ModrinthModPackFileModel { [JsonPropertyName("path")] public string? Path { get; set; } - [JsonPropertyName("hashes")] public IReadOnlyDictionary Hashes { get; set; } + [JsonPropertyName("hashes")] + public IReadOnlyDictionary Hashes { get; set; } = new Dictionary(); - [JsonPropertyName("downloads")] public string[] Downloads { get; set; } + [JsonPropertyName("downloads")] public string[] Downloads { get; set; } = []; [JsonPropertyName("fileSize")] public long Size { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackIndexModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackIndexModel.cs index 03b8a3f5..13a87c48 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackIndexModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthModPackIndexModel.cs @@ -15,9 +15,10 @@ public class ModrinthModPackIndexModel [JsonPropertyName("summary")] public string? Summary { get; set; } - [JsonPropertyName("files")] public ModrinthModPackFileModel[] Files { get; set; } + [JsonPropertyName("files")] public ModrinthModPackFileModel[] Files { get; set; } = []; - [JsonPropertyName("dependencies")] public IReadOnlyDictionary Dependencies { get; set; } + [JsonPropertyName("dependencies")] + public IReadOnlyDictionary Dependencies { get; set; } = new Dictionary(); } [JsonSerializable(typeof(ModrinthModPackIndexModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs index 3299aae6..0d712a86 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.Modrinth; public class ModrinthProjectDependencyInfo { - [JsonPropertyName("projects")] public ModrinthProjectInfo[] Projects { get; set; } + [JsonPropertyName("projects")] public ModrinthProjectInfo[] Projects { get; set; } = []; - [JsonPropertyName("versions")] public ModrinthVersionInfo[] Versions { get; set; } + [JsonPropertyName("versions")] public ModrinthVersionInfo[] Versions { get; set; } = []; } [JsonSerializable(typeof(ModrinthProjectDependencyInfo))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs index c638302c..6b1a99c9 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs @@ -6,45 +6,45 @@ namespace ProjBobcat.Class.Model.Modrinth; public class LicenseInfo { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public string? Id { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } } public class ModrinthProjectInfo : ModrinthProjectInfoBase { - [JsonPropertyName("id")] public string ProjectId { get; set; } + [JsonPropertyName("id")] public required string ProjectId { get; set; } - [JsonPropertyName("team")] public string TeamId { get; set; } + [JsonPropertyName("team")] public string? TeamId { get; set; } - [JsonPropertyName("body")] public string Body { get; set; } + [JsonPropertyName("body")] public string? Body { get; set; } - [JsonPropertyName("body_url")] public string BodyUrl { get; set; } + [JsonPropertyName("body_url")] public string? BodyUrl { get; set; } [JsonPropertyName("published")] public DateTime Published { get; set; } [JsonPropertyName("updated")] public DateTime Updated { get; set; } - [JsonPropertyName("status")] public string Status { get; set; } + [JsonPropertyName("status")] public string? Status { get; set; } [JsonPropertyName("moderator_message")] - public string ModeratorMessage { get; set; } + public string? ModeratorMessage { get; set; } - [JsonPropertyName("license")] public LicenseInfo License { get; set; } + [JsonPropertyName("license")] public LicenseInfo? License { get; set; } [JsonPropertyName("followers")] public int Followers { get; set; } - [JsonPropertyName("issues_url")] public string IssuesUrl { get; set; } + [JsonPropertyName("issues_url")] public string? IssuesUrl { get; set; } - [JsonPropertyName("source_url")] public string SourceUrl { get; set; } + [JsonPropertyName("source_url")] public string? SourceUrl { get; set; } - [JsonPropertyName("wiki_url")] public string WikiUrl { get; set; } + [JsonPropertyName("wiki_url")] public string? WikiUrl { get; set; } - [JsonPropertyName("discord_url")] public string DiscordUrl { get; set; } + [JsonPropertyName("discord_url")] public string? DiscordUrl { get; set; } - [JsonPropertyName("donation_urls")] public JsonElement[] DonationUrls { get; set; } + [JsonPropertyName("donation_urls")] public JsonElement[]? DonationUrls { get; set; } } [JsonSerializable(typeof(ModrinthProjectInfo))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoBase.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoBase.cs index fbff920b..857b2333 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoBase.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoBase.cs @@ -5,25 +5,25 @@ namespace ProjBobcat.Class.Model.Modrinth; public class ModrinthProjectInfoBase { - [JsonPropertyName("project_type")] public string ProjectType { get; set; } + [JsonPropertyName("project_type")] public required string ProjectType { get; set; } - [JsonPropertyName("slug")] public string Slug { get; set; } + [JsonPropertyName("slug")] public string? Slug { get; set; } - [JsonPropertyName("title")] public string Title { get; set; } + [JsonPropertyName("title")] public required string Title { get; set; } - [JsonPropertyName("description")] public string Description { get; set; } + [JsonPropertyName("description")] public required string Description { get; set; } - [JsonPropertyName("categories")] public string[] Categories { get; set; } + [JsonPropertyName("categories")] public string[] Categories { get; set; } = []; - [JsonPropertyName("versions")] public string[] Versions { get; set; } + [JsonPropertyName("versions")] public string[]? Versions { get; set; } [JsonPropertyName("downloads")] public int Downloads { get; set; } - [JsonPropertyName("icon_url")] public string IconUrl { get; set; } + [JsonPropertyName("icon_url")] public string? IconUrl { get; set; } - [JsonPropertyName("client_side")] public string ClientSide { get; set; } + [JsonPropertyName("client_side")] public string? ClientSide { get; set; } - [JsonPropertyName("server_side")] public string ServerSide { get; set; } + [JsonPropertyName("server_side")] public string? ServerSide { get; set; } - [JsonPropertyName("gallery")] public JsonElement[] Gallery { get; set; } + [JsonPropertyName("gallery")] public JsonElement[] Gallery { get; set; } = []; } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoSearchResult.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoSearchResult.cs index 8c86faa1..804b7f43 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoSearchResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfoSearchResult.cs @@ -5,9 +5,9 @@ namespace ProjBobcat.Class.Model.Modrinth; public class ModrinthProjectInfoSearchResult : ModrinthProjectInfoBase { - [JsonPropertyName("project_id")] public string ProjectId { get; set; } + [JsonPropertyName("project_id")] public required string ProjectId { get; set; } - [JsonPropertyName("author")] public string Author { get; set; } + [JsonPropertyName("author")] public required string Author { get; set; } [JsonPropertyName("follows")] public int Follows { get; set; } @@ -15,7 +15,7 @@ public class ModrinthProjectInfoSearchResult : ModrinthProjectInfoBase [JsonPropertyName("date_modified")] public DateTime DateModified { get; set; } - [JsonPropertyName("latest_version")] public string LatestVersion { get; set; } + [JsonPropertyName("latest_version")] public string? LatestVersion { get; set; } - [JsonPropertyName("license")] public string License { get; set; } + [JsonPropertyName("license")] public string? License { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchOptions.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchOptions.cs index d26244ff..0fdff53b 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchOptions.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchOptions.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.Modrinth; public class ModrinthSearchOptions { - public string Name { get; init; } + public string? Name { get; init; } public string? Category { get; init; } public string Index { get; init; } = "relevance"; public string? ProjectType { get; init; } = "mod"; diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs index f7d5c42c..ddb9a63f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.Modrinth; public class ModrinthSearchResult { - [JsonPropertyName("hits")] public ModrinthProjectInfoSearchResult[] Hits { get; set; } + [JsonPropertyName("hits")] public ModrinthProjectInfoSearchResult[] Hits { get; set; } = []; [JsonPropertyName("offset")] public int Offset { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs index e223911a..dba44f1f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs @@ -6,55 +6,55 @@ namespace ProjBobcat.Class.Model.Modrinth; public class ModrinthFileInfo { - [JsonPropertyName("hashes")] public IReadOnlyDictionary Hashes { get; set; } + [JsonPropertyName("hashes")] public IReadOnlyDictionary? Hashes { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } - [JsonPropertyName("filename")] public string FileName { get; set; } + [JsonPropertyName("filename")] public required string FileName { get; init; } [JsonPropertyName("primary")] public bool Primary { get; set; } } public class ModrinthDependency { - [JsonPropertyName("version_id")] public string VersionId { get; set; } + [JsonPropertyName("version_id")] public string? VersionId { get; set; } - [JsonPropertyName("project_id")] public string ProjectId { get; set; } + [JsonPropertyName("project_id")] public string? ProjectId { get; set; } - [JsonPropertyName("dependency_type")] public string DependencyType { get; set; } + [JsonPropertyName("dependency_type")] public string? DependencyType { get; set; } } public class ModrinthVersionInfo { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public string? Id { get; set; } - [JsonPropertyName("project_id")] public string ProjectId { get; set; } + [JsonPropertyName("project_id")] public string? ProjectId { get; set; } - [JsonPropertyName("author_id")] public string AuthorId { get; set; } + [JsonPropertyName("author_id")] public string? AuthorId { get; set; } [JsonPropertyName("featured")] public bool Featured { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("version_number")] public string VersionNumber { get; set; } + [JsonPropertyName("version_number")] public string? VersionNumber { get; set; } - [JsonPropertyName("changelog")] public string ChangeLog { get; set; } + [JsonPropertyName("changelog")] public string? ChangeLog { get; set; } - [JsonPropertyName("changelog_url")] public string ChangeLogUrl { get; set; } + [JsonPropertyName("changelog_url")] public string? ChangeLogUrl { get; set; } [JsonPropertyName("date_published")] public DateTime PublishDate { get; set; } [JsonPropertyName("downloads")] public int Downloads { get; set; } - [JsonPropertyName("version_type")] public string VersionType { get; set; } + [JsonPropertyName("version_type")] public string? VersionType { get; set; } - [JsonPropertyName("files")] public ModrinthFileInfo[] Files { get; set; } + [JsonPropertyName("files")] public ModrinthFileInfo[] Files { get; set; } = []; - [JsonPropertyName("loaders")] public string[] Loaders { get; set; } + [JsonPropertyName("loaders")] public string[]? Loaders { get; set; } - [JsonPropertyName("dependencies")] public ModrinthDependency[] Dependencies { get; set; } + [JsonPropertyName("dependencies")] public ModrinthDependency[]? Dependencies { get; set; } - [JsonPropertyName("game_versions")] public string[] GameVersion { get; set; } + [JsonPropertyName("game_versions")] public string[] GameVersion { get; set; } = []; } [JsonSerializable(typeof(ModrinthVersionInfo))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfile.cs b/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfile.cs index 404b4cb5..e3d7260a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfile.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfile.cs @@ -4,8 +4,8 @@ namespace ProjBobcat.Class.Model.Mojang; public class UserProfileProperty { - [JsonPropertyName("name")] public string Name { get; set; } - [JsonPropertyName("value")] public string Value { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } + [JsonPropertyName("value")] public required string Value { get; init; } } public class UserProfile @@ -13,8 +13,8 @@ public class UserProfile public const string MojangUserMineCraftProfileUrl = "https://api.mojang.com/users/profiles/minecraft/"; public const string MojangUserProfileUrl = "https://sessionserver.mojang.com/session/minecraft/profile/"; - [JsonPropertyName("id")] public string Id { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("id")] public string? Id { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } [JsonPropertyName("properties")] public UserProfileProperty[]? Properties { get; set; } } diff --git a/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfilePropertyValue.cs b/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfilePropertyValue.cs index cd18c7ff..8be82ce1 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfilePropertyValue.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Mojang/UserProfilePropertyValue.cs @@ -5,15 +5,15 @@ namespace ProjBobcat.Class.Model.Mojang; public class UrlModel { - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public required string Url { get; init; } } public class UserProfilePropertyValue { [JsonPropertyName("timestamp")] public long Timestamp { get; set; } - [JsonPropertyName("profileId")] public string ProfileId { get; set; } - [JsonPropertyName("profileName")] public string ProfileName { get; set; } - [JsonPropertyName("textures")] public IReadOnlyDictionary Textures { get; set; } + [JsonPropertyName("profileId")] public string? ProfileId { get; set; } + [JsonPropertyName("profileName")] public string? ProfileName { get; set; } + [JsonPropertyName("textures")] public IReadOnlyDictionary? Textures { get; set; } } [JsonSerializable(typeof(UserProfilePropertyValue))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs b/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs index 18d4e3db..8b7b2804 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs @@ -5,24 +5,24 @@ namespace ProjBobcat.Class.Model.Mojang; public class Latest { - [JsonPropertyName("release")] public string Release { get; set; } - [JsonPropertyName("snapshot")] public string Snapshot { get; set; } + [JsonPropertyName("release")] public required string Release { get; init; } + [JsonPropertyName("snapshot")] public required string Snapshot { get; init; } } public class VersionManifestVersionsModel { - [JsonPropertyName("id")] public string Id { get; set; } - [JsonPropertyName("type")] public string Type { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("id")] public required string Id { get; init; } + [JsonPropertyName("type")] public required string Type { get; init; } + [JsonPropertyName("url")] public required string Url { get; init; } [JsonPropertyName("time")] public DateTime Time { get; set; } [JsonPropertyName("releaseTime")] public DateTime ReleaseTime { get; set; } } public class VersionManifest { - [JsonPropertyName("latest")] public Latest Latest { get; set; } + [JsonPropertyName("latest")] public required Latest Latest { get; init; } - [JsonPropertyName("versions")] public VersionManifestVersionsModel[] Versions { get; set; } + [JsonPropertyName("versions")] public VersionManifestVersionsModel[]? Versions { get; set; } } [JsonSerializable(typeof(VersionManifest))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/NativeFileInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/NativeFileInfo.cs index a57df22d..bdf992fd 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/NativeFileInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/NativeFileInfo.cs @@ -2,6 +2,6 @@ public class NativeFileInfo { - public FileInfo FileInfo { get; set; } - public Extract Extract { get; set; } + public required FileInfo FileInfo { get; init; } + public Extract? Extract { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/NeoForge/NeoForgeVersionsModel.cs b/ProjBobcat/ProjBobcat/Class/Model/NeoForge/NeoForgeVersionsModel.cs index a7e38696..a38b54ec 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/NeoForge/NeoForgeVersionsModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/NeoForge/NeoForgeVersionsModel.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.NeoForge; public class NeoForgeVersionModel { - [JsonPropertyName("rawVersion")] public string RawVersion { get; set; } + [JsonPropertyName("rawVersion")] public required string RawVersion { get; init; } [JsonPropertyName("version")] public string? Version { get; set; } - [JsonPropertyName("mcversion")] public string MineCraftVersion { get; set; } + [JsonPropertyName("mcversion")] public required string MineCraftVersion { get; init; } } [JsonSerializable(typeof(NeoForgeVersionModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/OperatingSystem.cs b/ProjBobcat/ProjBobcat/Class/Model/OperatingSystem.cs deleted file mode 100644 index 3fb64781..00000000 --- a/ProjBobcat/ProjBobcat/Class/Model/OperatingSystem.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Text.Json.Serialization; - -namespace ProjBobcat.Class.Model; - -public class OperatingSystem -{ - [JsonPropertyName("name")] public string Name { get; set; } - - [JsonPropertyName("version")] public string Version { get; set; } -} \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Optifine/OptifineDownloadVersionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Optifine/OptifineDownloadVersionModel.cs index 683fb4e0..ca25a51b 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Optifine/OptifineDownloadVersionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Optifine/OptifineDownloadVersionModel.cs @@ -4,12 +4,18 @@ namespace ProjBobcat.Class.Model.Optifine; public class OptifineDownloadVersionModel { - [JsonPropertyName("_id")] public string Id { get; set; } - [JsonPropertyName("mcversion")] public string? McVersion { get; set; } - [JsonPropertyName("patch")] public string? Patch { get; set; } - [JsonPropertyName("type")] public string? Type { get; set; } - [JsonPropertyName("__v")] public int VersionLocker { get; set; } - [JsonPropertyName("filename")] public string FileName { get; set; } + [JsonPropertyName("_id")] + public required string Id { get; init; } + [JsonPropertyName("mcversion")] + public required string McVersion { get; init; } + [JsonPropertyName("patch")] + public required string Patch { get; init; } + [JsonPropertyName("type")] + public required string Type { get; init; } + [JsonPropertyName("__v")] + public required int VersionLocker { get; init; } + [JsonPropertyName("filename")] + public required string FileName { get; init; } } [JsonSerializable(typeof(OptifineDownloadVersionModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/PlayerUUID.cs b/ProjBobcat/ProjBobcat/Class/Model/PlayerUUID.cs index 996cfa06..4fccb873 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/PlayerUUID.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/PlayerUUID.cs @@ -23,12 +23,12 @@ public override void Write(Utf8JsonWriter writer, PlayerUUID value, JsonSerializ class PlayerUUIDTypeConverter : TypeConverter { - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) { return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) { if (value is string str) return new PlayerUUID(str); return base.ConvertFrom(context, culture, value); @@ -61,7 +61,7 @@ public int CompareTo(PlayerUUID other) return _guid.CompareTo(other._guid); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is PlayerUUID playerUuid) return _guid.Equals(playerUuid._guid); @@ -78,7 +78,7 @@ public override int GetHashCode() return _guid.GetHashCode(); } - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string? format, IFormatProvider? formatProvider) { return _guid.ToString(format, formatProvider); } diff --git a/ProjBobcat/ProjBobcat/Class/Model/ProgressReportBase.cs b/ProjBobcat/ProjBobcat/Class/Model/ProgressReportBase.cs index f402e07e..3f735787 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ProgressReportBase.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ProgressReportBase.cs @@ -6,9 +6,9 @@ namespace ProjBobcat.Class.Model; public class ProgressReportBase : IProgressReport { - public event EventHandler StageChangedEventDelegate; + public event EventHandler? StageChangedEventDelegate; - public virtual void InvokeStatusChangedEvent(string currentStage, double progress) + protected void InvokeStatusChangedEvent(string currentStage, double progress) { StageChangedEventDelegate?.Invoke(this, new StageChangedEventArgs { diff --git a/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltLoaderModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltLoaderModel.cs index 2dae2d03..b436a435 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltLoaderModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltLoaderModel.cs @@ -4,13 +4,13 @@ namespace ProjBobcat.Class.Model.Quilt; public class QuiltLoaderModel { - [JsonPropertyName("separator")] public string Separator { get; set; } + [JsonPropertyName("separator")] public string? Separator { get; set; } [JsonPropertyName("build")] public int Build { get; set; } - [JsonPropertyName("maven")] public string Maven { get; set; } + [JsonPropertyName("maven")] public string? Maven { get; set; } - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public string? Version { get; set; } } [JsonSerializable(typeof(QuiltLoaderModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltSupportGameModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltSupportGameModel.cs index 8963f293..d2a97fee 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltSupportGameModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Quilt/QuiltSupportGameModel.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.Quilt; public class QuiltSupportGameModel { - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public required string Version { get; init; } [JsonPropertyName("stable")] public bool Stable { get; set; } } diff --git a/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs index 021a90d3..7fef66a2 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs @@ -13,13 +13,14 @@ namespace ProjBobcat.Class.Model; public class FileInfo { [JsonIgnore] public string? Name { get; set; } - [JsonPropertyName("path")] public string Path { get; set; } + + [JsonPropertyName("path")] public string? Path { get; init; } - [JsonPropertyName("sha1")] public string Sha1 { get; set; } + [JsonPropertyName("sha1")] public string? Sha1 { get; set; } [JsonPropertyName("size")] public long Size { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } } #endregion @@ -28,10 +29,10 @@ public class FileInfo public class GameDownloadInfo { - [JsonPropertyName("client")] public FileInfo Client { get; set; } + [JsonPropertyName("client")] public FileInfo? Client { get; set; } [JsonPropertyName("client_mappings")] public FileInfo? ClientMappings { get; set; } - [JsonPropertyName("server")] public FileInfo Server { get; set; } + [JsonPropertyName("server")] public FileInfo? Server { get; set; } [JsonPropertyName("server_mappings")] public FileInfo? ServerMappings { get; set; } } @@ -41,15 +42,15 @@ public class GameDownloadInfo public class Asset { - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public required string Id { get; set; } - [JsonPropertyName("sha1")] public string Sha1 { get; set; } + [JsonPropertyName("sha1")] public string? Sha1 { get; set; } [JsonPropertyName("size")] public long Size { get; set; } [JsonPropertyName("totalSize")] public long TotalSize { get; set; } - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } } #endregion @@ -58,9 +59,9 @@ public class Asset public class Arguments { - [JsonPropertyName("game")] public JsonElement[] Game { get; set; } + [JsonPropertyName("game")] public JsonElement[]? Game { get; set; } - [JsonPropertyName("jvm")] public JsonElement[] Jvm { get; set; } + [JsonPropertyName("jvm")] public JsonElement[]? Jvm { get; set; } } #endregion @@ -69,34 +70,34 @@ public class Arguments public class Extract { - [JsonPropertyName("exclude")] public string[] Exclude { get; set; } + [JsonPropertyName("exclude")] public string[]? Exclude { get; set; } } public class Downloads { [JsonPropertyName("artifact")] public FileInfo? Artifact { get; set; } - [JsonPropertyName("classifiers")] public IReadOnlyDictionary Classifiers { get; set; } + [JsonPropertyName("classifiers")] public IReadOnlyDictionary? Classifiers { get; set; } } public class Library { [JsonPropertyName("downloads")] public Downloads? Downloads { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; set; } - [JsonPropertyName("extract")] public Extract Extract { get; set; } + [JsonPropertyName("extract")] public Extract? Extract { get; set; } - [JsonPropertyName("natives")] public IReadOnlyDictionary Natives { get; set; } + [JsonPropertyName("natives")] public IReadOnlyDictionary? Natives { get; set; } - [JsonPropertyName("rules")] public JvmRules[] Rules { get; set; } + [JsonPropertyName("rules")] public JvmRules[]? Rules { get; set; } - [JsonPropertyName("checksums")] public string[] CheckSums { get; set; } + [JsonPropertyName("checksums")] public string[]? CheckSums { get; set; } [JsonPropertyName("serverreq")] public bool ServerRequired { get; set; } [JsonPropertyName("clientreq")] public bool ClientRequired { get; set; } = true; - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } } #endregion @@ -105,16 +106,16 @@ public class Library public class Client { - [JsonPropertyName("argument")] public string Argument { get; set; } + [JsonPropertyName("argument")] public string? Argument { get; set; } - [JsonPropertyName("file")] public FileInfo File { get; set; } + [JsonPropertyName("file")] public FileInfo? File { get; set; } - [JsonPropertyName("type")] public string Type { get; set; } + [JsonPropertyName("type")] public string? Type { get; set; } } public class Logging { - [JsonPropertyName("client")] public Client Client { get; set; } + [JsonPropertyName("client")] public Client? Client { get; set; } } #endregion @@ -130,7 +131,7 @@ public class RawVersionModel /// Launch arguments for the older versions /// [JsonPropertyName("minecraftArguments")] - public string MinecraftArguments { get; set; } + public string? MinecraftArguments { get; set; } /// /// 启动参数 @@ -149,19 +150,19 @@ public class RawVersionModel /// 资源版本 /// [JsonPropertyName("assets")] - public string AssetsVersion { get; set; } + public string? AssetsVersion { get; set; } /// /// 游戏下载信息 /// [JsonPropertyName("downloads")] - public GameDownloadInfo Downloads { get; set; } + public GameDownloadInfo? Downloads { get; set; } /// /// 游戏版本 /// [JsonPropertyName("id")] - public string? Id { get; set; } + public required string Id { get; set; } [JsonPropertyName("javaVersion")] public JavaVersionModel? JavaVersion { get; set; } @@ -171,25 +172,25 @@ public class RawVersionModel /// version, based on which are be modifications with higher priority.) /// [JsonPropertyName("inheritsFrom")] - public string InheritsFrom { get; set; } + public string? InheritsFrom { get; set; } /// /// 库信息 /// [JsonPropertyName("libraries")] - public Library[] Libraries { get; set; } + public required Library[] Libraries { get; set; } /// /// 日志 /// [JsonPropertyName("logging")] - public Logging Logging { get; set; } + public Logging? Logging { get; set; } /// /// 主类 /// [JsonPropertyName("mainClass")] - public string? MainClass { get; set; } + public required string MainClass { get; set; } /// /// 最小启动器版本 @@ -213,7 +214,7 @@ public class RawVersionModel /// 类型 /// [JsonPropertyName("type")] - public string BuildType { get; set; } + public string? BuildType { get; set; } /// /// Jar 参数,LiteLoader 使用 diff --git a/ProjBobcat/ProjBobcat/Class/Model/ResourceCompleterCheckResult.cs b/ProjBobcat/ProjBobcat/Class/Model/ResourceCompleterCheckResult.cs index 07a30082..a94286dc 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ResourceCompleterCheckResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ResourceCompleterCheckResult.cs @@ -4,6 +4,6 @@ namespace ProjBobcat.Class.Model; public class ResourceCompleterCheckResult { - public bool IsLibDownloadFailed { get; set; } - public IEnumerable FailedFiles { get; set; } + public bool IsLibDownloadFailed { get; init; } + public required IReadOnlyCollection FailedFiles { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs index c19d3ab8..29a9d4cc 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs @@ -5,15 +5,15 @@ namespace ProjBobcat.Class.Model.ServerPing; public class PingPayload { - [JsonPropertyName("version")] public VersionPayload Version { get; set; } + [JsonPropertyName("version")] public VersionPayload? Version { get; set; } - [JsonPropertyName("players")] public PlayersPayload Players { get; set; } + [JsonPropertyName("players")] public PlayersPayload? Players { get; set; } [JsonPropertyName("description")] public JsonElement Description { get; set; } [JsonPropertyName("modinfo")] public ServerPingModInfo? ModInfo { get; set; } - [JsonPropertyName("favicon")] public string Icon { get; set; } + [JsonPropertyName("favicon")] public string? Icon { get; set; } } [JsonSerializable(typeof(PingPayload))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/Player.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/Player.cs index 5637d75b..d74f7335 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/Player.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/Player.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.ServerPing; public class Player { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("id")] public string Id { get; set; } + [JsonPropertyName("id")] public string? Id { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingModInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingModInfo.cs index d83cd4c6..021f11d5 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingModInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingModInfo.cs @@ -4,15 +4,14 @@ namespace ProjBobcat.Class.Model.ServerPing; public class ServerPingModInfo { - [JsonPropertyName("type")] public string Type { get; set; } + [JsonPropertyName("type")] public string? Type { get; set; } - [JsonPropertyName("modList")] public ModInfo[] ModList { get; set; } + [JsonPropertyName("modList")] public ModInfo[]? ModList { get; set; } } public class ModInfo { - [JsonPropertyName("modid")] public string ModId { get; set; } + [JsonPropertyName("modid")] public string? ModId { get; set; } - - [JsonPropertyName("version")] public string Version { get; set; } + [JsonPropertyName("version")] public string? Version { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingResult.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingResult.cs index 6daaa83a..f36c8107 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/ServerPingResult.cs @@ -2,6 +2,6 @@ public class ServerPingResult { - public PingPayload Response { get; set; } - public long Latency { get; set; } + public required PingPayload Response { get; init; } + public long Latency { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/VersionPayload.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/VersionPayload.cs index 64218c9d..4b0adb0e 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/VersionPayload.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/VersionPayload.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.Class.Model.ServerPing; public class VersionPayload { - [JsonPropertyName("protocol")] public int Protocol { get; set; } + [JsonPropertyName("protocol")] public int Protocol { get; init; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs index eb32beae..cddc4790 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs @@ -5,7 +5,7 @@ namespace ProjBobcat.Class.Model; public class ServerSettings : IDefaultValueChecker { - public string Address { get; set; } + public string? Address { get; set; } public ushort Port { get; set; } [JsonIgnore] public bool IsDefaultValue => IsDefault(); diff --git a/ProjBobcat/ProjBobcat/Class/Model/TaskResult.cs b/ProjBobcat/ProjBobcat/Class/Model/TaskResult.cs index dc77375e..1655f097 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/TaskResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/TaskResult.cs @@ -1,17 +1,10 @@ namespace ProjBobcat.Class.Model; -public class TaskResult +public class TaskResult(TaskResultStatus taskStatus, string message = "", T? value = default) { - public TaskResult(TaskResultStatus taskStatus, string message = "", T value = default) - { - TaskStatus = taskStatus; - Message = message; - Value = value; - } + public T? Value { get; } = value; - public T Value { get; } + public string Message { get; set; } = message; - public string Message { get; set; } - - public TaskResultStatus TaskStatus { get; set; } + public TaskResultStatus TaskStatus { get; set; } = taskStatus; } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Version/Item/BigIntegerItem.cs b/ProjBobcat/ProjBobcat/Class/Model/Version/Item/BigIntegerItem.cs index 76fe3974..595e3167 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Version/Item/BigIntegerItem.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Version/Item/BigIntegerItem.cs @@ -3,16 +3,11 @@ namespace ProjBobcat.Class.Model.Version.Item; -public class BigIntegerItem : IItem +public class BigIntegerItem(string bigIntStr) : IItem { - readonly BigInteger _value; + readonly BigInteger _value = BigInteger.TryParse(bigIntStr, out var outBigInt) ? outBigInt : BigInteger.Zero; - public BigIntegerItem(string bigIntStr) - { - _value = BigInteger.TryParse(bigIntStr, out var outBigInt) ? outBigInt : BigInteger.Zero; - } - - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (obj is not IItem item) return BigInteger.Zero.CompareTo(_value) == 0 ? 0 : 1; // 1.0 == 1, 1.1 > 1 @@ -31,7 +26,7 @@ public bool IsNull() return BigInteger.Zero.CompareTo(_value) == 0; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (this == obj) return true; if (obj is not BigIntegerItem that) return false; diff --git a/ProjBobcat/ProjBobcat/Class/Model/Version/Item/ListItem.cs b/ProjBobcat/ProjBobcat/Class/Model/Version/Item/ListItem.cs index b2820f3b..86860ade 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Version/Item/ListItem.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Version/Item/ListItem.cs @@ -7,7 +7,7 @@ namespace ProjBobcat.Class.Model.Version.Item; public class ListItem : List, IItem { - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (obj is not IItem item) { diff --git a/ProjBobcat/ProjBobcat/Class/Model/Version/Item/LongItem.cs b/ProjBobcat/ProjBobcat/Class/Model/Version/Item/LongItem.cs index dc3cf3bc..bb475cac 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Version/Item/LongItem.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Version/Item/LongItem.cs @@ -2,14 +2,9 @@ namespace ProjBobcat.Class.Model.Version.Item; -public class LongItem : IItem +public class LongItem(string longStr) : IItem { - readonly long _value; - - public LongItem(string longStr) - { - _value = long.TryParse(longStr, out var outLong) ? outLong : 0; - } + readonly long _value = long.TryParse(longStr, out var outLong) ? outLong : 0; public int CompareTo(object? obj) { diff --git a/ProjBobcat/ProjBobcat/Class/Model/VersionInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/VersionInfo.cs index 0ab42dd0..853af3bb 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/VersionInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/VersionInfo.cs @@ -8,33 +8,31 @@ public class VersionInfo /// 为启动器引用准备的带有tag的名称。 /// A name with a tag provided for the launcher's reference. /// - public string Name { get; set; } + public required string Name { get; set; } /// /// 该版本的真实id,例如1.14-forge-xxx /// The real id of this version, like 1.14-forge-xxx /// - public string? Id { get; set; } + public required string Id { get; set; } - public string DirName { get; set; } + public required string DirName { get; init; } public JavaVersionModel? JavaVersion { get; set; } - public string? MainClass { get; set; } - public string Assets { get; set; } + public required string MainClass { get; set; } + public string? Assets { get; init; } public Asset? AssetInfo { get; set; } - public List? Libraries { get; set; } - public List? Natives { get; set; } - public Logging Logging { get; set; } - public IEnumerable JvmArguments { get; set; } - public IEnumerable GameArguments { get; set; } - public Dictionary AvailableGameArguments { get; set; } + public required List Libraries { get; set; } + public required List Natives { get; set; } + public Logging? Logging { get; init; } + public IEnumerable? JvmArguments { get; set; } + public required IEnumerable GameArguments { get; set; } + public IReadOnlyDictionary? AvailableGameArguments { get; set; } -#nullable enable /// /// 在递归式继承中最古老的版本(递归终点)。 /// The oldest version inherited (recursive). /// public string? RootVersion { get; set; } -#nullable restore } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs index 76744880..7fee25c4 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs @@ -4,13 +4,17 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class AuthRefreshRequestModel { - [JsonPropertyName("accessToken")] public string AccessToken { get; set; } + [JsonPropertyName("accessToken")] + public required string AccessToken { get; init; } - [JsonPropertyName("clientToken")] public string ClientToken { get; set; } + [JsonPropertyName("clientToken")] + public required string ClientToken { get; init; } - [JsonPropertyName("requestUser")] public bool RequestUser { get; set; } + [JsonPropertyName("requestUser")] + public required bool RequestUser { get; init; } - [JsonPropertyName("selectedProfile")] public ProfileInfoModel SelectedProfile { get; set; } + [JsonPropertyName("selectedProfile")] + public required ProfileInfoModel SelectedProfile { get; init; } } [JsonSerializable(typeof(AuthRefreshRequestModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs index b449879d..396ea10f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs @@ -4,20 +4,24 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class Agent { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } - [JsonPropertyName("version")] public int Version { get; set; } + [JsonPropertyName("version")] public int Version { get; init; } } public class AuthRequestModel { - [JsonPropertyName("username")] public string Username { get; set; } + [JsonPropertyName("username")] + public required string Username { get; init; } - [JsonPropertyName("password")] public string Password { get; set; } + [JsonPropertyName("password")] + public required string Password { get; init; } - [JsonPropertyName("clientToken")] public string ClientToken { get; set; } + [JsonPropertyName("clientToken")] + public required string ClientToken { get; init; } - [JsonPropertyName("requestUser")] public bool RequestUser { get; set; } + [JsonPropertyName("requestUser")] + public bool RequestUser { get; init; } [JsonPropertyName("agent")] public Agent Agent { get; set; } = new() diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs index 01dfa844..c2307cfd 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class AuthResponseModel { - [JsonPropertyName("accessToken")] public string AccessToken { get; set; } + [JsonPropertyName("accessToken")] public string? AccessToken { get; set; } - [JsonPropertyName("clientToken")] public string ClientToken { get; set; } + [JsonPropertyName("clientToken")] public string? ClientToken { get; set; } [JsonPropertyName("availableProfiles")] public ProfileInfoModel[]? AvailableProfiles { get; set; } diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs index 6acfd168..c221b7f5 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class AuthTokenRequestModel { - [JsonPropertyName("accessToken")] public string AccessToken { get; set; } + [JsonPropertyName("accessToken")] public required string AccessToken { get; init; } - [JsonPropertyName("clientToken")] public string ClientToken { get; set; } + [JsonPropertyName("clientToken")] public required string ClientToken { get; init; } } [JsonSerializable(typeof(AuthTokenRequestModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs index 979ca160..6b113c3d 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs @@ -5,13 +5,13 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class ErrorModel { - [JsonPropertyName("error")] public string Error { get; set; } + [JsonPropertyName("error")] public string? Error { get; init; } - [JsonPropertyName("errorMessage")] public string ErrorMessage { get; set; } + [JsonPropertyName("errorMessage")] public string? ErrorMessage { get; init; } - [JsonPropertyName("cause")] public string Cause { get; set; } + [JsonPropertyName("cause")] public string? Cause { get; init; } - [JsonIgnore] public Exception Exception { get; set; } + [JsonIgnore] public Exception? Exception { get; init; } } [JsonSerializable(typeof(ErrorModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PlayerTextureInfoModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PlayerTextureInfoModel.cs index d30fe109..601702a7 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PlayerTextureInfoModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PlayerTextureInfoModel.cs @@ -7,9 +7,9 @@ public class PlayerTextureInfoModel { [JsonPropertyName("timestamp")] public long TimeStamp { get; set; } - [JsonPropertyName("profileId")] public string ProfileId { get; set; } + [JsonPropertyName("profileId")] public required string ProfileId { get; init; } - [JsonPropertyName("profileName")] public string ProfileName { get; set; } + [JsonPropertyName("profileName")] public required string ProfileName { get; init; } - [JsonPropertyName("textures")] public IReadOnlyDictionary Textures { get; set; } + [JsonPropertyName("textures")] public IReadOnlyDictionary? Textures { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ProfileInfoModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ProfileInfoModel.cs index dc25be3c..478b29d0 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ProfileInfoModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ProfileInfoModel.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class ProfileInfoModel { - [JsonPropertyName("id")] public PlayerUUID UUID { get; set; } + [JsonPropertyName("id")] public required PlayerUUID UUID { get; init; } - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } - [JsonPropertyName("properties")] public PropertyModel[] Properties { get; set; } + [JsonPropertyName("properties")] public PropertyModel[]? Properties { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PropertyModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PropertyModel.cs index e8c070ec..53e10f59 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PropertyModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/PropertyModel.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class PropertyModel { - [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("name")] public required string Name { get; init; } - [JsonPropertyName("value")] public string Value { get; set; } + [JsonPropertyName("value")] public required string Value { get; init; } - [JsonPropertyName("signature")] public string Signature { get; set; } + [JsonPropertyName("signature")] public string? Signature { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs index a5272a93..bf519b58 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs @@ -4,9 +4,9 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class SignOutRequestModel { - [JsonPropertyName("username")] public string Username { get; set; } + [JsonPropertyName("username")] public required string Username { get; init; } - [JsonPropertyName("password")] public string Password { get; set; } + [JsonPropertyName("password")] public required string Password { get; init; } } [JsonSerializable(typeof(SignOutRequestModel))] diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/TextureInfoModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/TextureInfoModel.cs index d7bc7c87..9d16ec8f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/TextureInfoModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/TextureInfoModel.cs @@ -5,7 +5,7 @@ namespace ProjBobcat.Class.Model.YggdrasilAuth; public class TextureInfoModel { - [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("url")] public string? Url { get; set; } [JsonPropertyName("metadata")] public JsonElement Metadata { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/UserInfoModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/UserInfoModel.cs index 88688ec3..7588917d 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/UserInfoModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/UserInfoModel.cs @@ -6,7 +6,7 @@ public class UserInfoModel { [JsonPropertyName("id")] public PlayerUUID UUID { get; set; } - [JsonPropertyName("username")] public string UserName { get; set; } + [JsonPropertyName("username")] public string? UserName { get; set; } - [JsonPropertyName("properties")] public PropertyModel[] Properties { get; set; } + [JsonPropertyName("properties")] public PropertyModel[]? Properties { get; set; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/VersionLocatorBase.cs b/ProjBobcat/ProjBobcat/Class/VersionLocatorBase.cs index 0b627adf..5fc14220 100644 --- a/ProjBobcat/ProjBobcat/Class/VersionLocatorBase.cs +++ b/ProjBobcat/ProjBobcat/Class/VersionLocatorBase.cs @@ -5,11 +5,11 @@ namespace ProjBobcat.Class; -public abstract class VersionLocatorBase : LauncherParserBase, IVersionLocator +public abstract class VersionLocatorBase(string rootPath) : LauncherParserBase(rootPath), IVersionLocator { - public ILauncherProfileParser LauncherProfileParser { get; set; } - public ILauncherAccountParser LauncherAccountParser { get; set; } - + public ILauncherProfileParser? LauncherProfileParser { get; init; } + public ILauncherAccountParser? LauncherAccountParser { get; init; } + public abstract VersionInfo? GetGame(string id); public abstract IEnumerable GetAllGames(); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs index 319b3b90..d32fb115 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs @@ -48,22 +48,22 @@ public MicrosoftAuthenticator() "请使用 Configure(MicrosoftAuthenticatorAPISettings apiSettings) 方法来配置验证器基础设置!"); } - public static MicrosoftAuthenticatorAPISettings ApiSettings { get; private set; } + public static MicrosoftAuthenticatorAPISettings? ApiSettings { get; private set; } public static string MSDeviceTokenRequestUrl => - $"https://login.microsoftonline.com/{ApiSettings.TenentId}/oauth2/v2.0/devicecode"; + $"https://login.microsoftonline.com/{ApiSettings!.TenentId}/oauth2/v2.0/devicecode"; - public static string MSDeviceTokenStatusUrl => - $"https://login.microsoftonline.com/{ApiSettings.TenentId}/oauth2/v2.0/token"; + public static string MSDeviceTokenStatusUrl => + $"https://login.microsoftonline.com/{ApiSettings!.TenentId}/oauth2/v2.0/token"; - public static string MSRefreshTokenRequestUrl => - $"https://login.microsoftonline.com/{ApiSettings.TenentId}/oauth2/v2.0/token"; + public static string MSRefreshTokenRequestUrl => + $"https://login.microsoftonline.com/{ApiSettings!.TenentId}/oauth2/v2.0/token"; static HttpClient DefaultClient => HttpClientHelper.DefaultClient; - public string Email { get; set; } - public Func> CacheTokenProvider { get; init; } - public ILauncherAccountParser LauncherAccountParser { get; set; } + public string? Email { get; set; } + public Func>? CacheTokenProvider { get; init; } + public required ILauncherAccountParser LauncherAccountParser { get; init; } public AuthResultBase Auth(bool userField = false) { @@ -86,7 +86,7 @@ public async Task AuthTaskAsync(bool userField = false) var (isCredentialValid, cacheAuthResult) = await CacheTokenProvider(); - if (!isCredentialValid) + if (!isCredentialValid || cacheAuthResult == null) return new MicrosoftAuthResult { AuthStatus = AuthStatus.Failed, @@ -141,15 +141,17 @@ await SendRequest(MSAuthXBLUrl, AuthXBLRequestModel.Get(accessToken), _ => "未知" }; + var errorMessage = errModel?.Message ?? "未知"; + if (!string.IsNullOrEmpty(errModel?.Redirect)) + errorMessage += $",相关链接:{errModel.Redirect}"; + var err = new ErrorModel { Cause = reason, Error = $"XSTS 认证失败,原因:{reason}", - ErrorMessage = errModel?.Message ?? "未知" + ErrorMessage = errorMessage }; - - if (!string.IsNullOrEmpty(errModel?.Redirect)) err.Error += $",相关链接:{errModel.Redirect}"; - + return new MicrosoftAuthResult { AuthStatus = AuthStatus.Failed, @@ -210,10 +212,23 @@ await SendRequest(MSAuthXBLUrl, AuthXBLRequestModel.Get(accessToken), #endregion + if (mcRes == null) + return new MicrosoftAuthResult + { + AuthStatus = AuthStatus.Failed, + Error = new ErrorModel + { + Error = "Mojang 服务器返回了无效的响应", + ErrorMessage = "XSTS 认证失败,可能是网络原因导致的", + Cause = "XSTS 认证失败" + } + }; + #region STAGE 4 - using var ownResRes = await HttpHelper.Get(MojangOwnershipUrl, - new Tuple("Bearer", mcRes.AccessToken)); + using var ownResRes = await HttpHelper.Get( + MojangOwnershipUrl, + ("Bearer", mcRes.AccessToken)); var ownRes = await ownResRes.Content.ReadFromJsonAsync(MojangOwnershipResponseModelContext.Default .MojangOwnershipResponseModel); @@ -235,7 +250,7 @@ await ownResRes.Content.ReadFromJsonAsync(MojangOwnershipResponseModelContext.De #region STAGE 5 using var profileResRes = - await HttpHelper.Get(MojangProfileUrl, new Tuple("Bearer", mcRes.AccessToken)); + await HttpHelper.Get(MojangProfileUrl, ("Bearer", mcRes.AccessToken)); var profileRes = await profileResRes.Content.ReadFromJsonAsync(MojangProfileResponseModelContext.Default .MojangProfileResponseModel); @@ -279,7 +294,7 @@ await profileResRes.Content.ReadFromJsonAsync(MojangErrorResponseModelContext.De Persistent = true, RemoteId = profileRes.Name, Type = "XBox", - UserProperites = Array.Empty(), + UserProperites = null, Username = profileRes.Name }; @@ -343,9 +358,9 @@ await profileResRes.Content.ReadFromJsonAsync(MojangErrorResponseModelContext.De }; } - public AuthResultBase GetLastAuthResult() + public AuthResultBase? GetLastAuthResult() { - var (_, value) = LauncherAccountParser.LauncherAccount.Accounts + var (_, value) = LauncherAccountParser.LauncherAccount.Accounts! .FirstOrDefault(x => x.Value.Username.Equals(Email, StringComparison.OrdinalIgnoreCase) && x.Value.Type.Equals("XBox", StringComparison.OrdinalIgnoreCase)); @@ -355,8 +370,8 @@ public AuthResultBase GetLastAuthResult() var sP = new ProfileInfoModel { - Name = value.MinecraftProfile.Name, - UUID = new PlayerUUID(value.MinecraftProfile.Id) + Name = value.MinecraftProfile?.Name ?? Email ?? string.Empty, + UUID = new PlayerUUID(value.MinecraftProfile?.Id ?? Email ?? string.Empty) }; return new MicrosoftAuthResult @@ -403,7 +418,7 @@ public static void Configure(MicrosoftAuthenticatorAPISettings apiSettings) var deviceTokenRequestDic = new[] { - new KeyValuePair("client_id", ApiSettings.ClientId), + new KeyValuePair("client_id", ApiSettings!.ClientId), new KeyValuePair("scope", string.Join(' ', ApiSettings.Scopes)) }; diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs index 3d91e6ad..76135448 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs @@ -18,12 +18,12 @@ public class OfflineAuthenticator : IAuthenticator /// /// 获取或设置用户名。 /// - public string Username { get; init; } + public required string Username { get; init; } /// /// 获取或设置启动程序配置文件分析器。 /// - public ILauncherAccountParser LauncherAccountParser { get; set; } + public required ILauncherAccountParser LauncherAccountParser { get; init; } /// /// 验证凭据。 diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs index 4e0143aa..431a66e7 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http.Json; @@ -28,12 +29,12 @@ public class YggdrasilAuthenticator : IAuthenticator /// /// 获取或设置邮箱。 /// - public string Email { get; init; } + public required string Email { get; init; } /// /// 获取或设置密码。 /// - public string Password { get; init; } + public required string Password { get; init; } /// /// 获取或设置验证服务器。 @@ -71,7 +72,7 @@ public class YggdrasilAuthenticator : IAuthenticator string SignOutAddress => $"{AuthServer}{(string.IsNullOrEmpty(AuthServer) ? OfficialAuthServer : "/authserver")}/signout"; - public ILauncherAccountParser LauncherAccountParser { get; set; } + public required ILauncherAccountParser LauncherAccountParser { get; init; } /// /// 验证凭据。 @@ -155,13 +156,28 @@ public async Task AuthTaskAsync(bool userField = false) Cause = "可能是因为您还没有购买正版游戏或是账户服务器出现了问题!" } }; + + if (result.AvailableProfiles == null || result.AvailableProfiles.Length == 0) + return new YggdrasilAuthResult + { + AuthStatus = AuthStatus.Failed, + Error = new ErrorModel + { + Error = "没有发现档案", + ErrorMessage = "没有在返回消息中发现任何可用的档案", + Cause = "可能是因为您还没有购买正版游戏或是账户服务器出现了问题!" + } + }; - var profiles = result.AvailableProfiles.ToDictionary(profile => profile.UUID, - profile => new AuthProfileModel { DisplayName = profile.Name }); + var profiles = + result.AvailableProfiles + .ToDictionary(profile => profile.UUID, + profile => new AuthProfileModel { DisplayName = profile.Name }) + .AsReadOnly(); foreach (var (playerUuid, authProfileModel) in profiles) { - var ids = LauncherAccountParser.LauncherAccount.Accounts.Where(a => + var ids = LauncherAccountParser.LauncherAccount.Accounts!.Where(a => (a.Value.MinecraftProfile?.Name?.Equals(authProfileModel.DisplayName, StringComparison.OrdinalIgnoreCase) ?? false) && (a.Value.MinecraftProfile?.Id?.Equals(playerUuid.ToString(), StringComparison.OrdinalIgnoreCase) ?? @@ -250,7 +266,7 @@ public async Task AuthTaskAsync(bool userField = false) public AuthResultBase GetLastAuthResult() { var profile = - LauncherAccountParser.LauncherAccount.Accounts.Values.FirstOrDefault(a => + LauncherAccountParser.LauncherAccount.Accounts!.Values.FirstOrDefault(a => a.Username.Equals(Email, StringComparison.OrdinalIgnoreCase)); if (profile is null) @@ -275,7 +291,7 @@ public AuthResultBase GetLastAuthResult() new ProfileInfoModel { Name = profile.Username, - Properties = profile.UserProperites.Select(x => new PropertyModel + Properties = profile.UserProperites?.Select(x => new PropertyModel { Name = x.Name, Value = x.Value @@ -302,6 +318,11 @@ public AuthResultBase GetLastAuthResult() public async Task AuthRefreshTaskAsync(AuthResponseModel response, bool userField = false) { + if (string.IsNullOrEmpty(response.AccessToken) || + string.IsNullOrEmpty(response.ClientToken) || + response.SelectedProfile == null) + throw new ArgumentException(nameof(response)); + var requestModel = new AuthRefreshRequestModel { AccessToken = response.AccessToken, @@ -327,7 +348,20 @@ public async Task AuthRefreshTaskAsync(AuthResponseModel respons Error = error }; case AuthResponseModel authResponse: - if (authResponse.SelectedProfile == null) + if (authResponse.User == null || + string.IsNullOrEmpty(authResponse.AccessToken)) + return new AuthResultBase + { + AuthStatus = AuthStatus.Failed, + Error = new ErrorModel + { + Error = "无效的用户字段", + ErrorMessage = "用户字段缺少了部分重要数据,请联系开发者" + } + }; + + if (authResponse.SelectedProfile == null || + (authResponse.AvailableProfiles == null || authResponse.AvailableProfiles.Length == 0)) return new AuthResultBase { AuthStatus = AuthStatus.Failed, @@ -339,11 +373,15 @@ public async Task AuthRefreshTaskAsync(AuthResponseModel respons } }; - var profiles = authResponse.AvailableProfiles.ToDictionary(profile => profile.UUID, - profile => new AuthProfileModel { DisplayName = profile.Name }); + var profiles = + authResponse.AvailableProfiles + .ToDictionary( + profile => profile.UUID, + profile => new AuthProfileModel { DisplayName = profile.Name }) + .AsReadOnly(); var uuid = authResponse.User.UUID.ToString(); - var (_, value) = LauncherAccountParser.LauncherAccount.Accounts.FirstOrDefault(a => + var (_, value) = LauncherAccountParser.LauncherAccount.Accounts!.FirstOrDefault(a => (a.Value.MinecraftProfile?.Name?.Equals(authResponse.User.UserName, StringComparison.OrdinalIgnoreCase) ?? false) && (a.Value.MinecraftProfile?.Id?.Equals(uuid, StringComparison.OrdinalIgnoreCase) ?? false)); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs index 279fa830..631af2bb 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs @@ -13,8 +13,9 @@ namespace ProjBobcat.DefaultComponent.Installer; public class FabricInstaller : InstallerBase, IFabricInstaller { - public IVersionLocator VersionLocator { get; init; } - public FabricLoaderArtifactModel LoaderArtifact { get; set; } + public required IVersionLocator VersionLocator { get; init; } + public required FabricLoaderArtifactModel LoaderArtifact { get; init; } + public override required string RootPath { get; init; } public string Install() { diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs index 6d1bcb7b..b3762e18 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs @@ -22,48 +22,46 @@ namespace ProjBobcat.DefaultComponent.Installer.ForgeInstaller; public partial class HighVersionForgeInstaller : InstallerBase, IForgeInstaller { -#if NET8_0_OR_GREATER [GeneratedRegex(@"^\[.+\]$")] private static partial Regex PathRegex(); [GeneratedRegex("^{.+}$")] private static partial Regex VariableRegex(); -#else - - static readonly Regex - PathRegex = new(@"^\[.+\]$", RegexOptions.Compiled), - VariableRegex = new("^{.+}$", RegexOptions.Compiled); - -#endif - readonly ConcurrentBag _failedFiles = []; int _totalDownloaded, _needToDownload, _totalProcessed, _needToProcess; - public string? JavaExecutablePath { get; init; } - - public string MineCraftVersionId { get; set; } - public string MineCraftVersion { get; set; } + public required string JavaExecutablePath { get; init; } + public override required string RootPath { get; init; } + public required string MineCraftVersionId { get; init; } + public required string MineCraftVersion { get; init; } + public required string DownloadUrlRoot { get; init; } + public required string ForgeExecutablePath { get; init; } + public required VersionLocatorBase VersionLocator { get; init; } - public string DownloadUrlRoot { get; set; } - public string? ForgeExecutablePath { get; set; } - - public VersionLocatorBase VersionLocator { get; set; } - - public FileInfo? CustomMojangClientMappings { get; set; } + public FileInfo? CustomMojangClientMappings { get; init; } public ForgeInstallResult InstallForge() { return InstallForgeTaskAsync().Result; } - public async Task InstallForgeTaskAsync() + ForgeInstallResult GetCorruptedFileResult() { - if (string.IsNullOrEmpty(ForgeExecutablePath)) - throw new ArgumentNullException("未指定\"ForgeExecutablePath\"参数"); - if (string.IsNullOrEmpty(JavaExecutablePath)) - throw new ArgumentNullException("未指定\"JavaExecutablePath\"参数"); + return new ForgeInstallResult + { + Succeeded = false, + Error = new ErrorModel + { + Cause = "损坏的 Forge 可执行文件", + Error = "安装前准备失败", + ErrorMessage = "损坏的 Forge 可执行文件,请确认您的路径是否正确" + } + }; + } + public async Task InstallForgeTaskAsync() + { if (!File.Exists(JavaExecutablePath)) return new ForgeInstallResult { @@ -98,20 +96,14 @@ public async Task InstallForgeTaskAsync() archive.Entries.FirstOrDefault(e => e.Key.Equals("version.json", StringComparison.OrdinalIgnoreCase)); if (versionJsonEntry == default) - return new ForgeInstallResult - { - Succeeded = false, - Error = new ErrorModel - { - Cause = "损坏的 Forge 可执行文件", - Error = "安装前准备失败", - ErrorMessage = "损坏的 Forge 可执行文件,请确认您的路径是否正确" - } - }; + return GetCorruptedFileResult(); await using var stream = versionJsonEntry.OpenEntryStream(); var versionJsonModel = await JsonSerializer.DeserializeAsync(stream, RawVersionModelContext.Default.RawVersionModel); + + if (versionJsonModel == default) + return GetCorruptedFileResult(); var forgeVersion = versionJsonModel.Id.Replace("-forge-", "-"); var id = string.IsNullOrEmpty(CustomId) ? versionJsonModel.Id : CustomId; @@ -135,6 +127,9 @@ public async Task InstallForgeTaskAsync() var installProfileEntry = archive.Entries.FirstOrDefault(e => e.Key.Equals("install_profile.json", StringComparison.OrdinalIgnoreCase)); + + if (installProfileEntry == default) + return GetCorruptedFileResult(); await using var ipStream = installProfileEntry.OpenEntryStream(); var ipModel = @@ -160,11 +155,11 @@ public async Task InstallForgeTaskAsync() ipModel.Data["BINPATCH"].Server = $"[{serverMaven}]"; - var serverBinMaven = serverMaven.ResolveMavenString(); + var serverBinMaven = serverMaven.ResolveMavenString()!; var serverBinPath = Path.Combine(RootPath, GamePathHelper.GetLibraryPath(serverBinMaven.Path)); - var di = new DirectoryInfo(Path.GetDirectoryName(serverBinPath)); + var di = new DirectoryInfo(Path.GetDirectoryName(serverBinPath)!); if (!di.Exists) di.Create(); @@ -180,11 +175,11 @@ public async Task InstallForgeTaskAsync() ipModel.Data["BINPATCH"].Client = $"[{clientMaven}]"; - var clientBinMaven = clientMaven.ResolveMavenString(); + var clientBinMaven = clientMaven.ResolveMavenString()!; var clientBinPath = Path.Combine(RootPath, GamePathHelper.GetLibraryPath(clientBinMaven.Path)); - var di = new DirectoryInfo(Path.GetDirectoryName(clientBinPath)); + var di = new DirectoryInfo(Path.GetDirectoryName(clientBinPath)!); if (!di.Exists) di.Create(); @@ -210,7 +205,7 @@ public async Task InstallForgeTaskAsync() { if (forgeUniversalJar != default) { - var forgeUniversalSubPath = forgeUniversalJar?.Key[(forgeUniversalJar.Key.IndexOf('/') + 1)..]; + var forgeUniversalSubPath = forgeUniversalJar.Key[(forgeUniversalJar.Key.IndexOf('/') + 1)..]; var forgeUniversalLibPath = Path.Combine(RootPath, GamePathHelper.GetLibraryPath(forgeUniversalSubPath)); @@ -225,7 +220,7 @@ public async Task InstallForgeTaskAsync() Succeeded = false }; - var forgeUniversalLibDir = Path.GetDirectoryName(forgeUniversalLibPath); + var forgeUniversalLibDir = Path.GetDirectoryName(forgeUniversalLibPath)!; if (!Directory.Exists(forgeUniversalLibDir)) Directory.CreateDirectory(forgeUniversalLibDir); @@ -237,13 +232,13 @@ public async Task InstallForgeTaskAsync() var forgeLibPath = Path.Combine(RootPath, GamePathHelper.GetLibraryPath(forgeSubPath)); - var forgeLibDir = Path.GetDirectoryName(forgeLibPath); + var forgeLibDir = Path.GetDirectoryName(forgeLibPath)!; if (!Directory.Exists(forgeLibDir)) Directory.CreateDirectory(forgeLibDir); await using var forgeFs = File.OpenWrite(forgeLibPath); - var fLDi = new DirectoryInfo(Path.GetDirectoryName(forgeLibPath)); + var fLDi = new DirectoryInfo(Path.GetDirectoryName(forgeLibPath)!); if (!fLDi.Exists) fLDi.Create(); @@ -257,10 +252,11 @@ public async Task InstallForgeTaskAsync() if (ipModel.Data.TryGetValue("MOJMAPS", out var mapsVal) && !string.IsNullOrEmpty(mapsVal.Client) && - CustomMojangClientMappings != null) + CustomMojangClientMappings != null && + !string.IsNullOrEmpty(CustomMojangClientMappings.Url)) { var clientMavenStr = mapsVal.Client.TrimStart('[').TrimEnd(']'); - var resolvedMappingMaven = clientMavenStr.ResolveMavenString(); + var resolvedMappingMaven = clientMavenStr.ResolveMavenString()!; var mappingPath = Path.GetDirectoryName(resolvedMappingMaven.Path); var mappingFileName = Path.GetFileName(resolvedMappingMaven.Path); var mappingDf = new DownloadFile @@ -297,16 +293,12 @@ public async Task InstallForgeTaskAsync() InvokeStatusChangedEvent("解析 Processor", 1); - string ResolvePathRegex(string val) + string? ResolvePathRegex(string? val) { -#if NET8_0_OR_GREATER if (string.IsNullOrEmpty(val) || string.IsNullOrEmpty(PathRegex().Match(val).Value)) return val; -#else - if (string.IsNullOrEmpty(val) || string.IsNullOrEmpty(PathRegex.Match(val).Value)) return val; -#endif var name = val[1..^1]; - var maven = name.ResolveMavenString(); + var maven = name.ResolveMavenString()!; var path = Path.Combine(RootPath, GamePathHelper.GetLibraryPath(maven.Path)); @@ -325,21 +317,26 @@ string ResolvePathRegex(string val) }; foreach (var (k, v) in ipModel.Data) + { + var resolvedKey = ResolvePathRegex(v.Client); + var resolvedValue = ResolvePathRegex(v.Server); + + if (string.IsNullOrEmpty(resolvedKey) || + string.IsNullOrEmpty(resolvedValue)) continue; + variables.TryAdd(k, new ForgeInstallProfileData { - Client = ResolvePathRegex(v.Client), - Server = ResolvePathRegex(v.Server) + Client = resolvedKey, + Server = resolvedValue }); + } - string ResolveVariableRegex(string val) + string? ResolveVariableRegex(string? val) { -#if NET8_0_OR_GREATER if (string.IsNullOrEmpty(val) || string.IsNullOrEmpty(VariableRegex().Match(val).Value)) return val; -#else - if (string.IsNullOrEmpty(val) || string.IsNullOrEmpty(VariableRegex.Match(val).Value)) return val; -#endif var key = val[1..^1]; + return variables[key].Client; } @@ -365,13 +362,22 @@ string ResolveVariableRegex(string val) if (proc.Outputs?.Any() ?? false) foreach (var (k, v) in proc.Outputs) - outputs.TryAdd(ResolveVariableRegex(k), ResolveVariableRegex(v)); + { + var resolvedKey = ResolveVariableRegex(k); + var resolvedValue = ResolveVariableRegex(v); + + if (string.IsNullOrEmpty(resolvedKey) || + string.IsNullOrEmpty(resolvedValue)) continue; + + outputs.TryAdd(resolvedKey, resolvedValue); + } var args = proc.Arguments .Select(arg => StringHelper.ReplaceByDic(arg, argsReplaceList)) .Select(ResolvePathRegex) .Select(ResolveVariableRegex) .Select(StringHelper.FixPathArgument) + .OfType() .ToArray(); var model = new ForgeInstallProcessorModel { @@ -397,8 +403,11 @@ string ResolveVariableRegex(string val) foreach (var lib in resolvedLibs) { + if (string.IsNullOrEmpty(lib.Path) || + string.IsNullOrEmpty(lib.Url)) continue; + if ( - lib.Name.StartsWith("net.minecraftforge:forge", StringComparison.OrdinalIgnoreCase) && + (lib.Name?.StartsWith("net.minecraftforge:forge", StringComparison.OrdinalIgnoreCase) ?? false) && string.IsNullOrEmpty(lib.Url) ) continue; @@ -468,7 +477,7 @@ string ResolveVariableRegex(string val) _needToProcess = procList.Count; foreach (var processor in procList) { - var maven = processor.Processor.Jar.ResolveMavenString(); + var maven = processor.Processor.Jar.ResolveMavenString()!; var libPath = Path.Combine(RootPath, GamePathHelper.GetLibraryPath(maven.Path)); using var libArchive = ArchiveFactory.Open(Path.GetFullPath(libPath)); @@ -476,6 +485,9 @@ string ResolveVariableRegex(string val) libArchive.Entries.FirstOrDefault(e => e.Key.Equals("META-INF/MANIFEST.MF", StringComparison.OrdinalIgnoreCase)); + if (libEntry == null) + return GetCorruptedFileResult(); + await using var libStream = libEntry.OpenEntryStream(); using var libSr = new StreamReader(libStream, Encoding.UTF8); var content = await libSr.ReadToEndAsync(); @@ -489,8 +501,9 @@ where lineSp[0].Equals("Main-Class", StringComparison.OrdinalIgnoreCase) var totalLibs = processor.Processor.ClassPath.ToList(); totalLibs.Add(processor.Processor.Jar); - var cp = totalLibs.Select(MavenHelper.ResolveMavenString) - .Select(m => Path.Combine(RootPath, GamePathHelper.GetLibraryPath(m.Path))); + var cp = totalLibs + .Select(MavenHelper.ResolveMavenString) + .Select(m => Path.Combine(RootPath, GamePathHelper.GetLibraryPath(m!.Path))); var cpStr = string.Join(Path.PathSeparator, cp); var parameter = new List { diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs index 7b2aa68e..b20b6802 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs @@ -16,19 +16,20 @@ namespace ProjBobcat.DefaultComponent.Installer.ForgeInstaller; public class LegacyForgeInstaller : InstallerBase, IForgeInstaller { - public string ForgeVersion { get; init; } - public string ForgeExecutablePath { get; set; } + public required string ForgeVersion { get; init; } + public required string ForgeExecutablePath { get; init; } + public override required string RootPath { get; init; } public VersionLocatorBase VersionLocator { get => throw new NotImplementedException(); - set => throw new NotImplementedException(); + init => throw new NotImplementedException(); } public string DownloadUrlRoot { get => throw new NotImplementedException(); - set => throw new NotImplementedException(); + init => throw new NotImplementedException(); } public ForgeInstallResult InstallForge() @@ -38,11 +39,6 @@ public ForgeInstallResult InstallForge() public async Task InstallForgeTaskAsync() { - if (string.IsNullOrEmpty(ForgeExecutablePath)) - throw new ArgumentNullException("未指定\"ForgeExecutablePath\"参数"); - if (string.IsNullOrEmpty(RootPath)) - throw new ArgumentNullException("未指定\"RootPath\"参数"); - try { InvokeStatusChangedEvent("解压安装文件", 0.05); @@ -106,12 +102,12 @@ public async Task InstallForgeTaskAsync() var forgeLibrary = profileModel.VersionInfo.Libraries.First(l => l.Name.StartsWith("net.minecraftforge:forge", StringComparison.OrdinalIgnoreCase)); - var mavenInfo = forgeLibrary.Name.ResolveMavenString(); + var mavenInfo = forgeLibrary.Name.ResolveMavenString()!; var libSubPath = GamePathHelper.GetLibraryPath(mavenInfo.Path); var forgeLibPath = Path.Combine(RootPath, libSubPath); - var libDi = new DirectoryInfo(Path.GetDirectoryName(forgeLibPath)); + var libDi = new DirectoryInfo(Path.GetDirectoryName(forgeLibPath)!); if (!libDi.Exists) libDi.Create(); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs index 7b278324..36e4ef08 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs @@ -16,11 +16,12 @@ namespace ProjBobcat.DefaultComponent.Installer; public class LiteLoaderInstaller : InstallerBase, ILiteLoaderInstaller { - const string SnapshotRoot = "http://dl.liteloader.com/versions/"; - const string ReleaseRoot = "http://repo.mumfrey.com/content/repositories/liteloader/"; + const string SnapshotRoot = "https://dl.liteloader.com/versions/"; + const string ReleaseRoot = "https://repo.mumfrey.com/content/repositories/liteloader/"; - public RawVersionModel InheritVersion { get; init; } - public LiteLoaderDownloadVersionModel VersionModel { get; init; } + public required RawVersionModel InheritVersion { get; init; } + public required LiteLoaderDownloadVersionModel VersionModel { get; init; } + public override required string RootPath { get; init; } public string Install() { diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs index e3eabc5b..7674ad51 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs @@ -18,15 +18,16 @@ namespace ProjBobcat.DefaultComponent.Installer.ModPackInstaller; public sealed class CurseForgeInstaller : ModPackInstallerBase, ICurseForgeInstaller { - public string ModPackPath { get; set; } - public string GameId { get; set; } + public override string RootPath { get; init; } = string.Empty; + public required string ModPackPath { get; init; } + public string? GameId { get; init; } public void Install() { InstallTaskAsync().Wait(); } - private async ValueTask<(bool, DownloadFile?)> TryGuessModDownloadLink(long fileId, string downloadPath) + async ValueTask<(bool, DownloadFile?)> TryGuessModDownloadLink(long fileId, string downloadPath) { try { @@ -79,6 +80,11 @@ public void Install() public async Task InstallTaskAsync() { + if (string.IsNullOrEmpty(GameId)) + throw new ArgumentNullException(nameof(GameId)); + if (string.IsNullOrEmpty(RootPath)) + throw new ArgumentNullException(nameof(RootPath)); + InvokeStatusChangedEvent("开始安装", 0); var manifest = await ReadManifestTask(); @@ -108,6 +114,10 @@ public async Task InstallTaskAsync() try { var downloadUrlRes = await CurseForgeAPIHelper.GetAddonDownloadUrl(t.Item1, t.Item2); + + if (string.IsNullOrEmpty(downloadUrlRes)) + throw new CurseForgeModResolveException(t.Item1, t.Item2); + var d = downloadUrlRes.Trim('"'); var fn = Path.GetFileName(d); @@ -136,7 +146,7 @@ public async Task InstallTaskAsync() var (guessed, df) = await TryGuessModDownloadLink(t.Item2, di.FullName); - if (!guessed) + if (!guessed || df == null) { try { @@ -205,13 +215,14 @@ public async Task InstallTaskAsync() foreach (var entry in archive.Entries) { - if (!entry.Key.StartsWith(manifest.Overrides, StringComparison.OrdinalIgnoreCase)) continue; + if (string.IsNullOrEmpty(manifest.Overrides) || + !entry.Key.StartsWith(manifest.Overrides, StringComparison.OrdinalIgnoreCase)) continue; var subPath = entry.Key[(manifest.Overrides.Length + 1)..]; if (string.IsNullOrEmpty(subPath)) continue; var path = Path.Combine(Path.GetFullPath(idPath), subPath); - var dirPath = Path.GetDirectoryName(path); + var dirPath = Path.GetDirectoryName(path)!; if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs index 1de00b2d..9591a802 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs @@ -4,7 +4,7 @@ namespace ProjBobcat.DefaultComponent.Installer.ModPackInstaller; -public class ModPackInstallerBase : InstallerBase +public abstract class ModPackInstallerBase : InstallerBase { protected readonly ConcurrentBag FailedFiles = []; protected int TotalDownloaded, NeedToDownload; diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs index e1653fde..b32fdff7 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs @@ -14,8 +14,9 @@ namespace ProjBobcat.DefaultComponent.Installer.ModPackInstaller; public sealed class ModrinthInstaller : ModPackInstallerBase, IModrinthInstaller { - public string GameId { get; set; } - public string ModPackPath { get; set; } + public string? GameId { get; init; } + public override string RootPath { get; init; } = string.Empty; + public required string ModPackPath { get; init; } public async Task ReadIndexTask() { @@ -42,6 +43,11 @@ public void Install() public async Task InstallTaskAsync() { + if (string.IsNullOrEmpty(GameId)) + throw new ArgumentNullException(nameof(GameId)); + if (string.IsNullOrEmpty(RootPath)) + throw new ArgumentNullException(nameof(RootPath)); + InvokeStatusChangedEvent("开始安装", 0); var index = await ReadIndexTask(); @@ -65,7 +71,7 @@ public async Task InstallTaskAsync() if (file.Downloads.Length == 0) continue; var fullPath = Path.Combine(idPath, file.Path); - var downloadDir = Path.GetDirectoryName(fullPath); + var downloadDir = Path.GetDirectoryName(fullPath)!; var fileName = Path.GetFileName(fullPath); var checkSum = file.Hashes.TryGetValue("sha1", out var sha1) ? sha1 : string.Empty; @@ -73,7 +79,7 @@ public async Task InstallTaskAsync() { CheckSum = checkSum, DownloadPath = downloadDir, - DownloadUri = file.Downloads.RandomSample(), + DownloadUri = file.Downloads.RandomSample()!, FileName = fileName, FileSize = file.Size }; @@ -111,7 +117,7 @@ public async Task InstallTaskAsync() if (string.IsNullOrEmpty(subPath)) continue; var path = Path.Combine(Path.GetFullPath(idPath), subPath); - var dirPath = Path.GetDirectoryName(path); + var dirPath = Path.GetDirectoryName(path)!; if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs index 7bd9be34..227afd04 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs @@ -17,9 +17,10 @@ namespace ProjBobcat.DefaultComponent.Installer; public class OptifineInstaller : InstallerBase, IOptifineInstaller { - public string? JavaExecutablePath { get; set; } - public string? OptifineJarPath { get; set; } - public OptifineDownloadVersionModel? OptifineDownloadVersion { get; set; } + public required string JavaExecutablePath { get; init; } + public required string OptifineJarPath { get; init; } + public required OptifineDownloadVersionModel OptifineDownloadVersion { get; init; } + public override required string RootPath { get; init; } public string Install() { diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs index 9b1b335d..23561832 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs @@ -19,8 +19,9 @@ public class QuiltInstaller : InstallerBase, IQuiltInstaller static HttpClient Client => HttpClientHelper.DefaultClient; - public QuiltLoaderModel LoaderArtifact { get; set; } - public string? MineCraftVersion { get; set; } + public override required string RootPath { get; init; } + public required QuiltLoaderModel LoaderArtifact { get; init; } + public required string MineCraftVersion { get; init; } public string Install() { @@ -29,11 +30,6 @@ public string Install() public async Task InstallTaskAsync() { - if (string.IsNullOrEmpty(MineCraftVersion)) - throw new NullReferenceException("MineCraftVersion 不能为 null"); - if (string.IsNullOrEmpty(RootPath)) - throw new NullReferenceException("RootPath 不能为 null"); - InvokeStatusChangedEvent("开始安装", 0); var url = $"{DefaultMetaUrl}/v3/versions/loader/{MineCraftVersion}/{LoaderArtifact.Version}/profile/json"; diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs index fbdaf159..159a4b1a 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs @@ -9,6 +9,7 @@ using ProjBobcat.Class.Model; using ProjBobcat.Class.Model.Auth; using ProjBobcat.Class.Model.JsonContexts; +using ProjBobcat.Exceptions; using ProjBobcat.Interface; namespace ProjBobcat.DefaultComponent.Launch; @@ -27,8 +28,13 @@ public class DefaultLaunchArgumentParser : LaunchArgumentParserBase, IArgumentPa /// /// /// - public DefaultLaunchArgumentParser(LaunchSettings launchSettings, ILauncherProfileParser launcherProfileParser, - IVersionLocator versionLocator, AuthResultBase authResult, string rootPath, string? rootVersion) + public DefaultLaunchArgumentParser( + LaunchSettings launchSettings, + ILauncherProfileParser launcherProfileParser, + IVersionLocator versionLocator, + AuthResultBase authResult, + string rootPath, + string? rootVersion) : base(rootPath, launchSettings, launcherProfileParser, versionLocator, authResult) { if (launchSettings == null || launcherProfileParser == null) throw new ArgumentNullException(); @@ -41,12 +47,13 @@ public DefaultLaunchArgumentParser(LaunchSettings launchSettings, ILauncherProfi RootPath = rootPath; LaunchSettings = launchSettings; LauncherProfileParser = launcherProfileParser; - VersionInfo = LaunchSettings.VersionLocator.GetGame(LaunchSettings.Version); + VersionInfo = LaunchSettings.VersionLocator.GetGame(LaunchSettings.Version) + ?? throw new UnknownGameNameException(LaunchSettings.Version); GameProfile = LauncherProfileParser.GetGameProfile(LaunchSettings.GameName); var sb = new StringBuilder(); foreach (var lib in VersionInfo.Libraries) - sb.Append($"{Path.Combine(RootPath, GamePathHelper.GetLibraryPath(lib.Path))}{Path.PathSeparator}"); + sb.Append($"{Path.Combine(RootPath, GamePathHelper.GetLibraryPath(lib.Path!))}{Path.PathSeparator}"); if (true) { @@ -60,7 +67,6 @@ public DefaultLaunchArgumentParser(LaunchSettings launchSettings, ILauncherProfi } ClassPath = sb.ToString(); - LastAuthResult = LaunchSettings.Authenticator.GetLastAuthResult(); } @@ -74,7 +80,7 @@ public IEnumerable ParseJvmHeadArguments() var gameArgs = LaunchSettings.GameArguments ?? LaunchSettings.FallBackGameArguments; - if (gameArgs.AdditionalJvmArguments?.Any() ?? false) + if (gameArgs!.AdditionalJvmArguments?.Any() ?? false) foreach (var jvmArg in gameArgs.AdditionalJvmArguments) yield return jvmArg; @@ -219,6 +225,12 @@ public IEnumerable ParseJvmArguments() public IEnumerable ParseGameArguments(AuthResultBase authResult) { + if (authResult.AuthStatus == AuthStatus.Failed || + authResult.AuthStatus == AuthStatus.Unknown || + authResult.SelectedProfile == null || + string.IsNullOrEmpty(authResult.AccessToken)) + throw new ArgumentNullException("无效的用户凭据,请检查登陆状态"); + var gameDir = _launchSettings.VersionInsulation ? Path.Combine(RootPath, GamePathHelper.GetGamePath(LaunchSettings.Version)) : RootPath; @@ -234,7 +246,7 @@ public IEnumerable ParseGameArguments(AuthResultBase authResult) _ => "Mojang" }; var xuid = authResult is MicrosoftAuthResult microsoftAuthResult - ? microsoftAuthResult.XBoxUid + ? microsoftAuthResult.XBoxUid ?? Guid.Empty.ToString("N") : Guid.Empty.ToString("N"); var mcArgumentsDic = new Dictionary @@ -242,11 +254,11 @@ public IEnumerable ParseGameArguments(AuthResultBase authResult) { "${version_name}", $"\"{LaunchSettings.Version}\"" }, { "${version_type}", $"\"{GameProfile?.Type ?? LaunchSettings.LauncherName}\"" }, { "${assets_root}", $"\"{AssetRoot}\"" }, - { "${assets_index_name}", VersionInfo.AssetInfo?.Id ?? VersionInfo.Assets }, + { "${assets_index_name}", VersionInfo.AssetInfo?.Id ?? VersionInfo.Assets ?? VersionInfo.Id }, { "${game_directory}", $"\"{gameDir}\"" }, - { "${auth_player_name}", authResult?.SelectedProfile?.Name }, - { "${auth_uuid}", authResult?.SelectedProfile?.UUID.ToString() }, - { "${auth_access_token}", authResult?.AccessToken }, + { "${auth_player_name}", authResult.SelectedProfile.Name }, + { "${auth_uuid}", authResult.SelectedProfile.UUID.ToString() }, + { "${auth_access_token}", authResult.AccessToken }, { "${user_properties}", "{}" }, //authResult?.User?.Properties.ResolveUserProperties() }, { "${user_type}", userType }, // use default value as placeholder { "${clientid}", clientId }, @@ -262,7 +274,7 @@ public List GenerateLaunchArguments() var javaPath = GameProfile?.JavaDir; if (string.IsNullOrEmpty(javaPath)) javaPath = LaunchSettings.FallBackGameArguments?.JavaExecutable ?? - LaunchSettings.GameArguments?.JavaExecutable; + LaunchSettings.GameArguments.JavaExecutable; var arguments = new List { @@ -318,8 +330,8 @@ public IEnumerable ParseGameLoggingArguments() /// public IEnumerable ParseAdditionalArguments() { - if (VersionInfo.AvailableGameArguments.Count == 0) yield break; - if (!VersionInfo.AvailableGameArguments.ContainsKey("has_custom_resolution")) yield break; + if ((VersionInfo.AvailableGameArguments?.Count ?? 0) == 0) yield break; + if (!VersionInfo.AvailableGameArguments!.ContainsKey("has_custom_resolution")) yield break; if (!(LaunchSettings.GameArguments?.Resolution?.IsDefault() ?? true)) { @@ -337,7 +349,7 @@ public IEnumerable ParseAdditionalArguments() yield return "--height"; yield return LaunchSettings.FallBackGameArguments.Resolution.Height.ToString(); } - else if (!(GameProfile.Resolution?.IsDefault() ?? true)) + else if (!GameProfile!.Resolution!.IsDefault()) { yield return "--width"; yield return GameProfile.Resolution.Width.ToString(); @@ -363,4 +375,7 @@ public IEnumerable ParseAdditionalArguments() yield return serverSettings.Port.ToString(); } } + + protected override string ClassPath { get; init; } + protected override VersionInfo VersionInfo { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs index 2f7a4eba..57662ba7 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs @@ -20,40 +20,52 @@ public class DefaultLauncherAccountParser : LauncherParserBase, ILauncherAccount /// /// /// - public DefaultLauncherAccountParser(string rootPath, Guid clientToken) + public DefaultLauncherAccountParser(string rootPath, Guid clientToken) : base(rootPath) { - RootPath = rootPath; _fullLauncherAccountPath = Path.Combine(rootPath, GamePathHelper.GetLauncherAccountPath()); if (!File.Exists(_fullLauncherAccountPath)) { - var launcherAccount = new LauncherAccountModel - { - Accounts = [], - MojangClientToken = clientToken.ToString("N") - }; - - LauncherAccount = launcherAccount; - - var launcherProfileJson = - JsonSerializer.Serialize(launcherAccount, typeof(LauncherAccountModel), - new LauncherAccountModelContext(JsonHelper.CamelCasePropertyNamesSettings())); - - if (!Directory.Exists(RootPath)) - Directory.CreateDirectory(RootPath); - - File.WriteAllText(_fullLauncherAccountPath, launcherProfileJson); + LauncherAccount = GenerateLauncherAccountModel(clientToken); } else { var launcherProfileJson = File.ReadAllText(_fullLauncherAccountPath, Encoding.UTF8); - LauncherAccount = JsonSerializer.Deserialize(launcherProfileJson, + var val = JsonSerializer.Deserialize(launcherProfileJson, LauncherAccountModelContext.Default.LauncherAccountModel); + + if (val == null) + { + LauncherAccount = GenerateLauncherAccountModel(clientToken); + return; + } + + LauncherAccount = val; } } - public LauncherAccountModel? LauncherAccount { get; set; } + LauncherAccountModel GenerateLauncherAccountModel(Guid clientToken) + { + var launcherAccount = new LauncherAccountModel + { + Accounts = [], + MojangClientToken = clientToken.ToString("N") + }; + + var launcherProfileJson = + JsonSerializer.Serialize(launcherAccount, typeof(LauncherAccountModel), + new LauncherAccountModelContext(JsonHelper.CamelCasePropertyNamesSettings())); + + if (!Directory.Exists(RootPath)) + Directory.CreateDirectory(RootPath); + + File.WriteAllText(_fullLauncherAccountPath, launcherProfileJson); + + return launcherAccount; + } + + public LauncherAccountModel LauncherAccount { get; set; } public bool ActivateAccount(string uuid) { @@ -83,7 +95,7 @@ public bool AddNewAccount(string uuid, AccountModel account, out Guid? id) } var oldRecord = LauncherAccount.Accounts - .FirstOrDefault(a => a.Value.MinecraftProfile.Id == account.MinecraftProfile.Id).Value; + .FirstOrDefault(a => a.Value.MinecraftProfile?.Id == account.MinecraftProfile?.Id).Value; if (oldRecord != null) { id = oldRecord.Id; @@ -134,12 +146,10 @@ public bool RemoveAccount(Guid id) if (!result.HasValue) return false; var (key, value) = result.Value; - if (value == default) - return false; - - LauncherAccount.Accounts.Remove(key); + LauncherAccount?.Accounts?.Remove(key); Save(); + return true; } diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs index 826c62a5..6882ca76 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs @@ -25,51 +25,69 @@ public sealed class DefaultLauncherProfileParser : LauncherParserBase, ILauncher /// /// /// - public DefaultLauncherProfileParser(string rootPath, Guid clientToken) + public DefaultLauncherProfileParser(string rootPath, Guid clientToken) : base(rootPath) { - RootPath = rootPath; _fullLauncherProfilePath = Path.Combine(rootPath, GamePathHelper.GetLauncherProfilePath()); - + if (!File.Exists(_fullLauncherProfilePath)) { - var launcherProfile = new LauncherProfileModel - { - ClientToken = clientToken.ToString("D"), - LauncherVersion = new LauncherVersionModel - { - Format = 1, - Name = string.Empty - }, - Profiles = [] - }; - - LauncherProfile = launcherProfile; - - var launcherProfileJson = - JsonSerializer.Serialize(launcherProfile, typeof(LauncherProfileModel), - new LauncherProfileModelContext(JsonHelper.CamelCasePropertyNamesSettings())); - - if (!Directory.Exists(RootPath)) - Directory.CreateDirectory(RootPath); - - File.WriteAllText(_fullLauncherProfilePath, launcherProfileJson); + LauncherProfile = GenerateLauncherProfile(clientToken, rootPath); } else { var launcherProfileJson = File.ReadAllText(_fullLauncherProfilePath, Encoding.UTF8); - LauncherProfile = JsonSerializer.Deserialize(launcherProfileJson, + var result = JsonSerializer.Deserialize(launcherProfileJson, LauncherProfileModelContext.Default.LauncherProfileModel); + + if (result == null) + { + LauncherProfile = GenerateLauncherProfile(clientToken, rootPath); + return; + } + + LauncherProfile = result; } } + LauncherProfileModel GenerateLauncherProfile( + Guid clientToken, + string rootPath) + { + var launcherProfile = new LauncherProfileModel + { + ClientToken = clientToken.ToString("D"), + LauncherVersion = new LauncherVersionModel + { + Format = 1, + Name = string.Empty + }, + Profiles = [], + SelectedUser = new SelectedUserModel() + }; + + LauncherProfile = launcherProfile; + + var launcherProfileJson = + JsonSerializer.Serialize(launcherProfile, typeof(LauncherProfileModel), + new LauncherProfileModelContext(JsonHelper.CamelCasePropertyNamesSettings())); + + if (!Directory.Exists(RootPath)) + Directory.CreateDirectory(rootPath); + + File.WriteAllText(_fullLauncherProfilePath, launcherProfileJson); + + return launcherProfile; + } + public LauncherProfileModel LauncherProfile { get; set; } public void AddNewGameProfile(GameProfileModel gameProfile) { + if (string.IsNullOrEmpty(gameProfile.Name)) return; if (IsGameProfileExist(gameProfile.Name)) return; - LauncherProfile.Profiles.Add(gameProfile.Name, gameProfile); + LauncherProfile.Profiles!.Add(gameProfile.Name, gameProfile); SaveProfile(); } @@ -81,8 +99,8 @@ public void EmptyGameProfiles() public GameProfileModel GetGameProfile(string name) { - var profile = LauncherProfile.Profiles.FirstOrDefault( - p => p.Value.Name.Equals(name, StringComparison.Ordinal)).Value ?? + var profile = LauncherProfile.Profiles!.FirstOrDefault( + p => p.Value.Name?.Equals(name, StringComparison.Ordinal) ?? false).Value ?? throw new UnknownGameNameException(name); profile.Resolution ??= new ResolutionModel(); @@ -92,12 +110,12 @@ public GameProfileModel GetGameProfile(string name) public bool IsGameProfileExist(string name) { - return LauncherProfile.Profiles.Any(p => p.Value.Name.Equals(name, StringComparison.Ordinal)); + return LauncherProfile.Profiles!.Any(p => p.Value.Name?.Equals(name, StringComparison.Ordinal) ?? false); } public void RemoveGameProfile(string name) { - LauncherProfile.Profiles.Remove(name); + LauncherProfile.Profiles!.Remove(name); } public void SaveProfile() @@ -116,12 +134,14 @@ public void SelectGameProfile(string name) { if (!IsGameProfileExist(name)) throw new KeyNotFoundException(); + LauncherProfile.SelectedUser ??= new SelectedUserModel(); LauncherProfile.SelectedUser.Profile = name; SaveProfile(); } public void SelectUser(PlayerUUID uuid) { + LauncherProfile.SelectedUser ??= new SelectedUserModel(); LauncherProfile.SelectedUser.Account = uuid.ToString(); SaveProfile(); } diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs index db6dbea1..d5cd2d64 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs @@ -25,15 +25,14 @@ public sealed class DefaultVersionLocator : VersionLocatorBase /// /// 指.minecraft/ Refers to .minecraft/ /// - public DefaultVersionLocator(string rootPath, Guid clientToken) + public DefaultVersionLocator(string rootPath, Guid clientToken) : base(rootPath) { - RootPath = rootPath; // .minecraft/ LauncherProfileParser = new DefaultLauncherProfileParser(rootPath, clientToken); //防止给定路径不存在的时候Parser遍历文件夹爆炸。 //Prevents errors in the parser's folder traversal when the given path does not exist. - if (!Directory.Exists(GamePathHelper.GetVersionPath(RootPath))) - Directory.CreateDirectory(GamePathHelper.GetVersionPath(RootPath)); + if (!Directory.Exists(GamePathHelper.GetVersionPath(rootPath))) + Directory.CreateDirectory(GamePathHelper.GetVersionPath(rootPath)); } public override IEnumerable GetAllGames() @@ -243,7 +242,7 @@ public override (List, List) GetNatives(IEnumerable
  • , List) GetNatives(IEnumerable
  • , List) GetNatives(IEnumerable
  • , List) GetNatives(IEnumerable
  • , List) GetNatives(IEnumerable
  • x.Key, y => y.Value); } @@ -493,7 +499,8 @@ public override (List, List) GetNatives(IEnumerable
  • arg.Split(' ')).SelectMany(a => a).Distinct().ToList(); result.GameArguments = finalGameArgs; - goto ProcessProfile; + ProcessProfile(result, id); + return result; } var libs = GetNatives(rawVersion.Libraries); @@ -507,15 +514,23 @@ public override (List, List) GetNatives(IEnumerable
  • + private void ProcessProfile(VersionInfo result, string id) + { + if (LauncherProfileParser == null) return; + + var oldProfile = LauncherProfileParser.LauncherProfile.Profiles!.FirstOrDefault(p => p.Value.LastVersionId?.Equals(id, StringComparison.Ordinal) ?? true); var gamePath = Path.Combine(RootPath, GamePathHelper.GetGamePath(id)); if (oldProfile.Equals(default(KeyValuePair))) { - LauncherProfileParser.LauncherProfile.Profiles.Add(id.ToGuidHash().ToString("N"), + LauncherProfileParser.LauncherProfile.Profiles!.Add(id.ToGuidHash().ToString("N"), new GameProfileModel { GameDir = gamePath, @@ -524,15 +539,12 @@ public override (List, List) GetNatives(IEnumerable
  • public sealed class DefaultGameCore : GameCoreBase { - string? _rootPath; + readonly string _rootPath = null!; /// /// 启动参数解析器 @@ -35,13 +35,13 @@ public IArgumentParser LaunchArgumentParser /// /// .minecraft 目录 /// - public override string? RootPath + public override required string RootPath { get => _rootPath; - set + init { if (string.IsNullOrEmpty(value)) - return; + throw new ArgumentNullException(nameof(RootPath)); _rootPath = Path.GetFullPath(value.TrimEnd('/')); } @@ -49,8 +49,11 @@ public override string? RootPath public bool EnableXmlLoggingOutput { get; init; } - public override async Task LaunchTaskAsync(LaunchSettings? settings) + public override async Task LaunchTaskAsync(LaunchSettings settings) { + if (VersionLocator.LauncherProfileParser == null) + throw new ArgumentNullException(nameof(VersionLocator.LauncherProfileParser)); + try { //逐步测量启动时间。 @@ -160,8 +163,13 @@ public override async Task LaunchTaskAsync(LaunchSettings? setting } }; - var argumentParser = new DefaultLaunchArgumentParser(settings, VersionLocator.LauncherProfileParser, - VersionLocator, authResult, RootPath, version.RootVersion) + var argumentParser = new DefaultLaunchArgumentParser( + settings, + VersionLocator.LauncherProfileParser, + VersionLocator, + authResult, + RootPath, + version.RootVersion) { EnableXmlLoggingOutput = EnableXmlLoggingOutput }; @@ -208,7 +216,9 @@ public override async Task LaunchTaskAsync(LaunchSettings? setting foreach (var n in version.Natives) { var path = - Path.Combine(RootPath, GamePathHelper.GetLibraryPath(n.FileInfo.Path)); + Path.Combine(RootPath, GamePathHelper.GetLibraryPath(n.FileInfo.Path!)); + + if (!File.Exists(path)) continue; // await using var stream = File.OpenRead(path); // using var reader = ReaderFactory.Open(stream); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs index 8ac78841..42d995d6 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs @@ -16,10 +16,10 @@ public abstract class GameCoreBase : IGameCore protected readonly EventHandlerList ListEventDelegates = new(); bool _disposedValue; - public virtual string? RootPath { get; set; } - public virtual Guid ClientToken { get; set; } - public virtual VersionLocatorBase VersionLocator { get; set; } - public virtual IGameLogResolver GameLogResolver { get; set; } + public virtual required string RootPath { get; init; } + public virtual required Guid ClientToken { get; init; } + public virtual required VersionLocatorBase VersionLocator { get; init; } + public virtual IGameLogResolver? GameLogResolver { get; init; } public event EventHandler GameExitEventDelegate { @@ -44,7 +44,7 @@ public event EventHandler LaunchLogEventDelegate /// /// /// - public virtual LaunchResult Launch(LaunchSettings? settings) + public virtual LaunchResult Launch(LaunchSettings settings) { return LaunchTaskAsync(settings).Result; } @@ -54,7 +54,7 @@ public virtual LaunchResult Launch(LaunchSettings? settings) /// /// /// - public abstract Task LaunchTaskAsync(LaunchSettings? settings); + public abstract Task LaunchTaskAsync(LaunchSettings settings); // // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器 // ~GameCoreBase() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/LogAnalysis/DefaultLogAnalyzer.cs b/ProjBobcat/ProjBobcat/DefaultComponent/LogAnalysis/DefaultLogAnalyzer.cs index 7751e581..dbc06ed2 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/LogAnalysis/DefaultLogAnalyzer.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/LogAnalysis/DefaultLogAnalyzer.cs @@ -10,7 +10,6 @@ namespace ProjBobcat.DefaultComponent.LogAnalysis; public partial class DefaultLogAnalyzer : ILogAnalyzer { -#if NET8_0_OR_GREATER [GeneratedRegex(@"(?<=\]: Warnings were found! ?[\n]+)[\w\W]+?(?=[\n]+\[)")] private static partial Regex WarningsMatch(); @@ -32,27 +31,6 @@ public partial class DefaultLogAnalyzer : ILogAnalyzer [GeneratedRegex(@"(?<=\tEntity's Exact location: )[^\n]+")] private static partial Regex EntityLocationMatch(); -#else - - static readonly Regex WarningsMatch = - new(@"(?<=\]: Warnings were found! ?[\n]+)[\w\W]+?(?=[\n]+\[)", RegexOptions.Compiled); - - static readonly Regex ModInstanceMatch1 = - new("(?<=Failed to create mod instance. ModID: )[^,]+", RegexOptions.Compiled); - - static readonly Regex ModInstanceMatch2 = - new(@"(?<=Failed to create mod instance. ModId )[^\n]+(?= for )", RegexOptions.Compiled); - - static readonly Regex BlockMatch = new(@"(?<=\tBlock: Block\{)[^\}]+", RegexOptions.Compiled); - - static readonly Regex BlockLocationMatch = new(@"(?<=\tBlock location: World: )\([^\)]+\)", RegexOptions.Compiled); - - static readonly Regex EntityMatch = new(@"(?<=\tEntity Type: )[^\n]+(?= \()", RegexOptions.Compiled); - - static readonly Regex EntityLocationMatch = new(@"(?<=\tEntity's Exact location: )[^\n]+", RegexOptions.Compiled); - -#endif - /// /// 日志文件最后写入时间限制(分钟) /// @@ -174,7 +152,6 @@ static IEnumerable AnalysisLogs(Dictionary AnalysisLogs(Dictionary 0 }) && - !(hasCrashes && crashes is { Count: > 0 }) && - subLogs.Length < 500)) - yield return - new AnalysisReport.AnalysisReport(CrashCauses.IncorrectPathEncodingOrMainClassNotFound); -#endif foreach (var report in ProcessGameLogs(subLogs)) yield return report with { From = fileName }; @@ -220,12 +187,7 @@ static IEnumerable AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary ProcessGameLogs(string logs) { foreach (var causeMap in GameLogsCausesMap) @@ -422,31 +333,19 @@ static IEnumerable AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary AnalysisLogs2(Dictionary ProcessCrashReports(string logs) { foreach (var causeMap in CrashCausesMap) @@ -630,66 +484,38 @@ static IEnumerable AnalysisLogs2(Dictionary GameLogType.Fatal, @@ -69,71 +54,41 @@ public GameLogType ResolveLogType(string log) "DEBUG" => GameLogType.Debug, _ => GameLogType.Unknown }; -#else - return TypeRegex.Match(log).Value switch - { - "FATAL" => GameLogType.Fatal, - "ERROR" => GameLogType.Error, - "WARN" => GameLogType.Warning, - "INFO" => GameLogType.Info, - "DEBUG" => GameLogType.Debug, - _ => GameLogType.Unknown - }; -#endif } public string ResolveStackTrace(string log) { -#if NET8_0_OR_GREATER var stackTrace = StackTraceAtRegex().Match(log).Value; -#else - var stackTrace = StackTraceAtRegex.Match(log).Value; -#endif return stackTrace; } public string ResolveExceptionMsg(string log) { -#if NET8_0_OR_GREATER var exceptionMsg = ExceptionRegex().Match(log).Value; -#else - var exceptionMsg = ExceptionRegex.Match(log).Value; -#endif - + return exceptionMsg; } public string ResolveSource(string log) { -#if NET8_0_OR_GREATER var content = SourceAndTypeRegex().Match(log).Value.Split('/').FirstOrDefault(); - var date = TimeFullRegex().Match(log).Value; -#else - var content = SourceAndTypeRegex.Match(log).Value.Split('/').FirstOrDefault(); - var date = TimeFullRegex.Match(log).Value; -#endif - var result = content?.Replace($"{date} [", string.Empty); + if (string.IsNullOrEmpty(content)) return string.Empty; + + var date = TimeFullRegex().Match(log).Value; + var result = content.Replace($"{date} [", string.Empty); return result; } public string ResolveTime(string log) { -#if NET8_0_OR_GREATER return TimeRegex().Match(log).Value; -#else - return TimeRegex.Match(log).Value; -#endif } public string ResolveTotalPrefix(string log) { -#if NET8_0_OR_GREATER return TotalPrefixRegex().Match(log).Value; -#else - return TotalPrefixRegex.Match(log).Value; -#endif } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs index a68e5a07..fd9533de 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs @@ -17,12 +17,12 @@ namespace ProjBobcat.DefaultComponent.ResourceInfoResolver; public sealed class AssetInfoResolver : ResolverBase { const string DefaultVersionManifestUrl = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; - readonly string _assetIndexUrlRoot; + readonly string? _assetIndexUrlRoot; - public string AssetIndexUriRoot + public string? AssetIndexUriRoot { get => _assetIndexUrlRoot; - init => _assetIndexUrlRoot = value.TrimEnd('/'); + init => _assetIndexUrlRoot = value?.TrimEnd('/'); } public string AssetUriRoot { get; init; } = "https://resources.download.minecraft.net/"; @@ -51,10 +51,10 @@ public override async IAsyncEnumerable ResolveResourceAsync() if (!(versions?.Any() ?? false)) yield break; var isAssetInfoNotExists = - string.IsNullOrEmpty(VersionInfo?.AssetInfo?.Url) && - string.IsNullOrEmpty(VersionInfo?.AssetInfo?.Id); + string.IsNullOrEmpty(VersionInfo.AssetInfo?.Url) && + string.IsNullOrEmpty(VersionInfo.AssetInfo?.Id); if (isAssetInfoNotExists && - string.IsNullOrEmpty(VersionInfo?.Assets)) + string.IsNullOrEmpty(VersionInfo.Assets)) yield break; var assetIndexesDi = @@ -65,7 +65,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() if (!assetIndexesDi.Exists) assetIndexesDi.Create(); if (!assetObjectsDi.Exists) assetObjectsDi.Create(); - var id = VersionInfo?.AssetInfo?.Id ?? VersionInfo.Assets; + var id = VersionInfo.AssetInfo?.Id ?? VersionInfo.Assets; var assetIndexesPath = Path.Combine(assetIndexesDi.FullName, $"{id}.json"); if (!File.Exists(assetIndexesPath)) { @@ -158,13 +158,8 @@ public override async IAsyncEnumerable ResolveResourceAsync() if (File.Exists(filePath)) { -#if NET8_0_OR_GREATER await using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var computedHash = (await SHA1.HashDataAsync(fs)).BytesToString(); -#else - var bytes = await File.ReadAllBytesAsync(filePath); - var computedHash = SHA1.HashData(bytes.AsSpan()).BytesToString(); -#endif if (computedHash.Equals(fi.Hash, StringComparison.OrdinalIgnoreCase)) continue; } diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/GameLoggingInfoResolver.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/GameLoggingInfoResolver.cs index 8b1fb2fd..fe0b6e7a 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/GameLoggingInfoResolver.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/GameLoggingInfoResolver.cs @@ -27,19 +27,17 @@ public override async IAsyncEnumerable ResolveResourceAsync() if (File.Exists(filePath)) { if (string.IsNullOrEmpty(VersionInfo.Logging?.Client?.File?.Sha1)) yield break; - -#if NET8_0_OR_GREATER + await using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var computedHash = (await SHA1.HashDataAsync(fs)).BytesToString(); -#else - var bytes = await File.ReadAllBytesAsync(filePath); - var computedHash = SHA1.HashData(bytes.AsSpan()).BytesToString(); -#endif if (computedHash.Equals(VersionInfo.Logging?.Client?.File?.Sha1, StringComparison.OrdinalIgnoreCase)) yield break; } + if (string.IsNullOrEmpty(VersionInfo.Logging?.Client?.File?.Url)) + yield break; + yield return new GameLoggingDownloadInfo { CheckSum = VersionInfo.Logging?.Client?.File?.Sha1, @@ -48,7 +46,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() Path = loggingPath, Title = fileName, Type = ResourceType.Logging, - Url = VersionInfo.Logging?.Client?.File?.Url + Url = VersionInfo.Logging!.Client!.File!.Url! }; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/LibraryInfoResolver.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/LibraryInfoResolver.cs index 3e119a66..014d44f8 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/LibraryInfoResolver.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/LibraryInfoResolver.cs @@ -23,11 +23,10 @@ public sealed class LibraryInfoResolver : ResolverBase public override async IAsyncEnumerable ResolveResourceAsync() { if (!CheckLocalFiles) yield break; - if (VersionInfo == null) yield break; OnResolve("开始进行游戏资源(Library)检查"); - if ((VersionInfo.Natives == null || VersionInfo.Natives.Count == 0) && - (VersionInfo.Libraries == null || VersionInfo.Libraries.Count == 0)) + if (VersionInfo.Natives.Count == 0 && + VersionInfo.Libraries.Count == 0) yield break; var libDi = new DirectoryInfo(Path.Combine(BasePath, GamePathHelper.GetLibraryRootPath())); @@ -41,7 +40,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() { foreach (var lib in VersionInfo.Libraries!) { - var libPath = GamePathHelper.GetLibraryPath(lib.Path); + var libPath = GamePathHelper.GetLibraryPath(lib.Path!); var filePath = Path.Combine(BasePath, libPath); Interlocked.Increment(ref checkedLib); @@ -53,13 +52,8 @@ public override async IAsyncEnumerable ResolveResourceAsync() { if (string.IsNullOrEmpty(lib.Sha1)) continue; -#if NET8_0_OR_GREATER - await using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); - var computedHash = (await SHA1.HashDataAsync(fs)).BytesToString(); -#else - var bytes = await File.ReadAllBytesAsync(filePath); - var computedHash = SHA1.HashData(bytes.AsSpan()).BytesToString(); -#endif + await using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); + var computedHash = (await SHA1.HashDataAsync(fs)).BytesToString(); if (computedHash.Equals(lib.Sha1, StringComparison.OrdinalIgnoreCase)) continue; } @@ -77,7 +71,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() { foreach (var native in VersionInfo.Natives!) { - var nativePath = GamePathHelper.GetLibraryPath(native.FileInfo.Path); + var nativePath = GamePathHelper.GetLibraryPath(native.FileInfo.Path!); var filePath = Path.Combine(BasePath, nativePath); if (File.Exists(filePath)) @@ -88,13 +82,8 @@ public override async IAsyncEnumerable ResolveResourceAsync() var progress = (double)checkedLib / libCount * 100; OnResolve(string.Empty, progress); -#if NET8_0_OR_GREATER - await using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); - var computedHash = (await SHA1.HashDataAsync(fs)).BytesToString(); -#else - var bytes = await File.ReadAllBytesAsync(filePath); - var computedHash = SHA1.HashData(bytes.AsSpan()).BytesToString(); -#endif + await using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); + var computedHash = (await SHA1.HashDataAsync(fs)).BytesToString(); if (computedHash.Equals(native.FileInfo.Sha1, StringComparison.OrdinalIgnoreCase)) continue; } @@ -124,7 +113,7 @@ LibraryDownloadInfo GetDownloadFile(FileInfo lL) _ => string.Empty }; - var symbolIndex = lL.Path.LastIndexOf('/'); + var symbolIndex = lL.Path!.LastIndexOf('/'); var fileName = lL.Path[(symbolIndex + 1)..]; var path = Path.Combine(BasePath, GamePathHelper.GetLibraryPath(lL.Path[..symbolIndex])); @@ -132,7 +121,7 @@ LibraryDownloadInfo GetDownloadFile(FileInfo lL) return new LibraryDownloadInfo { Path = path, - Title = lL.Name.Split(':')[1], + Title = lL.Name?.Split(':')[1] ?? fileName, Type = ResourceType.LibraryOrNative, Url = uri, FileSize = lL.Size, @@ -152,24 +141,24 @@ static LibraryType GetLibType(FileInfo fi) static bool IsQuiltLib(FileInfo fi) { - if (fi.Name.Contains("quiltmc", StringComparison.OrdinalIgnoreCase)) return true; - if (fi.Url.Contains("quiltmc", StringComparison.OrdinalIgnoreCase)) return true; + if (fi.Name?.Contains("quiltmc", StringComparison.OrdinalIgnoreCase) ?? false) return true; + if (fi.Url?.Contains("quiltmc", StringComparison.OrdinalIgnoreCase) ?? false) return true; return false; } static bool IsFabricLib(FileInfo fi) { - if (fi.Name.Contains("fabricmc", StringComparison.OrdinalIgnoreCase)) return true; - if (fi.Url.Contains("fabricmc", StringComparison.OrdinalIgnoreCase)) return true; + if (fi.Name?.Contains("fabricmc", StringComparison.OrdinalIgnoreCase) ?? false) return true; + if (fi.Url?.Contains("fabricmc", StringComparison.OrdinalIgnoreCase) ?? false) return true; return false; } static bool IsForgeLib(FileInfo fi) { - if (fi.Name.StartsWith("forge", StringComparison.Ordinal)) return true; - if (fi.Name.StartsWith("net.minecraftforge", StringComparison.Ordinal)) return true; + if (fi.Name?.StartsWith("forge", StringComparison.Ordinal) ?? false) return true; + if (fi.Name?.StartsWith("net.minecraftforge", StringComparison.Ordinal) ?? false) return true; if (HttpHelper.RegexMatchUri(fi?.Url ?? string.Empty) .Contains("minecraftforge", StringComparison.OrdinalIgnoreCase)) return true; diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs index 4902fbb5..c09983af 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs @@ -20,9 +20,9 @@ public event EventHandler GameResourceInfoReso remove => listEventDelegates.RemoveHandler(ResolveEventKey, value); } - public string BasePath { get; set; } + public required string BasePath { get; init; } public bool CheckLocalFiles { get; set; } - public VersionInfo? VersionInfo { get; set; } + public required VersionInfo VersionInfo { get; init; } public abstract IAsyncEnumerable ResolveResourceAsync(); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs index 2dba3371..afaec598 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs @@ -33,22 +33,20 @@ public override async IAsyncEnumerable ResolveResourceAsync() if (File.Exists(jarPath)) { if (string.IsNullOrEmpty(clientDownload.Sha1)) yield break; - -#if NET8_0_OR_GREATER + await using var jarFs = File.Open(jarPath, FileMode.Open, FileAccess.Read, FileShare.Read); var computedHash = (await SHA1.HashDataAsync(jarFs)).BytesToString(); -#else - var bytes = await File.ReadAllBytesAsync(jarPath); - var computedHash = SHA1.HashData(bytes.AsSpan()).BytesToString(); -#endif if (computedHash.Equals(clientDownload.Sha1, StringComparison.OrdinalIgnoreCase)) yield break; } + + if (string.IsNullOrEmpty(clientDownload.Url)) + yield break; yield return new VersionJarDownloadInfo { - CheckSum = clientDownload.Sha1, + CheckSum = clientDownload.Sha1 ?? string.Empty, FileName = $"{id}.jar", FileSize = clientDownload.Size, Path = Path.Combine(BasePath, GamePathHelper.GetGamePath(id)), diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs index 2a10042d..168dbc1e 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs @@ -14,12 +14,12 @@ namespace ProjBobcat.DefaultComponent.Service; public class ServerPingService : ProgressReportBase { - List _buffer; + List _buffer = null!; int _offset; - NetworkStream _stream; + NetworkStream _stream = null!; - public string Address { get; init; } - public ushort Port { get; init; } + public required string Address { get; init; } + public required ushort Port { get; init; } public int VersionId { get; init; } public override string ToString() @@ -27,7 +27,7 @@ public override string ToString() return $"{Address}:{Port}"; } - public ServerPingResult Run() + public ServerPingResult? Run() { return RunAsync().Result; } diff --git a/ProjBobcat/ProjBobcat/Event/DownloadFileCompletedEventArgs.cs b/ProjBobcat/ProjBobcat/Event/DownloadFileCompletedEventArgs.cs index 4e4c8c21..b0f115fd 100644 --- a/ProjBobcat/ProjBobcat/Event/DownloadFileCompletedEventArgs.cs +++ b/ProjBobcat/ProjBobcat/Event/DownloadFileCompletedEventArgs.cs @@ -2,16 +2,9 @@ namespace ProjBobcat.Event; -public class DownloadFileCompletedEventArgs : EventArgs +public class DownloadFileCompletedEventArgs(bool? success, Exception? ex, double averageSpeed) : EventArgs { - public DownloadFileCompletedEventArgs(bool? success, Exception? ex, double averageSpeed) - { - Success = success; - Error = ex; - AverageSpeed = averageSpeed; - } - - public double AverageSpeed { get; set; } - public bool? Success { get; } - public Exception? Error { get; } + public double AverageSpeed { get; set; } = averageSpeed; + public bool? Success { get; } = success; + public Exception? Error { get; } = ex; } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Event/ForgeInstallStageChangedEventArgs.cs b/ProjBobcat/ProjBobcat/Event/ForgeInstallStageChangedEventArgs.cs index 52d80517..a92a4f8f 100644 --- a/ProjBobcat/ProjBobcat/Event/ForgeInstallStageChangedEventArgs.cs +++ b/ProjBobcat/ProjBobcat/Event/ForgeInstallStageChangedEventArgs.cs @@ -4,6 +4,6 @@ namespace ProjBobcat.Event; public class ForgeInstallStageChangedEventArgs : EventArgs { - public string CurrentStage { get; set; } - public double Progress { get; set; } + public required string CurrentStage { get; init; } + public double Progress { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Event/GameResourceInfoResolveEventArgs.cs b/ProjBobcat/ProjBobcat/Event/GameResourceInfoResolveEventArgs.cs index 79e398f3..401da3d8 100644 --- a/ProjBobcat/ProjBobcat/Event/GameResourceInfoResolveEventArgs.cs +++ b/ProjBobcat/ProjBobcat/Event/GameResourceInfoResolveEventArgs.cs @@ -4,6 +4,6 @@ namespace ProjBobcat.Event; public class GameResourceInfoResolveEventArgs : EventArgs { - public double Progress { get; init; } - public string Status { get; init; } + public required double Progress { get; init; } + public string? Status { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Event/InstallerStageChangedEventArgs.cs b/ProjBobcat/ProjBobcat/Event/InstallerStageChangedEventArgs.cs index 2ed74623..0857dbb6 100644 --- a/ProjBobcat/ProjBobcat/Event/InstallerStageChangedEventArgs.cs +++ b/ProjBobcat/ProjBobcat/Event/InstallerStageChangedEventArgs.cs @@ -4,6 +4,6 @@ namespace ProjBobcat.Event; public class StageChangedEventArgs : EventArgs { - public string CurrentStage { get; set; } - public double Progress { get; set; } + public required string CurrentStage { get; init; } + public required double Progress { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Event/LaunchLogEventArgs.cs b/ProjBobcat/ProjBobcat/Event/LaunchLogEventArgs.cs index 3b6b8436..b7c31713 100644 --- a/ProjBobcat/ProjBobcat/Event/LaunchLogEventArgs.cs +++ b/ProjBobcat/ProjBobcat/Event/LaunchLogEventArgs.cs @@ -4,6 +4,6 @@ namespace ProjBobcat.Event; public class LaunchLogEventArgs : EventArgs { - public string Item { get; set; } - public TimeSpan ItemRunTime { get; set; } + public required string Item { get; init; } + public required TimeSpan ItemRunTime { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Exceptions/UnknownGameNameException.cs b/ProjBobcat/ProjBobcat/Exceptions/UnknownGameNameException.cs index e34a0b91..38b75f0b 100644 --- a/ProjBobcat/ProjBobcat/Exceptions/UnknownGameNameException.cs +++ b/ProjBobcat/ProjBobcat/Exceptions/UnknownGameNameException.cs @@ -9,20 +9,13 @@ namespace ProjBobcat.Exceptions; [Serializable] public class UnknownGameNameException : Exception { - /// - /// 创建一个 的新实例。 - /// - public UnknownGameNameException() - { - } - /// /// 创建一个 的新实例。 /// /// 解释异常原因的错误消息。 /// 导致当前异常的未知游戏名称。 /// 导致当前异常的异常。 - public UnknownGameNameException(string message, string gameName, Exception innerException) + public UnknownGameNameException(string message, string gameName, Exception? innerException) : base(message, innerException) { GameName = gameName; @@ -33,21 +26,13 @@ public UnknownGameNameException(string message, string gameName, Exception inner /// /// 导致当前异常的未知游戏名称。 /// 导致当前异常的异常。 - public UnknownGameNameException(string gameName, Exception innerException = null) + public UnknownGameNameException( + string gameName, + Exception? innerException = null) : this($"Unknown game name: {gameName}.", gameName, innerException) { } - /// - /// 用序列化数据初始化 类的新实例。 - /// - /// 包含有关所引发异常的序列化对象数据。 - /// 包含关于源或目标的上下文信息。 - protected UnknownGameNameException(SerializationInfo serializationInfo, StreamingContext context) - : base(serializationInfo, context) - { - } - /// /// 获取导致导致当前异常的未知游戏名称。 /// diff --git a/ProjBobcat/ProjBobcat/Interface/IAuthenticator.cs b/ProjBobcat/ProjBobcat/Interface/IAuthenticator.cs index ac27a591..fa6fce5d 100644 --- a/ProjBobcat/ProjBobcat/Interface/IAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/Interface/IAuthenticator.cs @@ -8,8 +8,8 @@ namespace ProjBobcat.Interface; /// public interface IAuthenticator { - ILauncherAccountParser LauncherAccountParser { get; set; } + ILauncherAccountParser LauncherAccountParser { get; init; } AuthResultBase Auth(bool userField); Task AuthTaskAsync(bool userField); - AuthResultBase GetLastAuthResult(); + AuthResultBase? GetLastAuthResult(); } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Interface/ICurseForgeInstaller.cs b/ProjBobcat/ProjBobcat/Interface/ICurseForgeInstaller.cs index ec1e24b8..12d05397 100644 --- a/ProjBobcat/ProjBobcat/Interface/ICurseForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/Interface/ICurseForgeInstaller.cs @@ -5,8 +5,8 @@ namespace ProjBobcat.Interface; public interface ICurseForgeInstaller : IInstaller { - string GameId { get; set; } - string ModPackPath { get; set; } + string? GameId { get; init; } + string ModPackPath { get; init; } Task ReadManifestTask(); void Install(); Task InstallTaskAsync(); diff --git a/ProjBobcat/ProjBobcat/Interface/IFabricInstaller.cs b/ProjBobcat/ProjBobcat/Interface/IFabricInstaller.cs index 6218063a..cb44d89a 100644 --- a/ProjBobcat/ProjBobcat/Interface/IFabricInstaller.cs +++ b/ProjBobcat/ProjBobcat/Interface/IFabricInstaller.cs @@ -5,7 +5,7 @@ namespace ProjBobcat.Interface; public interface IFabricInstaller : IInstaller { - FabricLoaderArtifactModel LoaderArtifact { get; set; } + FabricLoaderArtifactModel LoaderArtifact { get; init; } string Install(); Task InstallTaskAsync(); } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Interface/IForgeInstaller.cs b/ProjBobcat/ProjBobcat/Interface/IForgeInstaller.cs index 91256e5b..43b85f1f 100644 --- a/ProjBobcat/ProjBobcat/Interface/IForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/Interface/IForgeInstaller.cs @@ -6,9 +6,9 @@ namespace ProjBobcat.Interface; public interface IForgeInstaller : IInstaller { - string DownloadUrlRoot { get; set; } - string ForgeExecutablePath { get; set; } - VersionLocatorBase VersionLocator { get; set; } + string DownloadUrlRoot { get; init; } + string ForgeExecutablePath { get; init; } + VersionLocatorBase VersionLocator { get; init; } ForgeInstallResult InstallForge(); Task InstallForgeTaskAsync(); diff --git a/ProjBobcat/ProjBobcat/Interface/IGameCore.cs b/ProjBobcat/ProjBobcat/Interface/IGameCore.cs index 6e43c59d..194da76a 100644 --- a/ProjBobcat/ProjBobcat/Interface/IGameCore.cs +++ b/ProjBobcat/ProjBobcat/Interface/IGameCore.cs @@ -14,19 +14,19 @@ public interface IGameCore : IDisposable /// /// 获取或设置根目录。 /// - string? RootPath { get; set; } + string RootPath { get; init; } /// /// 获取或设置客户端令牌。 /// - Guid ClientToken { get; set; } + Guid ClientToken { get; init; } /// /// 获取或设置版本定位器。 /// - VersionLocatorBase VersionLocator { get; set; } + VersionLocatorBase VersionLocator { get; init; } - IGameLogResolver GameLogResolver { get; set; } + IGameLogResolver? GameLogResolver { get; init; } /// /// 启动游戏。 diff --git a/ProjBobcat/ProjBobcat/Interface/IGameResource.cs b/ProjBobcat/ProjBobcat/Interface/IGameResource.cs index d319a3bb..e6f43fe3 100644 --- a/ProjBobcat/ProjBobcat/Interface/IGameResource.cs +++ b/ProjBobcat/ProjBobcat/Interface/IGameResource.cs @@ -7,26 +7,26 @@ public interface IGameResource /// /// 下载目录 /// - string Path { get; set; } + string Path { get; init; } /// /// 标题 /// - string Title { get; set; } + string Title { get; init; } /// /// 文件类型 /// - ResourceType Type { get; set; } + ResourceType Type { get; init; } /// /// Url /// - string Url { get; set; } + string Url { get; init; } - string FileName { get; set; } + string FileName { get; init; } - long FileSize { get; set; } + long FileSize { get; init; } - string CheckSum { get; set; } + string? CheckSum { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Interface/IInstaller.cs b/ProjBobcat/ProjBobcat/Interface/IInstaller.cs index 18abc83d..2711835d 100644 --- a/ProjBobcat/ProjBobcat/Interface/IInstaller.cs +++ b/ProjBobcat/ProjBobcat/Interface/IInstaller.cs @@ -2,7 +2,7 @@ public interface IInstaller { - string CustomId { get; set; } - string RootPath { get; set; } - string InheritsFrom { get; set; } + string? CustomId { get; init; } + string RootPath { get; init; } + string? InheritsFrom { get; init; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Interface/IModrinthInstaller.cs b/ProjBobcat/ProjBobcat/Interface/IModrinthInstaller.cs index 1d848d38..8e054001 100644 --- a/ProjBobcat/ProjBobcat/Interface/IModrinthInstaller.cs +++ b/ProjBobcat/ProjBobcat/Interface/IModrinthInstaller.cs @@ -5,8 +5,8 @@ namespace ProjBobcat.Interface; public interface IModrinthInstaller : IInstaller { - string GameId { get; set; } - string ModPackPath { get; set; } + string? GameId { get; init; } + string ModPackPath { get; init; } Task ReadIndexTask(); void Install(); Task InstallTaskAsync(); diff --git a/ProjBobcat/ProjBobcat/Interface/IOptifineInstaller.cs b/ProjBobcat/ProjBobcat/Interface/IOptifineInstaller.cs index 6286af79..d04562d7 100644 --- a/ProjBobcat/ProjBobcat/Interface/IOptifineInstaller.cs +++ b/ProjBobcat/ProjBobcat/Interface/IOptifineInstaller.cs @@ -5,9 +5,9 @@ namespace ProjBobcat.Interface; public interface IOptifineInstaller : IInstaller { - string JavaExecutablePath { get; set; } - string OptifineJarPath { get; set; } - OptifineDownloadVersionModel OptifineDownloadVersion { get; set; } + string JavaExecutablePath { get; init; } + string OptifineJarPath { get; init; } + OptifineDownloadVersionModel OptifineDownloadVersion { get; init; } string Install(); Task InstallTaskAsync(); } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Interface/IQuiltInstaller.cs b/ProjBobcat/ProjBobcat/Interface/IQuiltInstaller.cs index 1e7a59e6..64f80037 100644 --- a/ProjBobcat/ProjBobcat/Interface/IQuiltInstaller.cs +++ b/ProjBobcat/ProjBobcat/Interface/IQuiltInstaller.cs @@ -5,7 +5,7 @@ namespace ProjBobcat.Interface; public interface IQuiltInstaller : IInstaller { - QuiltLoaderModel LoaderArtifact { get; set; } + QuiltLoaderModel LoaderArtifact { get; init; } string Install(); Task InstallTaskAsync(); } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Interface/IResourceInfoResolver.cs b/ProjBobcat/ProjBobcat/Interface/IResourceInfoResolver.cs index 50782366..2f9d30f1 100644 --- a/ProjBobcat/ProjBobcat/Interface/IResourceInfoResolver.cs +++ b/ProjBobcat/ProjBobcat/Interface/IResourceInfoResolver.cs @@ -7,9 +7,9 @@ namespace ProjBobcat.Interface; public interface IResourceInfoResolver : IDisposable { - string BasePath { get; set; } + string BasePath { get; init; } bool CheckLocalFiles { get; set; } - VersionInfo VersionInfo { get; set; } + VersionInfo VersionInfo { get; init; } IAsyncEnumerable ResolveResourceAsync(); IEnumerable ResolveResource(); diff --git a/ProjBobcat/ProjBobcat/Interface/IVersionLocator.cs b/ProjBobcat/ProjBobcat/Interface/IVersionLocator.cs index a4880553..e450fcca 100644 --- a/ProjBobcat/ProjBobcat/Interface/IVersionLocator.cs +++ b/ProjBobcat/ProjBobcat/Interface/IVersionLocator.cs @@ -6,8 +6,8 @@ namespace ProjBobcat.Interface; public interface IVersionLocator { - ILauncherProfileParser LauncherProfileParser { get; set; } - ILauncherAccountParser LauncherAccountParser { get; set; } + ILauncherProfileParser? LauncherProfileParser { get; init; } + ILauncherAccountParser? LauncherAccountParser { get; init; } /// /// 获取某个特定ID的游戏信息。 diff --git a/ProjBobcat/ProjBobcat/Platforms/Windows/DefaultMinecraftUWPCore.cs b/ProjBobcat/ProjBobcat/Platforms/Windows/DefaultMinecraftUWPCore.cs index 90da784c..b0ab6c5a 100644 --- a/ProjBobcat/ProjBobcat/Platforms/Windows/DefaultMinecraftUWPCore.cs +++ b/ProjBobcat/ProjBobcat/Platforms/Windows/DefaultMinecraftUWPCore.cs @@ -18,7 +18,7 @@ namespace ProjBobcat.Platforms.Windows; [SupportedOSPlatform(nameof(OSPlatform.Windows))] public class DefaultMineCraftUWPCore : GameCoreBase { - public override LaunchResult Launch(LaunchSettings? launchSettings = null) + public override LaunchResult Launch(LaunchSettings launchSettings) { var prevSpan = new TimeSpan(); var stopwatch = new Stopwatch(); diff --git a/ProjBobcat/ProjBobcat/ProjBobcat.csproj b/ProjBobcat/ProjBobcat/ProjBobcat.csproj index a35569bc..cc67f04a 100644 --- a/ProjBobcat/ProjBobcat/ProjBobcat.csproj +++ b/ProjBobcat/ProjBobcat/ProjBobcat.csproj @@ -6,7 +6,8 @@ Library - net6.0;net8.0 + net8.0 + CS8618,CS8619,CS8601,CS8602,CS8603,CS8604,CS8620,CS8622,CS8625,CS8765,CS8766,CS8767 @@ -45,7 +46,7 @@ true Bobcat.png https://github.com/Corona-Studio/ProjBobcat - 1.32.0 + 1.40.0 Corona Studio Corona Studio ProjBobcat