Nikolay Sivov : scrrun: Implement Count() property for folder collection.
Alexandre Julliard
julliard at winehq.org
Fri Jan 3 11:23:15 CST 2014
Module: wine
Branch: master
Commit: 51f5ab19990b453efdb5013e576984039b306b51
URL: http://source.winehq.org/git/wine.git/?a=commit;h=51f5ab19990b453efdb5013e576984039b306b51
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Fri Jan 3 16:34:44 2014 +0400
scrrun: Implement Count() property for folder collection.
---
dlls/scrrun/filesystem.c | 42 ++++++++++++++++++++++++++++++++++++---
dlls/scrrun/tests/filesystem.c | 30 ++++++++++++++++++++++++++-
2 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 949173a..c96ae6d 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -39,6 +39,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(scrrun);
struct foldercollection {
IFolderCollection IFolderCollection_iface;
LONG ref;
+ BSTR path;
};
struct folder {
@@ -383,7 +384,10 @@ static ULONG WINAPI foldercoll_Release(IFolderCollection *iface)
TRACE("(%p)->(%d)\n", This, ref);
if (!ref)
+ {
+ SysFreeString(This->path);
heap_free(This);
+ }
return ref;
}
@@ -471,8 +475,32 @@ static HRESULT WINAPI foldercoll_get__NewEnum(IFolderCollection *iface, IUnknown
static HRESULT WINAPI foldercoll_get_Count(IFolderCollection *iface, LONG *count)
{
struct foldercollection *This = impl_from_IFolderCollection(iface);
- FIXME("(%p)->(%p): stub\n", This, count);
- return E_NOTIMPL;
+ static const WCHAR allW[] = {'\\','*',0};
+ WIN32_FIND_DATAW data;
+ WCHAR pathW[MAX_PATH];
+ HANDLE handle;
+
+ TRACE("(%p)->(%p)\n", This, count);
+
+ if(!count)
+ return E_POINTER;
+
+ *count = 0;
+
+ strcpyW(pathW, This->path);
+ strcatW(pathW, allW);
+ handle = FindFirstFileW(pathW, &data);
+ if (handle == INVALID_HANDLE_VALUE)
+ return HRESULT_FROM_WIN32(GetLastError());
+
+ do
+ {
+ if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ *count += 1;
+ } while (FindNextFileW(handle, &data));
+ FindClose(handle);
+
+ return S_OK;
}
static const IFolderCollectionVtbl foldercollvtbl = {
@@ -489,7 +517,7 @@ static const IFolderCollectionVtbl foldercollvtbl = {
foldercoll_get_Count
};
-static HRESULT create_foldercoll(IFolderCollection **folders)
+static HRESULT create_foldercoll(BSTR path, IFolderCollection **folders)
{
struct foldercollection *This;
@@ -500,6 +528,12 @@ static HRESULT create_foldercoll(IFolderCollection **folders)
This->IFolderCollection_iface.lpVtbl = &foldercollvtbl;
This->ref = 1;
+ This->path = SysAllocString(path);
+ if (!This->path)
+ {
+ heap_free(This);
+ return E_OUTOFMEMORY;
+ }
*folders = &This->IFolderCollection_iface;
@@ -744,7 +778,7 @@ static HRESULT WINAPI folder_get_SubFolders(IFolder *iface, IFolderCollection **
if(!folders)
return E_POINTER;
- return create_foldercoll(folders);
+ return create_foldercoll(This->path, folders);
}
static HRESULT WINAPI folder_get_Files(IFolder *iface, IFileCollection **files)
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index b5d2e1f..23cbd2c 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -777,13 +777,17 @@ static void test_GetFolder(void)
static void test_FolderCollection(void)
{
+ static const WCHAR aW[] = {'\\','a',0};
+ static const WCHAR bW[] = {'\\','b',0};
IFolderCollection *folders;
- WCHAR buffW[MAX_PATH];
+ WCHAR buffW[MAX_PATH], pathW[MAX_PATH], path2W[MAX_PATH];
+ LONG count, count2;
IFolder *folder;
HRESULT hr;
BSTR str;
- GetWindowsDirectoryW(buffW, MAX_PATH);
+ GetTempPathW(MAX_PATH, buffW);
+
str = SysAllocString(buffW);
hr = IFileSystem3_GetFolder(fs3, str, &folder);
ok(hr == S_OK, "got 0x%08x\n", hr);
@@ -792,9 +796,31 @@ static void test_FolderCollection(void)
hr = IFolder_get_SubFolders(folder, NULL);
ok(hr == E_POINTER, "got 0x%08x\n", hr);
+ lstrcpyW(pathW, buffW);
+ lstrcatW(pathW, aW);
+ CreateDirectoryW(pathW, NULL);
+
hr = IFolder_get_SubFolders(folder, &folders);
ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 0;
+ hr = IFolderCollection_get_Count(folders, &count);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(count > 0, "got %d\n", count);
+
+ lstrcpyW(path2W, buffW);
+ lstrcatW(path2W, bW);
+ CreateDirectoryW(path2W, NULL);
+
+ /* every time property is requested it scans directory */
+ count2 = 0;
+ hr = IFolderCollection_get_Count(folders, &count2);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(count2 > count, "got %d, %d\n", count, count2);
+
+ RemoveDirectoryW(pathW);
+ RemoveDirectoryW(path2W);
+
IFolderCollection_Release(folders);
IFolder_Release(folder);
}
More information about the wine-cvs
mailing list