public async Task <bool> ExecuteAsync(TelegramBotClient botClient, Update update) { try { Conf.Update Latest = Conf.CheckForUpdates(); if (Conf.IsNewerVersionAvailable(Latest)) { Vars.UpdatePending = true; Vars.UpdateVersion = new Version(Latest.Latest); Vars.UpdateLevel = Latest.UpdateLevel; var UpdateString = Vars.CurrentLang.Message_UpdateAvailable .Replace("$1", Latest.Latest) .Replace("$2", Latest.Details) .Replace("$3", Methods.GetUpdateLevel(Latest.UpdateLevel)); await botClient.SendTextMessageAsync( update.Message.From.Id, UpdateString, ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); } else { Vars.UpdatePending = false; await botClient.SendTextMessageAsync( update.Message.From.Id, Vars.CurrentLang.Message_AlreadyUpToDate .Replace("$1", Latest.Latest) .Replace("$2", Vars.AppVer.ToString()) .Replace("$3", Latest.Details), ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); } return(true); } catch (Exception ex) { var ErrorString = Vars.CurrentLang.Message_UpdateCheckFailed.Replace("$1", ex.Message); await botClient.SendTextMessageAsync( update.Message.From.Id, ErrorString, ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); return(true); } }
public async Task <bool> Process() { Log("Application version: " + Vars.AppVer.ToString(), "CMD"); Log("Checking for updates...", "CMD"); Conf.Update Latest = Conf.CheckForUpdates(); if (Conf.IsNewerVersionAvailable(Latest)) { Log("Newer version found: " + Latest.Latest + ", main changes:\n" + Latest.Details, "CMD"); Log("Updating...", "CMD"); Log("Starting update download... (pmcenter_update.zip)", "CMD"); WebClient Downloader = new WebClient(); await Downloader.DownloadFileTaskAsync( new Uri(Vars.UpdateArchiveURL), Path.Combine(Vars.AppDirectory, "pmcenter_update.zip")); Log("Download complete. Extracting...", "CMD"); using (ZipArchive Zip = ZipFile.OpenRead(Path.Combine(Vars.AppDirectory, "pmcenter_update.zip"))) { foreach (ZipArchiveEntry Entry in Zip.Entries) { Log("Extracting: " + Path.Combine(Vars.AppDirectory, Entry.FullName), "CMD"); Entry.ExtractToFile(Path.Combine(Vars.AppDirectory, Entry.FullName), true); } } Log("Starting language file update...", "CMD"); await Downloader.DownloadFileTaskAsync( new Uri(Vars.CurrentConf.LangURL), Path.Combine(Vars.AppDirectory, "pmcenter_locale.json") ); Log("Cleaning up temporary files...", "CMD"); File.Delete(Path.Combine(Vars.AppDirectory, "pmcenter_update.zip")); Log("Update complete.", "CMD"); } else { Log("No newer version found.\nCurrently installed version: " + Vars.AppVer.ToString() + "\nThe latest version is: " + Latest.Latest, "CMD"); } return(true); }
public async Task <bool> ExecuteAsync(TelegramBotClient botClient, Update update) { try { Conf.Update Latest = Conf.CheckForUpdates(); if (Conf.IsNewerVersionAvailable(Latest)) { string UpdateString = Vars.CurrentLang.Message_UpdateAvailable .Replace("$1", Latest.Latest) .Replace("$2", Latest.Details) .Replace("$3", Methods.GetUpdateLevel(Latest.UpdateLevel)); await botClient.SendTextMessageAsync( update.Message.From.Id, UpdateString, ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); // where difference begins await botClient.SendTextMessageAsync( update.Message.From.Id, Vars.CurrentLang.Message_UpdateProcessing, ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); // download compiled package Log("Starting update download... (pmcenter_update.zip)", "BOT"); WebClient Downloader = new WebClient(); await Downloader.DownloadFileTaskAsync( new Uri(Vars.UpdateArchiveURL), Path.Combine(Vars.AppDirectory, "pmcenter_update.zip")); Log("Download complete. Extracting...", "BOT"); using (ZipArchive Zip = ZipFile.OpenRead(Path.Combine(Vars.AppDirectory, "pmcenter_update.zip"))) { foreach (ZipArchiveEntry Entry in Zip.Entries) { Log("Extracting: " + Path.Combine(Vars.AppDirectory, Entry.FullName), "BOT"); Entry.ExtractToFile(Path.Combine(Vars.AppDirectory, Entry.FullName), true); } } if (Vars.CurrentConf.AutoLangUpdate) { Log("Starting automatic language file update...", "BOT"); await Downloader.DownloadFileTaskAsync( new Uri(Vars.CurrentConf.LangURL), Path.Combine(Vars.AppDirectory, "pmcenter_locale.json") ); } Log("Cleaning up temporary files...", "BOT"); System.IO.File.Delete(Path.Combine(Vars.AppDirectory, "pmcenter_update.zip")); await botClient.SendTextMessageAsync( update.Message.From.Id, Vars.CurrentLang.Message_UpdateFinalizing, ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); Log("Exiting program... (Let the daemon do the restart job)", "BOT"); try { Environment.Exit(0); return(true); } catch (Exception ex) { Log("Failed to execute restart command: " + ex.ToString(), "BOT", LogLevel.ERROR); return(true); } // end of difference } else { await botClient.SendTextMessageAsync( update.Message.From.Id, Vars.CurrentLang.Message_AlreadyUpToDate .Replace("$1", Latest.Latest) .Replace("$2", Vars.AppVer.ToString()) .Replace("$3", Latest.Details), ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); return(true); } } catch (Exception ex) { string ErrorString = Vars.CurrentLang.Message_UpdateCheckFailed.Replace("$1", ex.ToString()); await botClient.SendTextMessageAsync( update.Message.From.Id, ErrorString, ParseMode.Markdown, false, Vars.CurrentConf.DisableNotifications, update.Message.MessageId); return(true); } }