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 { /// /// AppUpdateWin.xaml 的交互逻辑 /// 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); } } }