private async Task DeletePresetAsync()
        {
            if (this.dialogService.ShowConfirmation(
                    0xe11b,
                    16,
                    ResourceUtils.GetString("Language_Delete_Preset"),
                    ResourceUtils.GetString("Language_Delete_Preset_Confirmation").Replace("{preset}", this.SelectedPreset.Name),
                    ResourceUtils.GetString("Language_Yes"),
                    ResourceUtils.GetString("Language_No")))
            {
                try
                {
                    await Task.Run(() => {
                        string presetPath = System.IO.Path.Combine(WindowsPaths.AppData(), ProductInformation.ApplicationName, ApplicationPaths.EqualizerFolder, this.SelectedPreset.Name + FileFormats.DEQ);
                        System.IO.File.Delete(presetPath);
                    });

                    this.ApplyManualPreset();
                    this.InitializeAsync();
                }
                catch (Exception ex)
                {
                    LogClient.Error("An error occurred while deleting preset '{0}'. Exception: {1}", this.SelectedPreset.Name, ex.Message);

                    this.dialogService.ShowNotification(
                        0xe711,
                        16,
                        ResourceUtils.GetString("Language_Error"),
                        ResourceUtils.GetString("Language_Error_While_Deleting_Preset"),
                        ResourceUtils.GetString("Language_Ok"),
                        true,
                        ResourceUtils.GetString("Language_Log_File"));
                }
            }
        }
Beispiel #2
0
        private SettingsClient()
        {
            this.timer          = new System.Timers.Timer(100); // a 10th of a second
            this.timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);

            // Check in BaseSettings.xml if we're using the portable application
            this.baseSettingsDoc = XDocument.Load(this.baseSettingsFile);

            if (this.applicationFolder == null)
            {
                bool isPortable = false;

                // Set the path of Settings.xml
                if (this.TryGetBaseValue <bool>("Configuration", "IsPortable", ref isPortable))
                {
                    // Sets the application folder
                    if (isPortable)
                    {
                        this.applicationFolder = System.IO.Path.Combine(ProcessExecutable.ExecutionFolder(), ProcessExecutable.Name());
                    }
                    else
                    {
                        this.applicationFolder = System.IO.Path.Combine(WindowsPaths.AppData(), ProcessExecutable.Name());
                    }
                }
                else
                {
                    // By default, we save in the user's Roaming folder
                    this.applicationFolder = System.IO.Path.Combine(WindowsPaths.AppData(), ProcessExecutable.Name());
                }

                this.TryCreateApplicationFolder();
            }

            this.settingsFile = Path.Combine(this.applicationFolder, "Settings.xml");

            // Make sure there is a settings file.
            if (!File.Exists(this.settingsFile))
            {
                File.Copy(this.baseSettingsFile, this.settingsFile, true);
            }

            // Load the settings in memory
            this.LoadSettings();
        }
        private async Task SavePresetToFileAsync()
        {
            var showSaveDialog = true;

            var dlg = new Microsoft.Win32.SaveFileDialog();

            dlg.FileName         = string.Empty;
            dlg.DefaultExt       = FileFormats.DEQ;
            dlg.Filter           = string.Concat(ResourceUtils.GetString("Language_Equalizer_Presets"), " (", FileFormats.DEQ, ")|*", FileFormats.DEQ);
            dlg.InitialDirectory = System.IO.Path.Combine(WindowsPaths.AppData(), ProductInformation.ApplicationName, ApplicationPaths.EqualizerFolder);

            while (showSaveDialog)
            {
                if ((bool)dlg.ShowDialog())
                {
                    int existingCount = this.presets.Select((p) => p).Where((p) => p.Name.ToLower() == System.IO.Path.GetFileNameWithoutExtension(dlg.FileName).ToLower() & !p.IsRemovable).Count();

                    if (existingCount > 0)
                    {
                        dlg.FileName = string.Empty;

                        this.dialogService.ShowNotification(
                            0xe711,
                            16,
                            ResourceUtils.GetString("Language_Error"),
                            ResourceUtils.GetString("Language_Preset_Already_Taken"),
                            ResourceUtils.GetString("Language_Ok"),
                            false,
                            string.Empty);
                    }
                    else
                    {
                        showSaveDialog = false;

                        try
                        {
                            await Task.Run(() => {
                                System.IO.File.WriteAllLines(dlg.FileName, this.SelectedPreset.ToValueString().Split(';'));
                            });
                        }
                        catch (Exception ex)
                        {
                            LogClient.Error("An error occurred while saving preset to file '{0}'. Exception: {1}", dlg.FileName, ex.Message);

                            this.dialogService.ShowNotification(
                                0xe711,
                                16,
                                ResourceUtils.GetString("Language_Error"),
                                ResourceUtils.GetString("Language_Error_While_Saving_Preset"),
                                ResourceUtils.GetString("Language_Ok"),
                                true,
                                ResourceUtils.GetString("Language_Log_File"));
                        }
                        SettingsClient.Set <string>("Equalizer", "SelectedPreset", System.IO.Path.GetFileNameWithoutExtension(dlg.FileName));
                        this.InitializeAsync();
                    }
                }
                else
                {
                    showSaveDialog = false; // Makes sure the dialog doesn't re-appear when pressing cancel
                }
            }
        }