private void showProgress(string progressMsg) { this.Dispatcher.Invoke(() => { ProgressTxtBox.AppendText(progressMsg); ProgressTxtBox.AppendText(Environment.NewLine); ProgressTxtBox.ScrollToEnd(); }); }
public void CheckForUpdate() { Console.WriteLine("Checking for newer version..."); AntidoteKey = Registry.LocalMachine.CreateSubKey(@"Software\Antidote"); string Version = AntidoteKey.GetValue("Version").ToString(); RestRequest req = new RestRequest("update", Method.GET); req.AddParameter("client_version", Version, ParameterType.QueryString); restClient.ExecuteAsync(req, res => { Console.WriteLine("API RES RECEIVED!"); if (res.StatusCode == System.Net.HttpStatusCode.OK) { dynamic resDic = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(res.Content); String status = resDic.Status; if ("success".Equals(status)) { string ActCode = resDic.ActCode; if ("UPDATE_APP".Equals(ActCode)) { showProgress("업데이트 시작"); this.Dispatcher.Invoke(() => { this.WindowState = WindowState.Maximized; this.Topmost = true; this.ShowInTaskbar = true; this.Visibility = Visibility.Visible; DownloadProgressBar.IsIndeterminate = false; ProgressTxtBox.Clear(); this.Show(); }); SetTaskManager(false); string InstallerLocation = resDic.Data.InstallerLocation; installer_hash_from_server = resDic.Data.InstallerHash; new_version_code = resDic.Data.VersionCode; Console.WriteLine("Downloading installer... URL IS: " + InstallerLocation); SAVE_PATH = System.IO.Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData), "Antidote", "AntidoteInstaller.exe"); showProgress("설치파일 다운로드 시작"); using (WebClient wc = new WebClient()) { wc.DownloadProgressChanged += wc_DownloadProgressChanged; wc.DownloadFileCompleted += wc_DownloadFileCompleted; wc.DownloadFileAsync(new Uri(InstallerLocation), SAVE_PATH); } } else { Console.WriteLine("Update not needed"); workerBusy = false; } } } else { Console.WriteLine("Failed to ask server for update"); } }); }