Exemple #1
0
        private void DelayInputParseAndSave(object sender, EventArgs eventArgs)
        {
            TimeSpan newDelay;

            if (!TimeSpanParser.FromString(delayInput.Text, out newDelay))
            {
                MessageBox.Show(
                    Resources.Unable_To_Parse_Time_Message,
                    Resources.Unable_To_Parse_Time_Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                delayInput.Focus();
                return;
            }
            _startAfterDelay = newDelay;
            SaveSettings();
        }
Exemple #2
0
        public MainForm()
        {
            InitializeComponent();
            _trayGraphic = Graphics.FromImage(_trayBitmap);
            // Parse available devices from poclbm.exe
#if !DEBUG
            try
            {
#endif
            var poclbm = new Process()
            {
                StartInfo = new ProcessStartInfo("poclbm.exe")
                {
                    RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden
                }
            };
            var t = 0;
            poclbm.Start();
            var poclbmOutput = poclbm.StandardOutput;
            while (!poclbm.HasExited)
            {
                ++t;
                Thread.Sleep(1000);
                if (t <= 10)
                {
                    continue;
                }
                var result =
                    MessageBox.Show(
                        Resources.Poclbm_Is_Being_Slow_Message,
                        Resources.Poclbm_Is_Being_Slow_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    Application.Exit();
                }
            }
            string line;
            _openCLDevices = new Dictionary <int, string>();
            while (!poclbmOutput.EndOfStream)
            {
                line = poclbmOutput.ReadLine();
                Match m = Regex.Match(line, POCLBM_DEVICE_MATCH_PATTERN);
                if (m.Success)
                {
                    _openCLDevices.Add(int.Parse(m.Groups["id"].Value), m.Groups["device"].Value);
                    deviceSelection.Items.Add(m.Groups["device"].Value);
                }
            }
#if !DEBUG
        }

        catch (Exception e)
        {
            MessageBox.Show(
                String.Format(Resources.Poclbm_Device_Loading_Error_Message, e.Message),
                Resources.Poclbm_Error_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            Application.Exit();
        }
#endif
            // Load settings from the registry
            using (RegistryKey k = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\IdleMiner\"))
            {
                if (k == null)
                {
                    Registry.CurrentUser.CreateSubKey(@"SOFTWARE\IdleMiner\");
                    SaveSettings();
                }
                else
                {
#if !DEBUG
                    try
                    {
#endif
                    _startAfterDelay       = new TimeSpan((long)k.GetValue("Delay", 6000000000));
                    delayInput.Text        = TimeSpanParser.ToString(_startAfterDelay);
                    tabControl.SelectedTab = bool.Parse(k.GetValue("Advanced", false).ToString())
                                                     ? tabPageAdvanced
                                                     : tabPageBasic;
                    _dismissedBaloonTip        = bool.Parse(k.GetValue("AcknowledgedTray", false).ToString());
                    hideLaunchCheckbox.Checked = bool.Parse(k.GetValue("HideLaunch", true).ToString());
                    _selectedDevice            = (int)k.GetValue("Device", 0);
                    if (Uri.TryCreate(k.GetValue("PoolAddress", "").ToString(), UriKind.Absolute, out _poolAddress))
                    {
                        addressInput.Text = _poolAddress.ToString();
                    }
                    _username              = k.GetValue("Username", "").ToString();
                    usernameInput.Text     = _username;
                    vectorCheckbox.Checked = bool.Parse(k.GetValue("Vectors", true).ToString());
                    var encryptedPassword = k.GetValue("Password", "").ToString();
                    if (encryptedPassword != "")
                    {
                        _password          = new TripleDESStringEncryptor(_encryptionKey).DecryptString(encryptedPassword);
                        passwordInput.Text = _password;
                    }
                    var workSize = k.GetValue("WorkSize", 32).ToString();
                    workSizeComboBox.Text = workSize;
                    if (_openCLDevices.ContainsKey(_selectedDevice))
                    {
                        deviceSelection.Text = _openCLDevices[_selectedDevice];
                    }
#if !DEBUG
                }
                catch (Exception e)
                {
                    MessageBox.Show(String.Format(Properties.Resources.Settings_Loading_Error_Message, e.Message),
                                    Resources.Settings_Loading_Error_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // Load defaults
                    _startAfterDelay       = new TimeSpan(0, 10, 0);
                    tabControl.SelectedTab = tabPageBasic;
                    _selectedDevice        = 0;
                    SaveSettings();
                }
#endif
                }
            }
            // Map to save settings
            workSizeComboBox.SelectedValueChanged += (sender, args) => SaveSettings();
            vectorCheckbox.CheckStateChanged      += (sender, args) => SaveSettings();
            hideLaunchCheckbox.CheckedChanged     += (sender, args) => SaveSettings();
            usernameInput.TextChanged             += delegate
            {
                _username = usernameInput.Text;
                SaveSettings();
            };
            passwordInput.LostFocus += delegate
            {
                _password = passwordInput.Text;
                SaveSettings();
            };
            deviceSelection.TextChanged += DeviceSelectionProcessChange;
            addressInput.LostFocus      += AddressInputCheckAndSave;
            delayInput.LostFocus        += DelayInputParseAndSave;
            // Check to skip right to tray
        }