Mercurial > trustbridge
annotate ui/installwrapper.cpp @ 270:9d2ac9b6a5b0
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 02 Apr 2014 10:31:08 +0200 |
parents | 84ae353688e0 |
children | f23e0ccd5d14 |
rev | line source |
---|---|
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 #include "installwrapper.h" |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 #include <QFileInfo> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 #include <QTemporaryFile> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 #include <QApplication> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 #include <QDir> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 #include <QDebug> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 #include "logging.h" |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 InstallWrapper::InstallWrapper(QObject* parent, |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 const QString& path, const QStringList& instructions): |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 QThread(parent), |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 mCertListFile(path), |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 mInstructions(instructions) |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 QFileInfo getCinstProcInfo() { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 QFileInfo fi(QCoreApplication::applicationFilePath()); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 QDir myDir = fi.absoluteDir(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 QString instProcName = "cinst"; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 if (!fi.suffix().isEmpty()) { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 instProcName += "." + fi.suffix(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 return QFileInfo(myDir.absoluteFilePath(instProcName)); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
27 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 #ifdef WIN32 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 void InstallWrapper::run() |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 QTemporaryFile instructionsFile; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 QFileInfo cinstProcInfo = getCinstProcInfo(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
36 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 QString cinstFileName = QDir::toNativeSeparators( |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 getCinstProcInfo().absoluteFilePath()); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 if (!cinstProcInfo.isExecutable()) { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 emit error (tr("Could not find certificate installation process.")); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 return; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 instructionsFile.open(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
47 qt_ntfs_permission_lookup++; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
48 if (instructionsFile.permissions() ^ ( |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
49 QFileDevice::ReadUser | |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
50 QFileDevice::WriteUser | |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
51 QFileDevice::ReadOwner | |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
52 QFileDevice::WriteOwner)) { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
53 emit error (tr("Invalid permissions on temporary file.")); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
54 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
55 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
56 foreach (const QString &b64data, mInstructions) { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
57 instructionsFile.write(b64data.toLatin1()); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 instructionsFile.write("\n"); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
60 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
61 instructionsFile.close(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
62 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
63 QString parameters = "\"" + mCertListFile + "\" \"" +instructionsFile.fileName() + "\""; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
64 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 memset (&mExecInfo, 0, sizeof(SHELLEXECUTEINFOW)); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 mExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 mExecInfo.fMask = SEE_MASK_FLAG_NO_UI | |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
68 SEE_MASK_NOASYNC; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 mExecInfo.lpVerb = L"runas"; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 mExecInfo.lpFile = reinterpret_cast<LPCWSTR> (cinstFileName.utf16()); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
71 mExecInfo.lpParameters = reinterpret_cast<LPCWSTR> (parameters.utf16()); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
74 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
75 if (!ShellExecuteExW(&mExecInfo)) { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
76 char* errmsg = getLastErrorMsg(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 QString qerrmsg = QString::fromUtf8(errmsg); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 free(errmsg); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 emit(tr("Error executing process: %1").arg(qerrmsg)); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 qt_ntfs_permission_lookup--; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 #else |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
84 void InstallWrapper::run() |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
86 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
87 #endif |