comparison ui/main.cpp @ 634:80d1a80b3e8d

Factor out selftest for better test and reviewability
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 23 Jun 2014 16:43:07 +0200
parents 6c090638b2b4
children 376978e9cc61
comparison
equal deleted inserted replaced
633:6c090638b2b4 634:80d1a80b3e8d
5 * and comes with ABSOLUTELY NO WARRANTY! 5 * and comes with ABSOLUTELY NO WARRANTY!
6 * See LICENSE.txt for details. 6 * See LICENSE.txt for details.
7 */ 7 */
8 #include "mainwindow.h" 8 #include "mainwindow.h"
9 #include "processhelp.h" 9 #include "processhelp.h"
10 #include "binverify.h"
11 #include "logging.h" 10 #include "logging.h"
12 #include "strhelp.h" 11 #include "selftest.h"
13 12
14 #include <QApplication> 13 #include <QApplication>
15 #include <QSystemTrayIcon> 14 #include <QSystemTrayIcon>
16 #include <QtPlugin> 15 #include <QtPlugin>
17 #include <QMessageBox> 16 #include <QMessageBox>
38 #endif 37 #endif
39 38
40 int main(int argc, char **argv) 39 int main(int argc, char **argv)
41 { 40 {
42 /* First verify integrity even before calling QApplication*/ 41 /* First verify integrity even before calling QApplication*/
43 #ifdef Q_OS_WIN 42 if (!selftest()) {
44 {
45 wchar_t wPath[MAX_PATH];
46 char *utf8path = NULL;
47
48 if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) {
49 PRINTLASTERROR ("Failed to obtain module file name. Path too long?");
50 syslog_error_printf ("Integrity check failed.");
51 return -1;
52 }
53
54 /* wPath might not be 0 terminated */
55 wPath[MAX_PATH - 1] = '\0';
56
57 utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH));
58
59 if (utf8path == NULL) {
60 ERRORPRINTF ("Failed to convert module path to utf-8");
61 syslog_error_printf ("Integrity check failed.");
62 return -1;
63 }
64
65 if (!verify_binary (utf8path, strlen(utf8path)) != VerifyValid)
66 {
67 ERRORPRINTF ("Verification of the binary failed");
68 syslog_error_printf ("Integrity check failed.");
69 xfree(utf8path);
70 #ifdef RELEASE_BUILD
71 return -1;
72 #endif
73 }
74
75 xfree(utf8path);
76 }
77 #else
78 if (!verify_binary ("/proc/self/exe", 14) != VerifyValid)
79 {
80 syslog_error_printf ("Integrity check failed."); 43 syslog_error_printf ("Integrity check failed.");
81 #ifdef RELEASE_BUILD 44 #ifdef RELEASE_BUILD
82 return -1; 45 return -1;
83 #endif 46 #endif
84 } 47 }
85 #endif
86 48
87 QApplication app (argc, argv); 49 QApplication app (argc, argv);
88 50
89 QApplication::setQuitOnLastWindowClosed(false); 51 QApplication::setQuitOnLastWindowClosed(false);
90 QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION)); 52 QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION));

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