From be4aff376b710e67795e965f7b2ff97245f0fbb5 Mon Sep 17 00:00:00 2001 From: Rein Klazes Date: Mon, 12 Jan 2004 22:12:58 +0000 Subject: [PATCH] Handle the cases when initdir is either invalid, or specifies a file. --- dlls/commdlg/filedlg.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/dlls/commdlg/filedlg.c b/dlls/commdlg/filedlg.c index f039e885ab9..7cfd524ac47 100644 --- a/dlls/commdlg/filedlg.c +++ b/dlls/commdlg/filedlg.c @@ -1159,19 +1159,31 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) DWORD result; strcpyW(tmpBuf, fodInfos->initdir); - if (tmpBuf[strlenW(tmpBuf)-1] != '\\') { - strcatW(tmpBuf, szwSlash); + if( PathFileExistsW(tmpBuf) ) { + /* initdir does not have to be a directory. If a file is + * specified, the dir part is taken */ + if( PathIsDirectoryW(tmpBuf)) { + if (tmpBuf[strlenW(tmpBuf)-1] != '\\') { + strcatW(tmpBuf, szwSlash); + } + strcatW(tmpBuf, szwStar); + } + result = GetFullPathNameW(tmpBuf, MAX_PATH, tmpBuf2, &nameBit); + if (result) { + *nameBit = 0x00; + if (fodInfos->initdir) + MemFree(fodInfos->initdir); + fodInfos->initdir = MemAlloc((strlenW(tmpBuf2) + 1)*sizeof(WCHAR)); + strcpyW(fodInfos->initdir, tmpBuf2); + handledPath = TRUE; + TRACE("Value in InitDir changed to %s\n", debugstr_w(fodInfos->initdir)); + } } - strcatW(tmpBuf, szwStar); - result = GetFullPathNameW(tmpBuf, MAX_PATH, tmpBuf2, &nameBit); - if (result) { - *nameBit = 0x00; - if (fodInfos->initdir) - MemFree(fodInfos->initdir); - fodInfos->initdir = MemAlloc((strlenW(tmpBuf2) + 1)*sizeof(WCHAR)); - strcpyW(fodInfos->initdir, tmpBuf2); - handledPath = TRUE; - TRACE("Value in InitDir changed to %s\n", debugstr_w(fodInfos->initdir)); + else if (fodInfos->initdir) + { + MemFree(fodInfos->initdir); + fodInfos->initdir = NULL; + TRACE("Value in InitDir is not an existing path, changed to (nil)\n"); } } } -- 2.11.4.GIT