private void SaveSettings()
        {
            if (!App.SaveSettingsOnClose)
            {
                return;
            }

            var hookBefore      = Properties.Settings.Default.Hook;
            var blockTypeBefore = Properties.Settings.Default.BlockType;

            Properties.Settings.Default.UnmuteOnClose    = unmuteOnCloseCheckBox.IsChecked ?? Properties.Settings.Default.UnmuteOnClose;
            Properties.Settings.Default.MinimizeToTray   = minimizeToTrayRadioButton.IsChecked ?? Properties.Settings.Default.MinimizeToTray;
            Properties.Settings.Default.CheckForUpdates  = checkForUpdatesCheckBox.IsChecked ?? Properties.Settings.Default.CheckForUpdates;
            Properties.Settings.Default.DebugMode        = debugModeCheckBox.IsChecked ?? Properties.Settings.Default.DebugMode;
            Properties.Settings.Default.AggressiveMuting = aggressiveMutingCheckBox.IsChecked ?? Properties.Settings.Default.AggressiveMuting;
            Properties.Settings.Default.StartMinimized   = startMinimizedCheckBox.IsChecked ?? Properties.Settings.Default.StartMinimized;
            Properties.Settings.Default.StartOnLogin     = startOnLoginCheckBox.IsChecked ?? Properties.Settings.Default.StartOnLogin;
            Properties.Settings.Default.StartWithSpotify = startWithSpotifyCheckBox.IsChecked ?? Properties.Settings.Default.StartWithSpotify;
            Properties.Settings.Default.Hook             = mediaControlHookButton.IsChecked == true ? (string)mediaControlHookButton.Tag : (string)processAndWindowHookButton.Tag;
            Properties.Settings.Default.BlockType        = skipBlockTypeButton.IsChecked == true ? (string)skipBlockTypeButton.Tag : (string)muteBlockTypeButton.Tag;

            Autostart.SetEnabled(Properties.Settings.Default.StartOnLogin);
            if (StartWithSpotify.Available)
            {
                StartWithSpotify.SetEnabled(Properties.Settings.Default.StartWithSpotify);
            }

            Properties.Settings.Default.Save();

            if (hookBefore != Properties.Settings.Default.Hook || blockTypeBefore != Properties.Settings.Default.BlockType)
            {
                MessageBox.Show("You need to restart EZBlocker 3 for the changes to take effect.", "Restart required", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Example #2
0
        public static void Run(bool deleteSettings = false)
        {
            Autostart.Disable();
            StartWithSpotify.Disable();

            if (deleteSettings)
            {
                App.SaveSettingsOnClose = false;
                DeleteSettings();
            }

            Process.Start(new ProcessStartInfo()
            {
                FileName       = "cmd.exe",
                Arguments      = "/C choice /C Y /N /D Y /T 5 & DEL " + App.Location,
                WindowStyle    = ProcessWindowStyle.Hidden,
                CreateNoWindow = true,
            });

            Application.Current?.Dispatcher.Invoke(() => Application.Current.Shutdown());

            void DeleteSettings()
            {
                var appExecutableName = Path.GetFileName(App.Location);
                var appDataPath       = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                var containerPath     = Path.Combine(appDataPath, App.CompanyName);
                var containerDiretory = new DirectoryInfo(containerPath);

                var settingsDirectories = containerDiretory.GetDirectories()
                                          .Where(directory => directory.Name.StartsWith(appExecutableName));

                foreach (var settingsDir in settingsDirectories)
                {
                    settingsDir.RecursiveDelete();
                }

                if (!containerDiretory.EnumerateDirectories().Any() && !containerDiretory.EnumerateFiles().Any())
                {
                    containerDiretory.Delete();
                }
            }
        }
        private void SaveSettings()
        {
            if (!App.SaveSettingsOnClose)
            {
                return;
            }

            Properties.Settings.Default.UnmuteOnClose    = unmuteOnCloseCheckBox.IsChecked ?? Properties.Settings.Default.UnmuteOnClose;
            Properties.Settings.Default.MinimizeToTray   = minimizeToTrayRadioButton.IsChecked ?? Properties.Settings.Default.MinimizeToTray;
            Properties.Settings.Default.CheckForUpdates  = checkForUpdatesCheckBox.IsChecked ?? Properties.Settings.Default.CheckForUpdates;
            Properties.Settings.Default.DebugMode        = debugModeCheckBox.IsChecked ?? Properties.Settings.Default.DebugMode;
            Properties.Settings.Default.StartMinimized   = startMinimizedCheckBox.IsChecked ?? Properties.Settings.Default.StartMinimized;
            Properties.Settings.Default.StartOnLogin     = startOnLoginCheckBox.IsChecked ?? Properties.Settings.Default.StartOnLogin;
            Properties.Settings.Default.StartWithSpotify = startWithSpotifyCheckBox.IsChecked ?? Properties.Settings.Default.StartWithSpotify;

            Autostart.SetEnabled(Properties.Settings.Default.StartOnLogin);
            StartWithSpotify.SetEnabled(Properties.Settings.Default.StartWithSpotify);

            Properties.Settings.Default.Save();
        }