public static IEnumerable <WalletInstallInfo> GetInfo(RegistryKey regKeyBase, string regKeyStr)
        {
            using (Microsoft.Win32.RegistryKey key = regKeyBase.OpenSubKey(regKeyStr)) {
                if (key != null)
                {
                    foreach (string subkey_name in key.GetSubKeyNames().Where(k => !string.IsNullOrEmpty(k)))
                    {
                        using (RegistryKey subkey = key.OpenSubKey(subkey_name)) {
                            var dispName    = subkey.GetValue("DisplayName");
                            var dispVersion = subkey.GetValue("DisplayVersion");
                            var path        = subkey.GetValue("UninstallString");
                            if (dispName != null && dispName.ToString().ToUpper().StartsWith("EMERCOIN CORE"))
                            {
                                Version version = new Version(0, 0);
                                if (dispVersion != null)
                                {
                                    Version.TryParse(dispVersion.ToString(), out version);
                                }

                                var info = new WalletInstallInfo();
                                info.DisplayName = dispName.ToString();
                                info.Version     = version;
                                info.Folder      = path != null?Directory.GetParent(path.ToString()).FullName : string.Empty;

                                info.Bitness = dispName.ToString().ToUpper() == "Emercoin Core (64-bit)".ToUpper() ? BitnessEnum.x64 : BitnessEnum.x32;

                                yield return(info);
                            }
                        }
                    }
                }
            }
        }
        private bool walletClose(WalletInstallInfo walletInfo)
        {
            var  proc   = walletInfo.ActiveProcess();
            bool closed = false;

            // wallet is executing
            if (proc != null)
            {
                try
                {
                    closed = proc.CloseMainWindow();
                    closed = closed && proc.WaitForExit(15000);
                    if (!proc.HasExited)
                    {
                        proc.Kill();
                        proc.WaitForExit(15000);
                    }
                }
                catch {
                }
            }
            return(closed);
        }
        private async Task localModeLogic()
        {
            // get the best wallet instance among installed
            var walletApps = WalletInstallInfo.GetInfo();
            var walletApp  = walletApps.Count() > 0 ? walletApps.OrderBy(i => i.Version).ThenBy(i => i.Bitness).Last() : null;

            if (walletApp == null)
            {
                Process.Start("https://sourceforge.net/projects/emercoin/files/");
                throw new SettingsWizardException("No Emercoin Core applications installed on this computer");
            }

            var walletConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + "Emercoin" + "\\emercoin.conf";
            var confManager      = new EmercoinConfigManager(walletConfigPath);
            var conf             = confManager.ReadConfig();

            // check emercoin config if corresponds to publisher settings
            if (!conf.ValidateParameters(Settings.Instance.Port, Settings.Instance.Username, Settings.Instance.RpcPassword))
            {
                confManager.FixToActive(conf);
                confManager.WriteConfig(conf, walletConfigPath);

                Settings.Instance.Host        = "localhost";
                Settings.Instance.Port        = conf.GetParameterValue(EmercoinConfig.portParam) ?? string.Empty;
                Settings.Instance.Username    = conf.GetParameterValue(EmercoinConfig.userParam) ?? string.Empty;
                Settings.Instance.RpcPassword = conf.GetParameterValue(EmercoinConfig.rpcPasswordParam) ?? string.Empty;
                Settings.WriteSettings();
            }

            // restart wallet in order to apply new settings
            bool connectionOk = false;

            if (walletApp.IsExecuting())
            {
                // test connection
                var testWallet = new EmercoinWallet(Settings.Instance.Host, Settings.Instance.Port, Settings.Instance.Username, Settings.Instance.RpcPassword);

                try {
                    connectionOk = await testWallet.CheckConnection(Settings.Instance.RootDPOName);
                }
                catch (EmercoinWalletException ex) {
                }

                if (!connectionOk)
                {
                    this.walletClose(walletApp);

                    // wait and start wallet
                    Action <Task> startNewWallet = (t) =>
                    {
                        if (walletApp.IsExecuting())
                        {
                            throw new SettingsWizardException("Emercoin wallet wasn't able to close in time");
                        }
                        else
                        {
                            Process.Start(walletApp.FilePath);
                        }
                    };

                    await Task.Delay(15000).ContinueWith(startNewWallet);

                    await Task.Delay(15000);
                }
            }
            else
            {
                var proc = await Task.Run(() => Process.Start(walletApp.FilePath));

                await Task.Delay(15000);
            }

            // test wallet connection again
            var wallet = new EmercoinWallet(Settings.Instance.Host, Settings.Instance.Port, Settings.Instance.Username, Settings.Instance.RpcPassword);

            try {
                connectionOk = await wallet.CheckConnection(Settings.Instance.RootDPOName);

                this.StatusTextBlock.Text       = "Connected successfully";
                this.StatusTextBlock.Foreground = this.defaultColor;
            }
            catch (EmercoinWalletException ex) {
                throw new SettingsWizardException("Connection to the local wallet failed");
            }

            bool walletLocked = true;
            bool pwdChecked   = false;
            var  walletInfo   = await Task.Run(() => wallet.GetWalletInfo());

            walletLocked = (walletInfo != null && walletInfo.locked) || !string.IsNullOrEmpty(Settings.Instance.WalletPassphrase);
            if (walletLocked)
            {
                pwdChecked = await wallet.CheckWalletPassphrase(Settings.Instance.WalletPassphrase);

                if (!pwdChecked)
                {
                    throw new SettingsWizardException("Wallet passphrase check failed");
                }
            }

            this.closeDisabled = false;
            this.success       = connectionOk && (!walletLocked || pwdChecked);
        }