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