123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- // See https://aka.ms/new-console-template for more information
- using Serilog;
- using Serilog.Events;
- using System.Diagnostics;
- using System.IO.Compression;
- using System.Net;
- using System.Text.Json;
- using VeloeLauncherUpdater;
- var logger = new LoggerConfiguration()
- .MinimumLevel.Debug()
- .WriteTo.File("update.log", LogEventLevel.Debug)// restricted... is Optional
- .CreateLogger();
- try
- {
- string fileName = "VeloeMinecraftLauncher";
- if (OperatingSystem.IsWindows())
- fileName += ".exe";
- if (File.Exists(fileName))
- {
- FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);
- LatestLauncherVersion latestLauncherVersion;
- using (var httpClient = new HttpClient())
- {
- var jsonData = string.Empty;
- try
- {
- jsonData = httpClient.GetStringAsync("https://files.veloe.link/launcher/update/versions.json").Result;
- }
- catch (Exception)
- {
- logger.Error("Error occured on getting versions.json from the server.");
- throw;
- }
- latestLauncherVersion = string.IsNullOrEmpty(jsonData)
- ? new LatestLauncherVersion()
- : JsonSerializer.Deserialize<LatestLauncherVersion>(jsonData);
- }
- if (OperatingSystem.IsLinux())
- {
- logger.Information("Manual updates only.");
- return;
- }
- if (latestLauncherVersion != null)
- {
- string[] version = latestLauncherVersion.latest.Split('.');
- logger.Information("Latest launcher version on server: {0}", latestLauncherVersion.latest);
- string[] versionOnServer = fileVersionInfo.FileVersion.Split('.');
- logger.Information("Launcher version: {0}", fileVersionInfo.FileVersion);
- if (!(Int16.Parse(version[0]) > Int16.Parse(versionOnServer[0]) ||
- Int16.Parse(version[1]) > Int16.Parse(versionOnServer[1]) ||
- Int16.Parse(version[2]) > Int16.Parse(versionOnServer[2]) ||
- Int16.Parse(version[3]) > Int16.Parse(versionOnServer[3])))
- {
- logger.Information("No update required.");
- return;
- }
- }
- }
- WebClient webClient = new WebClient();
- try
- {
- logger.Information("Downloading latest.zip");
- string url = String.Empty;
- if (OperatingSystem.IsWindows())
- url = "https://files.veloe.link/launcher/update/latest.zip";
- if (OperatingSystem.IsLinux())
- url = "https://files.veloe.link/launcher/update/latest_linux-x64.zip";
- if (url == String.Empty)
- return;
- webClient.DownloadFile(new System.Uri(url), "latest.zip"); ;
- }
- catch (Exception ex)
- {
- logger.Error("Error occured on getting latest.zip from the server.");
- throw;
- }
- logger.Information("Unpacking latest.zip");
- ZipFile.ExtractToDirectory($"latest.zip", Directory.GetCurrentDirectory(), true);
- logger.Information("Deleting latest.zip");
- File.Delete($"latest.zip");
- }
- catch (Exception ex)
- {
- logger.Error(ex.Message);
- logger.Error("Path exe: {0}", Directory.GetCurrentDirectory());
- logger.Error(ex.StackTrace);
- }
|