123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.IO;
- using System.Net;
- using System.Windows;
- using System.Diagnostics;
- using System.Text.RegularExpressions;
- namespace MPE
- {
- static class Updater
- {///<summary> Выполняет проверку обновлений, если такие были нейдены предложит пользователю обновить приложение </summary>
- static System.Threading.Tasks.Task t;
- static readonly WebClient client = new WebClient();
- static bool fromSettings = false;
- public static void FindNewVersion(bool fromSettings = false)
- {
- Updater.fromSettings = fromSettings;
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
- if (!File.Exists("updater.exe")) client.DownloadFileAsync(new Uri("https://medoo48.bitbucket.io/Download/updater.exe"), "updater.exe");
- client.DownloadStringCompleted += Client_DownloadStringCompleted; ;
- t = System.Threading.Tasks.Task.Run(() => { try { client.DownloadStringAsync(new Uri("https://medoo48.bitbucket.io/index.html")); } catch { } });
- }
- static void Client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
- {
- try
- {
- Match version = new Regex(@"\d+\S\d+").Match(e.Result);
- if (version.Success)
- {
- if (Convert.ToDouble(version.Value.Replace(".", ",")) > Properties.Settings.Default.version)
- {// if new_version > current_version TODO...
- string url = "https://medoo48.bitbucket.io/Download/MPE.exe";
- if (MessageBox.Show($"Доступна новая версия[{version.Value}], загрузить?", "Обновление miniPosterEditor", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
- {
- client.DownloadFile(new Uri(url), ($"miniPosterEditor_{version.Value}.exe"));
- client.Dispose();
- if (File.Exists("updater.exe"))
- {
- Process.Start("updater.exe", $"miniPosterEditor_{version.Value}.exe MPE.exe");
- Process.GetCurrentProcess().Kill();//Завершаем собственный процесс
- }
- else MessageBox.Show("Обновление не может быть проиведено, так как отсутствует файл updater.exe!");
- }
- }
- else if (fromSettings) { MessageBox.Show($"Обновлений нет. У Вас работает актуальная версия {Properties.Settings.Default.version}"); fromSettings = false; }
- }
- }
- catch (Exception ex) { }
- }
- }
- }
|