Ejemplo n.º 1
0
        private void LoadIniButton_OnClick(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = TranslationHelper.Instance.TranslatorInstance.GetTranslation(
                "ApplicationSettingsWindow",
                "IniFileFilter", "INI files (*.ini)|*.ini");
            openFileDialog.FileName = "clawPDF.ini";

            if (openFileDialog.ShowDialog() != true)
            {
                return;
            }

            var message = TranslationHelper.Instance.TranslatorInstance.GetTranslation("ApplicationSettingsWindow",
                                                                                       "LoadSettingsFromFileWarning",
                                                                                       "By loading the file all settings and profiles will be overwritten. Do you want to continue?");
            var caption = TranslationHelper.Instance.TranslatorInstance.GetTranslation("ApplicationSettingsWindow",
                                                                                       "OverwriteAllSettings",
                                                                                       "Overwrite all settings");

            if (MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.YesNo, MessageWindowIcon.Warning) !=
                MessageWindowResponse.Yes)
            {
                return;
            }

            var ini = new IniStorage(Encoding.UTF8);

            var settings = SettingsHelper.CreateEmptySettings();

            settings.LoadData(ini, openFileDialog.FileName, SettingsHelper.UpgradeSettings);

            if (!SettingsHelper.CheckValidSettings(settings))
            {
                message = TranslationHelper.Instance.TranslatorInstance.GetTranslation("ApplicationSettingsWindow",
                                                                                       "InvalidSettingsWarning",
                                                                                       "The file does not appear to contain valid clawPDF settings.");
                caption = TranslationHelper.Instance.TranslatorInstance.GetTranslation("ApplicationSettingsWindow",
                                                                                       "InvalidSettings",
                                                                                       "Invalid settings");

                MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.OK, MessageWindowIcon.Error);
                return;
            }

            SettingsHelper.ApplySettings(settings);

            if (UpdateSettings != null)
            {
                UpdateSettings(settings);
            }

            var viewModel = ViewModel;

            DataContext = null;
            viewModel.ApplicationSettings = settings.ApplicationSettings;
            DataContext = viewModel;
        }
Ejemplo n.º 2
0
 private void ProfileSettingsWindow_OnClosing(object sender, CancelEventArgs e)
 {
     if (ViewModel.ButtonClickedToClose == ButtonClickedToClose.None)
     {
         if (!ViewModel.CheckForClosingWindowAndRestoreTheSettings())
         {
             e.Cancel = true;
             return;
         }
     }
     SettingsHelper.ApplySettings(Settings);
     SettingsHelper.SaveSettings();
 }
Ejemplo n.º 3
0
 private void SaveAppSettings()
 {
     SettingsHelper.Settings.ApplicationSettings = ViewModel.ApplicationSettings.Copy();
     SettingsHelper.ApplySettings(SettingsHelper.Settings);
 }
Ejemplo n.º 4
0
    private static IEnumerator CheckSettingsOnEnable(MaterialDialog dialog, float duration)
    {
        var result   = "";
        var settings = new Settings();

        try
        {
            if (SettingsHelper.SettingsFileExist())
            {
                Debug.Log("settings file found");
                settings = SettingsHelper.LoadSettings();
                if (settings == null)
                {
                    yield break;
                }

                if (SettingsHelper.CheckSettings(settings))
                {
                    Debug.Log("settings applied");
                    SettingsHelper.ApplySettings(settings);

                    result = "Файл найден\nНастройки применены";

                    /*ToastManager.Show("Файл найден\nНастройки применены"
                     *  , 2.0f);*/
                }
                else
                {
                    Debug.Log("settings file invalid");
                    SettingsHelper.DeleteSettingsFile();
                    settings = SettingsHelper.GetCurrentSettings();
                    SettingsHelper.WriteSettingsToFile(settings);
                    Debug.Log("created new settings file");
                    result = "Файл не найден или поврежден\nНастройки сброшены";

                    /*ToastManager.Show("Файл не найден или поврежден\nНастройки сброшены"
                     *  , 2.0f);*/
                }
            }
            else
            {
                Debug.Log("settings file not found");
                settings = SettingsHelper.GetCurrentSettings();
                SettingsHelper.WriteSettingsToFile(settings);
                Debug.Log("created new settings file");
                Debug.Log(settings);
                result = "Файл не найден или поврежден\nНастройки сброшены";

                /*ToastManager.Show("Файл не найден или поврежден\nНастройки сброшены"
                 *  , 2.0f);*/
            }
        }
        catch (Exception exception)
        {
            Debug.Log(exception);
        }

        yield return(new WaitForSeconds(duration));

        SettingsData.Settings = settings;
        dialog.Hide();
        ToastManager.Show(result, 2.0f);
    }