From: Francis De Brabandere <francisdb@gmail.com> Delegate to GetFileAttributesW and SetFileAttributesW, mirroring the existing IFile implementations of these methods. The returned value is masked to the same FileAttribute subset that IFile::get_Attributes exposes. --- dlls/scrrun/filesystem.c | 23 ++++++++++++--- dlls/scrrun/tests/filesystem.c | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index b523daaa1e2..75f52501b6c 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -2591,15 +2591,30 @@ static HRESULT WINAPI folder_get_ParentFolder(IFolder *iface, IFolder **parent) static HRESULT WINAPI folder_get_Attributes(IFolder *iface, FileAttribute *attr) { struct folder *This = impl_from_IFolder(iface); - FIXME("(%p)->(%p): stub\n", This, attr); - return E_NOTIMPL; + DWORD fa; + + TRACE("(%p)->(%p)\n", This, attr); + + if(!attr) + return E_POINTER; + + fa = GetFileAttributesW(This->path); + if(fa == INVALID_FILE_ATTRIBUTES) + return create_error(GetLastError()); + + *attr = fa & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | + FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE | + FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_COMPRESSED); + return S_OK; } static HRESULT WINAPI folder_put_Attributes(IFolder *iface, FileAttribute attr) { struct folder *This = impl_from_IFolder(iface); - FIXME("(%p)->(0x%x): stub\n", This, attr); - return E_NOTIMPL; + + TRACE("(%p)->(0x%x)\n", This, attr); + + return SetFileAttributesW(This->path, attr) ? S_OK : create_error(GetLastError()); } static HRESULT WINAPI folder_get_DateCreated(IFolder *iface, DATE *date) diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c index 7e9dab74987..14db34b8d02 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -1077,6 +1077,57 @@ static void test_GetFolder(void) SetCurrentDirectoryW(prev_path); } +static void test_Folder_Attributes(void) +{ + static const DWORD attr_mask = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | + FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE | + FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_COMPRESSED; + + WCHAR temp_path[MAX_PATH], dir_path[MAX_PATH]; + IFolder *folder; + FileAttribute fa; + DWORD gfa, new_gfa; + BSTR path; + HRESULT hr; + + GetTempPathW(MAX_PATH, temp_path); + lstrcpyW(dir_path, temp_path); + lstrcatW(dir_path, L"scrrun_attr_test"); + ok(CreateDirectoryW(dir_path, NULL), "CreateDirectory failed, error %ld\n", GetLastError()); + + path = SysAllocString(dir_path); + hr = IFileSystem3_GetFolder(fs3, path, &folder); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IFolder_get_Attributes(folder, NULL); + ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr); + + hr = IFolder_get_Attributes(folder, &fa); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + gfa = GetFileAttributesW(dir_path) & attr_mask; + ok(fa == gfa, "Unexpected flags %#x, expected %lx.\n", fa, gfa); + ok(fa & FILE_ATTRIBUTE_DIRECTORY, "directory bit not set, got %#x.\n", fa); + + /* FILE_ATTRIBUTE_READONLY is silently ignored on directories by Windows + * (it has a different meaning for folders), so exercise HIDDEN instead. */ + hr = IFolder_put_Attributes(folder, gfa | FILE_ATTRIBUTE_HIDDEN); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + new_gfa = GetFileAttributesW(dir_path) & attr_mask; + ok(new_gfa == (gfa | FILE_ATTRIBUTE_HIDDEN), "got %#lx, expected %lx\n", + new_gfa, gfa | FILE_ATTRIBUTE_HIDDEN); + + hr = IFolder_get_Attributes(folder, &fa); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(fa == new_gfa, "got %#x, expected %lx.\n", fa, new_gfa); + + hr = IFolder_put_Attributes(folder, gfa); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + IFolder_Release(folder); + SysFreeString(path); + RemoveDirectoryW(dir_path); +} + static void test_Folder_ParentFolder(void) { WCHAR windir[MAX_PATH]; @@ -3061,6 +3112,7 @@ START_TEST(filesystem) test_CopyFolder(); test_BuildPath(); test_GetFolder(); + test_Folder_Attributes(); test_Folder_ParentFolder(); test_FolderCollection(); test_FileCollection(); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10661