Exemplo n.º 1
0
        public KernelPageViewModel()
        {
            if (Design.IsInDesignMode)
            {
                return;
            }
            this.ChangeCurrentKernelMenu = new DelegateCommand <KernelMenu>((kernelMenu) => {
                SetCurrentKernelMenu(kernelMenu);
                this.PageNumber          = 1;
                KernelDownloadingVisible = Visibility.Collapsed;
            });
            this.Home = new DelegateCommand(() => {
                ChangeCurrentKernelMenu.Execute(_repositoryKernelMenu);
            });

            this._kernelMenus.Add(_repositoryKernelMenu);
            this._kernelMenus.Add(_uninstallKernelMenu);
            this.Add = new DelegateCommand(() => {
                new KernelViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
            });
            this.Search = new DelegateCommand(() => {
                this.PageNumber = 1;
            });
            this.ClearKeyword = new DelegateCommand(() => {
                Keyword = string.Empty;
            });
            this.PageSub = new DelegateCommand(() => {
                this.PageNumber = this.PageNumber - 1;
            });
            this.PageAdd = new DelegateCommand(() => {
                this.PageNumber = this.PageNumber + 1;
            });
            this.TagKernelBrand = new DelegateCommand <SysDicItemViewModel>(brandItem => {
                string outFileName     = Path.GetFileNameWithoutExtension(VirtualRoot.AppFileFullName) + $"_{brandItem.Value}.exe";
                string outDir          = Path.GetDirectoryName(VirtualRoot.AppFileFullName);
                string outFileFullName = Path.Combine(outDir, outFileName);
                VirtualRoot.TagKernelBrandId(brandItem.GetId(), VirtualRoot.AppFileFullName, outFileFullName);
                NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage($"打码成功:{outFileName}");
                Process.Start(outDir);
            });
            this.Home.Execute(null);
        }
Exemplo n.º 2
0
 private MainWindowViewModel()
 {
     if (App.IsInDesignMode)
     {
         return;
     }
     this.Refresh();
     this.CancelDownload = new DelegateCommand(() => {
         this._cancel?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.IsDownloading = true;
         string ntMinerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntMinerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntMinerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntMinerFile, version, progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         }, downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage = message;
             this.DownloadPercent = 0;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 if (VirtualRoot.IsMinerStudio)
                 {
                     Client.MinerStudioService.CloseMinerStudio();
                 }
                 else
                 {
                     Client.MinerClientService.CloseNTMiner();
                 }
                 TimeSpan.FromSeconds(3).Delay().ContinueWith((t) => {
                     string location = NTMinerRegistry.GetLocation();
                     if (string.IsNullOrEmpty(location) || !File.Exists(location))
                     {
                         location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ntMinerFile);
                     }
                     try {
                         if (File.Exists(location))
                         {
                             Guid kernelBrandId = VirtualRoot.GetKernelBrandId(location);
                             if (kernelBrandId != Guid.Empty)
                             {
                                 Logger.InfoDebugLine("打码开始");
                                 VirtualRoot.TagKernelBrandId(kernelBrandId, saveFileFullName, saveFileFullName);
                                 Logger.OkDebugLine("打码成功");
                             }
                         }
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e.Message, e);
                     }
                     Logger.InfoDebugLine("复制开始");
                     File.Copy(saveFileFullName, location, overwrite: true);
                     File.Delete(saveFileFullName);
                     Logger.InfoDebugLine("复制完成,删除旧文件");
                     string arguments = NTMinerRegistry.GetArguments();
                     Logger.InfoDebugLine("启动新程序");
                     Process.Start(location, arguments);
                     this.IsDownloading = false;
                     UIThread.Execute(() => {
                         Logger.InfoDebugLine("退出升级器");
                         Application.Current.MainWindow?.Close();
                     });
                 });
             }
             else
             {
                 TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out _cancel);
     }, () => !IsDownloading);
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("添加", "Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowDialogEx();
     });
 }