Compare commits
No commits in common. "2c780afea80ac717f429514fd6556865f92c2323" and "e24ee815bcd2695e3ff9a838a7d0e60618cf9810" have entirely different histories.
2c780afea8
...
e24ee815bc
@ -36,7 +36,7 @@ public class GameVersion
|
||||
foreach (IOPath subdir in Directory.GetDirectories(GetVersionsDir()))
|
||||
{
|
||||
string name = subdir.LastName().ToString();
|
||||
var d = new GameVersionProps(name);
|
||||
var d = new GameVersionProps(name, null);
|
||||
if(!File.Exists(d.LocalDescriptorPath))
|
||||
throw new Exception("Can't find version descriptor file in directory '{subdir}'. Rename it as directory name.");
|
||||
propsList.Add(d);
|
||||
@ -47,15 +47,14 @@ public class GameVersion
|
||||
return Task.FromResult(propsList);
|
||||
}
|
||||
|
||||
public static async Task<GameVersion> CreateFromPropsAsync(GameVersionProps props, bool checkHash)
|
||||
public static async Task<GameVersion> CreateFromPropsAsync(GameVersionProps props)
|
||||
{
|
||||
//TODO: refresh version descriptor from server
|
||||
if (!File.Exists(props.LocalDescriptorPath))
|
||||
{
|
||||
if (props.RemoteProps is null)
|
||||
if (props.RemoteDescriptorUrl is null)
|
||||
throw new NullReferenceException("can't download game version descriptor '"
|
||||
+ props.Name + "', because RemoteDescriptorUrl is null");
|
||||
await NetworkHelper.DownloadFile(props.RemoteProps.url, props.LocalDescriptorPath);
|
||||
await NetworkHelper.DownloadFile(props.RemoteDescriptorUrl, props.LocalDescriptorPath);
|
||||
}
|
||||
|
||||
return new GameVersion(props);
|
||||
@ -105,17 +104,17 @@ public class GameVersion
|
||||
[
|
||||
new AssetsDownloadTaskFactory(_descriptor),
|
||||
new LibrariesDownloadTaskFactory(_descriptor, _libraries),
|
||||
new VersionFileDownloadTaskFactory(_descriptor),
|
||||
];
|
||||
if (LauncherApp.Config.download_java)
|
||||
{
|
||||
taskFactories.Add(new JavaDownloadTaskFactory(_descriptor));
|
||||
}
|
||||
if (_descriptor.modpack != null)
|
||||
//TODO: modpack
|
||||
/*if (modpack != null)
|
||||
{
|
||||
taskFactories.Add(new ModpackDownloadTaskFactory(_descriptor));
|
||||
}
|
||||
// has to be downloaded last because it is used by GameVersionProps to check if version is installed
|
||||
taskFactories.Add(new VersionJarDownloadTaskFactory(_descriptor));
|
||||
taskFactories.Add(new ModpackDownloadTaskFactory(modpack));
|
||||
}*/
|
||||
|
||||
var networkTasks = new List<NetworkTask>();
|
||||
for (int i = 0; i < taskFactories.Count; i++)
|
||||
@ -177,7 +176,7 @@ public class GameVersion
|
||||
Dictionary<string, string> placeholder_values = new() {
|
||||
{ "resolution_width", "1600" },
|
||||
{ "resolution_height", "900" },
|
||||
{ "xms", LauncherApp.Config.max_memory.ToString() },
|
||||
{ "xms", "2048" },
|
||||
{ "xmx", LauncherApp.Config.max_memory.ToString() },
|
||||
{ "auth_player_name", LauncherApp.Config.player_name },
|
||||
{ "auth_access_token", uuid },
|
||||
@ -197,8 +196,6 @@ public class GameVersion
|
||||
{ "game_assets", GetAssetsDir().ToString() },
|
||||
{ "game_directory", WorkingDirectory.ToString() },
|
||||
{ "natives_directory", GetNativeLibrariesDir(_descriptor.id).ToString() },
|
||||
{ "library_directory", GetLibrariesDir().ToString() },
|
||||
{ "classpath_separator", ";"},
|
||||
{ "path", GetLog4jConfigFilePath().ToString() },
|
||||
{ "version_name", _descriptor.id },
|
||||
{ "version_type", _descriptor.type },
|
||||
|
||||
@ -134,7 +134,7 @@ public partial class MainWindow : Window
|
||||
if (selectedVersion == null)
|
||||
return;
|
||||
|
||||
var v = await GameVersion.CreateFromPropsAsync(selectedVersion, CheckGameFiles);
|
||||
var v = await GameVersion.CreateFromPropsAsync(selectedVersion);
|
||||
await v.UpdateFiles(CheckGameFiles, nt =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
|
||||
@ -26,7 +26,7 @@ public class GameVersionCatalog
|
||||
_ => p.OtherTypeAllowed
|
||||
};
|
||||
if(match)
|
||||
_versionPropsList.Add(new GameVersionProps(r));
|
||||
_versionPropsList.Add(new GameVersionProps(r.id, r.url));
|
||||
}
|
||||
return _versionPropsList;
|
||||
}
|
||||
|
||||
@ -17,9 +17,6 @@ public class GameVersionDescriptor
|
||||
public JavaVersion javaVersion { get; set; } = new() { component = "jre-legacy", majorVersion = 8 };
|
||||
public string? minecraftArguments { get; set; }
|
||||
public ArgumentsNew? arguments { get; set; }
|
||||
|
||||
// my additions
|
||||
public MyModpackRemoteProps? modpack { get; set; }
|
||||
}
|
||||
|
||||
public class Artifact
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class ModpackFilesManifest
|
||||
{
|
||||
public class FileProps
|
||||
{
|
||||
[JsonRequired] public string sha1 { get; set; }
|
||||
public bool allow_edit { get; set; } = false;
|
||||
}
|
||||
|
||||
/// relative_path, hash
|
||||
[JsonRequired] public Dictionary<string, FileProps> files { get; set; } = new();
|
||||
|
||||
public bool CheckFiles(IOPath basedir, bool checkHashes, HashSet<IOPath> unmatchedFilesLocalPaths)
|
||||
{
|
||||
foreach (var p in files)
|
||||
{
|
||||
var localPath = new IOPath(p.Key);
|
||||
var realPath = Path.Concat(basedir, localPath);
|
||||
if (!HashHelper.CheckFileSHA1(realPath, p.Value.sha1, checkHashes && !p.Value.allow_edit))
|
||||
{
|
||||
unmatchedFilesLocalPaths.Add(localPath);
|
||||
}
|
||||
}
|
||||
|
||||
return unmatchedFilesLocalPaths.Count == 0;
|
||||
}
|
||||
}
|
||||
@ -30,7 +30,7 @@ public class GameArguments : ArgumentsWithPlaceholders
|
||||
{
|
||||
foreach (var arg in av.value)
|
||||
{
|
||||
// if(!_raw_args.Contains(arg))
|
||||
if(!_raw_args.Contains(arg))
|
||||
_raw_args.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVe
|
||||
{
|
||||
public string Name { get; }
|
||||
public IOPath LocalDescriptorPath { get; }
|
||||
public RemoteVersionDescriptorProps? RemoteProps { get; }
|
||||
public string? RemoteDescriptorUrl { get; }
|
||||
private bool _isDownloaded;
|
||||
public bool IsDownloaded
|
||||
{
|
||||
@ -23,22 +23,13 @@ public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVe
|
||||
}
|
||||
public event Action<bool>? StatusChanged;
|
||||
|
||||
private GameVersionProps(string name, RemoteVersionDescriptorProps? remoteProps)
|
||||
public GameVersionProps(string name, string? url)
|
||||
{
|
||||
|
||||
Name = name;
|
||||
RemoteProps = remoteProps;
|
||||
LocalDescriptorPath = PathHelper.GetVersionDescriptorPath(name);
|
||||
RemoteDescriptorUrl = url;
|
||||
IsDownloaded = File.Exists(PathHelper.GetVersionJarFilePath(name));
|
||||
}
|
||||
|
||||
public GameVersionProps(string name)
|
||||
: this(name, null)
|
||||
{ }
|
||||
|
||||
public GameVersionProps(RemoteVersionDescriptorProps remoteProps)
|
||||
: this(remoteProps.id, remoteProps)
|
||||
{ }
|
||||
|
||||
public void DeleteFiles()
|
||||
{
|
||||
|
||||
@ -21,6 +21,7 @@ public class JavaArguments : ArgumentsWithPlaceholders
|
||||
"-Dminecraft.client.jar=${client_jar}",
|
||||
"-Dminecraft.launcher.brand=${launcher_name}",
|
||||
"-Dminecraft.launcher.version=${launcher_version}",
|
||||
"-cp", "${classpath}"
|
||||
];
|
||||
|
||||
private static readonly string[] _enabled_features =
|
||||
@ -38,17 +39,11 @@ public class JavaArguments : ArgumentsWithPlaceholders
|
||||
{
|
||||
foreach (var arg in av.value)
|
||||
{
|
||||
// if(!_raw_args.Contains(arg))
|
||||
if(!_raw_args.Contains(arg))
|
||||
_raw_args.Add(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!_raw_args.Contains("-cp"))
|
||||
{
|
||||
_raw_args.Add("-cp");
|
||||
_raw_args.Add("${classpath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class MyModpackRemoteProps
|
||||
{
|
||||
[JsonRequired] public int format_version { get; set; }
|
||||
[JsonRequired] public Artifact artifact { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class MyModpackV1
|
||||
{
|
||||
|
||||
// 1
|
||||
[JsonRequired] public int format_version { get; set; }
|
||||
[JsonRequired] public string name { get; set; }
|
||||
// zip archive with all files
|
||||
[JsonRequired] public Artifact zip { get; set; } = null!;
|
||||
// ModpackFilesManifest
|
||||
[JsonRequired] public Artifact manifest { get; set; } = null!;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
using System.Net.Http;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.сеть;
|
||||
|
||||
@ -40,25 +41,4 @@ public static class NetworkHelper
|
||||
?? throw new Exception($"can't deserialize {typeof(T).Name}");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<string> ReadOrDownload(IOPath filePath, string url,
|
||||
string? sha1, bool checkHashes)
|
||||
{
|
||||
if (HashHelper.CheckFileSHA1(filePath, sha1, checkHashes))
|
||||
return File.ReadAllText(filePath);
|
||||
|
||||
string txt = await NetworkHelper.GetString(url);
|
||||
File.WriteAllText(filePath, txt);
|
||||
return txt;
|
||||
}
|
||||
|
||||
public static async Task<T> ReadOrDownloadAndDeserialize<T>(IOPath filePath, string url,
|
||||
string? sha1, bool checkHashes)
|
||||
{
|
||||
string text = await ReadOrDownload(filePath, url, sha1, checkHashes);
|
||||
var result = JsonConvert.DeserializeObject<T>(text)
|
||||
?? throw new Exception($"can't deserialize {typeof(T).Name}");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using DTLib.Extensions;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
@ -11,12 +13,14 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
private const string ASSET_SERVER_URL = "https://resources.download.minecraft.net/";
|
||||
private GameVersionDescriptor _descriptor;
|
||||
private SHA1 _hasher;
|
||||
private IOPath _indexFilePath;
|
||||
List<AssetDownloadProperties> _assetsToDownload = new();
|
||||
|
||||
public AssetsDownloadTaskFactory(GameVersionDescriptor descriptor)
|
||||
{
|
||||
_descriptor = descriptor;
|
||||
_hasher = SHA1.Create();
|
||||
_indexFilePath = PathHelper.GetAssetIndexFilePath(_descriptor.assetIndex.id);
|
||||
}
|
||||
|
||||
@ -33,11 +37,16 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
||||
}
|
||||
private async Task<bool> CheckFilesAsync(bool checkHashes)
|
||||
{
|
||||
var assetIndex = await ReadOrDownloadAndDeserialize<AssetIndex>(
|
||||
_indexFilePath,
|
||||
_descriptor.assetIndex.url,
|
||||
_descriptor.assetIndex.sha1,
|
||||
checkHashes);
|
||||
if(!File.Exists(_indexFilePath))
|
||||
{
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading asset index to '{_indexFilePath}'");
|
||||
await DownloadFile(_descriptor.assetIndex.url, _indexFilePath);
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), "finished downloading asset index");
|
||||
}
|
||||
|
||||
string indexFileText = File.ReadAllText(_indexFilePath);
|
||||
var assetIndex = JsonConvert.DeserializeObject<AssetIndex>(indexFileText)
|
||||
?? throw new Exception($"can't deserialize asset index file '{_indexFilePath}'");
|
||||
|
||||
_assetsToDownload.Clear();
|
||||
// removing duplicates for Dictionary (idk how can it be possible, but Newtonsoft.Json creates them)
|
||||
@ -47,10 +56,17 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
||||
if (assetHashes.Add(pair.Value.hash))
|
||||
{
|
||||
var a = new AssetDownloadProperties(pair.Key, pair.Value);
|
||||
if (!HashHelper.CheckFileSHA1(a.filePath, a.hash, checkHashes))
|
||||
if (!File.Exists(a.filePath))
|
||||
{
|
||||
_assetsToDownload.Add(a);
|
||||
}
|
||||
else if(checkHashes)
|
||||
{
|
||||
await using var fs = File.OpenRead(a.filePath);
|
||||
string hash = _hasher.ComputeHash(fs).HashToString();
|
||||
if (hash != a.hash)
|
||||
_assetsToDownload.Add(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using System.Security.Cryptography;
|
||||
using DTLib.Extensions;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
using static Mlaumcherb.Client.Avalonia.сеть.NetworkHelper;
|
||||
@ -11,6 +13,7 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory
|
||||
"https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json";
|
||||
private GameVersionDescriptor _descriptor;
|
||||
private IOPath _javaVersionDir;
|
||||
private SHA1 _hasher;
|
||||
private JavaDistributiveManifest? _distributiveManifest;
|
||||
private List<(IOPath path, JavaDistributiveElementProps props)> _filesToDownload = new();
|
||||
|
||||
@ -18,6 +21,7 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
_descriptor = descriptor;
|
||||
_javaVersionDir = PathHelper.GetJavaRuntimeDir(_descriptor.javaVersion.component);
|
||||
_hasher = SHA1.Create();
|
||||
}
|
||||
|
||||
public async Task<NetworkTask?> CreateAsync(bool checkHashes)
|
||||
@ -48,10 +52,18 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
var artifact = pair.Value.downloads;
|
||||
IOPath file_path = Path.Concat(_javaVersionDir, pair.Key);
|
||||
if (!HashHelper.CheckFileSHA1(file_path, artifact.raw.sha1, checkHashes))
|
||||
if (!File.Exists(file_path))
|
||||
{
|
||||
_filesToDownload.Add((file_path, pair.Value));
|
||||
}
|
||||
else if(checkHashes)
|
||||
{
|
||||
using var fs = File.OpenRead(file_path);
|
||||
if (_hasher.ComputeHash(fs).HashToString() != artifact.raw.sha1)
|
||||
{
|
||||
_filesToDownload.Add((file_path, pair.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using DTLib.Extensions;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
@ -10,6 +12,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
private GameVersionDescriptor _descriptor;
|
||||
private Libraries _libraries;
|
||||
private SHA1 _hasher;
|
||||
private List<Libraries.JarLib> _libsToDownload = new();
|
||||
private IOPath _nativesDir;
|
||||
|
||||
@ -17,6 +20,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
_descriptor = descriptor;
|
||||
_libraries = libraries;
|
||||
_hasher = SHA1.Create();
|
||||
_nativesDir = PathHelper.GetNativeLibrariesDir(descriptor.id);
|
||||
}
|
||||
|
||||
@ -39,15 +43,21 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
|
||||
foreach (var l in _libraries.Libs)
|
||||
{
|
||||
if (!HashHelper.CheckFileSHA1(l.jarFilePath, l.artifact.sha1, checkHashes))
|
||||
if (!File.Exists(l.jarFilePath))
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
}
|
||||
//TODO: replace with actual native assets check
|
||||
else if (!nativeDirExists && l is Libraries.NativeLib)
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
}
|
||||
else if (checkHashes)
|
||||
{
|
||||
using var fs = File.OpenRead(l.jarFilePath);
|
||||
string hash = _hasher.ComputeHash(fs).HashToString();
|
||||
if(hash != l.artifact.sha1)
|
||||
_libsToDownload.Add(l);
|
||||
}
|
||||
}
|
||||
|
||||
return _libsToDownload.Count == 0;
|
||||
@ -78,8 +88,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
await DownloadFile(l.artifact.url, l.jarFilePath, _ct, pr.AddBytesCount);
|
||||
if (l is Libraries.NativeLib n)
|
||||
{
|
||||
await using var zipf = File.OpenRead(n.jarFilePath);
|
||||
//TODO: replace following code with manual extraction
|
||||
var zipf = File.OpenRead(n.jarFilePath);
|
||||
ZipFile.ExtractToDirectory(zipf, _nativesDir.ToString(), true);
|
||||
if (n.extractionOptions?.exclude != null)
|
||||
{
|
||||
|
||||
@ -1,102 +0,0 @@
|
||||
using System.IO.Compression;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||
|
||||
public class ModpackDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
INetworkTaskFactory _implementationVersion;
|
||||
|
||||
public ModpackDownloadTaskFactory(GameVersionDescriptor descriptor)
|
||||
{
|
||||
if(descriptor.modpack is null)
|
||||
throw new ArgumentNullException(nameof(descriptor.modpack));
|
||||
_implementationVersion = descriptor.modpack.format_version switch
|
||||
{
|
||||
1 => new MyModpackV1DownloadTaskFactory(descriptor),
|
||||
_ => throw new Exception($"Unknown Modpack format_version: {descriptor.modpack.format_version}")
|
||||
};
|
||||
}
|
||||
|
||||
public Task<NetworkTask?> CreateAsync(bool checkHashes)
|
||||
{
|
||||
return _implementationVersion.CreateAsync(checkHashes);
|
||||
}
|
||||
}
|
||||
|
||||
public class MyModpackV1DownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
private IOPath _modpackManifesPath;
|
||||
private readonly GameVersionDescriptor _descriptor;
|
||||
private IOPath _modpackDescriptorPath;
|
||||
private IOPath _versionDir;
|
||||
private MyModpackV1? _modpack;
|
||||
private ModpackFilesManifest? _modpackManifest;
|
||||
private HashSet<IOPath> _filesToDosnload = new();
|
||||
|
||||
public MyModpackV1DownloadTaskFactory(GameVersionDescriptor descriptor)
|
||||
{
|
||||
_descriptor = descriptor;
|
||||
_modpackDescriptorPath = PathHelper.GetModpackDescriptorPath(_descriptor.id);
|
||||
_modpackManifesPath = PathHelper.GetModpackManifestPath(_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 = 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}");
|
||||
|
||||
_modpackManifest = await NetworkHelper.ReadOrDownloadAndDeserialize<ModpackFilesManifest>(
|
||||
_modpackManifesPath,
|
||||
_modpack.manifest.url,
|
||||
_modpack.manifest.sha1,
|
||||
checkHashes);
|
||||
|
||||
if(!_modpackManifest.CheckFiles(_versionDir, checkHashes, _filesToDosnload))
|
||||
return new NetworkTask(
|
||||
$"modpack '{_descriptor.assetIndex.id}'",
|
||||
_modpack.zip.size,
|
||||
Download
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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("downloads/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}'");
|
||||
}
|
||||
}
|
||||
@ -1,19 +1,23 @@
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using System.Security.Cryptography;
|
||||
using DTLib.Extensions;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
using static Mlaumcherb.Client.Avalonia.сеть.NetworkHelper;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||
|
||||
public class VersionJarDownloadTaskFactory : INetworkTaskFactory
|
||||
public class VersionFileDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
private GameVersionDescriptor _descriptor;
|
||||
private IOPath _filePath;
|
||||
private SHA1 _hasher;
|
||||
|
||||
public VersionJarDownloadTaskFactory(GameVersionDescriptor descriptor)
|
||||
public VersionFileDownloadTaskFactory(GameVersionDescriptor descriptor)
|
||||
{
|
||||
_descriptor = descriptor;
|
||||
_filePath = PathHelper.GetVersionJarFilePath(_descriptor.id);
|
||||
_hasher = SHA1.Create();
|
||||
}
|
||||
|
||||
public Task<NetworkTask?> CreateAsync(bool checkHashes)
|
||||
@ -21,7 +25,7 @@ public class VersionJarDownloadTaskFactory : INetworkTaskFactory
|
||||
NetworkTask? networkTask = null;
|
||||
if (!CheckFiles(checkHashes))
|
||||
networkTask = new NetworkTask(
|
||||
$"game version jar '{_descriptor.id}'",
|
||||
$"version file '{_descriptor.id}'",
|
||||
GetTotalSize(),
|
||||
Download
|
||||
);
|
||||
@ -30,7 +34,18 @@ public class VersionJarDownloadTaskFactory : INetworkTaskFactory
|
||||
|
||||
private bool CheckFiles(bool checkHashes)
|
||||
{
|
||||
return HashHelper.CheckFileSHA1(_filePath, _descriptor.downloads?.client.sha1, checkHashes);
|
||||
if (!File.Exists(_filePath))
|
||||
return false;
|
||||
|
||||
if (!checkHashes)
|
||||
return true;
|
||||
|
||||
if (_descriptor.downloads is null)
|
||||
return true;
|
||||
|
||||
using var fs = File.OpenRead(_filePath);
|
||||
string hash = _hasher.ComputeHash(fs).HashToString();
|
||||
return hash == _descriptor.downloads.client.sha1;
|
||||
}
|
||||
|
||||
private long GetTotalSize()
|
||||
@ -43,10 +58,10 @@ public class VersionJarDownloadTaskFactory : INetworkTaskFactory
|
||||
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
||||
{
|
||||
if (_descriptor.downloads is null)
|
||||
throw new Exception($"can't download game version jar '{_descriptor.id}' because it has no download url");
|
||||
throw new Exception($"can't download version file '{_descriptor.id}' because it has no download url");
|
||||
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading game version jar '{_descriptor.id}'");
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading version file '{_descriptor.id}'");
|
||||
await DownloadFile(_descriptor.downloads.client.url, _filePath, ct, pr.AddBytesCount);
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading game version jar '{_descriptor.id}'");
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading version file '{_descriptor.id}'");
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
using System.Security.Cryptography;
|
||||
using DTLib.Extensions;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
public static class HashHelper
|
||||
{
|
||||
private static SHA1 _hasher;
|
||||
|
||||
static HashHelper()
|
||||
{
|
||||
_hasher = SHA1.Create();
|
||||
}
|
||||
|
||||
public static string HashFileSHA1(IOPath f)
|
||||
{
|
||||
using var fs = File.OpenRead(f);
|
||||
byte[] hash = _hasher.ComputeHash(fs);
|
||||
return hash.HashToString();
|
||||
}
|
||||
|
||||
public static bool CheckFileSHA1(IOPath f, string? sha1, bool checkHash)
|
||||
{
|
||||
if (!File.Exists(f))
|
||||
return false;
|
||||
|
||||
if(checkHash)
|
||||
return sha1 is not null && HashFileSHA1(f) == sha1;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,7 @@ public static class PathHelper
|
||||
Path.Concat(GetRootFullPath(), "assets");
|
||||
|
||||
public static IOPath GetAssetIndexFilePath(string id) =>
|
||||
Path.Concat(GetAssetsDir(), $"indexes/{id}.json"); // this path is hardcoded in the game
|
||||
Path.Concat(GetAssetsDir(), $"assets/indexes/{id}.json");
|
||||
|
||||
public static IOPath GetVersionDescriptorPath(string id) =>
|
||||
Path.Concat(GetVersionDir(id), id + ".json");
|
||||
@ -54,10 +54,4 @@ public static class PathHelper
|
||||
|
||||
public static IOPath GetLog4jConfigFilePath() =>
|
||||
Path.Concat(GetAssetsDir(), GetLog4jConfigFileName());
|
||||
|
||||
public static IOPath GetModpackDescriptorPath(string game_version) =>
|
||||
Path.Concat(GetVersionDir(game_version), "timerix_modpack.json");
|
||||
|
||||
public static IOPath GetModpackManifestPath(string game_version) =>
|
||||
Path.Concat(GetVersionDir(game_version), "timerix_modpack_files.json");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user