Browse Source

fabric dublicate libs in args fix

Veloe 4 months ago
parent
commit
1ae276bb58

+ 19 - 11
VeloeMinecraftLauncher/Utils/Starter/StartCommandBuilder.cs

@@ -30,7 +30,7 @@ internal static class StartCommandBuilder
             returnString.Append($"-Djava.library.path=\"{Path.GetDirectoryName(SettingsService.Instance.MinecraftForlderPath + "versions/" + version.InheritsFrom + "/natives/")}\""); //for forge, vanilla optifine, fabric
 
         returnString.Append(" -cp \"");
-
+        var libHashes = new HashSet<string>();
         // add libraries
         foreach (var library in version.Libraries)
         {
@@ -62,19 +62,25 @@ internal static class StartCommandBuilder
                 }
             }
 
-            //if no path
-            if (library.Downloads is null) //for optifine
+            bool _separatorFound = false;
+            bool IsSecondSeparator(char symbol,char separator = ':')
             {
-                var libPath = GetLibPathFromName(library.Name);
-                if (rulesVaild)
-                    returnString.Append(Path.GetFullPath(SettingsService.Instance.MinecraftForlderPath + "libraries/" + libPath) + separator);
-
-                continue;
+                if (symbol == separator)
+                    if (_separatorFound)
+                    {
+                        _separatorFound = false;
+                        return false;
+                    }
+                    else
+                        _separatorFound = true;
+                return true;
             }
 
             if (rulesVaild)
-                returnString.Append(Path.GetFullPath(SettingsService.Instance.MinecraftForlderPath + "libraries/" + library.Downloads.Artifact.Path) + separator);
-
+            {                                                                                                                                   // for optifine                     // default
+                returnString.Append(Path.GetFullPath(SettingsService.Instance.MinecraftForlderPath + "libraries/" + (library.Downloads is null ? GetLibPathFromName(library.Name) : library.Downloads.Artifact.Path)) + separator);
+                libHashes.Add(string.Concat(library.Name.TakeWhile(x => IsSecondSeparator(x))));
+            }
         }
 
         Entity.Version.Version? inheritsFrom = null;
@@ -94,6 +100,9 @@ internal static class StartCommandBuilder
                 if (library.Natives is not null)
                     continue;
 
+                if (libHashes.Contains(string.Join(':', library.Name.Split(':').Take(2))))
+                    continue;
+
                 if (library.Rules is not null)
                 {
                     rulesVaild = false;
@@ -101,7 +110,6 @@ internal static class StartCommandBuilder
                     {
                         bool isRuleOsExist = rule.Os is not null;
 
-
                         if (rule.Action == "allow" && rule.Os is null)
                         {
                             rulesVaild = true;

+ 2 - 2
VeloeMinecraftLauncher/VeloeMinecraftLauncher.csproj

@@ -10,8 +10,8 @@
 		<DebugType>embedded</DebugType>
 		<StartupObject>VeloeMinecraftLauncher.Program</StartupObject>
 		<PlatformTarget>x64</PlatformTarget>
-		<AssemblyVersion>1.6.0.177</AssemblyVersion>
-		<FileVersion>1.6.0.177</FileVersion>
+		<AssemblyVersion>1.6.0.188</AssemblyVersion>
+		<FileVersion>1.6.0.188</FileVersion>
 		<Configurations>Debug;Release</Configurations>
 		<Copyright>MIT</Copyright>
 		<RepositoryType>git</RepositoryType>