Initialize() публичный статический Метод

public static Initialize ( LanguageType lid ) : void
lid LanguageType
Результат void
Пример #1
0
        static void Main(string[] argv)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            CultureInfo.DefaultThreadCurrentCulture   = System.Globalization.CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentCulture       = System.Globalization.CultureInfo.InvariantCulture;
            //Console.OutputEncoding = System.Text.Encoding.Unicode;
            // #0 set this first so data parsing will work correctly
            Globals.JsonSettings = new JsonSerializerSettings {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                Culture = CultureInfo.InvariantCulture
            };

            // #1 first initialize config
            ConfigManager.Instance.GeneralConfig.InitializeConfig();
            ConfigManager.Instance.LegacyConfigMigration();

            if (ConfigManager.Instance.GeneralConfig.LogToFile)
            {
                Logger.ConfigureWithFile();
            }

            if (ConfigManager.Instance.GeneralConfig.DebugConsole)
            {
                Helpers.AllocConsole();
            }

            // #2 then parse args
            var commandLineArgs = new CommandLineParser(argv);

            Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion);

            if (!ConfigManager.Instance.GeneralConfig.IsFileExist() && !commandLineArgs.IsLang)
            {
                Helpers.ConsolePrint("NICEHASH", "No config file found. Running NiceHash Miner for the first time. Choosing a default language.");
                Application.Run(new Form_ChooseLanguage());
            }

            // Init languages
            International.Initialize(ConfigManager.Instance.GeneralConfig.Language);

            if (commandLineArgs.IsLang)
            {
                Helpers.ConsolePrint("NICEHASH", "Language is overwritten by command line parameter (-lang).");
                International.Initialize(commandLineArgs.LangValue);
                ConfigManager.Instance.GeneralConfig.Language = commandLineArgs.LangValue;
            }

            Application.Run(new Form_Main());
        }
Пример #2
0
        static void Main(string[] argv)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool ConfigExist = Config.ConfigFileExist();

            Config.InitializeConfig();

            if (Config.ConfigData.LogToFile)
            {
                Logger.ConfigureWithFile();
            }

            if (Config.ConfigData.DebugConsole)
            {
                Helpers.AllocConsole();
            }

            Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion);

            string tmp;

            if (!ConfigExist && !ParseCommandLine(argv, "-lang", out tmp))
            {
                Helpers.ConsolePrint("NICEHASH", "No config file found. Running NiceHash Miner for the first time. Choosing a default language.");
                Application.Run(new Form_ChooseLanguage());
            }

            // Init languages
            International.Initialize(Config.ConfigData.Language);

            if (argv.Length > 0)
            {
                if (ParseCommandLine(argv, "-lang", out tmp))
                {
                    int lang;
                    if (Int32.TryParse(tmp, out lang))
                    {
                        Helpers.ConsolePrint("NICEHASH", "Language is overwritten by command line parameter (-lang).");
                        International.Initialize(lang);
                        Config.ConfigData.Language = lang;
                    }
                }

                if (ParseCommandLine(argv, "-config", out tmp))
                {
                    Application.Run(new Form1(true));
                }
            }

            Application.Run(new Form1(false));
        }
Пример #3
0
        static void Main(string[] argv)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var commandLineArgs = new CommandLineParser(argv);

            bool ConfigExist = Config.ConfigFileExist();

            Config.InitializeConfig();

            if (Config.ConfigData.LogToFile)
            {
                Logger.ConfigureWithFile();
            }

            if (Config.ConfigData.DebugConsole)
            {
                Helpers.AllocConsole();
            }

            Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion);

            if (!ConfigExist && !commandLineArgs.IsLang)
            {
                Helpers.ConsolePrint("NICEHASH", "No config file found. Running NiceHash Miner for the first time. Choosing a default language.");
                Application.Run(new Form_ChooseLanguage());
            }

            // Init languages
            International.Initialize(Config.ConfigData.Language);

            if (commandLineArgs.IsLang)
            {
                Helpers.ConsolePrint("NICEHASH", "Language is overwritten by command line parameter (-lang).");
                International.Initialize(commandLineArgs.LangValue);
                Config.ConfigData.Language = commandLineArgs.LangValue;
            }

            Application.Run(new Form_Main(commandLineArgs.IsConfig));
        }
Пример #4
0
        static void Main(string[] argv)
        {
            // Set working directory to exe
            var pathSet = false;
            var path    = Path.GetDirectoryName(Application.ExecutablePath);

            if (path != null)
            {
                Environment.CurrentDirectory = path;
                pathSet = true;
            }

            // Add common folder to path for launched processes
            var pathVar = Environment.GetEnvironmentVariable("PATH");

            pathVar += ";" + Path.Combine(Environment.CurrentDirectory, "common");
            Environment.SetEnvironmentVariable("PATH", pathVar);


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            //Console.OutputEncoding = System.Text.Encoding.Unicode;
            // #0 set this first so data parsing will work correctly
            Globals.JsonSettings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                Culture = CultureInfo.InvariantCulture
            };

            // #1 first initialize config
            ConfigManager.InitializeConfig();

            // #2 check if multiple instances are allowed
            var startProgram = true;

            if (ConfigManager.GeneralConfig.AllowMultipleInstances == false)
            {
                try
                {
                    var current = Process.GetCurrentProcess();
                    foreach (var process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            startProgram = false;
                        }
                    }
                }
                catch { }
            }

            if (startProgram)
            {
                if (ConfigManager.GeneralConfig.LogToFile)
                {
                    Logger.ConfigureWithFile();
                }

                if (ConfigManager.GeneralConfig.DebugConsole)
                {
                    PInvokeHelpers.AllocConsole();
                }

                // init active display currency after config load
                ExchangeRateApi.ActiveDisplayCurrency = ConfigManager.GeneralConfig.DisplayCurrency;

                // #2 then parse args
                var commandLineArgs = new CommandLineParser(argv);

                Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion);

                if (!pathSet)
                {
                    Helpers.ConsolePrint("NICEHASH", "Path not set to executable");
                }

                var tosChecked = ConfigManager.GeneralConfig.agreedWithTOS == Globals.CurrentTosVer;
                if (!tosChecked || !ConfigManager.GeneralConfigIsFileExist() && !commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH",
                                         "No config file found. Running NiceHash Miner Legacy for the first time. Choosing a default language.");
                    Application.Run(new Form_ChooseLanguage());
                }

                // Init languages
                International.Initialize(ConfigManager.GeneralConfig.Language);

                if (commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH", "Language is overwritten by command line parameter (-lang).");
                    International.Initialize(commandLineArgs.LangValue);
                    ConfigManager.GeneralConfig.Language = commandLineArgs.LangValue;
                }

                // check WMI
                if (Helpers.IsWmiEnabled())
                {
                    if (ConfigManager.GeneralConfig.agreedWithTOS != Globals.CurrentTosVer)
                    {
                        return;
                    }

                    if (ConfigManager.GeneralConfig.BitcoinAddress.Trim() == "")
                    {
                        var dialogSwitch = new EnterBTCDialogSwitch();
                        Application.Run(dialogSwitch);
                        if (dialogSwitch.IsLogin)
                        {
                            var loginForm = new LoginForm();
                            Application.Run(loginForm);
                            if (BitcoinAddress.ValidateBitcoinAddress(loginForm.Btc))
                            {
                                ConfigManager.GeneralConfig.BitcoinAddress = loginForm.Btc;
                                ConfigManager.GeneralConfigFileCommit();
                            }
                        }

                        Application.Run(new Form_Main());
                    }
                }
                else
                {
                    MessageBox.Show(International.GetText("Program_WMI_Error_Text"),
                                    International.GetText("Program_WMI_Error_Title"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #5
0
        static void Main(string[] argv)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            //Console.OutputEncoding = System.Text.Encoding.Unicode;
            // #0 set this first so data parsing will work correctly
            Globals.JsonSettings = new JsonSerializerSettings {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                Culture = CultureInfo.InvariantCulture
            };

            // #1 first initialize config
            ConfigManager.InitializeConfig();

            // #2 check if multiple instances are allowed
            bool startProgram = true;

            if (ConfigManager.GeneralConfig.AllowMultipleInstances == false)
            {
                try {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            startProgram = false;
                        }
                    }
                } catch { }
            }

            if (startProgram)
            {
                if (ConfigManager.GeneralConfig.LogToFile)
                {
                    Logger.ConfigureWithFile();
                }

                if (ConfigManager.GeneralConfig.DebugConsole)
                {
                    Helpers.AllocConsole();
                }

                // init active display currency after config load
                ExchangeRateAPI.ActiveDisplayCurrency = ConfigManager.GeneralConfig.DisplayCurrency;

                // #2 then parse args
                var commandLineArgs = new CommandLineParser(argv);

                Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion);
                bool tosChecked = ConfigManager.GeneralConfig.agreedWithTOS == Globals.CURRENT_TOS_VER;
                if (!tosChecked || !ConfigManager.GeneralConfigIsFileExist() && !commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH", "No config file found. Running NiceHash Miner Legacy for the first time. Choosing a default language.");
                    Application.Run(new Form_ChooseLanguage());
                }

                // Init languages
                International.Initialize(ConfigManager.GeneralConfig.Language);

                if (commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH", "Language is overwritten by command line parameter (-lang).");
                    International.Initialize(commandLineArgs.LangValue);
                    ConfigManager.GeneralConfig.Language = commandLineArgs.LangValue;
                }

                // check WMI
                if (Helpers.IsWMIEnabled())
                {
                    if (ConfigManager.GeneralConfig.agreedWithTOS == Globals.CURRENT_TOS_VER)
                    {
                        Application.Run(new Form_Main());
                    }
                }
                else
                {
                    MessageBox.Show(International.GetText("Program_WMI_Error_Text"),
                                    International.GetText("Program_WMI_Error_Title"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #6
0
        static void Main(string[] argv)
        {
            // Set working directory to exe
            var pathSet = false;
            var path    = Path.GetDirectoryName(Application.ExecutablePath);

            if (path != null)
            {
                Environment.CurrentDirectory = path;
                pathSet = true;
            }

            // Add common folder to path for launched processes
            var pathVar = Environment.GetEnvironmentVariable("PATH");

            pathVar += ";" + Path.Combine(Environment.CurrentDirectory, "common");
            Environment.SetEnvironmentVariable("PATH", pathVar);


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            //Console.OutputEncoding = System.Text.Encoding.Unicode;
            // #0 set this first so data parsing will work correctly
            Globals.JsonSettings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                Culture = CultureInfo.InvariantCulture
            };

            // #1 first initialize config
            ConfigManager.InitializeConfig();

            // #2 check if multiple instances are allowed
            var startProgram = true;

            if (ConfigManager.GeneralConfig.AllowMultipleInstances == false)
            {
                try
                {
                    var current = Process.GetCurrentProcess();
                    foreach (var process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            startProgram = false;
                        }
                    }
                }
                catch { }
            }

            if (startProgram)
            {
                if (ConfigManager.GeneralConfig.LogToFile)
                {
                    Logger.ConfigureWithFile();
                }

                if (ConfigManager.GeneralConfig.DebugConsole)
                {
                    PInvokeHelpers.AllocConsole();
                }
                //**

                /*
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 4)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (File.Exists("internals\\MinerOptionPackage_glg.json"))
                 *      File.Delete("internals\\MinerOptionPackage_glg.json");
                 *
                 *  if (File.Exists("internals\\MinerOptionPackage_ClaymoreDual.json"))
                 *      File.Delete("internals\\MinerOptionPackage_ClaymoreDual.json");
                 *
                 *  if (File.Exists("bin\\ccminer_klaust\\ccminer.exe"))
                 *      File.Delete("bin\\ccminer_klaust\\ccminer.exe");
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 4;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 4.1)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (File.Exists("internals\\MinerOptionPackage_ClaymoreDual.json"))
                 *      File.Delete("internals\\MinerOptionPackage_ClaymoreDual.json");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 4.1;
                 * }
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 5)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 5;
                 * }
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 6)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 6;
                 * }
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 7)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 7;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 8)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 8;
                 * }
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 8.2)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 8.2;
                 * }
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 9)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 9;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 9.1)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  if (File.Exists("bin_3rdparty\\t-rex\\t-rex.exe"))
                 *      File.Delete("bin_3rdparty\\t-rex\\t-rex.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 9.1;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 9.2)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  if (File.Exists("bin_3rdparty\\t-rex\\t-rex.exe"))
                 *      File.Delete("bin_3rdparty\\t-rex\\t-rex.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 9.2;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 9.3)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  if (File.Exists("bin_3rdparty\\t-rex\\t-rex.exe"))
                 *      File.Delete("bin_3rdparty\\t-rex\\t-rex.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 9.3;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 10)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  if (File.Exists("bin_3rdparty\\t-rex\\t-rex.exe"))
                 *      File.Delete("bin_3rdparty\\t-rex\\t-rex.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 10;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 11)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  if (File.Exists("bin\\xmrig\\xmrig.exe"))
                 *      File.Delete("bin\\xmrig\\xmrig.exe");
                 *
                 *  if (File.Exists("bin_3rdparty\\t-rex\\t-rex.exe"))
                 *      File.Delete("bin_3rdparty\\t-rex\\t-rex.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 11;
                 * }
                 *
                 * if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 11.1)
                 * {
                 *  Helpers.ConsolePrint("NICEHASH", "Old version");
                 *  if (Directory.Exists("internals"))
                 *      Directory.Delete("internals", true);
                 *
                 *  if (File.Exists("bin_3rdparty\\t-rex\\t-rex.exe"))
                 *      File.Delete("bin_3rdparty\\t-rex\\t-rex.exe");
                 *
                 *  ConfigManager.GeneralConfig.ForkFixVersion = 11.1;
                 * }
                 */
                if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 11.2)
                {
                    Helpers.ConsolePrint("NICEHASH", "Old version");
                    if (Directory.Exists("internals"))
                    {
                        Directory.Delete("internals", true);
                    }
                    ConfigManager.GeneralConfig.ForkFixVersion = 11.2;
                }

                if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 12)
                {
                    Helpers.ConsolePrint("NICEHASH", "Old version");
                    if (Directory.Exists("internals"))
                    {
                        Directory.Delete("internals", true);
                    }
                    ConfigManager.GeneralConfig.ForkFixVersion = 12;
                }
                if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 12.1)
                {
                    Helpers.ConsolePrint("NICEHASH", "Old version");
                    if (Directory.Exists("internals"))
                    {
                        Directory.Delete("internals", true);
                    }
                    ConfigManager.GeneralConfig.ForkFixVersion = 12.1;
                }
                if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 13)
                {
                    Helpers.ConsolePrint("NICEHASH", "Old version");
                    if (Directory.Exists("internals"))
                    {
                        Directory.Delete("internals", true);
                    }
                    ConfigManager.GeneralConfig.ForkFixVersion = 13;
                }
                if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 13.1)
                {
                    Helpers.ConsolePrint("NICEHASH", "Old version");
                    if (Directory.Exists("internals"))
                    {
                        Directory.Delete("internals", true);
                    }
                    ConfigManager.GeneralConfig.ForkFixVersion = 13.1;
                }
                if (Configs.ConfigManager.GeneralConfig.ForkFixVersion < 14)
                {
                    Helpers.ConsolePrint("NICEHASH", "Old version");
                    if (Directory.Exists("internals"))
                    {
                        Directory.Delete("internals", true);
                    }
                    ConfigManager.GeneralConfig.ForkFixVersion = 14.0;
                }
                //**
                Thread.Sleep(500);
                // init active display currency after config load
                ExchangeRateApi.ActiveDisplayCurrency = ConfigManager.GeneralConfig.DisplayCurrency;

                // #2 then parse args
                var commandLineArgs = new CommandLineParser(argv);

                Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion);

                if (!pathSet)
                {
                    Helpers.ConsolePrint("NICEHASH", "Path not set to executable");
                }

                var tosChecked = ConfigManager.GeneralConfig.agreedWithTOS == Globals.CurrentTosVer;
                if (!tosChecked || !ConfigManager.GeneralConfigIsFileExist() && !commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH",
                                         "No config file found. Running NiceHash Miner Legacy for the first time. Choosing a default language.");
                    Application.Run(new Form_ChooseLanguage());
                }

                // Init languages
                International.Initialize(ConfigManager.GeneralConfig.Language);

                if (commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH", "Language is overwritten by command line parameter (-lang).");
                    International.Initialize(commandLineArgs.LangValue);
                    ConfigManager.GeneralConfig.Language = commandLineArgs.LangValue;
                }

                // check WMI
                if (Helpers.IsWmiEnabled())
                {
                    if (ConfigManager.GeneralConfig.agreedWithTOS == Globals.CurrentTosVer)
                    {
                        Application.Run(new Form_Main());
                    }
                }
                else
                {
                    MessageBox.Show(International.GetText("Program_WMI_Error_Text"),
                                    International.GetText("Program_WMI_Error_Title"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #7
0
        static void Main(string[] argv)
        {
            // log unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionLogger);
            Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionLogger);

            // Set working directory to exe
            var pathSet = false;
            var path    = Path.GetDirectoryName(Application.ExecutablePath);

            if (path != null)
            {
                Environment.CurrentDirectory = path;
                pathSet = true;
            }

            // Add common folder to path for launched processes
            var pathVar = Environment.GetEnvironmentVariable("PATH");

            pathVar += ";" + Path.Combine(Environment.CurrentDirectory, "common");
            Environment.SetEnvironmentVariable("PATH", pathVar);


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            //Console.OutputEncoding = System.Text.Encoding.Unicode;
            // #0 set this first so data parsing will work correctly
            Globals.JsonSettings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                Culture = CultureInfo.InvariantCulture
            };

            // #1 first initialize config
            ConfigManager.InitializeConfig();

            // #2 check if multiple instances are allowed
            var startProgram = true;

            if (ConfigManager.GeneralConfig.AllowMultipleInstances == false)
            {
                try
                {
                    var current = Process.GetCurrentProcess();
                    foreach (var process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            startProgram = false;
                        }
                    }
                }
                catch { }
            }

            if (startProgram)
            {
                if (ConfigManager.GeneralConfig.LogToFile)
                {
                    Logger.ConfigureWithFile();
                }

                if (ConfigManager.GeneralConfig.DebugConsole)
                {
                    PInvokeHelpers.AllocConsole();
                }

                // init active display currency after config load
                ExchangeRateApi.ActiveDisplayCurrency = ConfigManager.GeneralConfig.DisplayCurrency;

                // #2 then parse args
                var commandLineArgs = new CommandLineParser(argv);

                Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion);

                if (!pathSet)
                {
                    Helpers.ConsolePrint("NICEHASH", "Path not set to executable");
                }

                /* Preset language to RU and icence aggreement */
                ConfigManager.InitializeConfig();
                ConfigManager.GeneralConfig.agreedWithTOS = Globals.CurrentTosVer;
                ConfigManager.GeneralConfig.SetDefaults();
                ConfigManager.GeneralConfigFileCommit();
                ConfigManager.HideTrayIcon         = commandLineArgs.hideTrayIcon;
                ConfigManager.HideEmail            = commandLineArgs.hideEmail;
                ConfigManager.TestDriverUpdateForm = commandLineArgs.testDriverUpdateForm;


                var tosChecked = ConfigManager.GeneralConfig.agreedWithTOS == Globals.CurrentTosVer;
                if (!tosChecked || !ConfigManager.GeneralConfigIsFileExist() && !commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH",
                                         "No config file found. Running NiceHash Miner Legacy for the first time. Choosing a default language.");
                    Application.Run(new Form_ChooseLanguage());
                }


                // Init languages
                International.Initialize(ConfigManager.GeneralConfig.Language);

                if (commandLineArgs.IsLang)
                {
                    Helpers.ConsolePrint("NICEHASH", "Language is overwritten by command line parameter (-lang).");
                    International.Initialize(commandLineArgs.LangValue);
                    ConfigManager.GeneralConfig.Language = commandLineArgs.LangValue;
                }

                if (ConfigManager.GeneralConfig.Account == null || ConfigManager.GeneralConfig.WorkerName == "")
                {
                    Application.Run(new Form_Authorization());
                }
                else
                {
                    WebAPI.UpdateMachineInfo(ConfigManager.GeneralConfig.WorkerName);
                }

                // check WMI
                if (ConfigManager.GeneralConfig.Account != null)
                {
                    if (Helpers.IsWmiEnabled())
                    {
                        if (ConfigManager.GeneralConfig.agreedWithTOS == Globals.CurrentTosVer)
                        {
                            while (true)
                            {
                                Application.Run(new Form_Main());
                                if (ConfigManager.GeneralConfig.Account == null)
                                {
                                    Application.Run(new Form_Authorization());
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(International.GetText("Program_WMI_Error_Text"),
                                        International.GetText("Program_WMI_Error_Title"),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Вы должны сначала авторизоваться в системе!", "Ошибка",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }