Commit a9a2c9b5 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

scrrun: Fix Next() for file collection.

parent c633a517
...@@ -761,7 +761,7 @@ static ULONG WINAPI foldercoll_enumvariant_Release(IEnumVARIANT *iface) ...@@ -761,7 +761,7 @@ static ULONG WINAPI foldercoll_enumvariant_Release(IEnumVARIANT *iface)
return ref; 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}; static const WCHAR allW[] = {'*',0};
WCHAR pathW[MAX_PATH]; WCHAR pathW[MAX_PATH];
...@@ -776,10 +776,10 @@ static HANDLE start_enumeration(const WCHAR *path, WIN32_FIND_DATAW *data) ...@@ -776,10 +776,10 @@ static HANDLE start_enumeration(const WCHAR *path, WIN32_FIND_DATAW *data)
handle = FindFirstFileW(pathW, data); handle = FindFirstFileW(pathW, data);
if (handle == INVALID_HANDLE_VALUE) return 0; if (handle == INVALID_HANDLE_VALUE) return 0;
/* find first dir */ /* find first dir/file */
while (1) while (1)
{ {
if (is_dir_data(data)) if (file ? is_file_data(data) : is_dir_data(data))
break; break;
if (!FindNextFileW(handle, data)) if (!FindNextFileW(handle, data))
...@@ -807,7 +807,7 @@ static HRESULT WINAPI foldercoll_enumvariant_Next(IEnumVARIANT *iface, ULONG cel ...@@ -807,7 +807,7 @@ static HRESULT WINAPI foldercoll_enumvariant_Next(IEnumVARIANT *iface, ULONG cel
if (!handle) 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; if (!handle) return S_FALSE;
This->data.u.foldercoll.find = handle; This->data.u.foldercoll.find = handle;
...@@ -857,7 +857,7 @@ static HRESULT WINAPI foldercoll_enumvariant_Skip(IEnumVARIANT *iface, ULONG cel ...@@ -857,7 +857,7 @@ static HRESULT WINAPI foldercoll_enumvariant_Skip(IEnumVARIANT *iface, ULONG cel
if (!handle) 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; if (!handle) return S_FALSE;
This->data.u.foldercoll.find = handle; This->data.u.foldercoll.find = handle;
...@@ -957,43 +957,19 @@ static HRESULT WINAPI filecoll_enumvariant_Next(IEnumVARIANT *iface, ULONG celt, ...@@ -957,43 +957,19 @@ static HRESULT WINAPI filecoll_enumvariant_Next(IEnumVARIANT *iface, ULONG celt,
if (fetched) if (fetched)
*fetched = 0; *fetched = 0;
if (!handle) if (!celt) return S_OK;
{
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 (!handle)
{
if (is_file_data(&data))
break;
else
if (!FindNextFileW(handle, &data))
{ {
FindClose(handle); handle = start_enumeration(This->data.u.filecoll.coll->path, &data, TRUE);
return S_FALSE; if (!handle) return S_FALSE;
}
}
This->data.u.filecoll.find = handle; This->data.u.filecoll.find = handle;
} }
else if (celt) else if (!FindNextFileW(handle, &data))
FindNextFileW(handle, &data); return S_FALSE;
do do
{ {
if (count >= celt) break;
if (is_file_data(&data)) if (is_file_data(&data))
{ {
IFile *file; IFile *file;
...@@ -1007,17 +983,14 @@ static HRESULT WINAPI filecoll_enumvariant_Next(IEnumVARIANT *iface, ULONG celt, ...@@ -1007,17 +983,14 @@ static HRESULT WINAPI filecoll_enumvariant_Next(IEnumVARIANT *iface, ULONG celt,
V_VT(&var[count]) = VT_DISPATCH; V_VT(&var[count]) = VT_DISPATCH;
V_DISPATCH(&var[count]) = (IDispatch*)file; V_DISPATCH(&var[count]) = (IDispatch*)file;
count++; if (++count >= celt) break;
} }
} while (FindNextFileW(handle, &data)); } while (FindNextFileW(handle, &data));
if (count < celt)
return S_FALSE;
if (fetched) if (fetched)
*fetched = count; *fetched = count;
return S_OK; return (count < celt) ? S_FALSE : S_OK;
} }
static HRESULT WINAPI filecoll_enumvariant_Skip(IEnumVARIANT *iface, ULONG celt) static HRESULT WINAPI filecoll_enumvariant_Skip(IEnumVARIANT *iface, ULONG celt)
......
...@@ -1089,12 +1089,10 @@ todo_wine ...@@ -1089,12 +1089,10 @@ todo_wine
ok(0, "unexpected file %s was found\n", wine_dbgstr_w(str)); ok(0, "unexpected file %s was found\n", wine_dbgstr_w(str));
SysFreeString(str); SysFreeString(str);
/* FIXME: uncomment once Wine is fixed IFile_Release(file);
IFile_Release(file); */
VariantClear(&var); VariantClear(&var);
} }
todo_wine
ok(found_a == 1 && found_b == 1 && found_c == 1, ok(found_a == 1 && found_b == 1 && found_c == 1,
"each file should be found 1 time instead of %d/%d/%d\n", "each file should be found 1 time instead of %d/%d/%d\n",
found_a, found_b, found_c); found_a, found_b, found_c);
...@@ -1102,9 +1100,7 @@ todo_wine ...@@ -1102,9 +1100,7 @@ todo_wine
VariantInit(&var); VariantInit(&var);
fetched = -1; fetched = -1;
hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched); hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
todo_wine
ok(hr == S_FALSE, "got 0x%08x\n", hr); ok(hr == S_FALSE, "got 0x%08x\n", hr);
todo_wine
ok(fetched == 0, "got %d\n", fetched); ok(fetched == 0, "got %d\n", fetched);
hr = IEnumVARIANT_Reset(enumvar); hr = IEnumVARIANT_Reset(enumvar);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment