Quellcode durchsuchen

added fabric installer support

Veloe vor 3 Jahren
Ursprung
Commit
4444e0f348

+ 111 - 15
VeloeMinecraftLauncher/MinecraftLauncher/StartCommandBuilder.cs

@@ -22,70 +22,165 @@ namespace VeloeMinecraftLauncher.MinecraftLauncher
             if (version is null)
                 return returnString.ToString();
 
-            if(Settings.setMaxRam)
-                returnString.Append($"-Xmx{Settings.MaxRam}M ");
-
-            //for forge
+            // setting natives folder
             if (version.inheritsFrom is null)
                 returnString.Append($"-Djava.library.path={Settings.MinecraftForlderPath + "versions/" + version.id + "/natives/"}");
             else
-                returnString.Append($"-Djava.library.path={Settings.MinecraftForlderPath + "versions/" + version.inheritsFrom + "//natives/"}");
+                returnString.Append($"-Djava.library.path={Settings.MinecraftForlderPath + "versions/" + version.inheritsFrom + "/natives/"}"); //for forge, vanilla optifine, fabric
 
             returnString.Append(" -cp ");
 
+            // add libraries
             foreach(var library in version.libraries)
             {
+                bool rulesVaild = true;
+                //check if native
                 if (library.natives is not null)
                     continue;
 
+                //rules check
+                if (library.rules is not null)
+                {
+                    rulesVaild = false;
+                    foreach (var rule in library.rules)
+                    {
+                        bool isRuleOsExist = rule.os is not null;
+
+
+                        if (rule.action == "allow" && rule.os is null)
+                        {
+                            rulesVaild = true;
+                            continue;
+                        }
+
+                        if (rule.os is not null)
+                            if (rule.action == "allow" &&
+                                    (rule.os.name == "linux" && OperatingSystem.IsLinux() ||
+                                    rule.os.name == "windows" && OperatingSystem.IsWindows())
+                                )
+                            {
+                                rulesVaild = true;
+                                continue;
+                            }
+                    }
+                }
+
+                //if no path
                 if (library.downloads is null) //for optifine
                 {
+
                     string name = library.name;
                     var dirs = name.Split(':');
+                    dirs[0] = dirs[0].Replace('.','/');
                     var libPath = String.Empty;
                     foreach (var dir in dirs)
                     {
                         libPath += dir+"/";
                     }
-                    returnString.Append(Settings.MinecraftForlderPath + "libraries/" + libPath + dirs[dirs.Length-2]+"-"+dirs[dirs.Length-1]+".jar;");
+                    if (rulesVaild)
+                        returnString.Append(Settings.MinecraftForlderPath + "libraries/" + libPath + dirs[dirs.Length-2]+"-"+dirs[dirs.Length-1]+".jar;");
 
                     continue;
                 }
 
-                returnString.Append(Settings.MinecraftForlderPath + "libraries/" + library.downloads.artifact.path + separator);
+                if (rulesVaild)
+                    returnString.Append(Settings.MinecraftForlderPath + "libraries/" + library.downloads.artifact.path + separator);
 
             }
-            //for forge and vanilla optifine
+            
             Entity.Version.Version inheritsFrom = new();
             if (version.inheritsFrom is null)
-                returnString.Append(Settings.MinecraftForlderPath + "versions/" + version.id + "/" + version.id + ".jar");
+                returnString.Append(Settings.MinecraftForlderPath + "versions/" + version.id + "/" + version.id + ".jar"); //main jar file
             else
             {
+                //for forge, vanilla optifine, fabric
+                //add libraries from inherited version
                 var inheritsJsonString = File.ReadAllText(Settings.MinecraftForlderPath + "versions/" + version.inheritsFrom + "/" + version.inheritsFrom + ".json");
                 
                 inheritsFrom = JsonSerializer.Deserialize<Entity.Version.Version>(inheritsJsonString);
 
                 foreach (var library in inheritsFrom.libraries)
                 {
+                    bool rulesVaild = true;
                     if (library.natives is not null)
                         continue;
 
-                    returnString.Append(Settings.MinecraftForlderPath + "libraries/" + library.downloads.artifact.path + separator);
+                    if (library.rules is not null)
+                    {
+                        rulesVaild = false;
+                        foreach (var rule in library.rules)
+                        {
+                            bool isRuleOsExist = rule.os is not null;
+
+
+                            if (rule.action == "allow" && rule.os is null)
+                            {
+                                rulesVaild = true;
+                                continue;
+                            }
+
+                            if (rule.os is not null)
+                                if (rule.action == "allow" &&
+                                        (rule.os.name == "linux" && OperatingSystem.IsLinux() ||
+                                        rule.os.name == "windows" && OperatingSystem.IsWindows())
+                                    )
+                                {
+                                    rulesVaild = true;
+                                    continue;
+                                }
+                        }
+                    }
+
+                    if(rulesVaild)
+                        returnString.Append(Settings.MinecraftForlderPath + "libraries/" + library.downloads.artifact.path + separator);
     
                 }
+                //main jar file
                 //check here if there is jar file not inherited
-                if (File.Exists($"{Settings.MinecraftForlderPath}versions/{version.id}/{version.id}.jar"))
+                //check if it is not 0kb size (fabric)
+                var fileInfo = new FileInfo($"{Settings.MinecraftForlderPath}versions/{version.id}/{version.id}.jar");
+
+                if (fileInfo.Exists && fileInfo.Length > 0)
                     returnString.Append(Settings.MinecraftForlderPath + "versions/" + version.id + "/" + version.id + ".jar");//for optifine
                 else
                     returnString.Append(Settings.MinecraftForlderPath + "versions/" + version.inheritsFrom + "/" + version.inheritsFrom + ".jar");//for forge
             }
 
+           //check for jvm fabric options
+   
+            if (version.arguments is not null && version.inheritsFrom is not null)
+            {
+                if (version.arguments.jvm is not null)
+                    foreach (var argument in version.arguments.jvm)
+                    {
+                        if (argument is null)
+                            continue;
+
+                        var type = argument.GetType();
+
+                        if (!(argument is JsonElement))
+                            continue;
+
+                        if (!(((JsonElement)argument).ValueKind == JsonValueKind.String))
+                            continue;
+
+                        var value = ((JsonElement)argument).Deserialize(typeof(string));
+
+                        returnString.Append(" ");
+                        returnString.Append((value as string).Replace(" ", ""));
+                    }
+            }
+
+            //max ram
+            if (Settings.setMaxRam)
+                returnString.Append($" -Xmx{Settings.MaxRam}M ");
+
+
             returnString.Append(" " + version.mainClass);
 
             List<string> args = new List<string>();
             List<string> argsValues = new List<string>();
-
-            //TODO check here if all required arguments needed. Check inheritFrom if needed
+           
             if (version.arguments is not null)
             {
                 foreach (var argument in version.arguments.game)
@@ -141,6 +236,7 @@ namespace VeloeMinecraftLauncher.MinecraftLauncher
                 { "--tweakClass", false }
             };
 
+            //check if all required arguments provided. Use inheritFrom if needed
             foreach (var arg in args)
             {
                 argsProvided[arg] = true;
@@ -204,11 +300,11 @@ namespace VeloeMinecraftLauncher.MinecraftLauncher
                         returnString.Append(" --username " + username);
                         break;
                     case "--version":
-                        returnString.Append(" --version " + "\"Copy of VeloeLauncher\"");
+                        returnString.Append(" --version " + version.id /*"\"Copy of VeloeLauncher\""*/);
                         break;
                     case "--gameDir":
                         //for forge
-                        if (!(argsValues.Where(x => x.Contains("forge")).Count() > 0 || argsValues.Where(x => x.Contains("fabric")).Count() > 0))
+                        if (!(argsValues.Where(x => x.Contains("forge")).Count() > 0 || version.id.ToLower().Contains("fabric")))
                             returnString.Append(" --gameDir " + Settings.MinecraftForlderPath);
                         else
                             returnString.Append(" --gameDir " + Settings.MinecraftForlderPath + "versions/" + version.id);

+ 2 - 2
VeloeMinecraftLauncher/Models/Entity/Version/Version.cs

@@ -160,8 +160,8 @@ namespace VeloeMinecraftLauncher.Entity.Version
         public string mainClass { get; set; }
         public string minecraftArguments { get; set; }
         public int minimumLauncherVersion { get; set; }
-        public DateTime releaseTime { get; set; }
-        public DateTime time { get; set; }
+        public string releaseTime { get; set; }
+        public string time { get; set; }
         public string type { get; set; }
 
         public string inheritsFrom { get; set; }

+ 2 - 6
VeloeMinecraftLauncher/ViewModels/VersionsDownloaderViewModel.cs

@@ -20,8 +20,6 @@ namespace VeloeMinecraftLauncher.ViewModels
 {
     public class VersionsDownloaderViewModel : ViewModelBase
     {
-        int i = 0;
-
         private string startButton = "Download";
         private bool showOld = false;
         private bool showSnaps = false;
@@ -38,8 +36,6 @@ namespace VeloeMinecraftLauncher.ViewModels
         private int progress = 0;
         private string downloadingFileName;
 
-        Task downloadMinecraftTask;
-
         Serilog.ILogger logger;
 
         ObservableCollection<Entity.VersionManifest.Version> filteredVersions;
@@ -108,7 +104,7 @@ namespace VeloeMinecraftLauncher.ViewModels
                 {
                     using (var httpClient = new HttpClient())
                     {
-                    
+
                         var response = httpClient.GetAsync(@$"https://files.veloe.link/launcher/forge/Forge{value.id}/Forge{value.id}.json").Result;
 
                         if (response.IsSuccessStatusCode)
@@ -497,7 +493,7 @@ namespace VeloeMinecraftLauncher.ViewModels
                                     waitWhileBisy(ref webClient);
                                     continue;
                                 }
-                                if (rule.action == "allow" && (rule.os.name == "windows" && OperatingSystem.IsWindows() || rule.os.name == "linux" && OperatingSystem.IsLinux()))
+                                if (rule.action == "allow" && (rule.os.name == "windows" || rule.os.name == "linux" || rule.os.name == "osx" ))
                                 {
                                     if (!Directory.Exists(libPath))
                                     {