Revert to default folder in open-dialog if folder is deleted

Elias Norberg elno0959 at student.su.se
Fri Dec 12 11:38:53 CST 2008


---
 dlls/comdlg32/filedlg.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c
index e1eedd1..9307384 100644
--- a/dlls/comdlg32/filedlg.c
+++ b/dlls/comdlg32/filedlg.c
@@ -1092,6 +1092,7 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd)
   OSVERSIONINFOW osVi;
   static const WCHAR szwSlash[] = { '\\', 0 };
   static const WCHAR szwStar[] = { '*',0 };
+  static const WCHAR szwCRoot[] = { 'C', ':', '\\', 0 };
 
   static const TBBUTTON tbb[] =
   {
@@ -1357,6 +1358,30 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd)
           TRACE("No initial dir specified, using current dir of %s\n", debugstr_w(fodInfos->initdir));
       }
   }
+
+  /* Check that selected path does indeed exists, and if not, fallback to other directories */
+  if(!PathIsDirectoryW(fodInfos->initdir)) {
+        /* On Windows 98 or Windows 2000+, the default is to fallback to
+         *   My Documents if available
+         */
+      handledPath = FALSE;
+      if(win2000plus || win98plus) {
+          MemFree(fodInfos->initdir);
+          fodInfos->initdir = MemAlloc(MAX_PATH*sizeof(WCHAR));
+          if(COMDLG32_SHGetFolderPathW(hwnd, CSIDL_PERSONAL, 0, 0, fodInfos->initdir) == S_OK)
+             handledPath = TRUE;
+      }
+
+      /* If we're running as an older version, or if CSIDL_PERSONAL could not be found,
+       *  fallback to C:\ */
+      if( handledPath == FALSE ){
+	  MemFree(fodInfos->initdir);
+          fodInfos->initdir = MemAlloc((lstrlenW(szwCRoot) + 1)*sizeof(WCHAR));
+          lstrcpyW(fodInfos->initdir, szwCRoot);
+      }
+      TRACE("Specified initial dir is unavailable, falling back to %s\n",
+          debugstr_w(fodInfos->initdir));
+  }
   SetFocus(GetDlgItem(hwnd, IDC_FILENAME));
   TRACE("After manipulation, file = %s, dir = %s\n", debugstr_w(fodInfos->filename), debugstr_w(fodInfos->initdir));
 
-- 
1.5.6.3


--Kj7319i9nmIyA2yE--



More information about the wine-patches mailing list