3 Commits

Author SHA1 Message Date
679d89b4b0 removed symlink creation 2024-12-31 22:49:06 +05:00
228b3bc55f RemoteCatalog order changed 2024-12-31 21:53:54 +05:00
7882bb9bfd Fix for libraries in modpacks 2024-12-31 21:51:25 +05:00
5 changed files with 92 additions and 83 deletions

View File

@@ -22,8 +22,8 @@ public record Config
public int max_parallel_downloads { get; set; } = 16;
public GameVersionCatalogProps[] version_catalogs { get; set; } =
[
new() { name = "Тимериховое", url = "https://timerix.ddns.net/minecraft/catalog.json" },
new() { name = "Mojang", url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" },
new() { name = "Тимериховое", url = "https://timerix.ddns.net/minecraft/catalog.json" }
];

View File

@@ -39,8 +39,6 @@ public class GameVersion
public async Task Download(bool update, Action<NetworkTask> networkTaskCreatedCallback)
{
LauncherApp.Logger.LogInfo(Id, $"started updating version {Id}");
List<INetworkTaskFactory> taskFactories =

View File

@@ -29,21 +29,25 @@ public class MyModpackV1
public bool optional { get; set; }
}
public bool CheckFiles(IOPath basedir, bool checkHashes, bool downloadOptionalFiles, HashSet<IOPath> unmatchedFilesLocalPaths)
/// <param name="unmatchedFilesLocalPaths">relative, absolute</param>
public Dictionary<IOPath, IOPath> CheckFiles(IOPath basedir, bool checkHashes, bool downloadOptionalFiles)
{
Dictionary<IOPath, IOPath> unmatchedFiles = new();
IOPath launcherRoot = PathHelper.GetRootFullPath();
foreach (var p in files)
{
if(!downloadOptionalFiles && p.Value.optional)
continue;
var localPath = new IOPath(p.Key);
var realPath = Path.Concat(basedir, localPath);
if (!HashHelper.CheckFileSHA1(realPath, p.Value.sha1, checkHashes && !p.Value.allow_edit))
IOPath relativePath = new IOPath(p.Key);
var absolutePath = Path.Concat(relativePath.StartsWith("libraries")
? launcherRoot : basedir, relativePath);
if (!HashHelper.CheckFileSHA1(absolutePath, p.Value.sha1, checkHashes && !p.Value.allow_edit))
{
unmatchedFilesLocalPaths.Add(localPath);
unmatchedFiles.Add(relativePath, absolutePath);
}
}
return unmatchedFilesLocalPaths.Count == 0;
return unmatchedFiles;
}
}

View File

@@ -1,18 +1,18 @@
using System.IO.Compression;
using Mlaumcherb.Client.Avalonia.зримое;
using Mlaumcherb.Client.Avalonia.классы;
using Mlaumcherb.Client.Avalonia.холопы;
using Mlaumcherb.Client.Avalonia.классы;
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
public class ModpackDownloadTaskFactory : INetworkTaskFactory
{
INetworkTaskFactory _implementationVersion;
private GameVersionDescriptor _descriptor;
public ModpackDownloadTaskFactory(GameVersionDescriptor descriptor)
{
if(descriptor.modpack is null)
throw new ArgumentNullException(nameof(descriptor.modpack));
_descriptor = descriptor;
_implementationVersion = descriptor.modpack.format_version switch
{
1 => new MyModpackV1DownloadTaskFactory(descriptor),
@@ -24,72 +24,4 @@ public class ModpackDownloadTaskFactory : INetworkTaskFactory
{
return _implementationVersion.CreateAsync(checkHashes);
}
}
public class MyModpackV1DownloadTaskFactory : INetworkTaskFactory
{
private readonly GameVersionDescriptor _descriptor;
private IOPath _modpackDescriptorPath;
private IOPath _versionDir;
private MyModpackV1? _modpack;
private HashSet<IOPath> _filesToDosnload = new();
public MyModpackV1DownloadTaskFactory(GameVersionDescriptor descriptor)
{
_descriptor = descriptor;
_modpackDescriptorPath = PathHelper.GetModpackDescriptorPath(_descriptor.id);
_versionDir = PathHelper.GetVersionDir(_descriptor.id);
}
public async Task<NetworkTask?> CreateAsync(bool checkHashes)
{
if(_descriptor.modpack is null)
throw new ArgumentNullException(nameof(_descriptor.modpack));
(_modpack, bool didDownloadModpackDescriptor) = await NetworkHelper.ReadOrDownloadAndDeserialize<MyModpackV1>(
_modpackDescriptorPath,
_descriptor.modpack.artifact.url,
_descriptor.modpack.artifact.sha1,
checkHashes);
if (_modpack.format_version != _descriptor.modpack.format_version)
throw new Exception($"Modpack.format_version mismatches descriptor.modpack.version: " +
$"{_modpack.format_version} != {_descriptor.modpack.format_version}");
NetworkTask? networkTask = null;
if(!_modpack.CheckFiles(_versionDir, checkHashes, didDownloadModpackDescriptor, _filesToDosnload))
{
networkTask = new NetworkTask(
$"modpack '{_descriptor.assetIndex.id}'",
_modpack.zip.size,
Download
);
}
return networkTask;
}
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
{
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading modpack '{_modpack!.name}'");
if(string.IsNullOrEmpty(_modpack.zip.url))
throw new Exception($"modpack '{_modpack.name}' doesn't have a url to download");
var _archivePath = Path.Concat(PathHelper.GetCacheDir(), "modpacks", _modpack.name + ".zip");
await NetworkHelper.DownloadFile(_modpack.zip.url, _archivePath, ct, pr.AddBytesCount);
await using var zipf = File.OpenRead(_archivePath);
using var archive = new ZipArchive(zipf);
foreach (var entry in archive.Entries)
{
IOPath localPath = new(entry.FullName);
if(_filesToDosnload.Contains(localPath))
{
var real_path = Path.Concat(_versionDir, localPath);
Directory.Create(real_path.ParentDir());
entry.ExtractToFile(real_path.ToString(), true);
}
}
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading modpack '{_modpack.name}'");
}
}

View File

@@ -0,0 +1,75 @@
using System.IO.Compression;
using Mlaumcherb.Client.Avalonia.зримое;
using Mlaumcherb.Client.Avalonia.классы;
using Mlaumcherb.Client.Avalonia.холопы;
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
public class MyModpackV1DownloadTaskFactory : INetworkTaskFactory
{
private readonly GameVersionDescriptor _descriptor;
private IOPath _modpackDescriptorPath;
private IOPath _versionDir;
private MyModpackV1? _modpack;
// relative, absolute
private Dictionary<IOPath, IOPath> _filesToDosnload = new();
public MyModpackV1DownloadTaskFactory(GameVersionDescriptor descriptor)
{
_descriptor = descriptor;
_modpackDescriptorPath = PathHelper.GetModpackDescriptorPath(_descriptor.id);
_versionDir = PathHelper.GetVersionDir(_descriptor.id);
}
public async Task<NetworkTask?> CreateAsync(bool checkHashes)
{
if(_descriptor.modpack is null)
throw new ArgumentNullException(nameof(_descriptor.modpack));
(_modpack, bool didDownloadModpackDescriptor) = await NetworkHelper.ReadOrDownloadAndDeserialize<MyModpackV1>(
_modpackDescriptorPath,
_descriptor.modpack.artifact.url,
_descriptor.modpack.artifact.sha1,
checkHashes);
if (_modpack.format_version != _descriptor.modpack.format_version)
throw new Exception($"Modpack.format_version mismatches descriptor.modpack.version: " +
$"{_modpack.format_version} != {_descriptor.modpack.format_version}");
NetworkTask? networkTask = null;
_filesToDosnload = _modpack.CheckFiles(_versionDir, checkHashes, didDownloadModpackDescriptor);
if(_filesToDosnload.Count > 0)
{
networkTask = new NetworkTask(
$"modpack '{_modpack.name}'",
_modpack.zip.size,
Download
);
}
return networkTask;
}
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
{
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading modpack '{_modpack!.name}'");
if(string.IsNullOrEmpty(_modpack.zip.url))
throw new Exception($"modpack '{_modpack.name}' doesn't have a url to download");
var _archivePath = Path.Concat(PathHelper.GetCacheDir(), "modpacks", _modpack.name + ".zip");
await NetworkHelper.DownloadFile(_modpack.zip.url, _archivePath, ct, pr.AddBytesCount);
await using var zipf = File.OpenRead(_archivePath);
using var archive = new ZipArchive(zipf);
foreach (var entry in archive.Entries)
{
IOPath relativePath = new(entry.FullName);
if(_filesToDosnload.TryGetValue(relativePath, out var absolutePath))
{
Directory.Create(absolutePath.ParentDir());
entry.ExtractToFile(absolutePath.ToString(), true);
}
}
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading modpack '{_modpack.name}'");
}
}