123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Diagnostics;
- 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 : Window, ZJDownloadCallback
- {
- private readonly AppUpdatePageModel pageData = new AppUpdatePageModel();
-
- public AppUpdateWin(Model_App app)
- {
- InitializeComponent();
- pageData.appModel = app;
-
- DataContext = pageData;
- }
-
- private void btnDown_Click(object sender, RoutedEventArgs e)
- {
- Close();
- }
-
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
- public class AppUpdatePageModel : NotifyModel
- {
- public Model_App 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();
- }
-
- string filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
- if (filename != null)
- {
- 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)
- {
- }
- Environment.Exit(0);
- }
-
- public void downloadError(int position, string msg)
- {
- MessageWindow.Show(msg);
- }
- }
- }
|