Commit b4539f71 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

mstask: Reimplement ITask constructor using ITaskFolder methods.

parent 9fd03094
......@@ -23,6 +23,7 @@
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "taskschd.h"
#include "mstask.h"
#include "mstask_private.h"
#include "wine/debug.h"
......
......@@ -24,6 +24,7 @@
#include "winbase.h"
#include "objbase.h"
#include "rpcproxy.h"
#include "taskschd.h"
#include "mstask.h"
#include "mstask_private.h"
#include "wine/debug.h"
......
......@@ -26,6 +26,6 @@ extern ClassFactoryImpl MSTASK_ClassFactory DECLSPEC_HIDDEN;
extern HRESULT TaskTriggerConstructor(LPVOID *ppObj) DECLSPEC_HIDDEN;
extern HRESULT TaskSchedulerConstructor(LPVOID *ppObj) DECLSPEC_HIDDEN;
extern HRESULT TaskConstructor(LPCWSTR pwszTaskName, LPVOID *ppObj) DECLSPEC_HIDDEN;
extern HRESULT TaskConstructor(ITaskFolder *folder, const WCHAR *task_name, ITask **task, BOOL create) DECLSPEC_HIDDEN;
#endif /* __MSTASK_PRIVATE_H__ */
/*
* Copyright (C) 2008 Google (Roy Shea)
* Copyright (C) 2018 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -23,6 +24,7 @@
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "taskschd.h"
#include "mstask.h"
#include "mstask_private.h"
#include "wine/debug.h"
......@@ -34,7 +36,7 @@ typedef struct
ITask ITask_iface;
IPersistFile IPersistFile_iface;
LONG ref;
LPWSTR taskName;
IRegisteredTask *regtask;
LPWSTR applicationName;
LPWSTR parameters;
LPWSTR comment;
......@@ -58,7 +60,6 @@ static void TaskDestructor(TaskImpl *This)
HeapFree(GetProcessHeap(), 0, This->accountName);
HeapFree(GetProcessHeap(), 0, This->comment);
HeapFree(GetProcessHeap(), 0, This->parameters);
HeapFree(GetProcessHeap(), 0, This->taskName);
HeapFree(GetProcessHeap(), 0, This);
InterlockedDecrement(&dll_ref);
}
......@@ -761,28 +762,49 @@ static const IPersistFileVtbl MSTASK_IPersistFileVtbl =
MSTASK_IPersistFile_GetCurFile
};
HRESULT TaskConstructor(LPCWSTR pwszTaskName, LPVOID *ppObj)
HRESULT TaskConstructor(ITaskFolder *folder, const WCHAR *task_name, ITask **task, BOOL create)
{
TaskImpl *This;
int n;
IRegisteredTask *regtask;
BSTR bstr;
HRESULT hr;
TRACE("(%s, %p)\n", debugstr_w(pwszTaskName), ppObj);
TRACE("(%s, %p)\n", debugstr_w(task_name), task);
bstr = SysAllocString(task_name);
if (!bstr) return E_OUTOFMEMORY;
if (create)
{
static const char xml_tmplate[] =
"<?xml version=\"1.0\"?>\n"
"<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
"</Task>\n";
WCHAR xmlW[sizeof(xml_tmplate)];
VARIANT v_null;
MultiByteToWideChar(CP_ACP, 0, xml_tmplate, -1, xmlW, sizeof(xmlW)/sizeof(xmlW[0]));
V_VT(&v_null) = VT_NULL;
hr = ITaskFolder_RegisterTask(folder, bstr, xmlW, TASK_CREATE | TASK_UPDATE,
v_null, v_null, TASK_LOGON_NONE, v_null, &regtask);
}
else
hr = ITaskFolder_GetTask(folder, bstr, &regtask);
SysFreeString(bstr);
if (hr != S_OK) return hr;
This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
if (!This)
{
IRegisteredTask_Release(regtask);
return E_OUTOFMEMORY;
}
This->ITask_iface.lpVtbl = &MSTASK_ITaskVtbl;
This->IPersistFile_iface.lpVtbl = &MSTASK_IPersistFileVtbl;
This->ref = 1;
n = (lstrlenW(pwszTaskName) + 1) * sizeof(WCHAR);
This->taskName = HeapAlloc(GetProcessHeap(), 0, n);
if (!This->taskName)
{
HeapFree(GetProcessHeap(), 0, This);
return E_OUTOFMEMORY;
}
lstrcpyW(This->taskName, pwszTaskName);
This->regtask = regtask;
This->applicationName = NULL;
This->parameters = NULL;
This->comment = NULL;
......@@ -791,7 +813,7 @@ HRESULT TaskConstructor(LPCWSTR pwszTaskName, LPVOID *ppObj)
/* Default time is 3 days = 259200000 ms */
This->maxRunTime = 259200000;
*ppObj = &This->ITask_iface;
*task = &This->ITask_iface;
InterlockedIncrement(&dll_ref);
return S_OK;
}
......@@ -37,6 +37,7 @@ typedef struct
ITaskScheduler ITaskScheduler_iface;
LONG ref;
ITaskService *service;
ITaskFolder *root;
} TaskSchedulerImpl;
typedef struct
......@@ -58,6 +59,7 @@ static inline EnumWorkItemsImpl *impl_from_IEnumWorkItems(IEnumWorkItems *iface)
static void TaskSchedulerDestructor(TaskSchedulerImpl *This)
{
TRACE("%p\n", This);
ITaskFolder_Release(This->root);
ITaskService_Release(This->service);
HeapFree(GetProcessHeap(), 0, This);
InterlockedDecrement(&dll_ref);
......@@ -290,14 +292,15 @@ static HRESULT WINAPI MSTASK_ITaskScheduler_Delete(
static HRESULT WINAPI MSTASK_ITaskScheduler_NewWorkItem(
ITaskScheduler* iface,
LPCWSTR pwszTaskName,
LPCWSTR task_name,
REFCLSID rclsid,
REFIID riid,
IUnknown **ppunk)
IUnknown **task)
{
HRESULT hr;
TRACE("(%p, %s, %s, %s, %p)\n", iface, debugstr_w(pwszTaskName),
debugstr_guid(rclsid) ,debugstr_guid(riid), ppunk);
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
TRACE("(%p, %s, %s, %s, %p)\n", iface, debugstr_w(task_name),
debugstr_guid(rclsid), debugstr_guid(riid), task);
if (!IsEqualGUID(rclsid, &CLSID_CTask))
return CLASS_E_CLASSNOTAVAILABLE;
......@@ -305,8 +308,7 @@ static HRESULT WINAPI MSTASK_ITaskScheduler_NewWorkItem(
if (!IsEqualGUID(riid, &IID_ITask))
return E_NOINTERFACE;
hr = TaskConstructor(pwszTaskName, (LPVOID *)ppunk);
return hr;
return TaskConstructor(This->root, task_name, (ITask **)task, TRUE);
}
static HRESULT WINAPI MSTASK_ITaskScheduler_AddWorkItem(
......@@ -347,6 +349,7 @@ HRESULT TaskSchedulerConstructor(LPVOID *ppObj)
{
TaskSchedulerImpl *This;
ITaskService *service;
ITaskFolder *root;
VARIANT v_null;
HRESULT hr;
......@@ -363,15 +366,24 @@ HRESULT TaskSchedulerConstructor(LPVOID *ppObj)
return hr;
}
hr = ITaskService_GetFolder(service, NULL, &root);
if (hr != S_OK)
{
ITaskService_Release(service);
return hr;
}
This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
if (!This)
{
ITaskFolder_Release(root);
ITaskService_Release(service);
return E_OUTOFMEMORY;
}
This->ITaskScheduler_iface.lpVtbl = &MSTASK_ITaskSchedulerVtbl;
This->service = service;
This->root = root;
This->ref = 1;
*ppObj = &This->ITaskScheduler_iface;
......
......@@ -24,6 +24,7 @@
#include "winbase.h"
#include "objbase.h"
#include "winternl.h"
#include "taskschd.h"
#include "mstask.h"
#include "mstask_private.h"
#include "wine/debug.h"
......
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