scrrun: Implement Count() property for folder collection.
This commit is contained in:
parent
0802e301ff
commit
51f5ab1999
@ -39,6 +39,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(scrrun);
|
|||||||
struct foldercollection {
|
struct foldercollection {
|
||||||
IFolderCollection IFolderCollection_iface;
|
IFolderCollection IFolderCollection_iface;
|
||||||
LONG ref;
|
LONG ref;
|
||||||
|
BSTR path;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct folder {
|
struct folder {
|
||||||
@ -383,7 +384,10 @@ static ULONG WINAPI foldercoll_Release(IFolderCollection *iface)
|
|||||||
TRACE("(%p)->(%d)\n", This, ref);
|
TRACE("(%p)->(%d)\n", This, ref);
|
||||||
|
|
||||||
if (!ref)
|
if (!ref)
|
||||||
|
{
|
||||||
|
SysFreeString(This->path);
|
||||||
heap_free(This);
|
heap_free(This);
|
||||||
|
}
|
||||||
|
|
||||||
return ref;
|
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)
|
static HRESULT WINAPI foldercoll_get_Count(IFolderCollection *iface, LONG *count)
|
||||||
{
|
{
|
||||||
struct foldercollection *This = impl_from_IFolderCollection(iface);
|
struct foldercollection *This = impl_from_IFolderCollection(iface);
|
||||||
FIXME("(%p)->(%p): stub\n", This, count);
|
static const WCHAR allW[] = {'\\','*',0};
|
||||||
return E_NOTIMPL;
|
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 = {
|
static const IFolderCollectionVtbl foldercollvtbl = {
|
||||||
@ -489,7 +517,7 @@ static const IFolderCollectionVtbl foldercollvtbl = {
|
|||||||
foldercoll_get_Count
|
foldercoll_get_Count
|
||||||
};
|
};
|
||||||
|
|
||||||
static HRESULT create_foldercoll(IFolderCollection **folders)
|
static HRESULT create_foldercoll(BSTR path, IFolderCollection **folders)
|
||||||
{
|
{
|
||||||
struct foldercollection *This;
|
struct foldercollection *This;
|
||||||
|
|
||||||
@ -500,6 +528,12 @@ static HRESULT create_foldercoll(IFolderCollection **folders)
|
|||||||
|
|
||||||
This->IFolderCollection_iface.lpVtbl = &foldercollvtbl;
|
This->IFolderCollection_iface.lpVtbl = &foldercollvtbl;
|
||||||
This->ref = 1;
|
This->ref = 1;
|
||||||
|
This->path = SysAllocString(path);
|
||||||
|
if (!This->path)
|
||||||
|
{
|
||||||
|
heap_free(This);
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
*folders = &This->IFolderCollection_iface;
|
*folders = &This->IFolderCollection_iface;
|
||||||
|
|
||||||
@ -744,7 +778,7 @@ static HRESULT WINAPI folder_get_SubFolders(IFolder *iface, IFolderCollection **
|
|||||||
if(!folders)
|
if(!folders)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
return create_foldercoll(folders);
|
return create_foldercoll(This->path, folders);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI folder_get_Files(IFolder *iface, IFileCollection **files)
|
static HRESULT WINAPI folder_get_Files(IFolder *iface, IFileCollection **files)
|
||||||
|
@ -777,13 +777,17 @@ static void test_GetFolder(void)
|
|||||||
|
|
||||||
static void test_FolderCollection(void)
|
static void test_FolderCollection(void)
|
||||||
{
|
{
|
||||||
|
static const WCHAR aW[] = {'\\','a',0};
|
||||||
|
static const WCHAR bW[] = {'\\','b',0};
|
||||||
IFolderCollection *folders;
|
IFolderCollection *folders;
|
||||||
WCHAR buffW[MAX_PATH];
|
WCHAR buffW[MAX_PATH], pathW[MAX_PATH], path2W[MAX_PATH];
|
||||||
|
LONG count, count2;
|
||||||
IFolder *folder;
|
IFolder *folder;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
BSTR str;
|
BSTR str;
|
||||||
|
|
||||||
GetWindowsDirectoryW(buffW, MAX_PATH);
|
GetTempPathW(MAX_PATH, buffW);
|
||||||
|
|
||||||
str = SysAllocString(buffW);
|
str = SysAllocString(buffW);
|
||||||
hr = IFileSystem3_GetFolder(fs3, str, &folder);
|
hr = IFileSystem3_GetFolder(fs3, str, &folder);
|
||||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
@ -792,9 +796,31 @@ static void test_FolderCollection(void)
|
|||||||
hr = IFolder_get_SubFolders(folder, NULL);
|
hr = IFolder_get_SubFolders(folder, NULL);
|
||||||
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
lstrcpyW(pathW, buffW);
|
||||||
|
lstrcatW(pathW, aW);
|
||||||
|
CreateDirectoryW(pathW, NULL);
|
||||||
|
|
||||||
hr = IFolder_get_SubFolders(folder, &folders);
|
hr = IFolder_get_SubFolders(folder, &folders);
|
||||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
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);
|
IFolderCollection_Release(folders);
|
||||||
IFolder_Release(folder);
|
IFolder_Release(folder);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user