From d51a35c565ca4e39faa4eb2999d7c54878a43405 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 23 Jul 2013 18:50:46 +0200 Subject: [PATCH] scrrun: Add IFileSystem3::GetParentFolderName implementation. --- dlls/scrrun/filesystem.c | 45 +++++++++++++++++++++++++++++-- dlls/scrrun/tests/filesystem.c | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index 4f0b1636c1a..6af81235633 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -728,12 +728,53 @@ static HRESULT WINAPI filesys_GetDriveName(IFileSystem3 *iface, BSTR Path, return E_NOTIMPL; } +static inline DWORD get_parent_folder_name(const WCHAR *path, DWORD len) +{ + int i; + + if(!path) + return 0; + + for(i=len-1; i>=0; i--) + if(path[i]!='/' && path[i]!='\\') + break; + + for(; i>=0; i--) + if(path[i]=='/' || path[i]=='\\') + break; + + for(; i>=0; i--) + if(path[i]!='/' && path[i]!='\\') + break; + + if(i < 0) + return 0; + + if(path[i]==':' && i==1) + i++; + return i+1; +} + static HRESULT WINAPI filesys_GetParentFolderName(IFileSystem3 *iface, BSTR Path, BSTR *pbstrResult) { - FIXME("%p %s %p\n", iface, debugstr_w(Path), pbstrResult); + DWORD len; - return E_NOTIMPL; + TRACE("%p %s %p\n", iface, debugstr_w(Path), pbstrResult); + + if(!pbstrResult) + return E_POINTER; + + len = get_parent_folder_name(Path, SysStringLen(Path)); + if(!len) { + *pbstrResult = NULL; + return S_OK; + } + + *pbstrResult = SysAllocStringLen(Path, len); + if(!*pbstrResult) + return E_OUTOFMEMORY; + return S_OK; } static HRESULT WINAPI filesys_GetFileName(IFileSystem3 *iface, BSTR Path, diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c index b93927c04ad..3f0f95966c6 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -254,6 +254,54 @@ static void test_GetFileVersion(void) SysFreeString(path); } +static void test_GetParentFolderName(void) +{ + static const WCHAR path1[] = {'a',0}; + static const WCHAR path2[] = {'a','/','a','/','a',0}; + static const WCHAR path3[] = {'a','\\','a','\\','a',0}; + static const WCHAR path4[] = {'a','/','a','/','/','\\','\\',0}; + static const WCHAR path5[] = {'c',':','\\','\\','a',0}; + static const WCHAR path6[] = {'a','c',':','\\','a',0}; + static const WCHAR result2[] = {'a','/','a',0}; + static const WCHAR result3[] = {'a','\\','a',0}; + static const WCHAR result4[] = {'a',0}; + static const WCHAR result5[] = {'c',':','\\',0}; + static const WCHAR result6[] = {'a','c',':',0}; + + static const struct { + const WCHAR *path; + const WCHAR *result; + } tests[] = { + {NULL, NULL}, + {path1, NULL}, + {path2, result2}, + {path3, result3}, + {path4, result4}, + {path5, result5}, + {path6, result6} + }; + + BSTR path, result; + HRESULT hr; + int i; + + hr = IFileSystem3_GetParentFolderName(fs3, NULL, NULL); + ok(hr == E_POINTER, "GetParentFolderName returned %x, expected E_POINTER\n", hr); + + for(i=0; i