Module: wine Branch: master Commit: c0be0032dec3e3fd8327bdf1534f79796e322946 URL: http://source.winehq.org/git/wine.git/?a=commit;h=c0be0032dec3e3fd8327bdf153...
Author: Eric Pouech eric.pouech@wanadoo.fr Date: Wed Feb 21 21:55:35 2007 +0100
dbghelp: Implemented EnumDirTreeW.
---
dlls/dbghelp/dbghelp.spec | 2 +- dlls/dbghelp/path.c | 84 ++++++++++++++++++++++++++++++++++++++++++-- include/dbghelp.h | 2 + 3 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/dlls/dbghelp/dbghelp.spec b/dlls/dbghelp/dbghelp.spec index 174341c..0b5a1e4 100644 --- a/dlls/dbghelp/dbghelp.spec +++ b/dlls/dbghelp/dbghelp.spec @@ -1,7 +1,7 @@ @ stub DbgHelpCreateUserDump @ stub DbgHelpCreateUserDumpW @ stdcall EnumDirTree(long str str ptr ptr ptr) -@ stub EnumDirTreeW +@ stdcall EnumDirTreeW(long wstr wstr ptr ptr ptr) @ stdcall EnumerateLoadedModules(long ptr ptr) @ stdcall EnumerateLoadedModules64(long ptr ptr) @ stdcall EnumerateLoadedModulesW64(long ptr ptr) diff --git a/dlls/dbghelp/path.c b/dlls/dbghelp/path.c index 5abb8c9..fb7300f 100644 --- a/dlls/dbghelp/path.c +++ b/dlls/dbghelp/path.c @@ -201,6 +201,43 @@ BOOL WINAPI SymMatchFileName(char* file, char* match, return mptr == match - 1; }
+static BOOL do_searchW(const WCHAR* file, WCHAR* buffer, BOOL recurse, + PENUMDIRTREE_CALLBACKW cb, void* user) +{ + HANDLE h; + WIN32_FIND_DATAW fd; + unsigned pos; + BOOL found = FALSE; + static const WCHAR S_AllW[] = {'*','.','*','\0'}; + static const WCHAR S_DotW[] = {'.','\0'}; + static const WCHAR S_DotDotW[] = {'.','\0'}; + + pos = strlenW(buffer); + if (buffer[pos - 1] != '\') buffer[pos++] = '\'; + strcpyW(buffer + pos, S_AllW); + if ((h = FindFirstFileW(buffer, &fd)) == INVALID_HANDLE_VALUE) + return FALSE; + /* doc doesn't specify how the tree is enumerated... + * doing a depth first based on, but may be wrong + */ + do + { + if (!strcmpW(fd.cFileName, S_DotW) || !strcmpW(fd.cFileName, S_DotDotW)) continue; + + strcpyW(buffer + pos, fd.cFileName); + if (recurse && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + found = do_searchW(file, buffer, TRUE, cb, user); + else if (SymMatchFileNameW(buffer, (WCHAR*)file, NULL, NULL)) + { + if (!cb || cb(buffer, user)) found = TRUE; + } + } while (!found && FindNextFileW(h, &fd)); + if (!found) buffer[--pos] = '\0'; + FindClose(h); + + return found; +} + static BOOL do_search(const char* file, char* buffer, BOOL recurse, PENUMDIRTREE_CALLBACK cb, void* user) { @@ -247,17 +284,56 @@ BOOL WINAPI SearchTreeForFile(PCSTR root, PCSTR file, PSTR buffer) }
/****************************************************************** + * EnumDirTreeW (DBGHELP.@) + * + * + */ +BOOL WINAPI EnumDirTreeW(HANDLE hProcess, PCWSTR root, PCWSTR file, + LPWSTR buffer, PENUMDIRTREE_CALLBACKW cb, PVOID user) +{ + TRACE("(%p %s %s %p %p %p)\n", + hProcess, debugstr_w(root), debugstr_w(file), buffer, cb, user); + + strcpyW(buffer, root); + return do_searchW(file, buffer, TRUE, cb, user); +} + +/****************************************************************** * EnumDirTree (DBGHELP.@) * * */ +struct enum_dir_treeWA +{ + PENUMDIRTREE_CALLBACK cb; + void* user; + char name[MAX_PATH]; +}; + +static BOOL CALLBACK enum_dir_treeWA(LPCWSTR name, PVOID user) +{ + struct enum_dir_treeWA* edt = user; + + WideCharToMultiByte(CP_ACP, 0, name, -1, edt->name, MAX_PATH, NULL, NULL); + return edt->cb(edt->name, edt->user); +} + BOOL WINAPI EnumDirTree(HANDLE hProcess, PCSTR root, PCSTR file, LPSTR buffer, PENUMDIRTREE_CALLBACK cb, PVOID user) { - TRACE("(%p %s %s %p %p %p)\n", hProcess, root, file, buffer, cb, user); - - strcpy(buffer, root); - return do_search(file, buffer, TRUE, cb, user); + WCHAR rootW[MAX_PATH]; + WCHAR fileW[MAX_PATH]; + WCHAR bufferW[MAX_PATH]; + struct enum_dir_treeWA edt; + BOOL ret; + + edt.cb = cb; + edt.user = user; + MultiByteToWideChar(CP_ACP, 0, root, -1, rootW, MAX_PATH); + MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, MAX_PATH); + if ((ret = EnumDirTreeW(hProcess, rootW, fileW, bufferW, enum_dir_treeWA, &edt))) + WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL); + return ret; }
struct sffip diff --git a/include/dbghelp.h b/include/dbghelp.h index ba293ed..53c3783 100644 --- a/include/dbghelp.h +++ b/include/dbghelp.h @@ -1022,6 +1022,8 @@ BOOL WINAPI MakeSureDirectoryPathExists(PCSTR); BOOL WINAPI SearchTreeForFile(PCSTR, PCSTR, PSTR); typedef BOOL (CALLBACK *PENUMDIRTREE_CALLBACK)(LPCSTR, PVOID); BOOL WINAPI EnumDirTree(HANDLE, PCSTR, PCSTR, PSTR, PENUMDIRTREE_CALLBACK, void*); +typedef BOOL (CALLBACK *PENUMDIRTREE_CALLBACKW)(LPCWSTR, PVOID); +BOOL WINAPI EnumDirTreeW(HANDLE, PCWSTR, PCWSTR, PWSTR, PENUMDIRTREE_CALLBACKW, void*); BOOL WINAPI SymMatchFileName(PSTR, PSTR, PSTR*, PSTR*); BOOL WINAPI SymMatchFileNameW(PWSTR, PWSTR, PWSTR*, PWSTR*); PCHAR WINAPI SymSetHomeDirectory(HANDLE, PCSTR);