Nikolay Sivov : scrrun: Fix Next() for file collection.
Alexandre Julliard
julliard at winehq.org
Mon Mar 10 14:38:29 CDT 2014
Module: wine
Branch: master
Commit: a9a2c9b5391680ef55c01f8168b6ef7c9e78f8fa
URL: http://source.winehq.org/git/wine.git/?a=commit;h=a9a2c9b5391680ef55c01f8168b6ef7c9e78f8fa
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Mon Mar 10 13:23:14 2014 +0400
scrrun: Fix Next() for file collection.
---
dlls/scrrun/filesystem.c | 53 ++++++++++------------------------------
dlls/scrrun/tests/filesystem.c | 6 +----
2 files changed, 14 insertions(+), 45 deletions(-)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 70bc341..5b6d6cb 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -761,7 +761,7 @@ static ULONG WINAPI foldercoll_enumvariant_Release(IEnumVARIANT *iface)
return ref;
}
-static HANDLE start_enumeration(const WCHAR *path, WIN32_FIND_DATAW *data)
+static HANDLE start_enumeration(const WCHAR *path, WIN32_FIND_DATAW *data, BOOL file)
{
static const WCHAR allW[] = {'*',0};
WCHAR pathW[MAX_PATH];
@@ -776,10 +776,10 @@ static HANDLE start_enumeration(const WCHAR *path, WIN32_FIND_DATAW *data)
handle = FindFirstFileW(pathW, data);
if (handle == INVALID_HANDLE_VALUE) return 0;
- /* find first dir */
+ /* find first dir/file */
while (1)
{
- if (is_dir_data(data))
+ if (file ? is_file_data(data) : is_dir_data(data))
break;
if (!FindNextFileW(handle, data))
@@ -807,7 +807,7 @@ static HRESULT WINAPI foldercoll_enumvariant_Next(IEnumVARIANT *iface, ULONG cel
if (!handle)
{
- handle = start_enumeration(This->data.u.foldercoll.coll->path, &data);
+ handle = start_enumeration(This->data.u.foldercoll.coll->path, &data, FALSE);
if (!handle) return S_FALSE;
This->data.u.foldercoll.find = handle;
@@ -857,7 +857,7 @@ static HRESULT WINAPI foldercoll_enumvariant_Skip(IEnumVARIANT *iface, ULONG cel
if (!handle)
{
- handle = start_enumeration(This->data.u.foldercoll.coll->path, &data);
+ handle = start_enumeration(This->data.u.foldercoll.coll->path, &data, FALSE);
if (!handle) return S_FALSE;
This->data.u.foldercoll.find = handle;
@@ -957,43 +957,19 @@ static HRESULT WINAPI filecoll_enumvariant_Next(IEnumVARIANT *iface, ULONG celt,
if (fetched)
*fetched = 0;
+ if (!celt) return S_OK;
+
if (!handle)
{
- static const WCHAR allW[] = {'*',0};
- WCHAR pathW[MAX_PATH];
- BSTR parent = This->data.u.filecoll.coll->path;
- int len;
-
- strcpyW(pathW, parent);
- len = SysStringLen(parent);
- if (parent[len-1] != '\\')
- strcatW(pathW, bsW);
- strcatW(pathW, allW);
- handle = FindFirstFileW(pathW, &data);
- if (handle == INVALID_HANDLE_VALUE)
- return S_FALSE;
-
- while (1)
- {
- if (is_file_data(&data))
- break;
- else
- if (!FindNextFileW(handle, &data))
- {
- FindClose(handle);
- return S_FALSE;
- }
- }
-
+ handle = start_enumeration(This->data.u.filecoll.coll->path, &data, TRUE);
+ if (!handle) return S_FALSE;
This->data.u.filecoll.find = handle;
}
- else if (celt)
- FindNextFileW(handle, &data);
+ else if (!FindNextFileW(handle, &data))
+ return S_FALSE;
do
{
- if (count >= celt) break;
-
if (is_file_data(&data))
{
IFile *file;
@@ -1007,17 +983,14 @@ static HRESULT WINAPI filecoll_enumvariant_Next(IEnumVARIANT *iface, ULONG celt,
V_VT(&var[count]) = VT_DISPATCH;
V_DISPATCH(&var[count]) = (IDispatch*)file;
- count++;
+ if (++count >= celt) break;
}
} while (FindNextFileW(handle, &data));
- if (count < celt)
- return S_FALSE;
-
if (fetched)
*fetched = count;
- return S_OK;
+ return (count < celt) ? S_FALSE : S_OK;
}
static HRESULT WINAPI filecoll_enumvariant_Skip(IEnumVARIANT *iface, ULONG celt)
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index 2b7118f..0588509 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -1089,12 +1089,10 @@ todo_wine
ok(0, "unexpected file %s was found\n", wine_dbgstr_w(str));
SysFreeString(str);
- /* FIXME: uncomment once Wine is fixed
- IFile_Release(file); */
+ IFile_Release(file);
VariantClear(&var);
}
-todo_wine
ok(found_a == 1 && found_b == 1 && found_c == 1,
"each file should be found 1 time instead of %d/%d/%d\n",
found_a, found_b, found_c);
@@ -1102,9 +1100,7 @@ todo_wine
VariantInit(&var);
fetched = -1;
hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
-todo_wine
ok(hr == S_FALSE, "got 0x%08x\n", hr);
-todo_wine
ok(fetched == 0, "got %d\n", fetched);
hr = IEnumVARIANT_Reset(enumvar);
More information about the wine-cvs
mailing list