Example #1
0
 public static void Upgrade(string ntminerFileName, Action callback)
 {
     try {
         string updaterDirFullName = Path.Combine(VirtualRoot.GlobalDirFullName, "Updater");
         if (!Directory.Exists(updaterDirFullName))
         {
             Directory.CreateDirectory(updaterDirFullName);
         }
         OfficialServer.FileUrlService.GetNTMinerUpdaterUrlAsync((downloadFileUrl, e) => {
             try {
                 if (string.IsNullOrEmpty(downloadFileUrl))
                 {
                     callback?.Invoke();
                     return;
                 }
                 string argument = string.Empty;
                 if (!string.IsNullOrEmpty(ntminerFileName))
                 {
                     argument = "ntminerFileName=" + ntminerFileName;
                 }
                 if (VirtualRoot.IsMinerStudio)
                 {
                     argument += " --minerstudio";
                 }
                 string ntMinerUpdaterFileFullName = Path.Combine(updaterDirFullName, "NTMinerUpdater.exe");
                 Uri uri = new Uri(downloadFileUrl);
                 string updaterVersion = NTMinerRegistry.GetUpdaterVersion();
                 if (string.IsNullOrEmpty(updaterVersion) || !File.Exists(ntMinerUpdaterFileFullName) || uri.AbsolutePath != updaterVersion)
                 {
                     FileDownloader.ShowWindow(downloadFileUrl, "开源矿工更新器", (window, isSuccess, message, saveFileFullName) => {
                         try {
                             if (isSuccess)
                             {
                                 File.Copy(saveFileFullName, ntMinerUpdaterFileFullName, overwrite: true);
                                 File.Delete(saveFileFullName);
                                 NTMinerRegistry.SetUpdaterVersion(uri.AbsolutePath);
                                 window?.Close();
                                 Windows.Cmd.RunClose(ntMinerUpdaterFileFullName, argument);
                                 callback?.Invoke();
                             }
                             else
                             {
                                 NotiCenterWindowViewModel.Current.Manager.ShowErrorMessage(message);
                                 callback?.Invoke();
                             }
                         }
                         catch {
                             callback?.Invoke();
                         }
                     });
                 }
                 else
                 {
                     Windows.Cmd.RunClose(ntMinerUpdaterFileFullName, argument);
                     callback?.Invoke();
                 }
             }
             catch {
                 callback?.Invoke();
             }
         });
     }
     catch {
         callback?.Invoke();
     }
 }