[PATCH 3 of 3] shell32: implement SHPathPrepareForWrite
Vincent Povirk
madewokherd at gmail.com
Sun Sep 2 02:10:26 CDT 2007
fixes bug 9523
---
dlls/shell32/shell32_main.c | 57 +++++++++++++++++++++++++++++++++++---
dlls/shell32/tests/shpathprep.c | 20 +++++++-------
2 files changed, 62 insertions(+), 15 deletions(-)
diff --git a/dlls/shell32/shell32_main.c b/dlls/shell32/shell32_main.c
index 84e2c16..a81aeaf 100644
--- a/dlls/shell32/shell32_main.c
+++ b/dlls/shell32/shell32_main.c
@@ -1244,15 +1244,62 @@ HRESULT WINAPI DllCanUnloadNow(void)
*/
HRESULT WINAPI SHPathPrepareForWriteA(HWND hwnd, IUnknown *modless, LPCSTR path, DWORD flags)
{
- FIXME("%p %p %s 0x%08x\n", hwnd, modless, debugstr_a(path), flags);
- return S_OK;
+ WCHAR wpath[MAX_PATH];
+ MultiByteToWideChar( CP_ACP, 0, path, -1, wpath, MAX_PATH);
+ return SHPathPrepareForWriteW(hwnd, modless, wpath, flags);
}
/***********************************************************************
- * SHPathPrepareForWriteA (SHELL32.@)
+ * SHPathPrepareForWriteW (SHELL32.@)
*/
HRESULT WINAPI SHPathPrepareForWriteW(HWND hwnd, IUnknown *modless, LPCWSTR path, DWORD flags)
{
- FIXME("%p %p %s 0x%08x\n", hwnd, modless, debugstr_w(path), flags);
- return S_OK;
+ HRESULT res;
+ DWORD err;
+ WCHAR realpath[MAX_PATH];
+ int i;
+ int last_slash=0;
+
+ TRACE("%p %p %s 0x%80x\n", hwnd, modless, debugstr_w(path), flags);
+
+ if (flags & ~(SHPPFW_DIRCREATE|SHPPFW_ASKDIRCREATE|SHPPFW_IGNOREFILENAME))
+ FIXME("unimplemented flags 0x%08x\n", flags);
+
+ /* make a copy of the path so we can cut off the filename */
+ for (i=0; i<MAX_PATH; i++)
+ {
+ realpath[i] = path[i];
+ if (path[i] == '\\')
+ last_slash = i;
+ else if (path[i] == 0)
+ break;
+ }
+ realpath[MAX_PATH-1] = 0;
+
+ if (flags & SHPPFW_IGNOREFILENAME)
+ realpath[last_slash] = 0;
+
+ /* try to create the directory if asked to */
+ if (flags & (SHPPFW_DIRCREATE|SHPPFW_ASKDIRCREATE))
+ {
+ if (flags & SHPPFW_ASKDIRCREATE)
+ FIXME("treating SHPPFW_ASKDIRCREATE as SHPPFW_DIRCREATE\n");
+
+ SHCreateDirectoryExW(0, realpath, NULL);
+ }
+
+ /* check if we can access the directory */
+ res = GetFileAttributesW(realpath);
+
+ if (res == INVALID_FILE_ATTRIBUTES)
+ {
+ err = GetLastError();
+ if (err == ERROR_FILE_NOT_FOUND)
+ err = ERROR_PATH_NOT_FOUND;
+ return HRESULT_FROM_WIN32(err);
+ }
+ else if (res & FILE_ATTRIBUTE_DIRECTORY)
+ return S_OK;
+ else
+ return 0x8007010b;
}
diff --git a/dlls/shell32/tests/shpathprep.c b/dlls/shell32/tests/shpathprep.c
index 4e018b0..77202a5 100644
--- a/dlls/shell32/tests/shpathprep.c
+++ b/dlls/shell32/tests/shpathprep.c
@@ -82,27 +82,27 @@ START_TEST(shpathprep)
ok(res == S_OK, "res == 0x%08x\n", res);
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent", SHPPFW_NONE);
- todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+ ok(res == 0x80070003, "res == 0x%08x\n", res);
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\test1.txt", SHPPFW_NONE);
- todo_wine ok(res == 0x8007010b, "res == 0x%08x\n", res);
+ ok(res == 0x8007010b, "res == 0x%08x\n", res);
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\test1.txt", SHPPFW_DIRCREATE);
- todo_wine ok(res == 0x8007010b, "res == 0x%08x\n", res);
+ ok(res == 0x8007010b, "res == 0x%08x\n", res);
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\test1.txt\\", SHPPFW_NONE);
- todo_wine ok(res == 0x8007010b, "res == 0x%08x\n", res);
+ ok(res == 0x8007010b, "res == 0x%08x\n", res);
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent", SHPPFW_IGNOREFILENAME);
ok(res == S_OK, "res == 0x%08x\n", res);
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent\\", SHPPFW_IGNOREFILENAME);
- todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+ ok(res == 0x80070003, "res == 0x%08x\n", res);
ex = Exists("c:\\testdir\\nonexistent\\");
ok(!ex, "c:\\testdir\\nonexistent\\ exists but shouldn't\n");
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent\\somefile", SHPPFW_IGNOREFILENAME);
- todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+ ok(res == 0x80070003, "res == 0x%08x\n", res);
ex = Exists("c:\\testdir\\nonexistent\\");
ok(!ex, "c:\\testdir\\nonexistent\\ exists but shouldn't\n");
@@ -119,26 +119,26 @@ START_TEST(shpathprep)
ok(res == S_OK, "res == 0x%08x\n", res);
res = SHPathPrepareForWriteA(0, 0, ".\\testdir\\nonexistent", SHPPFW_DIRCREATE);
- todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+ ok(res == 0x80070003, "res == 0x%08x\n", res);
ex = Exists(".\\testdir\\nonexistent\\");
ok(!ex, ".\\testdir\\nonexistent\\ exists but shouldn't\n");
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\createdir", SHPPFW_DIRCREATE);
ok(res == S_OK, "res == 0x%08x\n", res);
ex = Exists("c:\\testdir\\createdir\\");
- todo_wine ok(ex, "c:\\testdir\\createdir\\ doesn't exist but should\n");
+ ok(ex, "c:\\testdir\\createdir\\ doesn't exist but should\n");
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\createdir\\subdir\\somefile", SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
ok(res == S_OK, "res == 0x%08x\n", res);
ex = Exists("c:\\testdir\\createdir\\subdir");
- todo_wine ok(ex, "c:\\testdir\\createdir\\subdir doesn't exist but should\n");
+ ok(ex, "c:\\testdir\\createdir\\subdir doesn't exist but should\n");
ex = Exists("c:\\testdir\\createdir\\subdir\\somefile");
ok(!ex, "c:\\testdir\\createdir\\subdir\\somefile exists but shouldn't\n");
res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\createdir2\\subdir\\", SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
ok(res == S_OK, "res == 0x%08x\n", res);
ex = Exists("c:\\testdir\\createdir2\\subdir");
- todo_wine ok(ex, "c:\\testdir\\createdir2\\subdir doesn't exist but should\n");
+ ok(ex, "c:\\testdir\\createdir2\\subdir doesn't exist but should\n");
/* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
--
1.5.2.5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winehq.org/pipermail/wine-patches/attachments/20070902/3c1472f6/attachment.htm
More information about the wine-patches
mailing list