[1/3] taskschd: Make ITaskFolder::CreateFolder, ITaskFolder::GetFolder and ITaskFolder::DeleteFolder use the RPC API.
Dmitry Timoshkov
dmitry at baikal.ru
Sun Apr 6 23:14:19 CDT 2014
---
dlls/taskschd/folder.c | 97 +++++++++++++++++++++++++++++++----------
dlls/taskschd/tests/scheduler.c | 1 -
2 files changed, 75 insertions(+), 23 deletions(-)
diff --git a/dlls/taskschd/folder.c b/dlls/taskschd/folder.c
index 7caad77..6bb0c38 100644
--- a/dlls/taskschd/folder.c
+++ b/dlls/taskschd/folder.c
@@ -25,6 +25,7 @@
#include "winreg.h"
#include "objbase.h"
#include "taskschd.h"
+#include "schrpc.h"
#include "taskschd_private.h"
#include "wine/unicode.h"
@@ -273,9 +274,47 @@ static HRESULT WINAPI TaskFolder_CreateFolder(ITaskFolder *iface, BSTR path, VAR
return hr;
}
+static WCHAR *get_full_path(const WCHAR *parent, const WCHAR *path)
+{
+ static const WCHAR bslash[] = { '\\', 0 };
+ WCHAR *folder_path;
+ int len = 0;
+
+ if (path) len = strlenW(path);
+
+ if (parent) len += strlenW(parent);
+
+ /* +1 if parent is not '\' terminated */
+ folder_path = heap_alloc((len + 2) * sizeof(WCHAR));
+ if (!folder_path) return NULL;
+
+ folder_path[0] = 0;
+
+ if (parent)
+ strcpyW(folder_path, parent);
+
+ if (path && *path)
+ {
+ len = strlenW(folder_path);
+ if (!len || folder_path[len - 1] != '\\')
+ strcatW(folder_path, bslash);
+
+ while (*path == '\\') path++;
+ strcatW(folder_path, path);
+ }
+
+ len = strlenW(folder_path);
+ if (!len)
+ strcatW(folder_path, bslash);
+
+ return folder_path;
+}
+
static HRESULT WINAPI TaskFolder_DeleteFolder(ITaskFolder *iface, BSTR name, LONG flags)
{
TaskFolder *folder = impl_from_ITaskFolder(iface);
+ WCHAR *folder_path;
+ HRESULT hr;
TRACE("%p,%s,%x\n", iface, debugstr_w(name), flags);
@@ -284,6 +323,13 @@ static HRESULT WINAPI TaskFolder_DeleteFolder(ITaskFolder *iface, BSTR name, LON
if (flags)
FIXME("unsupported flags %x\n", flags);
+ folder_path = get_full_path(folder->path, name);
+ if (!folder_path) return E_OUTOFMEMORY;
+
+ hr = SchRpcDelete(folder_path, 0);
+ heap_free(folder_path);
+ if (hr != S_OK) return hr;
+
return reg_delete_folder(folder->path, name);
}
@@ -403,43 +449,50 @@ static const ITaskFolderVtbl TaskFolder_vtbl =
HRESULT TaskFolder_create(const WCHAR *parent, const WCHAR *path, ITaskFolder **obj, BOOL create)
{
- static const WCHAR bslash[] = { '\\', 0 };
TaskFolder *folder;
WCHAR *folder_path;
- int len = 0;
HRESULT hr;
HKEY hfolder;
if (path)
{
- len = strlenW(path);
+ int len = strlenW(path);
if (len && path[len - 1] == '\\') return ERROR_INVALID_NAME;
}
- if (parent) len += strlenW(parent);
-
- /* +1 if parent is not '\' terminated */
- folder_path = heap_alloc((len + 2) * sizeof(WCHAR));
+ folder_path = get_full_path(parent, path);
if (!folder_path) return E_OUTOFMEMORY;
- folder_path[0] = 0;
-
- if (parent)
- strcpyW(folder_path, parent);
-
- if (path && *path)
+ if (create)
{
- len = strlenW(folder_path);
- if (!len || folder_path[len - 1] != '\\')
- strcatW(folder_path, bslash);
-
- while (*path == '\\') path++;
- strcatW(folder_path, path);
+ hr = SchRpcCreateFolder(folder_path, NULL, 0);
+ }
+ else
+ {
+ DWORD start_index, count, i;
+ TASK_NAMES names;
+
+ start_index = 0;
+ names = NULL;
+ hr = SchRpcEnumFolders(folder_path, 0, &start_index, 0, &count, &names);
+ if (hr == S_OK)
+ {
+ for (i = 0; i < count; i++)
+ MIDL_user_free(names[i]);
+ MIDL_user_free(names);
+ }
+ else
+ {
+ if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
+ hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
+ }
}
- len = strlenW(folder_path);
- if (!len)
- strcatW(folder_path, bslash);
+ if (FAILED(hr))
+ {
+ heap_free(folder_path);
+ return hr;
+ }
hr = create ? reg_create_folder(folder_path, &hfolder) : reg_open_folder(folder_path, &hfolder);
if (hr)
diff --git a/dlls/taskschd/tests/scheduler.c b/dlls/taskschd/tests/scheduler.c
index 0f89021..7f0669b 100644
--- a/dlls/taskschd/tests/scheduler.c
+++ b/dlls/taskschd/tests/scheduler.c
@@ -341,7 +341,6 @@ todo_wine
ITaskFolder_Release(subfolder);
hr = ITaskFolder_DeleteFolder(folder, Wine, 0);
-todo_wine
ok(hr == HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY), "expected ERROR_DIR_NOT_EMPTY, got %#x\n", hr);
hr = ITaskFolder_DeleteFolder(folder, Wine_Folder1_Folder2, 0);
--
1.9.1
More information about the wine-patches
mailing list