Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
            SentrySdk.Init("https://[email protected]/5380665");

            // backwards compatibility
            if (args.Contains("-validate"))
            {
                return;
            }

            if (!Utilities.IsAdministrator())
            {
                SentrySdk.AddBreadcrumb($"{nameof(Main)}: Application run with user privileges", nameof(Program));
                Utilities.Restart();
            }

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            if (DNSCryptHelper.IsInstalled() && DNSCryptHelper.IsRunning())
            {
                SentrySdk.AddBreadcrumb($"{nameof(Main)}: Add DNSCrypt to DNSServers list", nameof(Program));
                GlobalVars.DNSServers.Insert(0, DNSCryptHelper.GetDNSServer());
            }

            SentrySdk.AddBreadcrumb($"{nameof(Main)}: Application start", nameof(Program));
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
Exemplo n.º 2
0
        private void settingsLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SentrySdk.AddBreadcrumb($"{nameof(settingsLabel_LinkClicked)}", nameof(MainForm));

            var preIsInstalled = DNSCryptHelper.IsInstalled();
            var preIsRunning   = preIsInstalled && DNSCryptHelper.IsRunning();

            SentrySdk.AddBreadcrumb($"{nameof(settingsLabel_LinkClicked)}: {nameof(preIsInstalled)}={preIsInstalled}, {nameof(preIsRunning)}={preIsRunning}", nameof(MainForm));

            new SettingsForm().ShowDialog(this);

            // check installation
            var shouldRestart = preIsInstalled != DNSCryptHelper.IsInstalled();

            // check service
            if (!shouldRestart && preIsInstalled && preIsRunning != DNSCryptHelper.IsRunning())
            {
                shouldRestart = true;
            }

            SentrySdk.AddBreadcrumb($"{nameof(settingsLabel_LinkClicked)}: {nameof(shouldRestart)}={shouldRestart}", nameof(MainForm));

            if (shouldRestart)
            {
                Utilities.Restart();
            }
        }
Exemplo n.º 3
0
        private async void installButton_Click(object sender, System.EventArgs e)
        {
            SentrySdk.AddBreadcrumb($"{nameof(installButton_Click)}", nameof(SettingsForm));
            installButton.Enabled = false;

            if (DNSCryptHelper.IsInstalled())
            {
                SentrySdk.AddBreadcrumb($"{nameof(installButton_Click)}: Uninstall", nameof(SettingsForm));
                DNSCryptHelper.Uninstall(progressBar, statusLabel);
            }
            else
            {
                SentrySdk.AddBreadcrumb($"{nameof(installButton_Click)}: Install", nameof(SettingsForm));
                await DNSCryptHelper.Install(progressBar, statusLabel);
            }

            UpdateControls();
        }
Exemplo n.º 4
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;
                    }
                }
            }
        }