[PATCH 3 of 3] shell32: implement SHPathPrepareForWrite

Dmitry Timoshkov dmitry at codeweavers.com
Sun Sep 2 09:44:35 CDT 2007


"Vincent Povirk" <madewokherd at gmail.com> wrote:

>  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);

It's better to not use fixed buffer sizes but allocate the buffer dynamically.

> +    /* 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;

If the job must be done only when SHPPFW_IGNOREFILENAME is specified then
don't do it in all cases. And using strrchrW would simplify the code a bit.

> +    /* 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);
> +    }

Why there is no check for SHCreateDirectoryExW return value?

> +
> +    /* 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;

0x10b == 267, therefore 0x8007010b is HRESULT_FROM_WIN32(ERROR_DIRECTORY)

> --- 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);

Please use above and in other places symbolic error names instead of hex,
and print expected and received codes to make life easier for those who looks
at the (failing) test results without looking at the source.
 
For some reason your mailer attaches the patch in text and html formats,
it would save some time/traffic by avoiding html in wine-patches.


-- 
Dmitry.



More information about the wine-devel mailing list