comparison ui/mainwindow.cpp @ 563:aee3eb10bbba

Add unit test for sw update execution and fix shell execute params
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 22 May 2014 15:18:06 +0000
parents 4cc378f335f5
children ebfe1128ee97 02a89710a7cd
comparison
equal deleted inserted replaced
562:ccdc4c6b97ce 563:aee3eb10bbba
12 #include <QProgressDialog> 12 #include <QProgressDialog>
13 #include <QMessageBox> 13 #include <QMessageBox>
14 #include <QSystemTrayIcon> 14 #include <QSystemTrayIcon>
15 #include <QAction> 15 #include <QAction>
16 #include <QDialog> 16 #include <QDialog>
17 #include <QDir>
17 #include <QMenu> 18 #include <QMenu>
18 #include <QApplication> 19 #include <QApplication>
19 #include <QFile> 20 #include <QFile>
20 #include <QTimer> 21 #include <QTimer>
21 #include <QHBoxLayout> 22 #include <QHBoxLayout>
147 QFile::remove(installedFileName); 148 QFile::remove(installedFileName);
148 mSettings.remove("List/installed"); 149 mSettings.remove("List/installed");
149 mSettings.remove("List/installedDate"); 150 mSettings.remove("List/installedDate");
150 } 151 }
151 } else { 152 } else {
152 // Make sure the available notation is also removed
153 mSettings.remove("List/installed"); 153 mSettings.remove("List/installed");
154 mSettings.remove("List/installedDate"); 154 mSettings.remove("List/installedDate");
155 } 155 }
156 156
157 if (!swFileName.isEmpty()) { 157 if (!swFileName.isEmpty()) {
199 if (!instProcInfo.isExecutable()) { 199 if (!instProcInfo.isExecutable()) {
200 qWarning() << "Downloaded file: " << fileName << " is not executable."; 200 qWarning() << "Downloaded file: " << fileName << " is not executable.";
201 setState(TransferError); 201 setState(TransferError);
202 return; 202 return;
203 } 203 }
204 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
204 #ifdef WIN32 205 #ifdef WIN32
205 SHELLEXECUTEINFOW shExecInfo; 206 SHELLEXECUTEINFOW shExecInfo;
206 shExecInfo.lpFile = reinterpret_cast<LPCWSTR> ( 207 memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW));
207 QDir::toNativeSeparators(instProcInfo.absoluteFilePath()).utf16()); 208 shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
209
210 shExecInfo.lpFile = reinterpret_cast<LPCWSTR> (filePath.utf16());
211
212 shExecInfo.fMask = SEE_MASK_NOASYNC;
208 213
209 if (!is_admin()) { 214 if (!is_admin()) {
210 shExecInfo.lpVerb = L"open"; 215 shExecInfo.lpVerb = L"open";
211 } else { 216 } else {
212 shExecInfo.lpVerb = L"runas"; 217 shExecInfo.lpVerb = L"runas";
213 } 218 }
214 219
215 qDebug() << "Admin? " << is_admin(); 220 qDebug() << "Starting process: " << filePath;
216 qDebug() << "Starting processs: " << QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
217 221
218 if (!ShellExecuteExW(&shExecInfo)) { 222 if (!ShellExecuteExW(&shExecInfo)) {
219 /* Execution failed, maybe the user aborted the UAC check? */ 223 /* Execution failed, maybe the user aborted the UAC check? */
220 char* errmsg = getLastErrorMsg(); 224 char* errmsg = getLastErrorMsg();
221 QString qerrmsg = QString::fromUtf8(errmsg); 225 QString qerrmsg = QString::fromUtf8(errmsg);
222 free(errmsg); 226 free(errmsg);
223 qDebug() << "Failed to start process: " << qerrmsg; 227 qDebug() << "Failed to start process: " << qerrmsg;
224 setState(NewSoftwareAvailable); 228 setState(NewSoftwareAvailable);
225 return; 229 return;
226 } 230 }
227
228 #else /* WIN32 */ 231 #else /* WIN32 */
229 QProcess installerProcess; 232 qDebug() << "Starting process " << filePath;
230 installerProcess.setProgram(fileName); 233
231 234 if (!QProcess::startDetached(filePath)) {
232 qDebug() << "Starting process " << fileName;
233
234 if (!installerProcess.waitForStarted() ||
235 installerProcess.state() == QProcess::NotRunning) {
236 qDebug() << "Failed to start process."; 235 qDebug() << "Failed to start process.";
237 return; 236 return;
238 } 237 }
239 #endif 238 #endif
240 /* Installer process should now be running. We exit */ 239 /* Installer process should now be running. We exit */

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