[PATCH 7/8] scrrun: Move into source dir into destination dir if destination ends with separator in MoveFolder().
Robert Wilhelm
wine at gitlab.winehq.org
Wed Jun 29 10:47:08 CDT 2022
From: Robert Wilhelm <robert.wilhelm at gmx.net>
Signed-off-by: Robert Wilhelm <robert.wilhelm at gmx.net>
---
dlls/scrrun/filesystem.c | 14 ++++++++++++++
dlls/scrrun/tests/filesystem.c | 19 +++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 197fe9f3625..908ac53683b 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -3785,16 +3785,30 @@ static HRESULT WINAPI filesys_MoveFile(IFileSystem3 *iface, BSTR source, BSTR de
static HRESULT WINAPI filesys_MoveFolder(IFileSystem3 *iface, BSTR source, BSTR destination)
{
DWORD attrs;
+ int len,start,end;
+ WCHAR dst_path[MAX_PATH];
TRACE("%p %s %s\n", iface, debugstr_w(source), debugstr_w(destination));
if(!source || !destination)
return E_INVALIDARG;
+ if (FAILED(get_file_name( source, &start, &end)))
+ return E_INVALIDARG;
+
attrs = GetFileAttributesW(source);
if((attrs == INVALID_FILE_ATTRIBUTES) || !(attrs & FILE_ATTRIBUTE_DIRECTORY))
return CTL_E_PATHNOTFOUND;
+ len = lstrlenW(destination);
+
+ if (destination[len-1] == '\\')
+ {
+ memcpy(dst_path, destination, (len+1)*sizeof(WCHAR));
+ memcpy(dst_path+len, source + start, (end-start+1)*sizeof(WCHAR));
+ dst_path[len+end-start+1] = 0;
+ return MoveFileW(source, dst_path) ? S_OK : create_error(GetLastError());
+ }
return MoveFileW(source, destination) ? S_OK : create_error(GetLastError());
}
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index 4d144937840..da092f27d3b 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -2536,6 +2536,7 @@ static void test_MoveFile(void)
{
ITextStream *stream;
BSTR str, src, dst;
+ WCHAR buffW1[MAX_PATH],buffW2[MAX_PATH],pathW[MAX_PATH];
HRESULT hr;
str = SysAllocString(L"test.txt");
@@ -2598,6 +2599,24 @@ static void test_MoveFile(void)
hr = IFileSystem3_MoveFile(fs3, NULL, str);
ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
SysFreeString(str);
+
+ GetTempPathW(MAX_PATH, buffW1);
+ lstrcatW(buffW1,L"foo");
+ GetTempPathW(MAX_PATH, buffW2);
+ lstrcatW(buffW2,L"bar");
+ ok(CreateDirectoryW(buffW1, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW1));
+ ok(CreateDirectoryW(buffW2, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW2));
+ lstrcpyW(pathW,buffW2);
+ lstrcatW(pathW,L"\\");
+ src = SysAllocString(buffW1);
+ dst = SysAllocString(pathW);
+ hr = IFileSystem3_MoveFolder(fs3, src, dst);
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+ SysFreeString(src);
+ SysFreeString(dst);
+ 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));
}
static void test_MoveFolder(void)
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/343
More information about the wine-devel
mailing list