diff --git a/Mlaumcherb.Client.Avalonia/классы/Буржуазия/GameVersionDescriptor.cs b/Mlaumcherb.Client.Avalonia/классы/Буржуазия/GameVersionDescriptor.cs index 3d67d3f..580109d 100644 --- a/Mlaumcherb.Client.Avalonia/классы/Буржуазия/GameVersionDescriptor.cs +++ b/Mlaumcherb.Client.Avalonia/классы/Буржуазия/GameVersionDescriptor.cs @@ -67,7 +67,7 @@ public class Library public List? rules { get; set; } public Natives? natives { get; set; } public Extract? extract { get; set; } - [JsonRequired] public LibraryDownloads downloads { get; set; } = null!; + public LibraryDownloads? downloads { get; set; } } public class AssetIndexProperties diff --git a/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs b/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs index 5456a4a..06b7302 100644 --- a/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs +++ b/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs @@ -81,8 +81,8 @@ public class InstalledGameVersionProps : IComparable, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat }); descriptorRaw = parentDescriptorRaw; // removing dependency - descriptorRaw.Remove("inheritsFrom"); - File.WriteAllText(DescriptorPath, descriptorRaw.ToString()); + // descriptorRaw.Remove("inheritsFrom"); + // File.WriteAllText(DescriptorPath, descriptorRaw.ToString()); } var descriptor = descriptorRaw.ToObject() diff --git a/Mlaumcherb.Client.Avalonia/классы/Пролетариат/Libraries.cs b/Mlaumcherb.Client.Avalonia/классы/Пролетариат/Libraries.cs index 091c99a..86f98c2 100644 --- a/Mlaumcherb.Client.Avalonia/классы/Пролетариат/Libraries.cs +++ b/Mlaumcherb.Client.Avalonia/классы/Пролетариат/Libraries.cs @@ -7,13 +7,28 @@ public class Libraries { private static readonly string[] enabled_features = []; - public record JarLib(string name, IOPath jarFilePath, Artifact artifact); - public record NativeLib(string name, IOPath jarFilePath, Artifact artifact, Extract? extractionOptions) + public record JarLib(string name, IOPath jarFilePath, Artifact? artifact); + public record NativeLib(string name, IOPath jarFilePath, Artifact? artifact, Extract? extractionOptions) : JarLib(name, jarFilePath, artifact); public IReadOnlyCollection Libs { get; } - private IOPath GetJarFilePath(Artifact artifact) + public static IOPath GetPathFromMavenName(string mavenName, string ext = "jar") + { + int sep_0 = mavenName.IndexOf(':'); + if (sep_0 == -1) + throw new ArgumentException($"Invalid maven name: {mavenName}"); + int sep_1 = mavenName.IndexOf(':', sep_0 + 1); + if (sep_1 == -1) + throw new ArgumentException($"Invalid maven name: {mavenName}"); + var package = mavenName.Substring(0, sep_0).Replace('.', '/'); + var artifact = mavenName.Substring(sep_0 + 1, sep_1 - sep_0 - 1); + var version = mavenName.Substring(sep_1 + 1); + string file_name = $"{artifact}-{version}.{ext}"; + return Path.Concat(PathHelper.GetLibrariesDir(), package, artifact, version, file_name); + } + + private static IOPath GetPathFromArtifact(Artifact artifact) { string relativePath; if (!string.IsNullOrEmpty(artifact.path)) @@ -60,26 +75,30 @@ public class Libraries } Artifact artifact = null!; - if(l.downloads.classifiers != null && !l.downloads.classifiers.TryGetValue(nativesKey, out artifact!)) + if(l.downloads?.classifiers != null && !l.downloads.classifiers.TryGetValue(nativesKey, out artifact!)) throw new Exception($"can't find artifact for '{l.name}' with nativesKey '{nativesKey}'"); // skipping duplicates (WHO THE HELL CREATES THIS DISCRIPTORS AAAAAAAAA) if(!libHashes.Add(artifact.sha1)) continue; - libs.Add(new NativeLib(l.name, GetJarFilePath(artifact), artifact, l.extract)); + libs.Add(new NativeLib(l.name, GetPathFromArtifact(artifact), artifact, l.extract)); } else { - Artifact? artifact = l.downloads.artifact; - if (artifact == null) - throw new NullReferenceException($"artifact for '{l.name}' is null"); - - // skipping duplicates - if(!libHashes.Add(artifact.sha1)) - continue; - - libs.Add(new JarLib(l.name, GetJarFilePath(artifact), artifact)); + Artifact? artifact = l.downloads?.artifact; + if (artifact is null) + { + libs.Add(new JarLib(l.name, GetPathFromMavenName(l.name), artifact)); + } + else + { + // skipping duplicates + if (!libHashes.Add(artifact.sha1)) + continue; + + libs.Add(new JarLib(l.name, GetPathFromArtifact(artifact), artifact)); + } } } diff --git a/Mlaumcherb.Client.Avalonia/сеть/TaskFactories/LibrariesDownloadTaskFactory.cs b/Mlaumcherb.Client.Avalonia/сеть/TaskFactories/LibrariesDownloadTaskFactory.cs index 3d00145..aa14486 100644 --- a/Mlaumcherb.Client.Avalonia/сеть/TaskFactories/LibrariesDownloadTaskFactory.cs +++ b/Mlaumcherb.Client.Avalonia/сеть/TaskFactories/LibrariesDownloadTaskFactory.cs @@ -42,7 +42,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory foreach (var l in _libraries.Libs) { - if (!HashHelper.CheckFileSHA1(l.jarFilePath, l.artifact.sha1, checkHashes)) + if (!HashHelper.CheckFileSHA1(l.jarFilePath, l.artifact?.sha1, checkHashes)) { _libsToDownload.Add(l); } @@ -60,7 +60,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory { long total = 0; foreach (var l in _libsToDownload) - total += l.artifact.size; + total += l.artifact?.size ?? 0; return total; } @@ -76,7 +76,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory await Parallel.ForEachAsync(_libsToDownload, opt, async (l, _ct) => { LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"downloading library '{l.name}' to '{l.jarFilePath}'"); - if(string.IsNullOrEmpty(l.artifact.url)) + if(string.IsNullOrEmpty(l.artifact?.url)) throw new Exception($"library '{l.name}' doesn't have a url to download"); await DownloadFile(l.artifact.url, l.jarFilePath, _ct, pr.AddBytesCount); if (l is Libraries.NativeLib n) diff --git a/Mlaumcherb.Client.Avalonia/холопы/HashHelper.cs b/Mlaumcherb.Client.Avalonia/холопы/HashHelper.cs index b01c08a..73f6e4e 100644 --- a/Mlaumcherb.Client.Avalonia/холопы/HashHelper.cs +++ b/Mlaumcherb.Client.Avalonia/холопы/HashHelper.cs @@ -24,8 +24,8 @@ public static class HashHelper if (!File.Exists(f)) return false; - if(checkHash) - return sha1 is not null && HashFileSHA1(f) == sha1; + if(checkHash && sha1 is not null) + return HashFileSHA1(f) == sha1; return true; }