diff 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
line wrap: on
line diff
--- a/ui/main.cpp	Mon Jun 23 15:29:48 2014 +0200
+++ b/ui/main.cpp	Mon Jun 23 16:43:07 2014 +0200
@@ -7,9 +7,8 @@
  */
 #include "mainwindow.h"
 #include "processhelp.h"
-#include "binverify.h"
 #include "logging.h"
-#include "strhelp.h"
+#include "selftest.h"
 
 #include <QApplication>
 #include <QSystemTrayIcon>
@@ -40,49 +39,12 @@
 int main(int argc, char **argv)
 {
     /* First verify integrity even before calling QApplication*/
-#ifdef Q_OS_WIN
-    {
-      wchar_t wPath[MAX_PATH];
-      char *utf8path = NULL;
-
-      if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) {
-          PRINTLASTERROR ("Failed to obtain module file name. Path too long?");
-          syslog_error_printf ("Integrity check failed.");
-          return -1;
-      }
-
-      /* wPath might not be 0 terminated */
-      wPath[MAX_PATH - 1] = '\0';
-
-      utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH));
-
-      if (utf8path == NULL) {
-          ERRORPRINTF ("Failed to convert module path to utf-8");
-          syslog_error_printf ("Integrity check failed.");
-          return -1;
-      }
-
-      if (!verify_binary (utf8path, strlen(utf8path)) != VerifyValid)
-        {
-          ERRORPRINTF ("Verification of the binary failed");
-          syslog_error_printf ("Integrity check failed.");
-          xfree(utf8path);
-#ifdef RELEASE_BUILD
-          return -1;
-#endif
-        }
-
-      xfree(utf8path);
-    }
-#else
-    if (!verify_binary ("/proc/self/exe", 14) != VerifyValid)
-      {
+    if (!selftest()) {
         syslog_error_printf ("Integrity check failed.");
 #ifdef RELEASE_BUILD
         return -1;
 #endif
-      }
-#endif
+    }
 
     QApplication app (argc, argv);
 

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