星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AppUpdateWin.xaml.cs 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  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 : Window, ZJDownloadCallback
  15. {
  16. private readonly AppUpdatePageModel pageData = new AppUpdatePageModel();
  17. public AppUpdateWin(Model_App app)
  18. {
  19. InitializeComponent();
  20. pageData.appModel = app;
  21. DataContext = pageData;
  22. }
  23. private void btnDown_Click(object sender, RoutedEventArgs e)
  24. {
  25. Close();
  26. }
  27. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  28. {
  29. DragMove();
  30. }
  31. public class AppUpdatePageModel : NotifyModel
  32. {
  33. public Model_App appModel { get; set; }
  34. }
  35. private void Button_Click(object sender, RoutedEventArgs e)
  36. {
  37. Close();
  38. }
  39. private void gengxinClick(object sender, RoutedEventArgs e)
  40. {
  41. string fileUrl = APP.showImageUrl + pageData.appModel.versionpath;
  42. string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  43. DirectoryInfo info = new DirectoryInfo(path);
  44. if (!info.Exists)
  45. {
  46. info.Create();
  47. }
  48. string filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
  49. if (filename != null)
  50. {
  51. ZJDownloadUtil.downloadFileWithCallback(fileUrl, 999, Dispatcher, this);
  52. }
  53. }
  54. public void downloadBegin(int position)
  55. {
  56. progress_sp.Visibility = Visibility.Visible;
  57. content_sv.Visibility = Visibility.Collapsed;
  58. button_bottom.Visibility = Visibility.Collapsed;
  59. }
  60. public void downloadProgress(int position, int progress)
  61. {
  62. mprogress.Value = progress;
  63. parogress_tb.Text = $"正在更新,已下载{progress}%";
  64. }
  65. public void downloadEnd(int position, string filepath)
  66. {
  67. progress_sp.Visibility = Visibility.Collapsed;
  68. content_sv.Visibility = Visibility.Visible;
  69. button_bottom.Visibility = Visibility.Visible;
  70. try
  71. {
  72. using (Process process = new Process())
  73. {
  74. process.StartInfo.FileName = filepath;
  75. process.StartInfo.CreateNoWindow = true;
  76. process.StartInfo.UseShellExecute = false;
  77. process.StartInfo.RedirectStandardOutput = true;
  78. process.StartInfo.RedirectStandardError = true;
  79. process.Start();
  80. }
  81. }
  82. catch (Exception)
  83. {
  84. }
  85. Dispatcher.Invoke(new Action(() =>
  86. {
  87. Environment.Exit(0);
  88. }));
  89. Close();
  90. }
  91. public void downloadError(int position, string msg)
  92. {
  93. MessageWindow.Show(msg);
  94. }
  95. }
  96. }