Beispiel #1
0
 public void SetNoDeviceAction()
 {
     ApplicationStateManager.NoDeviceAction = () =>
     {
         this.Dispatcher.Invoke(() =>
         {
             var nhmNoDeviceDialog = new CustomDialog()
             {
                 Title            = Translations.Tr("No Supported Devices"),
                 Description      = Translations.Tr("No supported devices are found. Select the OK button for help or cancel to continue."),
                 OkText           = Translations.Tr("OK"),
                 CancelText       = Translations.Tr("Cancel"),
                 AnimationVisible = Visibility.Collapsed
             };
             nhmNoDeviceDialog.OKClick += (s, e) =>
             {
                 Process.Start(Links.NhmNoDevHelp);
             };
             nhmNoDeviceDialog.OnExit += (s, e) =>
             {
                 ApplicationStateManager.ExecuteApplicationExit();
             };
             ShowContentAsModalDialog(nhmNoDeviceDialog);
         });
     };
 }
        private static async Task GracefulShutdown()
        {
            try
            {
                Logger.Info(Tag, "Installer/uninstaller is running, attempting NHM shutdown");
                await ApplicationStateManager.BeforeExit();

                ApplicationStateManager.ExecuteApplicationExit();
                Logger.Info(Tag, "NHM closed successfully due to installer/uninstaller.");
            }
            catch (Exception ex)
            {
                Logger.Error(Tag, $"GracefulShutdown: {ex.Message}");
            }
        }
        private async Task MainWindow_OnClosingTask(System.ComponentModel.CancelEventArgs e)
        {
            // Only ever try to prevent closing once
            if (_miningStoppedOnClose)
            {
                return;
            }

            _miningStoppedOnClose = true;
            //e.Cancel = true;
            IsEnabled = false;
            //await _vm.StopMining();
            await ApplicationStateManager.BeforeExit();

            ApplicationStateManager.ExecuteApplicationExit();
            //Close();
        }
Beispiel #4
0
        internal static async Task <bool> StartUpdateProcess()
        {
            try
            {
                OnAutoUpdate?.Invoke();
                // #2 SAVE current state so we can resume it after the client updates
                ApplicationStateManager.SaveMiningState();
                await Task.Delay(5000); // wait 5 seconds

                await ApplicationStateManager.StopAllDevicesTask();

                await Task.Delay(5000); // wait 5 seconds

                // #3 restart accordingly if launcher or self containd app
                if (Launcher.IsLauncher)
                {
                    try
                    {
                        // TODO here save what version and maybe kind of update we have
                        File.Create(Paths.RootPath("do.update"));
                        ApplicationStateManager.ExecuteApplicationExit();
                    }
                    catch (Exception e)
                    {
                        Logger.Error("NICEHASH", $"Autoupdate IsLauncher error: {e.Message}");
                        // IF we fail restore mining state and show autoupdater failure nofitication
                        await ApplicationStateManager.RestoreMiningState();

                        // TODO notify that the auto-update wasn't successful
                    }
                }
                else
                {
                    // no launcher
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(Tag, $"StartUpdateProcess autoupdate Exception: {ex.Message}");
                return(false);
            }
            // if success we close app anyways
            return(true);
        }
 public void SetBurnCalledAction()
 {
     ApplicationStateManager.BurnCalledAction = () =>
     {
         this.Dispatcher.Invoke(() =>
         {
             var nhmBurnDialog = new CustomDialog()
             {
                 Title         = Translations.Tr("Burn Error!"),
                 Description   = Translations.Tr("Error during burn"),
                 OkText        = Translations.Tr("OK"),
                 CancelVisible = Visibility.Collapsed
             };
             nhmBurnDialog.OnExit += (s, e) => {
                 ApplicationStateManager.ExecuteApplicationExit();
             };
             ShowContentAsModalDialog(nhmBurnDialog);
         });
     };
 }
Beispiel #6
0
 public static void Execute(int pid, string path)
 {
     if (Launcher.IsLauncher)
     {
         try
         {
             File.Create(Paths.RootPath("do.runasadmin"));
             ApplicationStateManager.ExecuteApplicationExit();
         }
         catch (Exception e)
         {
             Logger.Error("NICEHASH", $"RunAsAdmin IsLauncher error: {e.Message}");
         }
     }
     else
     {
         try
         {
             var fileName  = Paths.RootPath("runnhmasadmin.exe");
             var startInfo = new ProcessStartInfo
             {
                 FileName        = fileName,
                 Arguments       = $"{pid} {path}",
                 Verb            = "runas",
                 UseShellExecute = true,
                 CreateNoWindow  = true
             };
             startInfo.WindowStyle = ProcessWindowStyle.Hidden; // used for hidden window
             using (var runAsAdmin = Process.Start(startInfo))
             {
                 runAsAdmin.WaitForExit();
             }
         }
         catch (Exception ex)
         {
             Logger.Error("NICEHASH", $"RunAsAdmin error: {ex.Message}");
         }
     }
 }
 private void CancelButton_OnClick(object sender, RoutedEventArgs e)
 {
     ApplicationStateManager.ExecuteApplicationExit();
 }
Beispiel #8
0
        private static async Task NhmAutoUpdateCheckLoop(CancellationToken stop)
        {
            try
            {
                // check for updates every 30s
                //var checkWaitTime = TimeSpan.FromSeconds(30);
                var         checkWaitTime = TimeSpan.FromSeconds(60); // TODO DEBUG
                Func <bool> isActive      = () => !stop.IsCancellationRequested;

                while (isActive())
                {
                    if (isActive())
                    {
                        await TaskHelpers.TryDelay(checkWaitTime, stop);
                    }

                    var isAutoUpdate  = UpdateSettings.Instance.AutoUpdateNiceHashMiner;
                    var hasNewVersion = VersionState.Instance.IsNewVersionAvailable;
                    // prevent sleep check
                    if (isActive() && isAutoUpdate && hasNewVersion && !Launcher.IsUpdatedFailed)
                    {
                        try
                        {
                            // determine what how to update
                            bool isUpdater = IsNHMInstalled() && IsRunningInstalledApp();
                            // #1 download updater.exe or zip depending on bin type
                            var url = isUpdater ? VersionState.Instance.GetNewVersionUpdaterUrl() : VersionState.Instance.GetNewVersionZipUrl();
                            var downloadRootPath = Path.Combine(Paths.Root, "updaters");
                            if (!Directory.Exists(downloadRootPath))
                            {
                                Directory.CreateDirectory(downloadRootPath);
                            }
                            var saveAsFile = isUpdater ? $"nhm_windows_updater_{VersionState.Instance.OnlineVersionStr}" : $"nhm_windows_{VersionState.Instance.OnlineVersionStr}";
                            var(success, downloadedFilePath) = await MinersDownloadManager.DownloadFileWebClientAsync(url, downloadRootPath, saveAsFile, DownloadProgress, ApplicationStateManager.ExitApplication.Token);

                            if (!success)
                            {
                                // TODO notify that we cannot download the miner updates file
                                continue;
                            }

                            OnAutoUpdate?.Invoke();
                            // #2 SAVE current state so we can resume it after the client updates
                            ApplicationStateManager.SaveMiningState();
                            await Task.Delay(5000); // wait 5 seconds

                            await ApplicationStateManager.StopAllDevicesTask();

                            await Task.Delay(5000); // wait 5 seconds

                            // #3 restart accordingly if launcher or self containd app
                            if (Launcher.IsLauncher)
                            {
                                try
                                {
                                    // TODO here save what version and maybe kind of update we have
                                    File.Create(Paths.RootPath("do.update"));
                                    ApplicationStateManager.ExecuteApplicationExit();
                                }
                                catch (Exception e)
                                {
                                    Logger.Error("NICEHASH", $"Autoupdate IsLauncher error: {e.Message}");
                                    // IF we fail restore mining state and show autoupdater failure nofitication
                                    await ApplicationStateManager.RestoreMiningState();

                                    // TODO notify that the auto-update wasn't successful
                                }
                            }
                            else
                            {
                                // TODO non launcher not priority right now
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(Tag, $"Check autoupdate Exception: {ex.Message}");
                        }
                    }
                }
            }
            catch (TaskCanceledException e)
            {
                Logger.Info(Tag, $"NhmAutoUpdateCheckLoop TaskCanceledException: {e.Message}");
            }
            catch (Exception e)
            {
                Logger.Error(Tag, $"NhmAutoUpdateCheckLoop Exception: {e.Message}");
            }
            finally
            {
                Logger.Info(Tag, "Exiting NhmAutoUpdateCheckLoop run cleanup");
                // cleanup
            }
        }
Beispiel #9
0
        internal static async Task StartUpdateProcess(bool isUpdater)
        {
            try
            {
                // Let user know that something is happening after update process started
                if (Launcher.IsLauncher)
                {
                    var notifications      = NotificationsManager.Instance.Notifications;
                    var updateNotification = notifications.Find(notif => notif.Group == NotificationsGroup.NhmUpdate);
                    updateNotification.NotificationContent = Translations.Tr("Update in progress...");
                }

                // determine what how to update
                // #1 download updater.exe or zip depending on bin type
                var url = isUpdater ? VersionState.Instance.GetNewVersionUpdaterUrl() : VersionState.Instance.GetNewVersionZipUrl();
                var downloadRootPath = Path.Combine(Paths.Root, "updaters");
                if (!Directory.Exists(downloadRootPath))
                {
                    Directory.CreateDirectory(downloadRootPath);
                }
                var saveAsFile = isUpdater ? $"nhm_windows_updater_{VersionState.Instance.OnlineVersionStr}" : $"nhm_windows_{VersionState.Instance.OnlineVersionStr}";
                var(success, downloadedFilePath) = await MinersDownloadManager.DownloadFileWebClientAsync(url, downloadRootPath, saveAsFile, DownloadProgress, ApplicationStateManager.ExitApplication.Token);

                if (!success)
                {
                    // TODO notify that we cannot download the miner updates file
                    return;
                }

                OnAutoUpdate?.Invoke();
                // #2 SAVE current state so we can resume it after the client updates
                ApplicationStateManager.SaveMiningState();
                await Task.Delay(5000); // wait 5 seconds

                await ApplicationStateManager.StopAllDevicesTask();

                await Task.Delay(5000); // wait 5 seconds

                // #3 restart accordingly if launcher or self containd app
                if (Launcher.IsLauncher)
                {
                    try
                    {
                        // TODO here save what version and maybe kind of update we have
                        File.Create(Paths.RootPath("do.update"));
                        ApplicationStateManager.ExecuteApplicationExit();
                    }
                    catch (Exception e)
                    {
                        Logger.Error("NICEHASH", $"Autoupdate IsLauncher error: {e.Message}");
                        // IF we fail restore mining state and show autoupdater failure nofitication
                        await ApplicationStateManager.RestoreMiningState();

                        // TODO notify that the auto-update wasn't successful
                    }
                }
                else
                {
                    // TODO non launcher not priority right now
                }
            } catch (Exception ex)
            {
                Logger.Error(Tag, $"Check autoupdate Exception: {ex.Message}");
            }
        }