Skip to content

Commit

Permalink
minor bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Dec 4, 2022
1 parent 46f2d2a commit f2fc458
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 11 additions & 6 deletions ProjBobcat/ProjBobcat/Class/Model/ServerSettings.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))};");
}


Expand Down Expand Up @@ -216,40 +215,47 @@ public IEnumerable<string> 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();

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();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ProjBobcat.DefaultComponent.Launch;
/// </summary>
public sealed class DefaultLauncherProfileParser : LauncherParserBase, ILauncherProfileParser
{
readonly string FullLauncherProfilePath;
readonly string _fullLauncherProfilePath;

/// <summary>
/// 构造函数
Expand All @@ -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
{
Expand All @@ -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<LauncherProfileModel>(launcherProfileJson);
}
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions ProjBobcat/ProjBobcat/Interface/IDefaultValueChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ProjBobcat.Interface;

public interface IDefaultValueChecker
{
bool IsDefault();
}
10 changes: 8 additions & 2 deletions ProjBobcat/ProjBobcat/ProjBobcat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIcon>Bobcat.png</PackageIcon>
<RepositoryUrl>https://github.com/Corona-Studio/ProjBobcat</RepositoryUrl>
<Version>1.20.0</Version>
<Version>1.21.0</Version>
<Authors>Corona Studio</Authors>
<Company>Corona Studio</Company>
<Product>ProjBobcat</Product>
<Description>The next-generation Minecraft launcher core written in C# providing the freest, fastest and the most complete experience.</Description>
<Copyright>Copyright © 2021 Corona Studio</Copyright>
<Copyright>Copyright © 2022 Corona Studio</Copyright>
<PackageIcon>Bobcat.png</PackageIcon>
<RepositoryUrl>https://github.com/Corona-Studio/ProjBobcat</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -62,6 +62,8 @@ add support for Quilt installation
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Corona-Studio/ProjBobcat</PackageProjectUrl>
<Title>$(AssemblyName)</Title>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -70,6 +72,10 @@ add support for Quilt installation
</ItemGroup>

<ItemGroup>
<None Include="..\..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\.editorconfig">
<Link>.editorconfig</Link>
</None>
Expand Down

0 comments on commit f2fc458

Please sign in to comment.