Esempio n. 1
0
        public async Task <bool> ExecuteAsync(TelegramBotClient botClient, Update update)
        {
            try
            {
                var Latest = Conf.CheckForUpdates();
                var CurrentLocalizedIndex = Conf.GetUpdateInfoIndexByLocale(Latest, Vars.CurrentLang.LangCode);
                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.UpdateCollection[CurrentLocalizedIndex].Details)
                                       .Replace("$3", Methods.GetUpdateLevel(Latest.UpdateLevel));
                    _ = await botClient.SendTextMessageAsync(
                        update.Message.From.Id,
                        UpdateString,
                        ParseMode.Markdown,
                        false,
                        Vars.CurrentConf.DisableNotifications,
                        update.Message.MessageId).ConfigureAwait(false);
                }
                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.UpdateCollection[CurrentLocalizedIndex].Details),
                        ParseMode.Markdown,
                        false,
                        Vars.CurrentConf.DisableNotifications,
                        update.Message.MessageId).ConfigureAwait(false);
                }
                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).ConfigureAwait(false);

                return(true);
            }
        }
Esempio n. 2
0
        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;
                    string UpdateString = Vars.CurrentLang.Message_UpdateAvailable
                                          .Replace("$1", Latest.Latest)
                                          .Replace("$2", Latest.Details);
                    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)
            {
                string 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);
            }
        }
Esempio n. 3
0
        public async Task <bool> Process()
        {
            Log($"Application version: {Vars.AppVer.ToString()}", "CMD");
            Log("Checking for updates...", "CMD");
            Log("Custom update channels and languages are currently unsupported in command line mode, will use \"master\" channel with English.", "CMD");
            var Latest = Conf.CheckForUpdates();

            if (Conf.IsNewerVersionAvailable(Latest))
            {
                Log($"Newer version found: {Latest.Latest}, main changes:\n{Latest.UpdateCollection[0].Details}", "CMD");
                Log("Updating...", "CMD");
                Log("Starting update download... (pmcenter_update.zip)", "CMD");
                using (var Downloader = new WebClient())
                {
                    await Downloader.DownloadFileTaskAsync(
                        new Uri(Vars.UpdateArchiveURL),
                        Path.Combine(Vars.AppDirectory, "pmcenter_update.zip")).ConfigureAwait(false);

                    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")
                        ).ConfigureAwait(false);
                }
                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);
        }
Esempio n. 4
0
        public async Task <bool> Process()
        {
            Log("Application version: " + Vars.AppVer.ToString(), "CMD");
            Log("Checking for updates...", "CMD");
            var 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");
                var 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);
        }
Esempio n. 5
0
        public async Task <bool> ExecuteAsync(TelegramBotClient botClient, Update update)
        {
            try
            {
                var Latest = Conf.CheckForUpdates();
                var CurrentLocalizedIndex = Conf.GetUpdateInfoIndexByLocale(Latest, Vars.CurrentLang.LangCode);
                if (Conf.IsNewerVersionAvailable(Latest))
                {
                    var UpdateString = Vars.CurrentLang.Message_UpdateAvailable
                                       .Replace("$1", Latest.Latest)
                                       .Replace("$2", Latest.UpdateCollection[CurrentLocalizedIndex].Details)
                                       .Replace("$3", Methods.GetUpdateLevel(Latest.UpdateLevel));
                    _ = await botClient.SendTextMessageAsync(
                        update.Message.From.Id,
                        UpdateString, ParseMode.Markdown,
                        false,
                        Vars.CurrentConf.DisableNotifications,
                        update.Message.MessageId).ConfigureAwait(false);

                    // where difference begins
                    _ = await botClient.SendTextMessageAsync(
                        update.Message.From.Id,
                        Vars.CurrentLang.Message_UpdateProcessing,
                        ParseMode.Markdown,
                        false,
                        Vars.CurrentConf.DisableNotifications,
                        update.Message.MessageId).ConfigureAwait(false);

                    // download compiled package
                    Log("Starting update download... (pmcenter_update.zip)", "BOT");
                    Log($"From address: {Latest.UpdateCollection[CurrentLocalizedIndex].UpdateArchiveAddress}", "BOT");
                    using (var Downloader = new WebClient())
                    {
                        await Downloader.DownloadFileTaskAsync(
                            new Uri(Latest.UpdateCollection[CurrentLocalizedIndex].UpdateArchiveAddress),
                            Path.Combine(Vars.AppDirectory, "pmcenter_update.zip")).ConfigureAwait(false);

                        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")
                                ).ConfigureAwait(false);
                        }
                    }
                    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).ConfigureAwait(false);

                    Log("Exiting program... (Let the daemon do the restart job)", "BOT");
                    Environment.Exit(0);
                    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.UpdateCollection[CurrentLocalizedIndex].Details),
                        ParseMode.Markdown,
                        false,
                        Vars.CurrentConf.DisableNotifications,
                        update.Message.MessageId).ConfigureAwait(false);

                    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).ConfigureAwait(false);

                return(true);
            }
        }
Esempio n. 6
0
        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);
                    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();
                    Downloader.DownloadFile(
                        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("Trying to execute restart command...", "BOT");
                    try
                    {
                        Process.Start(Vars.CurrentConf.RestartCommand, Vars.CurrentConf.RestartArgs);
                        Log("Executed.", "BOT");
                        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.Message);
                await botClient.SendTextMessageAsync(
                    update.Message.From.Id,
                    ErrorString,
                    ParseMode.Markdown,
                    false,
                    Vars.CurrentConf.DisableNotifications,
                    update.Message.MessageId);

                return(true);
            }
        }