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