From f2fc458e9464e9ba40ec259656a01f5cb3068a56 Mon Sep 17 00:00:00 2001 From: laolarou Date: Sun, 4 Dec 2022 11:46:41 -0800 Subject: [PATCH] minor bug fix --- .../Model/LauncherProfile/ResolutionModel.cs | 8 +++- .../ProjBobcat/Class/Model/ServerSettings.cs | 17 ++++++--- .../Installer/FabricInstaller.cs | 2 +- .../Launch/DefaultLaunchArgumentParser.cs | 38 +++++++++++-------- .../Launch/DefaultLauncherProfileParser.cs | 16 ++++---- .../Interface/IDefaultValueChecker.cs | 6 +++ ProjBobcat/ProjBobcat/ProjBobcat.csproj | 10 ++++- 7 files changed, 63 insertions(+), 34 deletions(-) create mode 100644 ProjBobcat/ProjBobcat/Interface/IDefaultValueChecker.cs diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/ResolutionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/ResolutionModel.cs index 8635adba..94db2e53 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/ResolutionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/ResolutionModel.cs @@ -1,12 +1,18 @@ using Newtonsoft.Json; +using ProjBobcat.Interface; namespace ProjBobcat.Class.Model.LauncherProfile; -public class ResolutionModel +public class ResolutionModel : IDefaultValueChecker { [JsonProperty("width")] public uint Width { get; set; } [JsonProperty("height")] public uint Height { get; set; } [JsonIgnore] public bool FullScreen { get; set; } + + public bool IsDefault() + { + return Width == 0 && Height == 0; + } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs index 08c2c106..2fab1927 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs @@ -1,19 +1,24 @@ using Newtonsoft.Json; +using ProjBobcat.Interface; namespace ProjBobcat.Class.Model; -public class ServerSettings +public class ServerSettings : IDefaultValueChecker { - public string Address { get; set; } - public ushort Port { get; set; } + public string Address { get; init; } + public ushort Port { get; init; } + [JsonIgnore] public bool IsDefaultValue => IsDefault(); [JsonIgnore] public string DisplayStr => ToString(); - [JsonIgnore] public bool IsDefault => string.IsNullOrEmpty(Address) || Port == 0; - public override string ToString() { - if (IsDefault) return "[N/A]"; + if (IsDefault()) return "[N/A]"; return $"{Address}:{Port}"; } + + public bool IsDefault() + { + return string.IsNullOrEmpty(Address) && Port == 0; + } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs index 6a0ed7b8..8a33aaf8 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs @@ -14,7 +14,7 @@ namespace ProjBobcat.DefaultComponent.Installer; public class FabricInstaller : InstallerBase, IFabricInstaller { - public IVersionLocator VersionLocator { get; set; } + public IVersionLocator VersionLocator { get; init; } public FabricLoaderArtifactModel LoaderArtifact { get; set; } public string Install() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs index f0691817..4e88c245 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs @@ -44,8 +44,7 @@ public DefaultLaunchArgumentParser(LaunchSettings launchSettings, ILauncherProfi var sb = new StringBuilder(); foreach (var lib in VersionInfo.Libraries) { - sb.AppendFormat("{0};", - Path.Combine(RootPath, GamePathHelper.GetLibraryPath(lib.Path))); + sb.Append($"{Path.Combine(RootPath, GamePathHelper.GetLibraryPath(lib.Path))};"); } @@ -216,19 +215,15 @@ public IEnumerable ParseAdditionalArguments() if (!VersionInfo.AvailableGameArguments.Any()) yield break; if (!VersionInfo.AvailableGameArguments.ContainsKey("has_custom_resolution")) yield break; - if ((LaunchSettings.GameArguments?.Resolution?.Height ?? 0) > 0 && - (LaunchSettings.GameArguments?.Resolution?.Width ?? 0) > 0) + if (!(LaunchSettings.GameArguments?.Resolution?.IsDefault() ?? true)) { yield return "--width"; - yield return (GameProfile.Resolution?.Width ?? LaunchSettings.GameArguments.Resolution.Width) - .ToString(); + yield return LaunchSettings.GameArguments.Resolution.Width.ToString(); yield return "--height"; - yield return (GameProfile.Resolution?.Height ?? LaunchSettings.GameArguments.Resolution.Height) - .ToString(); + yield return LaunchSettings.GameArguments.Resolution.Height.ToString(); } - else if ((LaunchSettings.FallBackGameArguments?.Resolution?.Width ?? 0) > 0 - && (LaunchSettings.FallBackGameArguments?.Resolution?.Height ?? 0) > 0) + else if (!(LaunchSettings.FallBackGameArguments?.Resolution?.IsDefault() ?? true)) { yield return "--width"; yield return LaunchSettings.FallBackGameArguments.Resolution.Width.ToString(); @@ -236,20 +231,31 @@ public IEnumerable ParseAdditionalArguments() yield return "--height"; yield return LaunchSettings.FallBackGameArguments.Resolution.Height.ToString(); } + else if (!(GameProfile.Resolution?.IsDefault() ?? true)) + { + yield return "--width"; + yield return GameProfile.Resolution.Width.ToString(); + + yield return "--height"; + yield return GameProfile.Resolution.Height.ToString(); + } if (LaunchSettings.GameArguments?.ServerSettings == null && LaunchSettings.FallBackGameArguments?.ServerSettings == null) yield break; var serverSettings = LaunchSettings.GameArguments?.ServerSettings ?? - LaunchSettings.FallBackGameArguments.ServerSettings; + LaunchSettings.FallBackGameArguments?.ServerSettings; - if (string.IsNullOrEmpty(serverSettings.Address)) yield break; + if (serverSettings != null && !serverSettings.IsDefault()) + { + if (string.IsNullOrEmpty(serverSettings.Address)) yield break; - yield return "--server"; - yield return serverSettings.Address; + yield return "--server"; + yield return serverSettings.Address; - yield return "--port"; - yield return serverSettings.Port.ToString(); + yield return "--port"; + yield return serverSettings.Port.ToString(); + } } /// diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs index 84d44bc7..b92102d4 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs @@ -18,7 +18,7 @@ namespace ProjBobcat.DefaultComponent.Launch; /// public sealed class DefaultLauncherProfileParser : LauncherParserBase, ILauncherProfileParser { - readonly string FullLauncherProfilePath; + readonly string _fullLauncherProfilePath; /// /// 构造函数 @@ -28,9 +28,9 @@ public sealed class DefaultLauncherProfileParser : LauncherParserBase, ILauncher public DefaultLauncherProfileParser(string rootPath, Guid clientToken) { RootPath = rootPath; - FullLauncherProfilePath = Path.Combine(rootPath, GamePathHelper.GetLauncherProfilePath()); + _fullLauncherProfilePath = Path.Combine(rootPath, GamePathHelper.GetLauncherProfilePath()); - if (!File.Exists(FullLauncherProfilePath)) + if (!File.Exists(_fullLauncherProfilePath)) { var launcherProfile = new LauncherProfileModel { @@ -51,12 +51,12 @@ public DefaultLauncherProfileParser(string rootPath, Guid clientToken) if (!Directory.Exists(RootPath)) Directory.CreateDirectory(RootPath); - File.WriteAllText(FullLauncherProfilePath, launcherProfileJson); + File.WriteAllText(_fullLauncherProfilePath, launcherProfileJson); } else { var launcherProfileJson = - File.ReadAllText(FullLauncherProfilePath, Encoding.UTF8); + File.ReadAllText(_fullLauncherProfilePath, Encoding.UTF8); LauncherProfile = JsonConvert.DeserializeObject(launcherProfileJson); } } @@ -100,13 +100,13 @@ public void RemoveGameProfile(string name) public void SaveProfile() { - if (File.Exists(FullLauncherProfilePath)) - File.Delete(FullLauncherProfilePath); + if (File.Exists(_fullLauncherProfilePath)) + File.Delete(_fullLauncherProfilePath); var launcherProfileJson = JsonConvert.SerializeObject(LauncherProfile, JsonHelper.CamelCasePropertyNamesSettings); - File.WriteAllText(FullLauncherProfilePath, launcherProfileJson); + File.WriteAllText(_fullLauncherProfilePath, launcherProfileJson); } public void SelectGameProfile(string name) diff --git a/ProjBobcat/ProjBobcat/Interface/IDefaultValueChecker.cs b/ProjBobcat/ProjBobcat/Interface/IDefaultValueChecker.cs new file mode 100644 index 00000000..b6ba036d --- /dev/null +++ b/ProjBobcat/ProjBobcat/Interface/IDefaultValueChecker.cs @@ -0,0 +1,6 @@ +namespace ProjBobcat.Interface; + +public interface IDefaultValueChecker +{ + bool IsDefault(); +} \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/ProjBobcat.csproj b/ProjBobcat/ProjBobcat/ProjBobcat.csproj index 2bf3abad..377468c0 100644 --- a/ProjBobcat/ProjBobcat/ProjBobcat.csproj +++ b/ProjBobcat/ProjBobcat/ProjBobcat.csproj @@ -40,12 +40,12 @@ true Bobcat.png https://github.com/Corona-Studio/ProjBobcat - 1.20.0 + 1.21.0 Corona Studio Corona Studio ProjBobcat The next-generation Minecraft launcher core written in C# providing the freest, fastest and the most complete experience. - Copyright © 2021 Corona Studio + Copyright © 2022 Corona Studio Bobcat.png https://github.com/Corona-Studio/ProjBobcat git @@ -62,6 +62,8 @@ add support for Quilt installation snupkg MIT https://github.com/Corona-Studio/ProjBobcat + $(AssemblyName) + README.md @@ -70,6 +72,10 @@ add support for Quilt installation + + True + \ + .editorconfig