[PATCH 7/7] scrrun: Support wildcards in MoveFolder().
Robert Wilhelm
wine at gitlab.winehq.org
Wed Jul 6 06:08:10 CDT 2022
From: Robert Wilhelm <robert.wilhelm at gmx.net>
Signed-off-by: Robert Wilhelm <robert.wilhelm at gmx.net>
---
dlls/scrrun/Makefile.in | 2 +-
dlls/scrrun/filesystem.c | 49 ++++++++++++++++++++++++----------
dlls/scrrun/tests/filesystem.c | 33 ++++++++++++++++++++++-
3 files changed, 68 insertions(+), 16 deletions(-)
diff --git a/dlls/scrrun/Makefile.in b/dlls/scrrun/Makefile.in
index 12be899162b..21798694587 100644
--- a/dlls/scrrun/Makefile.in
+++ b/dlls/scrrun/Makefile.in
@@ -1,6 +1,6 @@
MODULE = scrrun.dll
IMPORTLIB = scrrun
-IMPORTS = uuid oleaut32 version advapi32
+IMPORTS = uuid oleaut32 version advapi32 shlwapi
EXTRADLLFLAGS = -Wb,--prefer-native
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 785e1e233cf..3fc7fcc0e81 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -29,6 +29,7 @@
#include "olectl.h"
#include "dispex.h"
#include "ntsecapi.h"
+#include "shlwapi.h"
#include "scrrun.h"
#include "scrrun_private.h"
@@ -3768,32 +3769,52 @@ static HRESULT WINAPI filesys_MoveFolder(IFileSystem3 *iface, BSTR source, BSTR
{
DWORD attrs;
int len;
- WCHAR src_drive[MAX_PATH],src_dir[MAX_PATH],dst_path[MAX_PATH],
+ WCHAR src_path[MAX_PATH],src_drive[MAX_PATH],src_dir[MAX_PATH],dst_path[MAX_PATH],
file_name[MAX_PATH],file_ext[MAX_PATH];
+ WIN32_FIND_DATAW ffd;
+ HANDLE f;
+ BOOL wildcard = FALSE;
TRACE("%p %s %s\n", iface, debugstr_w(source), debugstr_w(destination));
if(!source || !destination)
return E_INVALIDARG;
- attrs = GetFileAttributesW(source);
- if((attrs == INVALID_FILE_ATTRIBUTES) || !(attrs & FILE_ATTRIBUTE_DIRECTORY))
- return CTL_E_PATHNOTFOUND;
+ _wsplitpath(source, src_drive, src_dir, file_name, file_ext);
+ if (wcschr(file_name,'*') || wcschr(file_name,'?') ||wcschr(file_ext,'*') || wcschr(file_ext,'?'))
+ wildcard = TRUE;
+
+ if (!wildcard) {
+ attrs = GetFileAttributesW(source);
+ if((attrs == INVALID_FILE_ATTRIBUTES) || !(attrs & FILE_ATTRIBUTE_DIRECTORY))
+ return CTL_E_PATHNOTFOUND;
+ }
_wsplitpath(source, src_drive, src_dir, file_name, file_ext);
len = lstrlenW(destination);
- if (destination[len-1] == '\\') {
- lstrcpyW(dst_path, destination);
- lstrcatW(dst_path, file_name);
- if (*file_ext) {
- lstrcatW(dst_path, L".");
- lstrcatW(dst_path, file_ext);
- }
- TRACE(" %s %s\n", debugstr_w(source), debugstr_w(dst_path));
- return MoveFileW(source, dst_path) ? S_OK : create_error(GetLastError());
+ if (wildcard || destination[len-1] == '\\')
+ {
+ f = FindFirstFileW(source, &ffd);
+ if(f == INVALID_HANDLE_VALUE)
+ return create_error(GetLastError());
+
+ do {
+ lstrcpyW(dst_path, destination);
+ lstrcpyW(src_path, src_drive);
+ lstrcatW(src_path, src_dir);
+ if (!PathAppendW(src_path, ffd.cFileName)) return create_error(GetLastError());
+ if (!PathAppendW(dst_path, ffd.cFileName)) return create_error(GetLastError());
+ if (!MoveFileW(src_path, dst_path))
+ return create_error(GetLastError());
+ } while(FindNextFileW(f, &ffd));
+ FindClose(f);
}
- return MoveFileW(source, destination) ? S_OK : create_error(GetLastError());
+ else
+ {
+ return MoveFileW(source, destination) ? S_OK : create_error(GetLastError());
+ }
+ return S_OK;
}
static inline HRESULT copy_file(const WCHAR *source, DWORD source_len,
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index be7f090daec..5a2ad229b49 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -2603,7 +2603,7 @@ static void test_MoveFile(void)
static void test_MoveFolder(void)
{
BSTR src, dst, str;
- WCHAR buffW1[MAX_PATH],buffW2[MAX_PATH],pathW[MAX_PATH];
+ WCHAR buffW1[MAX_PATH],buffW2[MAX_PATH],pathW[MAX_PATH],srcW[MAX_PATH];
HRESULT hr;
File *file;
@@ -2674,6 +2674,37 @@ static void test_MoveFolder(void)
lstrcatW(pathW,L"foo");
ok(RemoveDirectoryW(pathW), "can't remove %s directory\n", wine_dbgstr_w(pathW));
ok(RemoveDirectoryW(buffW2), "can't remove %s directory\n", wine_dbgstr_w(buffW2));
+
+ GetTempPathW(MAX_PATH, buffW1);
+ lstrcatW(buffW1,L"foo1");
+ GetTempPathW(MAX_PATH, buffW2);
+ lstrcatW(buffW2,L"foo2");
+ GetTempPathW(MAX_PATH, srcW);
+ lstrcatW(srcW,L"foo?");
+ GetTempPathW(MAX_PATH, pathW);
+ lstrcatW(pathW,L"bar");
+ RemoveDirectoryW(buffW1);
+ RemoveDirectoryW(buffW2);
+ RemoveDirectoryW(pathW);
+ ok(CreateDirectoryW(buffW1, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW1));
+ ok(CreateDirectoryW(buffW2, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW2));
+ ok(CreateDirectoryW(pathW, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(pathW));
+ src = SysAllocString(srcW);
+ dst = SysAllocString(pathW);
+ hr = IFileSystem3_MoveFolder(fs3, src, dst);
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+ SysFreeString(src);
+ SysFreeString(dst);
+ lstrcpyW(buffW1,pathW);
+ lstrcatW(buffW1,L"\\");
+ lstrcatW(buffW1,L"foo1");
+ lstrcpyW(buffW2,pathW);
+ lstrcatW(buffW2,L"\\");
+ lstrcatW(buffW2,L"foo2");
+ ok(RemoveDirectoryW(buffW1), "can't remove %s directory\n", wine_dbgstr_w(buffW1));
+ ok(RemoveDirectoryW(buffW2), "can't remove %s directory\n", wine_dbgstr_w(buffW2));
+ ok(RemoveDirectoryW(pathW), "can't remove %s directory\n", wine_dbgstr_w(pathW));
+
}
static void test_DoOpenPipeStream(void)
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/391
More information about the wine-devel
mailing list