Commit 23e38d4d authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

scrrun: Add IFileSystem3::DeleteFile implementation.

parent c7abcd74
......@@ -1360,12 +1360,60 @@ static HRESULT WINAPI filesys_GetSpecialFolder(IFileSystem3 *iface,
return E_NOTIMPL;
}
static inline HRESULT delete_file(const WCHAR *file, DWORD file_len, VARIANT_BOOL force)
{
WCHAR path[MAX_PATH];
DWORD len, name_len;
WIN32_FIND_DATAW ffd;
HANDLE f;
f = FindFirstFileW(file, &ffd);
if(f == INVALID_HANDLE_VALUE)
return create_error(GetLastError());
len = get_parent_folder_name(file, file_len);
if(len+1 >= MAX_PATH)
return E_FAIL;
if(len) {
memcpy(path, file, len*sizeof(WCHAR));
path[len++] = '\\';
}
do {
if(ffd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE))
continue;
name_len = strlenW(ffd.cFileName);
if(len+name_len+1 >= MAX_PATH) {
FindClose(f);
return E_FAIL;
}
memcpy(path+len, ffd.cFileName, (name_len+1)*sizeof(WCHAR));
TRACE("deleting %s\n", debugstr_w(path));
if(!DeleteFileW(path)) {
if(!force || !SetFileAttributesW(path, FILE_ATTRIBUTE_NORMAL)
|| !DeleteFileW(path)) {
FindClose(f);
return create_error(GetLastError());
}
}
} while(FindNextFileW(f, &ffd));
FindClose(f);
return S_OK;
}
static HRESULT WINAPI filesys_DeleteFile(IFileSystem3 *iface, BSTR FileSpec,
VARIANT_BOOL Force)
{
FIXME("%p %s %d\n", iface, debugstr_w(FileSpec), Force);
TRACE("%p %s %d\n", iface, debugstr_w(FileSpec), Force);
return E_NOTIMPL;
if(!FileSpec)
return E_POINTER;
return delete_file(FileSpec, SysStringLen(FileSpec), Force);
}
static HRESULT WINAPI filesys_DeleteFolder(IFileSystem3 *iface, BSTR FolderSpec,
......
......@@ -491,7 +491,7 @@ static void test_GetFile(void)
ok(!file, "file != NULL\n");
ok(hr == CTL_E_FILENOTFOUND, "GetFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
hf = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
hf = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_READONLY, NULL);
if(hf == INVALID_HANDLE_VALUE) {
skip("Can't create temporary file\n");
SysFreeString(path);
......@@ -513,7 +513,16 @@ static void test_GetFile(void)
ok(V_I4(&size) == 0, "V_I4(&size) = %d, expected 0\n", V_I4(&size));
IFile_Release(file);
DeleteFileW(path);
hr = IFileSystem3_DeleteFile(fs3, path, FALSE);
ok(hr==CTL_E_PERMISSIONDENIED || broken(hr==S_OK),
"DeleteFile returned %x, expected CTL_E_PERMISSIONDENIED\n", hr);
if(hr != S_OK) {
hr = IFileSystem3_DeleteFile(fs3, path, TRUE);
ok(hr == S_OK, "DeleteFile returned %x, expected S_OK\n", hr);
}
hr = IFileSystem3_DeleteFile(fs3, path, TRUE);
ok(hr == CTL_E_FILENOTFOUND, "DeleteFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
SysFreeString(path);
}
......
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