Example #1
0
        private void saveConfigButton_Click(object sender, System.EventArgs e)
        {
            SentrySdk.AddBreadcrumb($"{nameof(saveConfigButton_Click)}", nameof(SettingsForm));

            var config = DNSCryptHelper.LoadConfig();

            foreach (var pair in _controls)
            {
                var setting = (ComboBoxItem)pair.Value.SelectedItem;
                config = pair.Key.SetSetting(config, (string)setting.Value);
            }

            DNSCryptHelper.SaveConfig(config);

            Utilities.ButtonSuccessAnimation(sender);
        }
Example #2
0
        public void UpdateControls()
        {
            SentrySdk.AddBreadcrumb($"{nameof(UpdateControls)}", nameof(SettingsForm));

            installButton.Text    = "Download and install";
            installButton.Enabled = true;

            serviceButton.Text    = "Start service";
            serviceButton.Enabled = true;

            configButton.Enabled = true;
            debugButton.Enabled  = true;

            foreach (var pair in _controls)
            {
                pair.Value.Enabled = true;
            }

            configRecommendedButton.Enabled = true;
            configPrivacyButton.Enabled     = true;
            saveConfigButton.Enabled        = true;
            loadConfigButton.Enabled        = true;

            if (!DNSCryptHelper.IsInstalled())
            {
                // not installed
                SentrySdk.AddBreadcrumb($"{nameof(UpdateControls)}: Not installed", nameof(SettingsForm));

                serviceButton.Enabled = false;
                configButton.Enabled  = false;
                debugButton.Enabled   = false;

                foreach (var pair in _controls)
                {
                    pair.Value.Enabled = false;
                }

                configRecommendedButton.Enabled = false;
                configPrivacyButton.Enabled     = false;
                saveConfigButton.Enabled        = false;
                loadConfigButton.Enabled        = false;
            }
            else
            {
                // installed
                SentrySdk.AddBreadcrumb($"{nameof(UpdateControls)}: Installed", nameof(SettingsForm));

                installButton.Text = "Uninstall";

                if (DNSCryptHelper.IsRunning())
                {
                    // running
                    SentrySdk.AddBreadcrumb($"{nameof(UpdateControls)}: Running", nameof(SettingsForm));

                    installButton.Enabled = false;
                    serviceButton.Text    = "Stop service";
                    configButton.Enabled  = false;
                    debugButton.Enabled   = false;

                    foreach (var pair in _controls)
                    {
                        pair.Value.Enabled = false;
                    }

                    configRecommendedButton.Enabled = false;
                    configPrivacyButton.Enabled     = false;
                    saveConfigButton.Enabled        = false;
                    loadConfigButton.Enabled        = false;
                }
                else
                {
                    // not running
                    SentrySdk.AddBreadcrumb($"{nameof(UpdateControls)}: Not running", nameof(SettingsForm));
                }

                // load controls
                var config = DNSCryptHelper.LoadConfig();

                foreach (var pair in _controls)
                {
                    var currentSetting = pair.Key.GetCurrentSetting(config);
                    var settings       = pair.Key.GetSettings(config);

                    pair.Value.Items.Clear();

                    var selectedItem = (object)null;

                    foreach (var item in settings)
                    {
                        pair.Value.Items.Add(item);

                        if ((string)item.Value == currentSetting)
                        {
                            selectedItem = item;
                        }
                    }

                    if (selectedItem != null)
                    {
                        pair.Value.SelectedItem = selectedItem;
                    }
                    else
                    {
                        pair.Value.SelectedIndex = 0;
                    }
                }
            }
        }