diff --git a/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj b/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj index 9fe7199..6e5af0b 100644 --- a/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj +++ b/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj @@ -22,7 +22,7 @@ - + diff --git a/Млаумчерб.Клиент/классы/Libraries.cs b/Млаумчерб.Клиент/классы/Libraries.cs index e846d48..60556d9 100644 --- a/Млаумчерб.Клиент/классы/Libraries.cs +++ b/Млаумчерб.Клиент/классы/Libraries.cs @@ -7,7 +7,7 @@ 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, IOPath nativeFilesDir, Extract? extractionOptions) + public record NativeLib(string name, IOPath jarFilePath, Artifact artifact, Extract? extractionOptions) : JarLib(name, jarFilePath, artifact); public IReadOnlyCollection Libs { get; } @@ -43,9 +43,9 @@ public class Libraries if(!libHashes.Add(artifact.sha1)) continue; - IOPath dir = Пути.GetVersionDir(descriptor.id); - IOPath jarPath = Path.Concat(dir, Path.ReplaceRestrictedChars(l.name)); - libs.Add(new NativeLib(l.name, jarPath, artifact, dir, l.extract)); + string urlTail = artifact.url.AsSpan().After("://").After('/').ToString(); + IOPath jarFilePath = Path.Concat(Пути.GetLibrariesDir(), urlTail); + libs.Add(new NativeLib(l.name, jarFilePath, artifact, l.extract)); } else { @@ -57,8 +57,9 @@ public class Libraries if(!libHashes.Add(artifact.sha1)) continue; - IOPath path = artifact.url.AsSpan().After("://").After('/').ToString(); - libs.Add(new JarLib(l.name, Path.Concat(Пути.GetLibrariesDir(), path), artifact)); + string urlTail = artifact.url.AsSpan().After("://").After('/').ToString(); + IOPath jarFilePath = Path.Concat(Пути.GetLibrariesDir(), urlTail); + libs.Add(new JarLib(l.name, jarFilePath, artifact)); } } diff --git a/Млаумчерб.Клиент/классы/Буржуазия.cs b/Млаумчерб.Клиент/классы/Буржуазия.cs index 35cb6b1..cf10e79 100644 --- a/Млаумчерб.Клиент/классы/Буржуазия.cs +++ b/Млаумчерб.Клиент/классы/Буржуазия.cs @@ -52,5 +52,14 @@ public static class Буржуазия } return allowed; - } + } + + public static string GetOs() => + Environment.OSVersion.Platform switch + { + PlatformID.Win32NT => "windows", + PlatformID.Unix => "linux", + PlatformID.MacOSX => "osx", + _ => throw new ArgumentOutOfRangeException(Environment.OSVersion.Platform.ToString()) + }; } diff --git a/Млаумчерб.Клиент/классы/Пути.cs b/Млаумчерб.Клиент/классы/Пути.cs index 8891eed..4052b69 100644 --- a/Млаумчерб.Клиент/классы/Пути.cs +++ b/Млаумчерб.Клиент/классы/Пути.cs @@ -25,6 +25,9 @@ public static class Пути public static IOPath GetLibrariesDir() => Path.Concat(Приложение.Настройки.путь_к_кубачу, "libraries"); + public static IOPath GetNativeLibrariesDir(string id) => + Path.Concat(GetVersionDir(id), "natives", Буржуазия.GetOs()); + public static IOPath GetJavaRuntimesDir() => Path.Concat(Приложение.Настройки.путь_к_кубачу, "java"); diff --git a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs index 662627d..672fa28 100644 --- a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs +++ b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs @@ -99,7 +99,7 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory private async Task Download(NetworkProgressReporter pr, CancellationToken ct) { - Приложение.Логгер.LogInfo(nameof(Сеть), "started downloading assets"); + Приложение.Логгер.LogInfo(nameof(Сеть), $"started downloading assets '{_descriptor.assetIndex.id}'"); ParallelOptions opt = new() { MaxDegreeOfParallelism = ParallelDownloadsN, CancellationToken = ct }; await Parallel.ForEachAsync(_assetsToDownload, opt, async (a, _ct) => @@ -107,6 +107,6 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory Приложение.Логгер.LogDebug(nameof(Сеть), $"downloading asset '{a.name}' {a.hash}"); await DownloadFileHTTP(a.url, a.filePath, _ct, pr.AddBytesCount); }); - Приложение.Логгер.LogInfo(nameof(Сеть), "finished downloading assets"); + Приложение.Логгер.LogInfo(nameof(Сеть), $"finished downloading assets '{_descriptor.assetIndex.id}'"); } } \ No newline at end of file diff --git a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs index d9c2d6f..79fab6d 100644 --- a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs +++ b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs @@ -1,4 +1,5 @@ -using System.Security.Cryptography; +using System.IO.Compression; +using System.Security.Cryptography; using DTLib.Extensions; using Млаумчерб.Клиент.видимое; using Млаумчерб.Клиент.классы; @@ -12,12 +13,14 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory private Libraries _libraries; private SHA1 _hasher; private List _libsToDownload = new(); + private IOPath _nativesDir; public LibrariesDownloadTaskFactory(VersionDescriptor descriptor, Libraries libraries) { _descriptor = descriptor; _libraries = libraries; _hasher = SHA1.Create(); + _nativesDir = Пути.GetNativeLibrariesDir(descriptor.id); } public Task CreateAsync(bool checkHashes) @@ -35,6 +38,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory private bool CheckFiles(bool checkHashes) { _libsToDownload.Clear(); + bool nativeDirExists = Directory.Exists(_nativesDir); foreach (var l in _libraries.Libs) { @@ -42,6 +46,10 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory { _libsToDownload.Add(l); } + else if (!nativeDirExists && l is Libraries.NativeLib) + { + _libsToDownload.Add(l); + } else if (checkHashes) { using var fs = File.OpenRead(l.jarFilePath); @@ -64,15 +72,30 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory private async Task Download(NetworkProgressReporter pr, CancellationToken ct) { - Приложение.Логгер.LogInfo(nameof(Сеть), "started downloading libraries"); + Приложение.Логгер.LogInfo(nameof(Сеть), $"started downloading libraries '{_descriptor.id}'"); ParallelOptions opt = new() { MaxDegreeOfParallelism = ParallelDownloadsN, CancellationToken = ct }; await Parallel.ForEachAsync(_libsToDownload, opt, async (l, _ct) => { Приложение.Логгер.LogDebug(nameof(Сеть), $"downloading library '{l.name}' to '{l.jarFilePath}'"); await DownloadFileHTTP(l.artifact.url, l.jarFilePath, _ct, pr.AddBytesCount); - //TODO: extract natives from jar + if (l is Libraries.NativeLib n) + { + var zipf = File.OpenRead(n.jarFilePath); + ZipFile.ExtractToDirectory(zipf, _nativesDir.ToString(), true); + if (n.extractionOptions?.exclude != null) + { + foreach (var excluded in n.extractionOptions.exclude) + { + IOPath path = Path.Concat(_nativesDir, excluded); + if(Directory.Exists(path)) + Directory.Delete(path); + if(File.Exists(path)) + File.Delete(path); + } + } + } }); - Приложение.Логгер.LogInfo(nameof(Сеть), "finished downloading libraries"); + Приложение.Логгер.LogInfo(nameof(Сеть), $"finished downloading libraries '{_descriptor.id}'"); } } \ No newline at end of file diff --git a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs index 3a44c22..5cb4787 100644 --- a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs +++ b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs @@ -1,5 +1,6 @@ using System.Security.Cryptography; using DTLib.Extensions; +using Млаумчерб.Клиент.видимое; using Млаумчерб.Клиент.классы; using static Млаумчерб.Клиент.сеть.Сеть; @@ -46,8 +47,10 @@ public class VersionFileDownloadTaskFactory : INetworkTaskFactory return _descriptor.downloads.client.size; } - private Task Download(NetworkProgressReporter pr, CancellationToken ct) + private async Task Download(NetworkProgressReporter pr, CancellationToken ct) { - return DownloadFileHTTP(_descriptor.downloads.client.url, _filePath, ct, pr.AddBytesCount); + Приложение.Логгер.LogInfo(nameof(Сеть), $"started downloading version file '{_descriptor.id}'"); + await DownloadFileHTTP(_descriptor.downloads.client.url, _filePath, ct, pr.AddBytesCount); + Приложение.Логгер.LogInfo(nameof(Сеть), $"finished downloading version file '{_descriptor.id}'"); } } \ No newline at end of file