comparison ui/installwrapper.cpp @ 399:55cbe0a482ce

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 16 Apr 2014 10:01:02 +0200
parents a507e5f1b999
children 17e1c8f37d72
comparison
equal deleted inserted replaced
398:9e6a2c2033ed 399:55cbe0a482ce
67 if (!writeChoices(&choicesFile)) { 67 if (!writeChoices(&choicesFile)) {
68 emit error(tr("Failed to write temporary file.")); 68 emit error(tr("Failed to write temporary file."));
69 return; 69 return;
70 } 70 }
71 71
72 QString parameters = "\"list=" + mCertListFile +
73 "\" \"choices=" + choicesFile.fileName() + "\"";
74
75 #ifdef WIN32 72 #ifdef WIN32
76 /* QProcess on Windows uses CreateProcess but we have to 73 /* QProcess on Windows uses CreateProcess but we have to
77 * use the runas shell command to get the UAC prompt if necessary. 74 * use the runas shell command to get the UAC prompt if necessary.
78 * So we have to handle the process ourself. Starting with 75 * So we have to handle the process ourself. Starting with
79 * shell execute also means that we can not have stdout and stderr 76 * shell execute also means that we can not have stdout and stderr
82 * also makes use of output debug string. */ 79 * also makes use of output debug string. */
83 DWORD retval = 0; 80 DWORD retval = 0;
84 SHELLEXECUTEINFOW shExecInfo; 81 SHELLEXECUTEINFOW shExecInfo;
85 82
86 memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW)); 83 memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW));
84
85 /* Windows needs each parameter packed in " */
86 QString parameters = "\"list=" + mCertListFile +
87 "\" \"choices=" + choicesFile.fileName() + "\"";
87 88
88 shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW); 89 shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
89 shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; 90 shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
90 shExecInfo.lpVerb = L"runas"; 91 shExecInfo.lpVerb = L"runas";
91 shExecInfo.lpFile = reinterpret_cast<LPCWSTR> (cinstFileName.utf16()); 92 shExecInfo.lpFile = reinterpret_cast<LPCWSTR> (cinstFileName.utf16());
123 } else { 124 } else {
124 char* errmsg = getLastErrorMsg(); 125 char* errmsg = getLastErrorMsg();
125 QString qerrmsg = QString::fromUtf8(errmsg); 126 QString qerrmsg = QString::fromUtf8(errmsg);
126 free(errmsg); 127 free(errmsg);
127 emit error (tr("Failed to check process status: %1").arg(qerrmsg)); 128 emit error (tr("Failed to check process status: %1").arg(qerrmsg));
129 CloseHandle(shExecInfo.hProcess);
130 return;
128 } 131 }
129 CloseHandle(shExecInfo.hProcess); 132 CloseHandle(shExecInfo.hProcess);
130 133
131 if (retval != 0) { 134 if (retval != 0) {
132 /* TODO make this nicer */ 135 /* TODO make this nicer */
133 emit error (tr("The process failed with return code. %1").arg(retval)); 136 emit error (tr("The process failed with return code. %1").arg(retval));
137 return;
134 } 138 }
135 return;
136 #else /* WIN32 */ 139 #else /* WIN32 */
137 QProcess installerProcess; 140 QProcess installerProcess;
138 installerProcess.setProgram(cinstProcInfo.absoluteFilePath()); 141 installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
139 installerProcess.waitForStarted(); 142 QStringList parameters;
140 if (installerProcess.state() == QProcess::NotRunning) { 143
144 choicesFile.setAutoRemove(false);
145 parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName();
146 installerProcess.setArguments(parameters);
147
148
149 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
150 installerProcess.start();
151 if (!installerProcess.waitForStarted() ||
152 installerProcess.state() == QProcess::NotRunning) {
141 emit error (tr("Failed to start installer process.")); 153 emit error (tr("Failed to start installer process."));
142 return; 154 return;
143 } 155 }
144 156
145 installerProcess.waitForFinished(); 157 installerProcess.waitForFinished();
146 158
147 if (installerProcess.exitStatus() == QProcess::CrashExit) { 159 if (installerProcess.exitStatus() == QProcess::CrashExit) {
148 /* Woops */ 160 /* Woops */
149 qWarning() << "Installer process crashed"; 161 emit error (tr("Failed to complete installation."));
162 return;
150 } else if (installerProcess.exitStatus() != QProcess::NormalExit) { 163 } else if (installerProcess.exitStatus() != QProcess::NormalExit) {
151 /* Can not Happen. there are only those two values but maybe 164 /* Can not Happen. there are only those two values but maybe
152 * qt changed.. */ 165 * qt changed.. */
153 qWarning() << "Exit status neither normal nor crash."; 166 emit error (tr("Failed to complete installation."));
154 return; 167 return;
155 } 168 }
156 169
157 if (installerProcess.exitCode() == 0) { 170 if (installerProcess.exitCode() == 0) {
158 qDebug() << "output: " << installerProcess.readAllStandardOutput(); 171 qDebug() << "output: " << installerProcess.readAllStandardOutput();
161 qDebug() << "Installer Process returned: " << installerProcess.exitCode(); 174 qDebug() << "Installer Process returned: " << installerProcess.exitCode();
162 qDebug() << "output: " << installerProcess.readAllStandardOutput(); 175 qDebug() << "output: " << installerProcess.readAllStandardOutput();
163 return; 176 return;
164 } 177 }
165 #endif 178 #endif
179 emit installationSuccessful();
166 } 180 }

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