123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.IO;
- using System.Management;
- using System.Windows;
- using System.Windows.Input;
- using XHWK.Model;
- using XHWK.WKTool.Helpers;
- using static XHWK.WKTool.Helpers.ZJDownloadUtil;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// AppUpdateWin.xaml 的交互逻辑
- /// </summary>
- public partial class AppUpdateWin : ZJDownloadCallback
- {
- private readonly AppUpdatePageModel _pageData = new AppUpdatePageModel();
-
- public AppUpdateWin(ModelApp app)
- {
- InitializeComponent();
- _pageData.appModel = app;
- DataContext = _pageData;
- }
-
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
- public class AppUpdatePageModel : NotifyModel
- {
- public ModelApp appModel { get; set; }
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- Close();
- }
-
- private void GengxinClick(object sender, RoutedEventArgs e)
- {
- string fileUrl = App.showImageUrl + _pageData.appModel.versionpath;
- string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
- DirectoryInfo info = new DirectoryInfo(path);
- if (!info.Exists)
- {
- info.Create();
- }
- ZJDownloadUtil.downloadFileWithCallback
- (
- fileUrl,
- 999,
- Dispatcher,
- this
- );
- }
-
- public void downloadBegin(int position)
- {
- ProgressSp.Visibility = Visibility.Visible;
- ContentSv.Visibility = Visibility.Collapsed;
- ButtonBottom.Visibility = Visibility.Collapsed;
- }
-
- public void downloadProgress(int position, int progress)
- {
- Mprogress.Value = progress;
- ParogressTb.Text = $"正在更新,已下载{progress}%";
- }
-
- public void downloadEnd(int position, string filepath)
- {
- ProgressSp.Visibility = Visibility.Collapsed;
- ContentSv.Visibility = Visibility.Visible;
- ButtonBottom.Visibility = Visibility.Visible;
- try
- {
- using (var managementClass = new ManagementClass("Win32_Process"))
- {
- var processInfo = new ManagementClass("Win32_ProcessStartup");
- processInfo.Properties["CreateFlags"].Value = 0x00000008;
-
- var inParameters = managementClass.GetMethodParameters("Create");
- inParameters["CommandLine"] = filepath;
- inParameters["ProcessStartupInformation"] = processInfo;
-
- var result = managementClass.InvokeMethod("Create", inParameters, null);
- if ((result != null) && ((uint)result.Properties["ReturnValue"].Value != 0))
- {
- Console.WriteLine(@"Process ID: {0}", result.Properties["ProcessId"].Value);
- }
- }
- }
- catch (Exception)
- {
- // ignored
- }
- Application.Current.Shutdown();
- }
-
- public void downloadError(int position, string msg)
- {
- MessageWindow.Show(msg);
- }
- }
- }
|