Browse Source

Environment.CurrentDirectory is modified after call to GetOpenFileName | GetSaveFileName call.

José Manuel Nieto Sánchez 9 years ago
parent
commit
934cc3bafd
1 changed files with 7 additions and 0 deletions
  1. 7 0
      src/Windows/Avalonia.Win32/SystemDialogImpl.cs

+ 7 - 0
src/Windows/Avalonia.Win32/SystemDialogImpl.cs

@@ -88,9 +88,16 @@ namespace Avalonia.Win32
 
 
                     var pofn = &ofn;
                     var pofn = &ofn;
 
 
+                    // We should save the current directory to restore it later.
+                    var currentDirectory = Environment.CurrentDirectory;
+
                     var res = dialog is OpenFileDialog
                     var res = dialog is OpenFileDialog
                         ? UnmanagedMethods.GetOpenFileName(new IntPtr(pofn))
                         ? UnmanagedMethods.GetOpenFileName(new IntPtr(pofn))
                         : UnmanagedMethods.GetSaveFileName(new IntPtr(pofn));
                         : UnmanagedMethods.GetSaveFileName(new IntPtr(pofn));
+
+                    // Restore the old current directory, since GetOpenFileName and GetSaveFileName change it after they're called
+                    Environment.CurrentDirectory = currentDirectory;
+
                     if (!res)
                     if (!res)
                         return null;
                         return null;
                     if (dialog?.Filters.Count > 0)
                     if (dialog?.Filters.Count > 0)