// 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; Console.WriteLine("Hello, World!"); var logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File("update.log", LogEventLevel.Debug)// restricted... is Optional .CreateLogger(); try { FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo("VeloeMinecraftLauncher.exe"); LatestLauncherVersion latestLauncherInfo; using (var webClient = new HttpClient()) { var jsonData = string.Empty; try { jsonData = webClient.GetStringAsync("https://files.veloe.link/launcher/update/versions.json").Result; } catch (Exception) { logger.Error("Error occured on getting versions.json from the server."); throw; } latestLauncherInfo = string.IsNullOrEmpty(jsonData) ? new LatestLauncherVersion() : JsonSerializer.Deserialize(jsonData); } if (latestLauncherInfo is not null) { string[] version = latestLauncherInfo.latest.Split('.'); logger.Information("Latest version on server: {0}", latestLauncherInfo.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])) { WebClient webClient = new WebClient(); try { logger.Information("Downloading latest.zip"); webClient.DownloadFile(new System.Uri("https://files.veloe.link/launcher/update/latest.zip"), "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"); } else { logger.Information("No update required."); } } } catch (Exception ex) { logger.Error(ex.Message); logger.Error("Path exe: {0}", Directory.GetCurrentDirectory()); logger.Error(ex.StackTrace); }