diff --git a/MinecraftLaunch/Classes/Enums/Platform.cs b/MinecraftLaunch/Classes/Enums/Platform.cs new file mode 100644 index 0000000..fa5dc1a --- /dev/null +++ b/MinecraftLaunch/Classes/Enums/Platform.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MinecraftLaunch.Classes.Enums +{ + public enum Platform + { + windows, + linux, + osx, + unknown + } +} diff --git a/MinecraftLaunch/Classes/Models/Game/LibraryJsonEntry.cs b/MinecraftLaunch/Classes/Models/Game/LibraryJsonEntry.cs index 34a872f..98a8a39 100644 --- a/MinecraftLaunch/Classes/Models/Game/LibraryJsonEntry.cs +++ b/MinecraftLaunch/Classes/Models/Game/LibraryJsonEntry.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using MinecraftLaunch.Classes.Enums; using MinecraftLaunch.Classes.Models.Download; namespace MinecraftLaunch.Classes.Models.Game { @@ -10,14 +11,15 @@ public record LibraryJsonEntry { public DownloadsEntry Downloads { get; set; } [JsonPropertyName("natives")] - public Dictionary Natives { get; set; } + public Dictionary Natives { get; set; } } - public record RuleModel { + public record RuleModel + { [JsonPropertyName("action")] public string Action { get; set; } [JsonPropertyName("os")] - public Dictionary System { get; set; } + public Dictionary System { get; set; } } } diff --git a/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs b/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs index 5f45b65..35fb333 100644 --- a/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs +++ b/MinecraftLaunch/Components/Fetcher/JavaFetcher.cs @@ -6,6 +6,7 @@ using System.Runtime.InteropServices; using MinecraftLaunch.Classes.Interfaces; using MinecraftLaunch.Classes.Models.Game; +using MinecraftLaunch.Classes.Enums; namespace MinecraftLaunch.Components.Fetcher { public class JavaFetcher : IFetcher> { @@ -67,9 +68,9 @@ public ImmutableArray Fetch() { public async ValueTask> FetchAsync() { return EnvironmentUtil.GetPlatformName() switch { - "windows" => FetchWindowJava(), - "osx" => await FetchMacJavaAsync(), - "linux" => await FetchLinuxJavaAsync(), + Platform.windows => FetchWindowJava(), + Platform.osx => await FetchMacJavaAsync(), + Platform.linux => await FetchLinuxJavaAsync(), _ => FetchWindowJava() }; } diff --git a/MinecraftLaunch/Components/Launcher/ArgumentsBuilder.cs b/MinecraftLaunch/Components/Launcher/ArgumentsBuilder.cs index 848ef87..800094b 100644 --- a/MinecraftLaunch/Components/Launcher/ArgumentsBuilder.cs +++ b/MinecraftLaunch/Components/Launcher/ArgumentsBuilder.cs @@ -148,9 +148,9 @@ private string GetClasspath() { } private static IEnumerable GetEnvironmentJvmArguments() { - string platformName = EnvironmentUtil.GetPlatformName(); - if (!(platformName == "windows")) { - if (platformName == "osx") + Platform platformName = EnvironmentUtil.GetPlatformName(); + if (!(platformName == Platform.windows)) { + if (platformName == Platform.osx) yield return "-XstartOnFirstThread"; } else { yield return "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump"; diff --git a/MinecraftLaunch/Components/Resolver/LibrariesResolver.cs b/MinecraftLaunch/Components/Resolver/LibrariesResolver.cs index 180efbd..f786f0d 100644 --- a/MinecraftLaunch/Components/Resolver/LibrariesResolver.cs +++ b/MinecraftLaunch/Components/Resolver/LibrariesResolver.cs @@ -4,6 +4,7 @@ using MinecraftLaunch.Extensions; using MinecraftLaunch.Classes.Interfaces; using MinecraftLaunch.Classes.Models.Game; +using MinecraftLaunch.Classes.Enums; namespace MinecraftLaunch.Components.Resolver; @@ -111,13 +112,13 @@ private bool GetLibraryEnable(IEnumerable rules) { foreach (var os in item.System) { switch (os.Value) { - case "windows": + case Platform.windows: windows = true; break; - case "linux": + case Platform.linux: linux = true; break; - case "osx": + case Platform.osx: osx = true; break; } @@ -130,13 +131,13 @@ private bool GetLibraryEnable(IEnumerable rules) { foreach (var os in item.System) { switch (os.Value) { - case "windows": + case Platform.windows: windows = false; break; - case "linux": + case Platform.linux: linux = false; break; - case "osx": + case Platform.osx: osx = false; break; } @@ -145,9 +146,9 @@ private bool GetLibraryEnable(IEnumerable rules) { } return EnvironmentUtil.GetPlatformName() switch { - "windows" => windows, - "linux" => linux, - "osx" => osx, + Platform.windows => windows, + Platform.linux=> linux, + Platform.osx => osx, _ => false, }; } diff --git a/MinecraftLaunch/Utilities/EnvironmentUtil.cs b/MinecraftLaunch/Utilities/EnvironmentUtil.cs index 543006e..75e341d 100644 --- a/MinecraftLaunch/Utilities/EnvironmentUtil.cs +++ b/MinecraftLaunch/Utilities/EnvironmentUtil.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using MinecraftLaunch.Classes.Enums; +using System.Runtime.InteropServices; namespace MinecraftLaunch.Utilities { public class EnvironmentUtil { @@ -14,16 +15,16 @@ public static bool IsLinux public static bool IsWindow => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - public static string GetPlatformName() { + public static Platform GetPlatformName() { if (IsMac) { - return "osx"; + return Platform.osx; } else if (IsLinux) { - return "linux"; + return Platform.linux; } else if (IsWindow) { - return "windows"; + return Platform.windows; } - return "unknown"; + return Platform.unknown; } } } diff --git a/MinecraftLaunch/Utilities/ZipUtil.cs b/MinecraftLaunch/Utilities/ZipUtil.cs index 7c8f499..8bc7b95 100644 --- a/MinecraftLaunch/Utilities/ZipUtil.cs +++ b/MinecraftLaunch/Utilities/ZipUtil.cs @@ -1,4 +1,5 @@ -using System.IO.Compression; +using MinecraftLaunch.Classes.Enums; +using System.IO.Compression; namespace MinecraftLaunch.Utilities { public class ZipUtil { @@ -10,9 +11,9 @@ public static void ExtractNatives(string targetFolder, IEnumerable files DirectoryUtil.DeleteAllFiles(targetFolder); var extension = EnvironmentUtil.GetPlatformName() switch { - "windows" => ".dll", - "linux" => ".so", - "osx" => ".dylib", + Platform.windows => ".dll", + Platform.linux => ".so", + Platform.osx => ".dylib", _ => "." };