Esempio n. 1
0
        private void EditConfig(string path = null)
        {
            ConfigFile file = new ConfigFile();

            if (path != null)
            {
                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    file.File = path;
                }
                else
                {
                    Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
                    {
                        Multiselect = false,
                        Filter      = l.ConfigFileDialogFilterDescription + "|*.config"
                    };

                    if (openFileDialog.ShowDialog() == true)
                    {
                        file.File = openFileDialog.FileName;
                    }
                    else
                    {
                        return;
                    }
                }
                if (file.File is null)
                {
                    return;
                }
                try
                {
                    file.LoadConfigFile();
                }
                catch (IOException)
                {
                    MessageBox.Show(l.OpenConfigEditorIOError, l.OpenConfigEditorErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                catch (Exception)
                {
                    MessageBox.Show(l.OpenConfigEditorFileError, l.OpenConfigEditorErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            ConfigEditor configWindow = new ConfigEditor();

            configWindow.Owner       = this;
            configWindow.DataContext = file;
            configWindow.ShowDialog();
        }
Esempio n. 2
0
        private void EditConfig(string path = null)
        {
            ConfigFile file = new ConfigFile();

            if (path != null)
            {
                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    file.File = path;
                }
                else
                {
                    Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
                    {
                        Multiselect = false,
                        Filter      = l.Resources.ConfigFileDialogFilterDescription + "|*.config"
                    };

                    if (openFileDialog.ShowDialog() == true)
                    {
                        file.File = openFileDialog.FileName;
                    }
                    else
                    {
                        return;
                    }
                }
                if (file.File is null)
                {
                    return;
                }
                file.LoadConfigFile();
            }

            ConfigEditor configWindow = new ConfigEditor();

            configWindow.Owner       = this;
            configWindow.DataContext = file;
            configWindow.ShowDialog();
        }