|
@@ -0,0 +1,695 @@
|
|
|
+using ReactiveUI;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using System.IO;
|
|
|
+using System.IO.Compression;
|
|
|
+using System.Linq;
|
|
|
+using System.Net;
|
|
|
+using System.Net.Http;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using VeloeMinecraftLauncher.Entity.Assets;
|
|
|
+using VeloeMinecraftLauncher.Entity.VersionManifest;
|
|
|
+using VeloeMinecraftLauncher.MinecraftLauncher;
|
|
|
+
|
|
|
+namespace VeloeMinecraftLauncher.ViewModels
|
|
|
+{
|
|
|
+ public class VersionsDownloaderViewModel : ViewModelBase
|
|
|
+ {
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ private string startButton = "Download";
|
|
|
+ private bool showOld = false;
|
|
|
+ private bool showSnaps = false;
|
|
|
+ private bool installFabric = false;
|
|
|
+ private bool installForge = false;
|
|
|
+ private bool installOptifine = false;
|
|
|
+ private bool installForgeOptifine = false;
|
|
|
+ private bool installFabricVisible = false;
|
|
|
+ private bool installForgeVisible = false;
|
|
|
+ private bool installOptifineVisible = false;
|
|
|
+ private bool installForgeOptifineVisible = false;
|
|
|
+ private bool downloadJava = false;
|
|
|
+ private bool isControlsEnabled = true;
|
|
|
+ private int progress = 0;
|
|
|
+ private string downloadingFileName;
|
|
|
+
|
|
|
+ Task downloadMinecraftTask;
|
|
|
+
|
|
|
+ Serilog.ILogger logger;
|
|
|
+
|
|
|
+ ObservableCollection<Entity.VersionManifest.Version> filteredVersions;
|
|
|
+ Entity.VersionManifest.Version filteredVersion;
|
|
|
+ VersionManifest versionManifest;
|
|
|
+
|
|
|
+ public VersionsDownloaderViewModel()
|
|
|
+ {
|
|
|
+ logger = Settings.logger;
|
|
|
+ if (FilteredVerions is null)
|
|
|
+ {
|
|
|
+ FilteredVerions = new ObservableCollection<Entity.VersionManifest.Version>();
|
|
|
+ }
|
|
|
+ logger.Debug("Getting versionManifest.json");
|
|
|
+ versionManifest = Downloader.DownloadAndDeserializeJsonData<VersionManifest>("https://launchermeta.mojang.com/mc/game/version_manifest_v2.json");
|
|
|
+ logger.Debug("Updating available versions to download.");
|
|
|
+ updateList();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Entity.VersionManifest.Version FilteredVersion
|
|
|
+ {
|
|
|
+ get { return filteredVersion; }
|
|
|
+ set {
|
|
|
+ this.RaiseAndSetIfChanged(ref filteredVersion, value);
|
|
|
+
|
|
|
+ InstallFabric = false;
|
|
|
+ InstallForge = false;
|
|
|
+ InstallOptifine = false;
|
|
|
+ InstallForgeOptifine = false;
|
|
|
+
|
|
|
+ using (var httpClient = new HttpClient())
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var response = httpClient.GetAsync(@$"https://files.veloe.link/launcher/forge/Forge{value.id}/Forge{value.id}.json").Result;
|
|
|
+
|
|
|
+ if (response.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ InstallForgeVisible = true;
|
|
|
+ response = httpClient.GetAsync(@$"https://files.veloe.link/launcher/forge/Forge{value.id}/Optifine{value.id}.jar").Result;
|
|
|
+ if (response.IsSuccessStatusCode)
|
|
|
+ InstallForgeOptifineVisible = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ InstallForgeVisible = false;
|
|
|
+ InstallForgeOptifineVisible = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ response = httpClient.GetAsync(@$"https://files.veloe.link/launcher/fabric/Fabric{value.id}/Fabric{value.id}.json").Result;
|
|
|
+
|
|
|
+ if (response.IsSuccessStatusCode)
|
|
|
+ InstallFabricVisible = true;
|
|
|
+ else
|
|
|
+ installFabricVisible = false;
|
|
|
+
|
|
|
+ response = httpClient.GetAsync(@$"https://files.veloe.link/launcher/optifine/Optifine{value.id}/Optifine{value.id}.json").Result;
|
|
|
+
|
|
|
+ if (response.IsSuccessStatusCode)
|
|
|
+ InstallOptifineVisible = true;
|
|
|
+ else
|
|
|
+ InstallOptifineVisible = false;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public ObservableCollection<Entity.VersionManifest.Version>FilteredVerions
|
|
|
+ {
|
|
|
+ get => filteredVersions; set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref filteredVersions, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string StartButton
|
|
|
+ {
|
|
|
+ get => startButton; set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref startButton, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool ShowOld
|
|
|
+ {
|
|
|
+ get { return showOld; }
|
|
|
+ set {
|
|
|
+ this.RaiseAndSetIfChanged(ref showOld, value);
|
|
|
+ updateList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool ShowSnaps
|
|
|
+ {
|
|
|
+ get { return showSnaps; }
|
|
|
+ set {
|
|
|
+ this.RaiseAndSetIfChanged(ref showSnaps, value);
|
|
|
+ updateList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int Progress
|
|
|
+ {
|
|
|
+ get { return progress; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref progress, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string DownloadingFileName
|
|
|
+ {
|
|
|
+ get { return downloadingFileName; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref downloadingFileName, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallForge
|
|
|
+ {
|
|
|
+ get { return installForge; }
|
|
|
+ set {
|
|
|
+ this.RaiseAndSetIfChanged(ref installForge, value);
|
|
|
+
|
|
|
+ if (InstallFabric)
|
|
|
+ InstallFabric = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallFabric
|
|
|
+ {
|
|
|
+ get { return installFabric; }
|
|
|
+ set {
|
|
|
+ this.RaiseAndSetIfChanged(ref installFabric, value);
|
|
|
+ if (InstallForge)
|
|
|
+ InstallForge = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallOptifine
|
|
|
+ {
|
|
|
+ get { return installOptifine; }
|
|
|
+ set {
|
|
|
+ this.RaiseAndSetIfChanged(ref installOptifine, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallForgeOptifine
|
|
|
+ {
|
|
|
+ get { return installForgeOptifine; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref installForgeOptifine, value);
|
|
|
+ if (value)
|
|
|
+ InstallForge = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallForgeVisible
|
|
|
+ {
|
|
|
+ get { return installForgeVisible; }
|
|
|
+ set => this.RaiseAndSetIfChanged(ref installForgeVisible, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallFabricVisible
|
|
|
+ {
|
|
|
+ get { return installFabricVisible; }
|
|
|
+ set => this.RaiseAndSetIfChanged(ref installFabricVisible, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallOptifineVisible
|
|
|
+ {
|
|
|
+ get { return installOptifineVisible; }
|
|
|
+ set => this.RaiseAndSetIfChanged(ref installOptifineVisible, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool InstallForgeOptifineVisible
|
|
|
+ {
|
|
|
+ get { return installForgeOptifineVisible; }
|
|
|
+ set => this.RaiseAndSetIfChanged(ref installForgeOptifineVisible, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool DownloadJava
|
|
|
+ {
|
|
|
+ get { return downloadJava; }
|
|
|
+ set { this.RaiseAndSetIfChanged(ref downloadJava, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsControlsEnabled
|
|
|
+ {
|
|
|
+ get { return isControlsEnabled; }
|
|
|
+ set { this.RaiseAndSetIfChanged(ref isControlsEnabled, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task OnStartBunttonClick()
|
|
|
+ {
|
|
|
+ Task.Run(()=>StartDownload());
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<TaskStatus> StartDownload()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (FilteredVersion is null)
|
|
|
+ return TaskStatus.Faulted;
|
|
|
+ IsControlsEnabled = false;
|
|
|
+ logger.Debug("Downloading minecraft {0}", FilteredVersion.id);
|
|
|
+ var webClient = new WebClient();
|
|
|
+
|
|
|
+ logger.Debug("Downloading {0}.json", FilteredVersion.id);
|
|
|
+ var versonJson = Downloader.DownloadAndDeserializeJsonData<Entity.Version.Version>(FilteredVersion.url);
|
|
|
+
|
|
|
+ if (versonJson != null)
|
|
|
+ {
|
|
|
+ webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
|
|
|
+ //download java
|
|
|
+ if (DownloadJava)
|
|
|
+ {
|
|
|
+ logger.Debug("Getting required Java version.");
|
|
|
+ if (versonJson.javaVersion.majorVersion != null)
|
|
|
+ {
|
|
|
+ string javaUrl = "";
|
|
|
+ switch (versonJson.javaVersion.majorVersion)
|
|
|
+ {
|
|
|
+ case 8:
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsWindows())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/8/windows64/java.zip";
|
|
|
+ if (!Environment.Is64BitOperatingSystem && OperatingSystem.IsWindows())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/8/windows32/java.zip";
|
|
|
+
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsLinux())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/8/linux64/java.zip";
|
|
|
+ if (!Environment.Is64BitOperatingSystem && OperatingSystem.IsLinux())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/8/linux32/java.zip";
|
|
|
+ break;
|
|
|
+ case 16:
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsWindows())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/16/windows64/java.zip";
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsLinux())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/16/linux64/java.zip";
|
|
|
+ break;
|
|
|
+ case 17:
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsWindows())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/17/windows64/java.zip";
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsLinux())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/17/linux64/java.zip";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 18:
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsWindows())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/18/windows64/java.zip";
|
|
|
+ if (Environment.Is64BitOperatingSystem && OperatingSystem.IsLinux())
|
|
|
+ javaUrl = "https://files.veloe.link/launcher/java/18/linux64/java.zip";
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (javaUrl != "")
|
|
|
+ {
|
|
|
+ logger.Debug("Downloading Java");
|
|
|
+ DownloadingFileName = "java.zip";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(javaUrl), Settings.MinecraftForlderPath + "java.zip");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ logger.Debug("Unpacking Java");
|
|
|
+ DownloadingFileName = "Unpacking java.zip";
|
|
|
+ ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}java.zip", Settings.MinecraftForlderPath, true);
|
|
|
+ File.Delete($"{Settings.MinecraftForlderPath}java.zip");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ logger.Debug("Required Java version don't found in json file."); //log that java was not downloaded;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //download json
|
|
|
+ var path = Settings.MinecraftForlderPath + "/versions/" + FilteredVersion.id;
|
|
|
+ if (!Directory.Exists(path))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", path);
|
|
|
+ Directory.CreateDirectory(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.Debug("Downloading {0}", $"{FilteredVersion.id}.json");
|
|
|
+ DownloadingFileName = $"{FilteredVersion.id}.json";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(FilteredVersion.url), path + "/" + FilteredVersion.id + ".json");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+ //download jar
|
|
|
+ if (!Directory.Exists(path))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", path);
|
|
|
+ Directory.CreateDirectory(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.Debug("Downloading {0}", $"{FilteredVersion.id}.jar");
|
|
|
+ DownloadingFileName = $"{FilteredVersion.id}.jar";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(versonJson.downloads.client.url), path + "/" + FilteredVersion.id + ".jar");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ //download libraries
|
|
|
+ logger.Debug("Downloading libraries.");
|
|
|
+ foreach (var library in versonJson.libraries)
|
|
|
+ {
|
|
|
+ var libPath = Settings.MinecraftForlderPath + "libraries/";
|
|
|
+ string[] libPathSplit = new[] { "" };
|
|
|
+ string libUrl = "";
|
|
|
+ // getting path and url if universal lib
|
|
|
+ if (library.natives is null)
|
|
|
+ {
|
|
|
+ libPath = Settings.MinecraftForlderPath + "libraries/";
|
|
|
+ libPathSplit = library.downloads.artifact.path.Split('/');
|
|
|
+ libUrl = library.downloads.artifact.url;
|
|
|
+ for (int i = 0; i < libPathSplit.Length - 1; i++)
|
|
|
+ {
|
|
|
+ libPath += libPathSplit[i] + "/";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ { // getting path if native
|
|
|
+ libPath = Settings.MinecraftForlderPath + "libraries/";
|
|
|
+ libPathSplit = new[] { "" };
|
|
|
+ libUrl = "";
|
|
|
+
|
|
|
+ if (OperatingSystem.IsWindows() && library.natives.windows is not null)
|
|
|
+ {
|
|
|
+ if (library.downloads.classifiers.NativesWindows is not null)
|
|
|
+ {
|
|
|
+ libPathSplit = library.downloads.classifiers.NativesWindows.path.Split('/');
|
|
|
+ libUrl = library.downloads.classifiers.NativesWindows.url;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (Environment.Is64BitOperatingSystem)
|
|
|
+ {
|
|
|
+ libPathSplit = library.downloads.classifiers.NativesWindows64.path.Split('/');
|
|
|
+ libUrl = library.downloads.classifiers.NativesWindows64.url;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ libPathSplit = library.downloads.classifiers.NativesWindows32.path.Split('/');
|
|
|
+ libUrl = library.downloads.classifiers.NativesWindows32.url;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (OperatingSystem.IsLinux() && library.natives.linux is not null)
|
|
|
+ {
|
|
|
+ libPathSplit = library.downloads.classifiers.NativesLinux.path.Split('/');
|
|
|
+ libUrl = library.downloads.classifiers.NativesLinux.url;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < libPathSplit.Length - 1; i++)
|
|
|
+ {
|
|
|
+ libPath += libPathSplit[i] + "/";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //if no lib url
|
|
|
+ if (libUrl == String.Empty)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ //checking rules
|
|
|
+ if (library.rules == null)
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(libPath))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", path);
|
|
|
+ Directory.CreateDirectory(libPath);
|
|
|
+ }
|
|
|
+ logger.Debug("Downloading: {0}", libPathSplit.Last());
|
|
|
+ DownloadingFileName = libPathSplit.Last();
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(libUrl), libPath + "/" + libPathSplit.Last());
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var rule in library.rules)
|
|
|
+ {
|
|
|
+ if (rule.action == "allow" && rule.os is null)
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(libPath))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", path);
|
|
|
+ Directory.CreateDirectory(libPath);
|
|
|
+ }
|
|
|
+ logger.Debug("Downloading: {0}", libPathSplit.Last());
|
|
|
+ DownloadingFileName = libPathSplit.Last();
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(libUrl), libPath + "/" + libPathSplit.Last());
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (rule.action == "allow" && (rule.os.name == "windows" && OperatingSystem.IsWindows() || rule.os.name == "linux" && OperatingSystem.IsLinux()))
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(libPath))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", path);
|
|
|
+ Directory.CreateDirectory(libPath);
|
|
|
+ }
|
|
|
+ logger.Debug("Downloading: {0}", libPathSplit.Last());
|
|
|
+ DownloadingFileName = libPathSplit.Last();
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(libUrl), libPath + "/" + libPathSplit.Last());
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //unpacking native libs
|
|
|
+ if (library.natives is not null || library.downloads.classifiers is not null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(Settings.MinecraftForlderPath + "versions/" + versonJson.id + "/natives/"))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", Settings.MinecraftForlderPath + "versions/" + versonJson.id + "/natives/");
|
|
|
+ Directory.CreateDirectory(Settings.MinecraftForlderPath + "versions/" + versonJson.id + "/natives/");
|
|
|
+ }
|
|
|
+ logger.Debug("Extracting {0} to {1}", libPathSplit.Last(), Settings.MinecraftForlderPath + "versions/" + versonJson.id + "/natives/");
|
|
|
+ ZipFile.ExtractToDirectory(libPath + "/" + libPathSplit.Last(), Settings.MinecraftForlderPath + "versions/" + versonJson.id + "/natives/", true);
|
|
|
+ }
|
|
|
+ catch (IOException ex)
|
|
|
+ {
|
|
|
+ logger.Error("IOException in VersionsDownloaderViewModel on native lib extraction");
|
|
|
+ }
|
|
|
+ //TODO delete META-INF and sha1 files after
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var assetsJson = Downloader.DownloadAndDeserializeJsonData<AssetsManifest>(versonJson.assetIndex.url);
|
|
|
+ var assetsPath = Settings.MinecraftForlderPath + "assets/" + versonJson.assets + "/objects";
|
|
|
+ var assetsUrl = "https://resources.download.minecraft.net/";
|
|
|
+
|
|
|
+ //download assets json
|
|
|
+ logger.Debug("Downloading: {0}", versonJson.assets + ".json");
|
|
|
+ Downloader.DownloadFile(versonJson.assetIndex.url, Settings.MinecraftForlderPath + "/assets/" + versonJson.assets + "/indexes/", versonJson.assets + ".json");
|
|
|
+
|
|
|
+ //download assets
|
|
|
+ foreach (var asset in assetsJson.Objects)
|
|
|
+ {
|
|
|
+ var folder = asset.Value.hash.Substring(0, 2);
|
|
|
+ if (!Directory.Exists(assetsPath + "/" + folder))
|
|
|
+ Directory.CreateDirectory(assetsPath + "/" + folder);
|
|
|
+
|
|
|
+ string chksum = String.Empty;
|
|
|
+ //here hash check
|
|
|
+ if (File.Exists(assetsPath + "/" + folder + "/" + asset.Value.hash))
|
|
|
+ {
|
|
|
+ FileStream fop = File.OpenRead(assetsPath + "/" + folder + "/" + asset.Value.hash);
|
|
|
+ byte[] hash = System.Security.Cryptography.SHA1.Create().ComputeHash(fop);
|
|
|
+ chksum = BitConverter.ToString(hash).Replace("-", String.Empty).ToLower();
|
|
|
+
|
|
|
+ fop.Close();
|
|
|
+ fop.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chksum != asset.Value.hash)
|
|
|
+ {
|
|
|
+ logger.Debug("Downloading: {0}", asset.Value.hash);
|
|
|
+ DownloadingFileName = $"Asset {asset.Value.hash}";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(assetsUrl + folder + "/" + asset.Value.hash), assetsPath + "/" + folder + "/" + asset.Value.hash);
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (InstallForge)
|
|
|
+ {
|
|
|
+ var forgePath = $"Forge{versonJson.id}";
|
|
|
+ var forgeUrl = $"https://files.veloe.link/launcher/forge/Forge{versonJson.id}/";
|
|
|
+
|
|
|
+ if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/Forge{versonJson.id}"))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}versions/" + forgePath);
|
|
|
+ Directory.CreateDirectory($"{Settings.MinecraftForlderPath}versions/" + forgePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.Debug("Downloading: {0}", $"Forge{versonJson.id}.json");
|
|
|
+ DownloadingFileName = $"Forge{versonJson.id}.json";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri($"{forgeUrl}Forge{versonJson.id}.json"), Settings.MinecraftForlderPath + "versions/" + forgePath + "/" + forgePath + ".json");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ logger.Debug("Downloading: {0}", "libraries.zip");
|
|
|
+ DownloadingFileName = "libraries.zip";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(forgeUrl + "libraries.zip"), Settings.MinecraftForlderPath + "versions/" + forgePath + "/libraries.zip");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ logger.Debug("Extracting: {0}", "libraries.zip");
|
|
|
+ DownloadingFileName = "Unpacking libraries.zip";
|
|
|
+ ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}versions/Forge{versonJson.id}/libraries.zip", Settings.MinecraftForlderPath, true);
|
|
|
+ File.Delete($"{Settings.MinecraftForlderPath}versions/Forge{versonJson.id}/libraries.zip");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (InstallOptifine)
|
|
|
+ {
|
|
|
+ var optifinePath = $"Optifine{versonJson.id}";
|
|
|
+ var optifineUrl = $"https://files.veloe.link/launcher/optifine/Optifine{versonJson.id}/";
|
|
|
+
|
|
|
+ if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/Optifine{versonJson.id}"))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}Optifine/" + optifinePath);
|
|
|
+ Directory.CreateDirectory($"{Settings.MinecraftForlderPath}Optifine/" + optifinePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.Debug("Downloading: {0}", $"Optifine{versonJson.id}.json");
|
|
|
+ DownloadingFileName = $"Optifine{versonJson.id}.json";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri($"{optifineUrl}Optifine{versonJson.id}.json"), Settings.MinecraftForlderPath + "versions/" + optifinePath + "/" + optifinePath + ".json");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ logger.Debug("Downloading: {0}", $"Optifine{versonJson.id}.json");
|
|
|
+ DownloadingFileName = $"Optifine{versonJson.id}.json";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri($"{optifineUrl}Optifine{versonJson.id}.jar"), Settings.MinecraftForlderPath + "versions/" + optifinePath + "/" + optifinePath + ".jar");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ logger.Debug("Downloading: {0}", "libraries.zip");
|
|
|
+ DownloadingFileName = "libraries.zip";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(optifineUrl + "libraries.zip"), Settings.MinecraftForlderPath + "versions/" + optifinePath + "/libraries.zip");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ logger.Debug("Extracting: {0}", "libraries.zip");
|
|
|
+ DownloadingFileName = "Unpacking libraries.zip";
|
|
|
+ ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}versions/Optifine{versonJson.id}/libraries.zip", Settings.MinecraftForlderPath, true);
|
|
|
+ File.Delete($"{Settings.MinecraftForlderPath}versions/Optifine{versonJson.id}/libraries.zip");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (InstallForgeOptifine)
|
|
|
+ {
|
|
|
+ if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/Forge{versonJson.id}/mods"))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}versions/Forge" + versonJson.id + "/mods");
|
|
|
+ Directory.CreateDirectory($"{Settings.MinecraftForlderPath}versions/Forge" + versonJson.id + "/mods");
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.Debug("Downloading: {0}", $"Optifine{versonJson.id}.jar");
|
|
|
+ DownloadingFileName = $"Optifine{versonJson.id}.jar";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(@$"https://files.veloe.link/launcher/forge/Forge{versonJson.id}/Optifine{versonJson.id}.jar"),
|
|
|
+ Settings.MinecraftForlderPath + "versions/Forge" + versonJson.id + "/mods/" + "Optifine" + versonJson.id + ".jar");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+ }
|
|
|
+
|
|
|
+ webClient.DownloadProgressChanged -= WebClient_DownloadProgressChanged;
|
|
|
+ Progress = 100;
|
|
|
+ logger.Debug("Downloading finished.");
|
|
|
+ DownloadingFileName = "Finished!";
|
|
|
+ IsControlsEnabled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ webClient.Dispose();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ IsControlsEnabled = true;
|
|
|
+ DownloadingFileName = $"Error occured while downloading {FilteredVersion.id}.";
|
|
|
+ logger.Error(ex.Message);
|
|
|
+ logger.Error(ex.StackTrace);
|
|
|
+ return TaskStatus.Faulted;
|
|
|
+ }
|
|
|
+ return TaskStatus.RanToCompletion;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async void OnStartMcTfcBunttonClick()
|
|
|
+ {
|
|
|
+ Task.Run(() => StartDownloadMcTfc());
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<TaskStatus> StartDownloadMcTfc()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FilteredVersion = FilteredVerions.Where(x => x.id == "1.12.2").FirstOrDefault();
|
|
|
+
|
|
|
+ if (FilteredVersion is null)
|
|
|
+ return TaskStatus.Faulted;
|
|
|
+
|
|
|
+
|
|
|
+ InstallForge = true;
|
|
|
+ InstallForgeOptifine = true;
|
|
|
+
|
|
|
+ await StartDownload();
|
|
|
+
|
|
|
+ IsControlsEnabled = false;
|
|
|
+ var mcTfcUrl = $"https://files.veloe.link/launcher/McTFC/McTFC.zip";
|
|
|
+
|
|
|
+ if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/McTFC"))
|
|
|
+ {
|
|
|
+ logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}versions/McTFC");
|
|
|
+ Directory.CreateDirectory($"{Settings.MinecraftForlderPath}versions/McTFC");
|
|
|
+ }
|
|
|
+
|
|
|
+ WebClient webClient = new WebClient();
|
|
|
+
|
|
|
+ webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
|
|
|
+
|
|
|
+ logger.Debug("Downloading: {0}", "McTFC.zip");
|
|
|
+ DownloadingFileName = "McTFC.zip";
|
|
|
+ webClient.DownloadFileAsync(new System.Uri(mcTfcUrl), Settings.MinecraftForlderPath + "versions/McTFC.zip");
|
|
|
+ waitWhileBisy(ref webClient);
|
|
|
+
|
|
|
+ logger.Debug("Extracting: {0}", "McTFC.zip");
|
|
|
+ DownloadingFileName = "Unpacking McTFC.zip";
|
|
|
+ ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}versions/McTFC.zip", Settings.MinecraftForlderPath + "versions/McTFC", true);
|
|
|
+ File.Delete($"{Settings.MinecraftForlderPath}versions/McTFC.zip");
|
|
|
+
|
|
|
+ webClient.DownloadProgressChanged -= WebClient_DownloadProgressChanged;
|
|
|
+ Progress = 100;
|
|
|
+ logger.Debug("Downloading McTFC finished.");
|
|
|
+ DownloadingFileName = "Finished McTFC!";
|
|
|
+ IsControlsEnabled = true;
|
|
|
+ webClient.Dispose();
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ IsControlsEnabled = true;
|
|
|
+ DownloadingFileName = "Error occured while downloading McTFC.";
|
|
|
+ logger.Error(ex.Message);
|
|
|
+ logger.Error(ex.StackTrace);
|
|
|
+ return TaskStatus.Faulted;
|
|
|
+ }
|
|
|
+ return TaskStatus.RanToCompletion;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void waitWhileBisy(ref WebClient webClient)
|
|
|
+ {
|
|
|
+ while(webClient.IsBusy)
|
|
|
+ {
|
|
|
+ //Progress = webClientProgress;
|
|
|
+ Task.Delay(100).Wait();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
|
|
+ {
|
|
|
+ Progress = e.ProgressPercentage;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateList()
|
|
|
+ {
|
|
|
+ FilteredVerions.Clear();
|
|
|
+
|
|
|
+ if (versionManifest.versions is null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ foreach (var version in versionManifest.versions)
|
|
|
+ {
|
|
|
+ if (ShowSnaps && version.type == "snapshot" || ShowOld && version.type is ("old_alpha" or "old_beta") || version.type == "release")
|
|
|
+ FilteredVerions.Add(version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|