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

mstask: Implement setting and getting an application name using IExecAction.

parent d42e42e3
...@@ -37,8 +37,8 @@ typedef struct ...@@ -37,8 +37,8 @@ typedef struct
IPersistFile IPersistFile_iface; IPersistFile IPersistFile_iface;
LONG ref; LONG ref;
ITaskDefinition *task; ITaskDefinition *task;
IExecAction *action;
LPWSTR task_name; LPWSTR task_name;
LPWSTR applicationName;
LPWSTR parameters; LPWSTR parameters;
LPWSTR comment; LPWSTR comment;
DWORD maxRunTime; DWORD maxRunTime;
...@@ -58,6 +58,8 @@ static inline TaskImpl *impl_from_IPersistFile( IPersistFile *iface ) ...@@ -58,6 +58,8 @@ static inline TaskImpl *impl_from_IPersistFile( IPersistFile *iface )
static void TaskDestructor(TaskImpl *This) static void TaskDestructor(TaskImpl *This)
{ {
TRACE("%p\n", This); TRACE("%p\n", This);
if (This->action)
IExecAction_Release(This->action);
ITaskDefinition_Release(This->task); ITaskDefinition_Release(This->task);
HeapFree(GetProcessHeap(), 0, This->task_name); HeapFree(GetProcessHeap(), 0, This->task_name);
HeapFree(GetProcessHeap(), 0, This->accountName); HeapFree(GetProcessHeap(), 0, This->accountName);
...@@ -427,73 +429,68 @@ static HRESULT WINAPI MSTASK_ITask_GetAccountInformation( ...@@ -427,73 +429,68 @@ static HRESULT WINAPI MSTASK_ITask_GetAccountInformation(
return S_OK; return S_OK;
} }
static HRESULT WINAPI MSTASK_ITask_SetApplicationName( static HRESULT WINAPI MSTASK_ITask_SetApplicationName(ITask *iface, LPCWSTR appname)
ITask* iface,
LPCWSTR pwszApplicationName)
{ {
DWORD n;
TaskImpl *This = impl_from_ITask(iface); TaskImpl *This = impl_from_ITask(iface);
LPWSTR tmp_name; DWORD len;
TRACE("(%p, %s)\n", iface, debugstr_w(pwszApplicationName)); TRACE("(%p, %s)\n", iface, debugstr_w(appname));
/* Empty application name */ /* Empty application name */
if (pwszApplicationName[0] == 0) if (!appname || !appname[0])
{ return IExecAction_put_Path(This->action, NULL);
HeapFree(GetProcessHeap(), 0, This->applicationName);
This->applicationName = NULL;
return S_OK;
}
/* Attempt to set pwszApplicationName to a path resolved application name */ /* Attempt to set pwszApplicationName to a path resolved application name */
n = SearchPathW(NULL, pwszApplicationName, NULL, 0, NULL, NULL); len = SearchPathW(NULL, appname, NULL, 0, NULL, NULL);
if (n) if (len)
{ {
tmp_name = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR)); LPWSTR tmp_name;
HRESULT hr;
tmp_name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!tmp_name) if (!tmp_name)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
n = SearchPathW(NULL, pwszApplicationName, NULL, n, tmp_name, NULL); len = SearchPathW(NULL, appname, NULL, len, tmp_name, NULL);
if (n) if (len)
{ hr = IExecAction_put_Path(This->action, tmp_name);
HeapFree(GetProcessHeap(), 0, This->applicationName);
This->applicationName = tmp_name;
return S_OK;
}
else else
HeapFree(GetProcessHeap(), 0, tmp_name); hr = HRESULT_FROM_WIN32(GetLastError());
HeapFree(GetProcessHeap(), 0, tmp_name);
return hr;
} }
/* If unable to path resolve name, simply set to pwszApplicationName */ /* If unable to path resolve name, simply set to appname */
n = (lstrlenW(pwszApplicationName) + 1); return IExecAction_put_Path(This->action, (BSTR)appname);
tmp_name = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
if (!tmp_name)
return E_OUTOFMEMORY;
lstrcpyW(tmp_name, pwszApplicationName);
HeapFree(GetProcessHeap(), 0, This->applicationName);
This->applicationName = tmp_name;
return S_OK;
} }
static HRESULT WINAPI MSTASK_ITask_GetApplicationName( static HRESULT WINAPI MSTASK_ITask_GetApplicationName(ITask *iface, LPWSTR *appname)
ITask* iface,
LPWSTR *ppwszApplicationName)
{ {
DWORD n;
TaskImpl *This = impl_from_ITask(iface); TaskImpl *This = impl_from_ITask(iface);
HRESULT hr;
BSTR path;
DWORD len;
TRACE("(%p, %p)\n", iface, ppwszApplicationName); TRACE("(%p, %p)\n", iface, appname);
n = This->applicationName ? lstrlenW(This->applicationName) + 1 : 1; hr = IExecAction_get_Path(This->action, &path);
*ppwszApplicationName = CoTaskMemAlloc(n * sizeof(WCHAR)); if (hr != S_OK) return hr;
if (!*ppwszApplicationName)
return E_OUTOFMEMORY;
if (!This->applicationName) len = path ? lstrlenW(path) + 1 : 1;
*ppwszApplicationName[0] = 0; *appname = CoTaskMemAlloc(len * sizeof(WCHAR));
if (*appname)
{
if (!path)
*appname[0] = 0;
else
lstrcpyW(*appname, path);
hr = S_OK;
}
else else
lstrcpyW(*ppwszApplicationName, This->applicationName); hr = E_OUTOFMEMORY;
return S_OK; SysFreeString(path);
return hr;
} }
static HRESULT WINAPI MSTASK_ITask_SetParameters( static HRESULT WINAPI MSTASK_ITask_SetParameters(
...@@ -767,6 +764,7 @@ HRESULT TaskConstructor(ITaskService *service, const WCHAR *task_name, ITask **t ...@@ -767,6 +764,7 @@ HRESULT TaskConstructor(ITaskService *service, const WCHAR *task_name, ITask **t
{ {
TaskImpl *This; TaskImpl *This;
ITaskDefinition *taskdef; ITaskDefinition *taskdef;
IActionCollection *actions;
HRESULT hr; HRESULT hr;
TRACE("(%s, %p)\n", debugstr_w(task_name), task); TRACE("(%s, %p)\n", debugstr_w(task_name), task);
...@@ -786,7 +784,6 @@ HRESULT TaskConstructor(ITaskService *service, const WCHAR *task_name, ITask **t ...@@ -786,7 +784,6 @@ HRESULT TaskConstructor(ITaskService *service, const WCHAR *task_name, ITask **t
This->ref = 1; This->ref = 1;
This->task = taskdef; This->task = taskdef;
This->task_name = heap_strdupW(task_name); This->task_name = heap_strdupW(task_name);
This->applicationName = NULL;
This->parameters = NULL; This->parameters = NULL;
This->comment = NULL; This->comment = NULL;
This->accountName = NULL; This->accountName = NULL;
...@@ -794,7 +791,20 @@ HRESULT TaskConstructor(ITaskService *service, const WCHAR *task_name, ITask **t ...@@ -794,7 +791,20 @@ HRESULT TaskConstructor(ITaskService *service, const WCHAR *task_name, ITask **t
/* Default time is 3 days = 259200000 ms */ /* Default time is 3 days = 259200000 ms */
This->maxRunTime = 259200000; This->maxRunTime = 259200000;
*task = &This->ITask_iface; hr = ITaskDefinition_get_Actions(This->task, &actions);
InterlockedIncrement(&dll_ref); if (hr == S_OK)
return S_OK; {
hr = IActionCollection_Create(actions, TASK_ACTION_EXEC, (IAction **)&This->action);
IActionCollection_Release(actions);
if (hr == S_OK)
{
*task = &This->ITask_iface;
InterlockedIncrement(&dll_ref);
return S_OK;
}
}
ITaskDefinition_Release(This->task);
ITask_Release(&This->ITask_iface);
return hr;
} }
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