public static void CheckUpdate() { var currentVersion = GetCurrentVersion(); var latestVersion = GetLatestVersion(); if (currentVersion != latestVersion) { Console.WriteLine($"You are using clio version {currentVersion}, however version {latestVersion} is available."); if (OSPlatformChecker.IsWindowsEnvironment()) { ShowNugetUpdateMessage(); } else { Console.WriteLine($"You should consider upgrading via the \'clio update-cli\' command.", ConsoleColor.DarkYellow); } } }
public static int UpdateCli(UpdateCliOptions options) { if (OSPlatformChecker.IsWindowsEnvironment()) { ShowNugetUpdateMessage(); return(1); } try { var url = GetLastReleaseUrl(); var dir = AppDomain.CurrentDomain.BaseDirectory; string updaterDirPath = Path.Combine(dir, "Update"); string tempDirPath = Path.Combine(dir, "Update", "Temp"); string filePath = Path.Combine(updaterDirPath, "update.zip"); string updaterName = "updater.dll"; Directory.CreateDirectory(tempDirPath); if (options.CurrentVersion) { var currentVersion = GetCurrentVersion(); Console.WriteLine($"You are using clio version {currentVersion}."); } Console.WriteLine("Download update."); using (var client = new WebClient()) { client.DownloadFile(url, filePath); } ZipFile.ExtractToDirectory(filePath, tempDirPath, true); var updaterFile = new FileInfo(Path.Combine(tempDirPath, updaterName)); updaterFile.CopyTo(Path.Combine(dir, updaterFile.Name), true); var updateCmdPath = Path.Combine(dir, "update.cmd"); var proc = new Process { StartInfo = { FileName = updateCmdPath } }; Console.WriteLine("Start update."); proc.Start(); return(0); } catch (Exception) { Console.WriteLine("Update error."); return(1); } }