You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.xaml.cs 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Program;
  16. using System.Diagnostics;
  17. using System.IO;
  18. using System.ComponentModel;
  19. namespace InstallerUpdater
  20. {
  21. /// <summary>
  22. /// Interaction logic for MainWindow.xaml
  23. /// </summary>
  24. public partial class MainWindow : Window
  25. {
  26. BackgroundWorker asyncDownloader = new BackgroundWorker();
  27. public MainWindow()
  28. {
  29. InitializeComponent();
  30. asyncDownloader.DoWork += AsyncDownloader_DoWork;
  31. asyncDownloader.RunWorkerCompleted += AsyncDownloader_RunWorkerCompleted;
  32. if (asyncDownloader.IsBusy)
  33. {
  34. MessageBox.Show("更新失败,请汇报");
  35. Process.Start(System.IO.Path.Combine(Updater.Dir, "Installer.exe"));
  36. Application.Current.Shutdown();
  37. }
  38. else
  39. asyncDownloader.RunWorkerAsync();
  40. }
  41. private void AsyncDownloader_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
  42. {
  43. if (e.Result == null)
  44. {
  45. MessageBox.Show("更新失败,请汇报");
  46. }
  47. else if ((bool)e.Result)
  48. {
  49. MessageBox.Show("已成功更新下载器,即将启动下载器");
  50. }
  51. else
  52. {
  53. MessageBox.Show("更新失败,请汇报");
  54. }
  55. Process.Start(System.IO.Path.Combine(Updater.Dir, "Installer.exe"));
  56. Application.Current.Shutdown();
  57. }
  58. private void AsyncDownloader_DoWork(object? sender, DoWorkEventArgs e)
  59. {
  60. if (asyncDownloader.CancellationPending)
  61. {
  62. e.Cancel = true;
  63. return;
  64. }
  65. else
  66. {
  67. if (Updater.UpdateInstaller())
  68. e.Result = true;
  69. else
  70. e.Result = false;
  71. }
  72. }
  73. }
  74. }