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.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. MessageBox.Show("这是旧版");
  31. asyncDownloader.DoWork += AsyncDownloader_DoWork;
  32. asyncDownloader.RunWorkerCompleted += AsyncDownloader_RunWorkerCompleted;
  33. if (asyncDownloader.IsBusy)
  34. {
  35. MessageBox.Show("更新失败,请汇报");
  36. Process.Start(System.IO.Path.Combine(Updater.Dir, "Installer.exe"));
  37. Application.Current.Shutdown();
  38. }
  39. else
  40. asyncDownloader.RunWorkerAsync();
  41. }
  42. private void AsyncDownloader_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
  43. {
  44. if (e.Result == null)
  45. {
  46. MessageBox.Show("更新失败,请汇报");
  47. }
  48. else if ((bool)e.Result)
  49. {
  50. MessageBox.Show("已成功更新下载器,即将启动下载器");
  51. }
  52. else
  53. {
  54. MessageBox.Show("更新失败,请汇报");
  55. }
  56. Process.Start(System.IO.Path.Combine(Updater.Dir, "Installer.exe"));
  57. Application.Current.Shutdown();
  58. }
  59. private void AsyncDownloader_DoWork(object? sender, DoWorkEventArgs e)
  60. {
  61. if (asyncDownloader.CancellationPending)
  62. {
  63. e.Cancel = true;
  64. return;
  65. }
  66. else
  67. {
  68. if (Updater.UpdateInstaller())
  69. e.Result = true;
  70. else
  71. e.Result = false;
  72. }
  73. }
  74. }
  75. }