星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppUpdateWin.xaml.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.IO;
  3. using System.Management;
  4. using System.Windows;
  5. using System.Windows.Input;
  6. using XHWK.Model;
  7. using XHWK.WKTool.Helpers;
  8. using static XHWK.WKTool.Helpers.ZJDownloadUtil;
  9. namespace XHWK.WKTool
  10. {
  11. /// <summary>
  12. /// AppUpdateWin.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class AppUpdateWin : ZJDownloadCallback
  15. {
  16. private readonly AppUpdatePageModel _pageData = new AppUpdatePageModel();
  17. public AppUpdateWin(ModelApp app)
  18. {
  19. InitializeComponent();
  20. _pageData.appModel = app;
  21. DataContext = _pageData;
  22. }
  23. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  24. {
  25. DragMove();
  26. }
  27. public class AppUpdatePageModel : NotifyModel
  28. {
  29. public ModelApp appModel { get; set; }
  30. }
  31. private void Button_Click(object sender, RoutedEventArgs e)
  32. {
  33. Close();
  34. }
  35. private void GengxinClick(object sender, RoutedEventArgs e)
  36. {
  37. string fileUrl = App.showImageUrl + _pageData.appModel.versionpath;
  38. string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  39. DirectoryInfo info = new DirectoryInfo(path);
  40. if (!info.Exists)
  41. {
  42. info.Create();
  43. }
  44. ZJDownloadUtil.downloadFileWithCallback
  45. (
  46. fileUrl,
  47. 999,
  48. Dispatcher,
  49. this
  50. );
  51. }
  52. public void downloadBegin(int position)
  53. {
  54. ProgressSp.Visibility = Visibility.Visible;
  55. ContentSv.Visibility = Visibility.Collapsed;
  56. ButtonBottom.Visibility = Visibility.Collapsed;
  57. }
  58. public void downloadProgress(int position, int progress)
  59. {
  60. Mprogress.Value = progress;
  61. ParogressTb.Text = $"正在更新,已下载{progress}%";
  62. }
  63. public void downloadEnd(int position, string filepath)
  64. {
  65. ProgressSp.Visibility = Visibility.Collapsed;
  66. ContentSv.Visibility = Visibility.Visible;
  67. ButtonBottom.Visibility = Visibility.Visible;
  68. try
  69. {
  70. using (var managementClass = new ManagementClass("Win32_Process"))
  71. {
  72. var processInfo = new ManagementClass("Win32_ProcessStartup");
  73. processInfo.Properties["CreateFlags"].Value = 0x00000008;
  74. var inParameters = managementClass.GetMethodParameters("Create");
  75. inParameters["CommandLine"] = filepath;
  76. inParameters["ProcessStartupInformation"] = processInfo;
  77. var result = managementClass.InvokeMethod("Create", inParameters, null);
  78. if ((result != null) && ((uint)result.Properties["ReturnValue"].Value != 0))
  79. {
  80. Console.WriteLine(@"Process ID: {0}", result.Properties["ProcessId"].Value);
  81. }
  82. }
  83. }
  84. catch (Exception)
  85. {
  86. // ignored
  87. }
  88. Application.Current.Shutdown();
  89. }
  90. public void downloadError(int position, string msg)
  91. {
  92. MessageWindow.Show(msg);
  93. }
  94. }
  95. }