private void Button_Click(object sender, RoutedEventArgs e) { if (MyStatic.Type == UpdateType.None) { MyStatic.RunApp(); } Hide(); DownLoader.Show(); DownLoader.StartDownload(); }
private void DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { Status.Content = $"{ExtractUpdate}..."; Procents.Content = 0.ToString("0.0%"); Progress.Value = 0; new Task(() => { Thread.Sleep(400); using (MemoryStream Mem = new MemoryStream(e.Result)) { ZipArchive archive = new ZipArchive(Mem, ZipArchiveMode.Update); //archive.ExtractToDirectory("./"); int counter = 0, max = archive.Entries.Count; foreach (ZipArchiveEntry file in archive.Entries) { string completeFileName = System.IO.Path.Combine("./", file.FullName); string directory = System.IO.Path.GetDirectoryName(completeFileName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (file.Name != "") { file.ExtractToFile(completeFileName, true); } counter++; double procents = (double)counter / (double)max; MyExtentions.AsyncWorker(() => { Procents.Content = procents.ToString("0.0%"); Progress.Value = procents * 100; }); } } Thread.Sleep(200); MyExtentions.AsyncWorker(() => { Status.Content = "Updated"; MyStatic.RunApp(true); }); }).Start(); }
public void StartDownload() { Status.Content = $"{DownloadingUpdate}..."; if (string.IsNullOrEmpty(MyStatic.DownloadURL)) { MyStatic.GetSomeData(); } WebClient web = new WebClient(); web.DownloadDataAsync(new Uri(MyStatic.DownloadURL)); web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged); web.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadDataCompleted); Process proc = new Process(); proc.StartInfo.FileName = "CMD.exe"; proc.StartInfo.Arguments = "/c taskkill /f /im " + MyStatic.RunAfterUpdate; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.Start(); proc.WaitForExit(); }
private void RemindMeLater_Click(object sender, RoutedEventArgs e) { MyStatic.RunApp(); }
private void Window_Closed(object sender, EventArgs e) { MyStatic.RunApp(); }
private void ParseComandline() { string version = ""; string[] args = Environment.GetCommandLineArgs(); string next = ""; List <string> allowedParams = new List <string> { //Команды замены текстов UI "/Title", "/WhatNew", "/RemindLater", "/UpdateNow", "/Available", "/Current", "/PleaseWait", "/DownloadingFile", "/ExtractingUpdate", //Методы обновления "/GitHub", "/XMLS", "/API", //Настройки "/JustDownload", "/LogLang", "/Version", "/RunApp", "/RunAppParams", "/DarkTheme" }; foreach (var arg in args) { if (allowedParams.Contains(arg)) { switch (arg) { //Методы обновления case "/GitHub": //GitHub Releases MyStatic.Type = UpdateType.GitHubReleases; break; case "/XMLS": //XMLServer (Не сделан) MyStatic.Type = UpdateType.XMLServer; break; case "/API": //wsxz.ru/api/ (Не сделан) MyStatic.Type = UpdateType.WSXZApi; break; //Настройки case "/JustDownload": //Только скачивание и распаковывание Button_Click(UpdateNow, new RoutedEventArgs()); return; case "/DarkTheme": var uri = new Uri("DarkTheme.xaml", UriKind.Relative); ResourceDictionary resourceDict = Application.LoadComponent(uri) as ResourceDictionary; Application.Current.Resources.MergedDictionaries.Clear(); Application.Current.Resources.MergedDictionaries.Add(resourceDict); break; } next = arg; } else if (!string.IsNullOrEmpty(next)) { switch (next) { //Команды замены текстов UI case "/Title": DownLoader.Title = Title = arg; break; case "/WhatNew": WN.Content = arg; break; case "/RemindLater": RemindMeLater.Content = arg; break; case "/UpdateNow": UpdateNow.Content = arg; break; case "/Available": AvailableVer.Content = arg; break; case "/Current": CurrentVer.Content = arg; break; case "/PleaseWait": DownLoader.PleaseWait.Content = arg; break; case "/DownloadingFile": Downloader.DownloadingUpdate = arg; break; case "/ExtractingUpdate": Downloader.ExtractUpdate = arg; break; //Методы обновления case "/GitHub": case "/XMLS": case "/API": MyStatic.LinkOrToken = arg; break; //Настройки case "/LogLang": //Язык логов MyStatic.LogLanguage = arg; break; case "/Version": //Версия version = arg; break; case "/RunApp": //Что запускать MyStatic.RunAfterUpdate = arg; break; case "/RunAppParams": //Параметры запуска MyStatic.RunAfterUpdateParams = arg; break; } next = ""; } } if (MyStatic.Type == UpdateType.None) { MyStatic.RunApp(); } //Если версия не указана берем ее сами if (string.IsNullOrEmpty(version)) { if (File.Exists(MyStatic.RunAfterUpdate)) { var versionInfo = FileVersionInfo.GetVersionInfo(MyStatic.RunAfterUpdate); version = versionInfo.ProductVersion; } } if (!MyStatic.CheckVersion(version, out string lV) && File.Exists(MyStatic.RunAfterUpdate)) { MyStatic.RunApp(); } else { AvailableVer.Content += " - " + lV; if (!string.IsNullOrEmpty(version)) { CurrentVer.Content += " - " + version; } else { CurrentVer.Content = ""; } UpdLog.Text = MyStatic.GetUpdateLog(version); } }