/// <summary> /// Checks for/parses update.xml on server /// </summary> private void bgWorker2_DoWork(object sender, DoWorkEventArgs ee) { Updatable application = (Updatable)ee.Argument; // Check for update on server if (!Update.ExistsOnServer(application.ExeUpdateXmlLocation)) { ee.Cancel = true; } else // Parse update xml { Update.Parse(application.ExeUpdateXmlLocation); ee.Result = UpDateFile.Instance; } }
/// <summary> /// Checks for an update for the program passed. /// If there is an update, a dialog asking to download will appear /// </summary> public void DoExeUpdate() { Debug.Write("\n| DoExeUpdate |\n"); Updatable applicationInfo = new Updatable(); this.applicationInfo = applicationInfo; // Set up backgroundworker this.bgWorker2 = new BackgroundWorker(); this.bgWorker2.DoWork += new DoWorkEventHandler(bgWorker2_DoWork); this.bgWorker2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker2_RunWorkerCompleted); if (!this.bgWorker2.IsBusy) { this.bgWorker2.RunWorkerAsync(this.applicationInfo); } }
/// <summary> /// Hack to close program, delete original, move the new one to that location /// </summary> /// <param name="tempFilePath">The temporary file's path</param> /// <param name="currentPath">The path of the current application</param> /// <param name="newPath">The new path for the new file</param> /// <param name="launchArgs">The launch arguments</param> public async Task UpdateApplication(string tempFilePath, string fileN) { Debug.Write("\n| UpdateApp " + fileN + " |\n"); string directory = UpDateFile.Instance.GetDirectory(fileN); if (directory == "base") { directory = System.IO.Path.Combine(Directory.GetCurrentDirectory(), fileN); } else { directory = System.IO.Path.Combine(Directory.GetCurrentDirectory(), directory, fileN); } if (UpDateFile.Instance.GetDirectory(fileN) != "base") { try { string subPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), UpDateFile.Instance.GetDirectory(fileN)); bool IsExists = System.IO.Directory.Exists(subPath); if (!IsExists) { System.IO.Directory.CreateDirectory(subPath); } } catch (Exception ex) { string strErrorMsg = "Could not delete " + fileName + "! Error was:\r\n\r\n" + ex.ToString(); System.Windows.MessageBox.Show(strErrorMsg, "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } Updatable applicationInfo = new Updatable(); this.applicationInfo = applicationInfo; string appName = Assembly.GetExecutingAssembly().GetName().Name; if (appName == applicationInfo.ApplicationName && fileN == appName + ".exe") { try { string argument = "/C choice /C Y /N /D Y /T 3 & Del /F /Q \"{0}\" & choice /C Y /N /D Y /T 1 & Move /Y \"{1}\" \"{2}\" & Start \"\" /D \"{3}\" \"{4}\" "; ProcessStartInfo Info = new ProcessStartInfo(); Info.Arguments = String.Format(argument, directory, TempFilePath, directory, System.IO.Path.GetDirectoryName(directory), System.IO.Path.GetFileName(directory)); Info.WindowStyle = ProcessWindowStyle.Hidden; Info.CreateNoWindow = true; Info.FileName = "cmd.exe"; Process.Start(Info); Dispatcher.BeginInvoke((Action)(() => { this.Close(); })); } catch (Exception ex) { string strErrorMsg = "Could not delete " + fileName + "! Error was:\r\n\r\n" + ex.ToString(); System.Windows.MessageBox.Show(strErrorMsg, "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } else { try { System.IO.File.Copy(tempFilePath, directory, true); } catch (Exception ex) { string strErrorMsg = "Could not delete " + fileName + "! Error was:\r\n\r\n" + ex.ToString(); System.Windows.MessageBox.Show(strErrorMsg, "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } }