星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AppUpdateWin.xaml.cs 3.5KB

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