Exemplo n.º 1
0
 public static void SwitchAmdComputeMode()
 {
     try
     {
         var fileName  = Paths.AppRootPath("AmdComputeModeSwitcher.exe");
         var startInfo = new ProcessStartInfo
         {
             FileName        = fileName,
             Verb            = "runas",
             UseShellExecute = true,
             CreateNoWindow  = true
         };
         startInfo.WindowStyle = ProcessWindowStyle.Hidden; // used for hidden window
         using (var amdModeSwitcher = new Process {
             StartInfo = startInfo
         })
         {
             amdModeSwitcher.Start();
             amdModeSwitcher?.WaitForExit(10 * 1000);
             if (amdModeSwitcher?.ExitCode != 0)
             {
                 Logger.Info("NICEHASH", "amdModeSwitcher returned error code: " + amdModeSwitcher.ExitCode);
             }
             else
             {
                 Logger.Info("NICEHASH", "amdModeSwitcher all OK");
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error("NICEHASH", $"SwitchAmdComputeMode error: {ex.Message}");
     }
 }
Exemplo n.º 2
0
        private static void TryAddNvmlToEnvPath(bool useNvmlFallback)
        {
            if (_tryAddNvmlToEnvPathCalled)
            {
                return;
            }
            _tryAddNvmlToEnvPathCalled = true; // call this ONLY ONCE AND NEVER AGAIN

            // default path
            var nvmlRootPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
                               "\\NVIDIA Corporation\\NVSMI";
            var nvmlRootPathTag = "DEFAULT";

            if (useNvmlFallback)
            {
                nvmlRootPath    = Paths.AppRootPath("NVIDIA");
                nvmlRootPathTag = "FALLBACK";
            }

            Logger.Info(Tag, $"Adding NVML to PATH. {nvmlRootPathTag} path='{nvmlRootPath}'");
            if (Directory.Exists(nvmlRootPath))
            {
                // Add to env so it can find nvml.dll
                var pathVar = Environment.GetEnvironmentVariable("PATH");
                pathVar += ";" + nvmlRootPath;
                Environment.SetEnvironmentVariable("PATH", pathVar);
            }
        }
Exemplo n.º 3
0
 public void Init()
 {
     if (TriedInit)
     {
         return;
     }
     TriedInit = true;
     try
     {
         using var sr = new StreamReader(Paths.AppRootPath("GPUprofiles.json"));
         var raw = sr.ReadToEnd();
         ProfileData = JsonConvert.DeserializeObject <Profiles>(raw);
         if (ProfileData != null)
         {
             SuccessInit = true;
         }
         if (SuccessInit)
         {
             _systemContainsSupportedDevices = AvailableDevices.Devices.Any(dev => IsSupportedDeviceName(dev.Name));
             OnPropertyChanged(nameof(SystemContainsSupportedDevices));
             OnPropertyChanged(nameof(SystemContainsSupportedDevicesNotSystemElevated));
         }
         Logger.Info(Tag, $"Init: {SuccessInit}");
         Logger.Info(Tag, $"System contains supported devices: {SystemContainsSupportedDevices}");
     }
     catch (Exception ex)
     {
         Logger.Error(Tag, ex.Message);
     }
 }
Exemplo n.º 4
0
        private void BaseDialogWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var gifPath = Paths.AppRootPath("assets", "enter_BTC_manually.gif");

            if (File.Exists(gifPath))
            {
                _showMeHowWindow      = new ManuallyEnterBTCTutorial();
                _showMeHowWindow.Left = this.Left + this.Width;
                _showMeHowWindow.Top  = this.Top;
                _showMeHowWindow.Show();
            }
        }
        // if we get multiple platforms copy the OpenCL.dll to nhml root
        public static async Task <(string rawOutput, OpenCLDeviceDetectionResult parsed)> TryQueryOpenCLDevicesAsyncFallback()
        {
            Logger.Info(Tag, "TryQueryOpenCLDevicesAsyncFallback START");
            try
            {
                Logger.Info(Tag, "TryQueryOpenCLDevicesAsyncFallback trying to copy OpenCL.dll");
                File.Copy(Paths.AppRootPath("OpenCL", "OpenCL.dll"), Paths.Root, true);
            }
            catch (Exception e)
            {
                Logger.Error(Tag, $"TryQueryOpenCLDevicesAsyncFallback trying to copy OpenCL.dll error: {e.Message}");
            }
            var result = await DeviceDetectionPrinter.GetDeviceDetectionResultAsync <OpenCLDeviceDetectionResult>("ocl -n", 60 * 1000);

            Logger.Info(Tag, "TryQueryOpenCLDevicesAsyncFallback END");
            return(result);
        }
 public static bool AddException()
 {
     try
     {
         var fileName  = Paths.AppRootPath("AddWindowsDefenderExclusion.exe");
         var startInfo = new ProcessStartInfo
         {
             FileName        = fileName,
             Arguments       = $"add {AppDir}",
             Verb            = "runas",
             UseShellExecute = true,
             CreateNoWindow  = true
         };
         startInfo.WindowStyle = ProcessWindowStyle.Hidden; // used for hidden window
         using (var addDefenderException = new Process {
             StartInfo = startInfo
         })
         {
             addDefenderException.Start();
             addDefenderException?.WaitForExit(10 * 1000);
             if (addDefenderException?.ExitCode != 0)
             {
                 Logger.Info("NICEHASH", "addDefenderException returned error code: " + addDefenderException.ExitCode);
             }
             else
             {
                 var cwd = AppDir;
                 using (var userRegistryKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\" + APP_GUID.GUID, true))
                 {
                     userRegistryKey.SetValue("WindowsDefenderExclusion" + lastIndex, cwd);
                     Logger.Info("NICEHASH", "addDefenderException all OK");
                 }
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error("NICEHASH", $"AddDefenderException error: {ex.Message}");
     }
     return(false);
 }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         var gifPath = Paths.AppRootPath("assets", "enter_BTC_manually.gif");
         if (File.Exists(gifPath))
         {
             LoginHowToGif.Source = new Uri(gifPath);
         }
         else
         {
             Close();
         }
     }
     catch (Exception ex)
     {
         Logger.Error("ManuallyEnterBTCTutorial", $"Window_Loaded error: {ex}.");
         Close();
     }
 }
Exemplo n.º 8
0
 public static void UpdateFirewallRules()
 {
     try
     {
         var fileName  = Paths.AppRootPath("FirewallRules.exe");
         var startInfo = new ProcessStartInfo
         {
             FileName = fileName,
             //Arguments = $"{Directory.GetCurrentDirectory()} update miner_plugins",
             Arguments       = $"{Paths.Root} update miner_plugins",
             Verb            = "runas",
             UseShellExecute = true,
             CreateNoWindow  = true
         };
         startInfo.WindowStyle = ProcessWindowStyle.Hidden; // used for hidden window
         using (var setFirewallRulesProcess = new Process {
             StartInfo = startInfo
         })
         {
             setFirewallRulesProcess.Start();
             setFirewallRulesProcess?.WaitForExit(10 * 1000);
             if (setFirewallRulesProcess?.ExitCode != 0)
             {
                 Logger.Info("NICEHASH", "setFirewallRulesProcess returned error code: " + setFirewallRulesProcess.ExitCode);
             }
             else
             {
                 Logger.Info("NICEHASH", "setFirewallRulesProcess all OK");
                 var installedPlugins = MinerPluginsManager.GetPluginUUIDsAndVersionsList();
                 _pluginsUUIDsWithVersions = installedPlugins;
                 InternalConfigs.WriteFileSettings(_firewallRulesAddedFilePath, _pluginsUUIDsWithVersions);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error("NICEHASH", $"SetFirewallRules error: {ex.Message}");
     }
 }
 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.AppRootPath("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}");
         }
     }
 }