diff --git a/CHANGELIST.md b/CHANGELIST.md
index cb2879c7..cd869440 100644
--- a/CHANGELIST.md
+++ b/CHANGELIST.md
@@ -35,6 +35,7 @@
- Fill out internal tests around Redump library
- Refine the "missing disc" text
- Overhaul XeMID handling
+- Fix output dialog issues in Options window
### 2.1 (2021-07-22)
- Enum, no more
diff --git a/MPF/ViewModels/MainViewModel.cs b/MPF/ViewModels/MainViewModel.cs
index 49b9f75a..4ac7b16c 100644
--- a/MPF/ViewModels/MainViewModel.cs
+++ b/MPF/ViewModels/MainViewModel.cs
@@ -7,7 +7,6 @@ using System.Windows.Controls;
using System.Windows.Media;
using WinForms = System.Windows.Forms;
using BurnOutSharp;
-using MPF.Core.Converters;
using MPF.Core.Data;
using MPF.Core.Utilities;
using MPF.Library;
diff --git a/MPF/ViewModels/OptionsViewModel.cs b/MPF/ViewModels/OptionsViewModel.cs
index 9fb983ae..06e55e1b 100644
--- a/MPF/ViewModels/OptionsViewModel.cs
+++ b/MPF/ViewModels/OptionsViewModel.cs
@@ -114,7 +114,7 @@ namespace MPF.GUI.ViewModels
///
/// Browse and set a path based on the invoking button
///
- private void BrowseForPath(Button button)
+ private void BrowseForPath(System.Windows.Controls.Button button)
{
// If the button is null, we can't do anything
if (button == null)
@@ -126,23 +126,30 @@ namespace MPF.GUI.ViewModels
// TODO: hack for now, then we'll see
bool shouldBrowseForPath = pathSettingName == "DefaultOutputPath";
- CommonDialog dialog = shouldBrowseForPath ? (CommonDialog)CreateFolderBrowserDialog() : CreateOpenFileDialog();
+ string currentPath = TextBoxForPathSetting(pathSettingName)?.Text;
+ string initialDirectory = AppDomain.CurrentDomain.BaseDirectory;
+ if (!shouldBrowseForPath && !string.IsNullOrEmpty(currentPath))
+ initialDirectory = Path.GetDirectoryName(Path.GetFullPath(currentPath));
+
+ CommonDialog dialog = shouldBrowseForPath
+ ? (CommonDialog)CreateFolderBrowserDialog()
+ : CreateOpenFileDialog(initialDirectory);
using (dialog)
{
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
- string path;
- bool exists;
+ string path = string.Empty;
+ bool exists = false;
- if (shouldBrowseForPath)
+ if (shouldBrowseForPath && dialog is FolderBrowserDialog folderBrowserDialog)
{
- path = (dialog as FolderBrowserDialog).SelectedPath;
+ path = folderBrowserDialog.SelectedPath;
exists = Directory.Exists(path);
}
- else
+ else if (dialog is OpenFileDialog openFileDialog)
{
- path = (dialog as OpenFileDialog).FileName;
+ path = openFileDialog.FileName;
exists = File.Exists(path);
}
@@ -153,7 +160,7 @@ namespace MPF.GUI.ViewModels
else
{
CustomMessageBox.Show(
- "Specified path doesn't exists!",
+ "Specified path doesn't exist!",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error
@@ -204,11 +211,11 @@ namespace MPF.GUI.ViewModels
///
/// Create an open file dialog box
///
- private static OpenFileDialog CreateOpenFileDialog()
+ private static OpenFileDialog CreateOpenFileDialog(string initialDirectory)
{
return new OpenFileDialog()
{
- InitialDirectory = AppDomain.CurrentDomain.BaseDirectory,
+ InitialDirectory = initialDirectory,
Filter = "Executables (*.exe)|*.exe",
FilterIndex = 0,
RestoreDirectory = true,
@@ -220,7 +227,8 @@ namespace MPF.GUI.ViewModels
///
/// Setting name to find
/// TextBox for that setting
- private TextBox TextBoxForPathSetting(string name) => Parent.FindName(name + "TextBox") as TextBox;
+ private System.Windows.Controls.TextBox TextBoxForPathSetting(string name) =>
+ Parent.FindName(name + "TextBox") as System.Windows.Controls.TextBox;
#endregion
@@ -230,7 +238,7 @@ namespace MPF.GUI.ViewModels
/// Handler for generic Click event
///
private void BrowseForPathClick(object sender, EventArgs e) =>
- BrowseForPath(sender as Button);
+ BrowseForPath(sender as System.Windows.Controls.Button);
///
/// Handler for AcceptButton Click event