annotate ui/taskscheduler.cpp @ 1373:00fcb9c4d16b

(issue179) Handle SW verify failures and try to redownload the update
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 24 Nov 2014 16:46:08 +0100
parents 8de162b91a22
children
rev   line source
827
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 #ifdef WIN32
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 #include "taskscheduler.h"
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 * Software engineering by Intevation GmbH
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 *
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 * This file is Free Software under the GNU GPL (v>=2)
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8 * and comes with ABSOLUTELY NO WARRANTY!
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 * See LICENSE.txt for details.
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 */
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #include <windows.h>
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #include <QDate>
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #include <QDebug>
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 #include <QApplication>
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 #define TASK_NAME L"TrustBridge Update"
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 TaskScheduler::TaskScheduler() :
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 mInitialized (false),
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22 mTaskScheduler (NULL)
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 HRESULT hr;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 hr = CoInitialize(NULL);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 if(FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 qDebug() << "TaskScheduler CoInitializeEx failed: " << hr;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 return;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 hr = CoCreateInstance(CLSID_CTaskScheduler,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 NULL,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 CLSCTX_INPROC_SERVER,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 IID_ITaskScheduler,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 (void**)&mTaskScheduler);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 if(FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 qDebug() << "TaskScheduler create instance failed: " << hr;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 CoUninitialize();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 return;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 mInitialized = true;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44 qDebug() << "Initialization done";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 return;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 TaskScheduler::~TaskScheduler() {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 qDebug() << "TaskSched dtor;";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51 if (!isInitialized()) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 return;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 mTaskScheduler->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 CoUninitialize();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 bool createTrigger(ITask *task, const QTime &startTime)
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 ITaskTrigger *pITaskTrigger = NULL;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 WORD piNewTrigger = 0;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 HRESULT hr;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 TASK_TRIGGER pTrigger;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 ZeroMemory(&pTrigger, sizeof (TASK_TRIGGER));
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 QDate startdate = QDate::currentDate();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 if (!startTime.isValid() || task == NULL) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 qDebug() << "Invalid args.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 hr = task->CreateTrigger(&piNewTrigger,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 &pITaskTrigger);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76 qDebug() << "Failed to create trigger.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 pTrigger.wBeginDay = startdate.day();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81 pTrigger.wBeginMonth = startdate.month();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82 pTrigger.wBeginYear = startdate.year();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
83 pTrigger.wStartHour = startTime.hour();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84 pTrigger.wStartMinute = startTime.minute();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85 pTrigger.cbTriggerSize = sizeof (TASK_TRIGGER);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86 pTrigger.TriggerType = TASK_TIME_TRIGGER_DAILY;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 pTrigger.Type.Daily.DaysInterval = 1;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 hr = pITaskTrigger->SetTrigger(&pTrigger);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 pITaskTrigger->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 qDebug() << "Failed to create trigger.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97 return true;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 bool TaskScheduler::createDailyTask(const QString &executable,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101 const QString &args,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102 const QTime &startTime) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103 ITask *task = NULL;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
104 IPersistFile *persistFile = NULL;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 HRESULT hr;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
106
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 hr = mTaskScheduler->NewWorkItem(TASK_NAME,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 CLSID_CTask,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109 IID_ITask,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110 (IUnknown**)&task);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 qDebug() << "Failed to create new work item.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 /* Set the task parameters */
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118 hr = task->SetApplicationName(reinterpret_cast<LPCWSTR> (executable.utf16()));
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 qDebug() << "Failed to set application name.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 hr = task->SetParameters(reinterpret_cast<LPCWSTR> (args.utf16()));
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
127 qDebug() << "Failed to set parameters.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
132 hr = task->SetComment(reinterpret_cast<LPCWSTR>(QObject::tr("TrustBridge automatic update check.").utf16()));
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
134 qDebug() << "Failed to set comment.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
138
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 QString username = QString::fromLocal8Bit(qgetenv("USERNAME").constData());
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 if (username.isEmpty()) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 qDebug() << "Failed to obtain username from envrionment.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
143 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146 hr = task->SetAccountInformation(reinterpret_cast<LPCWSTR>(username.utf16()), NULL);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 qDebug() << "Failed to set username.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 hr = task->SetFlags(TASK_FLAG_RUN_ONLY_IF_LOGGED_ON);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 qDebug() << "Failed to set flags.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 /* Now create the trigger for this task */
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 if (!createTrigger(task, startTime)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 qDebug() << "Failed to create trigger.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
168
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169 hr = task->QueryInterface(IID_IPersistFile,
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 (void **)&persistFile);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
173 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
174 qDebug() << "Failed to get persist file interface.";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
175 task->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
176 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
177 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
178
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
179 hr = persistFile->Save(NULL, TRUE);
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
180 persistFile->Release();
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
181 if (FAILED(hr)) {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
182 qDebug() << "Failed to save task";
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
183 return false;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
184 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
185
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
186 return true;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
187 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
188 #endif /* WIN32 */

http://wald.intevation.org/projects/trustbridge/