public void InitInternals() { // set ethlargement path _ethlargementBinPath = EthlargementBinPath(); var pluginRoot = Path.Combine(Paths.MinerPluginsPath(), PluginUUID); var pluginRootIntenrals = Path.Combine(pluginRoot, "internals"); var supportedDevicesSettingsPath = Path.Combine(pluginRootIntenrals, "SupportedDevicesSettings.json"); var fileMinerOptionsPackage = InternalConfigs.ReadFileSettings <SupportedDevicesSettings>(supportedDevicesSettingsPath); if (fileMinerOptionsPackage != null && fileMinerOptionsPackage.UseUserSettings) { _supportedDevicesSettings = fileMinerOptionsPackage; } else { InternalConfigs.WriteFileSettings(supportedDevicesSettingsPath, _supportedDevicesSettings); } // Filter out supported ones var supportedDevicesNames = _supportedDevicesSettings.SupportedDeviceNames; if (supportedDevicesNames == null) { return; } Func <string, bool> isSupportedName = (string name) => supportedDevicesNames.Any(supportedPart => name.Contains(supportedPart)); var unsupportedDevicesUUIDs = _registeredSupportedDevices.Where(kvp => !isSupportedName(kvp.Value)).Select(kvp => kvp.Key).ToArray(); foreach (var removeKey in unsupportedDevicesUUIDs) { _registeredSupportedDevices.Remove(removeKey); } }
static SupportedAlgorithmsFilter() { // new platform #if (TESTNET || TESTNETDEV || PRODUCTION_NEW) _filteredAlgorithms.Add(new List <AlgorithmType> { AlgorithmType.MTP }); #else // old platform _filteredAlgorithms.Add(new List <AlgorithmType> { AlgorithmType.GrinCuckarood29 }); _filteredAlgorithms.Add(new List <AlgorithmType> { AlgorithmType.BeamV2 }); #endif var internalSettings = InternalConfigs.ReadFileSettings <List <List <AlgorithmType> > >(_internalSettingFilePath); if (internalSettings != null) { _filteredAlgorithms = internalSettings; } else { InternalConfigs.WriteFileSettings(_internalSettingFilePath, _filteredAlgorithms); } }
// TODO maybe just swap the dictionaries??? /// <summary> /// Change SMA profits to new values /// </summary> /// <param name="newSma">Algorithm/profit dictionary with new values</param> public static void UpdateSmaPaying(Dictionary <AlgorithmType, double> newSma) { CheckInit(); lock (_currentPayingRates) { foreach (var algo in newSma.Keys) { if (_currentPayingRates.ContainsKey(algo)) { _currentPayingRates[algo] = newSma[algo]; #if FILLSMA var paying = 1; _currentPayingRates[algo] = paying; #endif } } if (ConfigManager.GeneralConfig.UseSmaCache) { // Cache while in lock so file is not accessed on multiple threads var isFileSaved = InternalConfigs.WriteFileSettings(CachedFile, newSma); if (!isFileSaved) { Logger.Error(Tag, "CachedSma not saved"); } } } HasData = true; }
public static void DeviceConfigFileCommit(ComputeDevice device) { var devSettingsPath = GetDeviceSettingsPath(device.Uuid); var configs = device.GetDeviceConfig(); InternalConfigs.WriteFileSettings(devSettingsPath, configs); }
// TODO maybe just swap the dictionaries??? /// <summary> /// Change SMA profits to new values /// </summary> /// <param name="newSma">Algorithm/profit dictionary with new values</param> public static void UpdateSmaPaying(Dictionary <AlgorithmType, double> newSma) { lock (_currentPayingRates) { foreach (var algo in newSma.Keys) { if (_currentPayingRates.ContainsKey(algo)) { _currentPayingRates[algo] = newSma[algo]; if (BuildOptions.FORCE_MINING || BuildOptions.FORCE_PROFITABLE) { _currentPayingRates[algo] = 1000; } } } if (MiscSettings.Instance.UseSmaCache) { // Cache while in lock so file is not accessed on multiple threads var isFileSaved = InternalConfigs.WriteFileSettings(CachedFile, newSma); if (!isFileSaved) { Logger.Error(Tag, "CachedSma not saved"); } } } HasData = true; }
public static void GeneralConfigFileCommit() { ApplicationStateManager.App.Dispatcher.Invoke(() => { InternalConfigs.WriteFileSettings(GeneralConfigPath, GeneralConfig); ShowRestartRequired?.Invoke(null, IsRestartNeeded()); }); }
public static void CommitBenchmarksForDevice(ComputeDevice device) { // since we have multitrheaded benchmarks lock (_lock) lock (device) { var devSettingsPath = GetDeviceSettingsPath(device.Uuid); var configs = device.GetDeviceConfig(); InternalConfigs.WriteFileSettings(devSettingsPath, configs); } }
internal static void SaveMiningState() { var devicesRestoreStates = new Dictionary <string, DeviceRestoreState>(); foreach (var dev in AvailableDevices.Devices) { devicesRestoreStates[dev.Uuid] = new DeviceRestoreState { IsStarted = dev.StartState, LastState = dev.State }; } InternalConfigs.WriteFileSettings(_miningStateFilePath, devicesRestoreStates); }
static GetValueOrErrorSettings() { var settingsPath = Paths.MinerPluginsPath("BrokenMinerPluginUUID", "settings.json"); var globalBenchmarkExceptions = InternalConfigs.ReadFileSettings <Dictionary <string, bool> >(settingsPath); if (globalBenchmarkExceptions != null) { _settings = globalBenchmarkExceptions; } else { InternalConfigs.WriteFileSettings(settingsPath, _settings); } }
static BenchmarkProcessSettings() { const string globalBenchmarkExceptionsPath = @"internals\GlobalBenchmarkExceptions.json"; var globalBenchmarkExceptions = InternalConfigs.ReadFileSettings <Dictionary <string, string> >(globalBenchmarkExceptionsPath); if (globalBenchmarkExceptions != null) { GlobalBenchmarkExceptions = globalBenchmarkExceptions; } else { InternalConfigs.WriteFileSettings(globalBenchmarkExceptionsPath, GlobalBenchmarkExceptions); } }
static SupportedPluginsFilter() { string internalSettingFilePath = Paths.InternalsPath("SupportedPluginsFilter.json"); var internalSettings = InternalConfigs.ReadFileSettings <List <string> >(internalSettingFilePath); if (internalSettings != null) { _filteredPlugins = internalSettings; } else { InternalConfigs.WriteFileSettings(internalSettingFilePath, _filteredPlugins); } }
static MinersBinsUrls() { string binsUrlSettings = Paths.RootPath("miner_bins_urls.json"); var fileSettings = InternalConfigs.ReadFileSettings <MinersBinsUrlsSettings>(binsUrlSettings); if (fileSettings != null && fileSettings.UseFileSettings && fileSettings.PluginsUrls != null) { _pluginsUrls = fileSettings.PluginsUrls; } else { InternalConfigs.WriteFileSettings(binsUrlSettings, new MinersBinsUrlsSettings { PluginsUrls = _pluginsUrls }); } }
static SupportedAlgorithmsFilter() { // TESTNET #if (TESTNET || TESTNETDEV || PRODUCTION_NEW) _filteredAlgorithms.Add(new List <AlgorithmType> { AlgorithmType.MTP }); #endif var internalSettings = InternalConfigs.ReadFileSettings <List <List <AlgorithmType> > >(_internalSettingFilePath); if (internalSettings != null) { _filteredAlgorithms = internalSettings; } else { InternalConfigs.WriteFileSettings(_internalSettingFilePath, _filteredAlgorithms); } }
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 void SaveMoveConfig(DeviceType deviceType, AlgorithmType algorithmType, string sourcePath) { lock (_configsLock) { try { string destinationPath = Path.Combine(GetMinerConfigsRoot(), $"{algorithmType.ToString()}_{deviceType.ToString()}.txt"); var dirPath = Path.GetDirectoryName(destinationPath); if (Directory.Exists(dirPath) == false) { Directory.CreateDirectory(dirPath); } var readConfigContent = File.ReadAllText(sourcePath); // make it JSON readConfigContent = "{" + readConfigContent + "}"; // remove old if any if (File.Exists(destinationPath)) { File.Delete(destinationPath); } // move to path File.Move(sourcePath, destinationPath); var cachedFileSettings = $"cached_{algorithmType.ToString()}_{deviceType.ToString()}.json"; var cachedFileSettingsPath = Path.Combine(GetMinerConfigsRoot(), cachedFileSettings); var uuids = _registeredDeviceUUIDTypes.Where(kvp => kvp.Value == deviceType).Select(kvp => kvp.Key).ToList(); object cachedSettings = null; //TODO load and save switch (deviceType) { case DeviceType.CPU: var cpuConfig = JsonConvert.DeserializeObject <CpuConfig>(readConfigContent); SetCpuConfig(algorithmType, cpuConfig); cachedSettings = new CachedCpuSettings { CachedConfig = cpuConfig, DeviceUUIDs = uuids }; break; case DeviceType.AMD: var amdConfig = JsonConvert.DeserializeObject <AmdConfig>(readConfigContent); SetAmdConfig(algorithmType, amdConfig); cachedSettings = new CachedAmdSettings { CachedConfig = amdConfig, DeviceUUIDs = uuids }; break; case DeviceType.NVIDIA: var nvidiaConfig = JsonConvert.DeserializeObject <NvidiaConfig>(readConfigContent); SetNvidiaConfig(algorithmType, nvidiaConfig); cachedSettings = new CachedNvidiaSettings { CachedConfig = nvidiaConfig, DeviceUUIDs = uuids }; break; } if (cachedSettings != null) { var header = "// This config file was autogenerated by NHML."; header += "\n// \"DeviceUUIDs\" is used to check if we have same devices and should not be edited."; header += "\n// \"CachedConfig\" can be edited as it is used as config template (edit this only if you know what you are doing)"; header += "\n// If \"DeviceUUIDs\" is different (new devices added or old ones removed) this file will be overwritten and \"CachedConfig\" will be set to defaults."; header += "\n\n"; var jsonText = JsonConvert.SerializeObject(cachedSettings, Formatting.Indented); var headerWithConfigs = header + jsonText; InternalConfigs.WriteFileSettings(cachedFileSettingsPath, headerWithConfigs); } } catch (Exception e) { Logger.Error("XmrStakPlugin", $"SaveMoveConfig error: {e.Message}"); } } }
public static void GeneralConfigFileCommit() { CommitBenchmarks(); InternalConfigs.WriteFileSettings(GeneralConfigPath, GeneralConfig); ShowRestartRequired?.Invoke(null, IsRestartNeeded()); }
// TODO add more options static void Main(string[] args) { PluginBase.IS_CALLED_FROM_PACKER = true; if (args.Length < 1) { Console.WriteLine("Set miner plugins root path"); return; } var exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var pluginPackagesFolder = Path.Combine(exePath, "plugins_packages"); var pluginsSearchRoot = args[0]; // get all managed plugin dll's var dllFiles = Directory.GetFiles(pluginsSearchRoot, "*.dll", SearchOption.AllDirectories) .Where(filePath => !filePath.Contains("MinerPlugin") && filePath.Contains("net45") && filePath.Contains("Release") && !filePath.Contains("bin")).ToList(); var packedPlugins = new HashSet <string>(); if (Directory.Exists(pluginPackagesFolder)) { Console.WriteLine("Deleting old plugins packages"); Directory.Delete(pluginPackagesFolder, true); } if (!Directory.Exists(pluginPackagesFolder)) { Directory.CreateDirectory(pluginPackagesFolder); } // what plugins to bundle var bundlePlugins = new List <string> { "2257f160-7236-11e9-b20c-f9f12eb6d835", // CCMinerTpruvotPlugin "70984aa0-7236-11e9-b20c-f9f12eb6d835", // ClaymoreDual14Plugin //"92fceb00-7236-11e9-b20c-f9f12eb6d835", // CPUMinerPlugin "1b7019d0-7237-11e9-b20c-f9f12eb6d835", // GMinerPlugin "435f0820-7237-11e9-b20c-f9f12eb6d835", // LolMinerBeamPlugin "59bba2c0-b1ef-11e9-8e4e-bb1e2c6e76b4", // MiniZPlugin "6c07f7a0-7237-11e9-b20c-f9f12eb6d835", // NBMinerPlugin "f5d4a470-e360-11e9-a914-497feefbdfc8", // PhoenixPlugin "abc3e2a0-7237-11e9-b20c-f9f12eb6d835", // TeamRedMinerPlugin "d47d9b00-7237-11e9-b20c-f9f12eb6d835", // TRexPlugin //"3d4e56b0-7238-11e9-b20c-f9f12eb6d835", // XmrStakPlugin "5532d300-7238-11e9-b20c-f9f12eb6d835", // ZEnemyPlugin //"4aec5ec0-10f8-11ea-bad3-8dea21141bbb", // XmrStakRxPlugin "1046ea50-c261-11e9-8e4e-bb1e2c6e76b4", // XMRig }; var bundlePluginsDlls = new Dictionary <string, string>(); foreach (var filePath in dllFiles) { var dllDir = Path.GetDirectoryName(filePath); var loaded = MinerPluginHost.LoadPlugin(dllDir); if (loaded.Count() == 0) { // log what we couldn't load and continue Console.WriteLine($"Skipping: {filePath}"); continue; } var newPlugins = MinerPluginHost.MinerPlugin .Where(kvp => packedPlugins.Contains(kvp.Key) == false) .Select(kvp => kvp.Value); foreach (var plugin in newPlugins) { try { CheckPluginMetaData(plugin); } catch (Exception e) { Console.WriteLine($"CheckPluginMetaData ERROR!!!!!!!!! {e.Message}"); } } foreach (var plugin in newPlugins) { try { if (bundlePlugins.Contains(plugin.PluginUUID)) { bundlePluginsDlls.Add(plugin.PluginUUID, filePath); } var pluginZipFileName = GetPluginPackageName(plugin); var dllPackageZip = Path.Combine(pluginPackagesFolder, pluginZipFileName); Console.WriteLine($"Packaging: {dllPackageZip}"); var fileName = Path.GetFileName(filePath); using (var archive = ZipFile.Open(dllPackageZip, ZipArchiveMode.Create)) { archive.CreateEntryFromFile(filePath, fileName); } packedPlugins.Add(plugin.PluginUUID); AddPluginToPluginPackageInfos(plugin); } catch (Exception e) { Console.WriteLine(e.Message); } } } try { var preinstalledDlls = Path.Combine(exePath, "miner_plugins"); if (!Directory.Exists(preinstalledDlls)) { Directory.CreateDirectory(preinstalledDlls); } foreach (var kvp in bundlePluginsDlls) { var preinstalledDllPlugin = Path.Combine(exePath, "miner_plugins", kvp.Key); var fileName = Path.GetFileName(kvp.Value); var dllPath = Path.Combine(preinstalledDllPlugin, fileName); if (!Directory.Exists(preinstalledDllPlugin)) { Directory.CreateDirectory(preinstalledDllPlugin); } File.Copy(kvp.Value, dllPath); } } catch (Exception e) { Console.WriteLine(e.Message); } // dump our plugin packages InternalConfigs.WriteFileSettings(Path.Combine(pluginPackagesFolder, "update.json"), PluginPackageInfos); var deleteFolder = Path.Combine(exePath, "miner_plugins", "BrokenMinerPluginUUID"); Directory.Delete(deleteFolder, true); }
public static void BlacklistPluginsCommit() { var configs = BlacklistedPlugins.Instance; InternalConfigs.WriteFileSettings(BlacklistedPluginsPath, configs); }
private static void CommitToFile() => InternalConfigs.WriteFileSettings(BlacklistedPluginsPath, BlacklistedPluginUUIDs);
// TODO add more options static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Set miner plugins root path"); return; } var exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var pluginPackagesFolder = Path.Combine(exePath, "plugins_packages"); var pluginsSearchRoot = args[0]; // get all managed plugin dll's var dllFiles = Directory.GetFiles(pluginsSearchRoot, "*.dll", SearchOption.AllDirectories) .Where(filePath => !filePath.Contains("MinerPlugin") && filePath.Contains("net45") && filePath.Contains("Release") && !filePath.Contains("bin")).ToList(); var packedPlugins = new HashSet <string>(); if (Directory.Exists(pluginPackagesFolder)) { Console.WriteLine("Deleting old plugins packages"); Directory.Delete(pluginPackagesFolder, true); } if (!Directory.Exists(pluginPackagesFolder)) { Directory.CreateDirectory(pluginPackagesFolder); } foreach (var filePath in dllFiles) { var dllDir = Path.GetDirectoryName(filePath); var loaded = MinerPluginHost.LoadPlugin(dllDir); if (loaded.Count() == 0) { // log what we couldn't load and continue Console.WriteLine($"Skipping: {filePath}"); continue; } var newPlugins = MinerPluginHost.MinerPlugin .Where(kvp => packedPlugins.Contains(kvp.Key) == false) .Select(kvp => kvp.Value); foreach (var plugin in newPlugins) { var pluginZipFileName = GetPluginPackageName(plugin); var dllPackageZip = Path.Combine(pluginPackagesFolder, pluginZipFileName); Console.WriteLine($"Packaging: {dllPackageZip}"); var fileName = Path.GetFileName(filePath); using (var archive = ZipFile.Open(dllPackageZip, ZipArchiveMode.Create)) { archive.CreateEntryFromFile(filePath, fileName); } packedPlugins.Add(plugin.PluginUUID); AddPluginToPluginPackageInfos(plugin); } } // dump our plugin packages InternalConfigs.WriteFileSettings(Path.Combine(pluginPackagesFolder, "update.json"), PluginPackageInfos); }
public static void GeneralConfigFileCommit() { CommitBenchmarks(); InternalConfigs.WriteFileSettings(GeneralConfigPath, GeneralConfig); }
private static void CommitToFile() => InternalConfigs.WriteFileSettings(AcceptedPluginsPath, AcceptedPluginUUIDs);