From ac0bcf4a90fbc0101427c93fa941eb41fec1763f Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Wed, 15 May 2024 07:42:43 +0900 Subject: [PATCH] [SHLWAPI][SHLWAPI_APITEST][SDK] PathFileExistsDefExtAndAttributesW (#6879) Implementing missing features... JIRA issue: CORE-19278 - Implement PathFileExistsDefExtAndAttributesW function. - Add its prototype to . - Modify shlwapi.spec. - Add PathFileExistsDefExtAndAttributesW testcase. --- dll/win32/shlwapi/shlwapi.spec | 2 +- dll/win32/shlwapi/utils.cpp | 38 ++++++++++++ .../rostests/apitests/shlwapi/CMakeLists.txt | 1 + .../PathFileExistsDefExtAndAttributesW.c | 61 +++++++++++++++++++ modules/rostests/apitests/shlwapi/testlist.c | 2 + sdk/include/reactos/shlwapi_undoc.h | 10 ++- 6 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 modules/rostests/apitests/shlwapi/PathFileExistsDefExtAndAttributesW.c diff --git a/dll/win32/shlwapi/shlwapi.spec b/dll/win32/shlwapi/shlwapi.spec index 53e67a7800e..821a2ed241c 100644 --- a/dll/win32/shlwapi/shlwapi.spec +++ b/dll/win32/shlwapi/shlwapi.spec @@ -508,7 +508,7 @@ 508 stdcall -noname SHPropertyBag_WriteDWORD(ptr wstr long) 509 stdcall -noname IUnknown_OnFocusChangeIS(ptr ptr long) 510 stdcall -noname SHLockSharedEx(ptr long long) -511 stdcall -stub -noname PathFileExistsDefExtAndAttributesW(wstr long ptr) +511 stdcall -noname PathFileExistsDefExtAndAttributesW(wstr long ptr) 512 stub -ordinal IStream_ReadPidl 513 stub -ordinal IStream_WritePidl 514 stdcall -noname IUnknown_ProfferService(ptr ptr ptr ptr) diff --git a/dll/win32/shlwapi/utils.cpp b/dll/win32/shlwapi/utils.cpp index a27bcd90f94..673d6d77f99 100644 --- a/dll/win32/shlwapi/utils.cpp +++ b/dll/win32/shlwapi/utils.cpp @@ -77,3 +77,41 @@ IContextMenu_Invoke( return ret; } + +/************************************************************************* + * PathFileExistsDefExtAndAttributesW [SHLWAPI.511] + * + * @param pszPath The path string. + * @param dwWhich The WHICH_... flags. + * @param pdwFileAttributes A pointer to the file attributes. Optional. + * @return TRUE if successful. + */ +BOOL WINAPI +PathFileExistsDefExtAndAttributesW( + _Inout_ LPWSTR pszPath, + _In_ DWORD dwWhich, + _Out_opt_ LPDWORD pdwFileAttributes) +{ + TRACE("(%s, 0x%lX, %p)\n", debugstr_w(pszPath), dwWhich, pdwFileAttributes); + + if (pdwFileAttributes) + *pdwFileAttributes = INVALID_FILE_ATTRIBUTES; + + if (!pszPath) + return FALSE; + + if (!dwWhich || (*PathFindExtensionW(pszPath) && (dwWhich & WHICH_OPTIONAL))) + return PathFileExistsAndAttributesW(pszPath, pdwFileAttributes); + + if (!PathFileExistsDefExtW(pszPath, dwWhich)) + { + if (pdwFileAttributes) + *pdwFileAttributes = INVALID_FILE_ATTRIBUTES; + return FALSE; + } + + if (pdwFileAttributes) + *pdwFileAttributes = GetFileAttributesW(pszPath); + + return TRUE; +} diff --git a/modules/rostests/apitests/shlwapi/CMakeLists.txt b/modules/rostests/apitests/shlwapi/CMakeLists.txt index 7a9a57e40aa..95271b056ae 100644 --- a/modules/rostests/apitests/shlwapi/CMakeLists.txt +++ b/modules/rostests/apitests/shlwapi/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories($) list(APPEND SOURCE AssocQueryString.c + PathFileExistsDefExtAndAttributesW.c PathFindOnPath.c PathIsUNC.c PathIsUNCServer.c diff --git a/modules/rostests/apitests/shlwapi/PathFileExistsDefExtAndAttributesW.c b/modules/rostests/apitests/shlwapi/PathFileExistsDefExtAndAttributesW.c new file mode 100644 index 00000000000..a1a74944d8b --- /dev/null +++ b/modules/rostests/apitests/shlwapi/PathFileExistsDefExtAndAttributesW.c @@ -0,0 +1,61 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: Tests for PathFileExistsDefExtAndAttributesW + * COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ + */ + +#include +#include +#include +#include + +START_TEST(PathFileExistsDefExtAndAttributesW) +{ + WCHAR szPath[MAX_PATH]; + DWORD attrs; + BOOL ret; + + /* NULL check */ + ret = PathFileExistsDefExtAndAttributesW(NULL, 0, NULL); + ok_int(ret, FALSE); + + /* Not existent file */ + lstrcpynW(szPath, L"Not Existent File.txt", _countof(szPath)); + ret = PathFileExistsDefExtAndAttributesW(szPath, 0, NULL); + ok_int(ret, FALSE); + + /* "Windows" directory */ + GetWindowsDirectoryW(szPath, _countof(szPath)); + ret = PathFileExistsDefExtAndAttributesW(szPath, 0, NULL); + ok_int(ret, TRUE); + + /* "Windows" directory with attributes check */ + attrs = 0; + ret = PathFileExistsDefExtAndAttributesW(szPath, 0, &attrs); + ok_int(ret, TRUE); + ok(attrs != 0 && attrs != INVALID_FILE_ATTRIBUTES, "attrs was 0x%lX\n", attrs); + + /* Find notepad.exe */ + SearchPathW(NULL, L"notepad.exe", NULL, _countof(szPath), szPath, NULL); + ret = PathFileExistsW(szPath); + ok_int(ret, TRUE); + + /* Remove .exe */ + PathRemoveExtensionW(szPath); + ret = PathFileExistsW(szPath); + ok_int(ret, FALSE); + + /* Add .exe */ + ret = PathFileExistsDefExtAndAttributesW(szPath, WHICH_EXE, NULL); + ok_int(ret, TRUE); + ret = PathFileExistsW(szPath); + ok_int(ret, TRUE); + + /* notepad.cmd doesn't exist */ + PathRemoveExtensionW(szPath); + ret = PathFileExistsDefExtAndAttributesW(szPath, WHICH_CMD, NULL); + ok_int(ret, FALSE); + ret = PathFileExistsW(szPath); + ok_int(ret, FALSE); +} diff --git a/modules/rostests/apitests/shlwapi/testlist.c b/modules/rostests/apitests/shlwapi/testlist.c index 9f94155cf15..9bb74d7ee34 100644 --- a/modules/rostests/apitests/shlwapi/testlist.c +++ b/modules/rostests/apitests/shlwapi/testlist.c @@ -2,6 +2,7 @@ #include extern void func_AssocQueryString(void); +extern void func_PathFileExistsDefExtAndAttributesW(void); extern void func_PathFindOnPath(void); extern void func_isuncpath(void); extern void func_isuncpathserver(void); @@ -19,6 +20,7 @@ extern void func_StrFormatByteSizeW(void); const struct test winetest_testlist[] = { { "AssocQueryString", func_AssocQueryString }, + { "PathFileExistsDefExtAndAttributesW", func_PathFileExistsDefExtAndAttributesW }, { "PathFindOnPath", func_PathFindOnPath }, { "PathIsUNC", func_isuncpath }, { "PathIsUNCServer", func_isuncpathserver }, diff --git a/sdk/include/reactos/shlwapi_undoc.h b/sdk/include/reactos/shlwapi_undoc.h index fd1ac3f3c82..cd2cc1882b8 100644 --- a/sdk/include/reactos/shlwapi_undoc.h +++ b/sdk/include/reactos/shlwapi_undoc.h @@ -283,7 +283,8 @@ ShellMessageBoxWrapW( _In_ UINT fuStyle, ...); -/* dwWhich flags for PathFileExistsDefExtW and PathFindOnPathExW */ +/* dwWhich flags for PathFileExistsDefExtW, PathFindOnPathExW, + * and PathFileExistsDefExtAndAttributesW */ #define WHICH_PIF (1 << 0) #define WHICH_COM (1 << 1) #define WHICH_EXE (1 << 2) @@ -309,6 +310,13 @@ ShellMessageBoxWrapW( #define PATH_CHAR_CLASS_ANY 0xffffffff BOOL WINAPI PathFileExistsDefExtW(LPWSTR lpszPath, DWORD dwWhich); + +BOOL WINAPI +PathFileExistsDefExtAndAttributesW( + _Inout_ LPWSTR pszPath, + _In_ DWORD dwWhich, + _Out_opt_ LPDWORD pdwFileAttributes); + BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs, DWORD dwWhich); VOID WINAPI FixSlashesAndColonW(LPWSTR); BOOL WINAPI PathIsValidCharA(char c, DWORD dwClass);