david_ac adding a commandline parameter for the data dir, as requested by svenstaro
authornemo
Fri, 08 May 2009 01:49:11 +0000
changeset 2034 decdf48cffd7
parent 2033 860b9aea5e86
child 2035 70734c4f52a7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
QTfrontend/main.cpp
--- a/QTfrontend/main.cpp	Thu May 07 23:57:39 2009 +0000
+++ b/QTfrontend/main.cpp	Fri May 08 01:49:11 2009 +0000
@@ -21,6 +21,8 @@
 #include <QLocale>
 #include <QMessageBox>
 #include <QPlastiqueStyle>
+#include <QRegExp>
+#include <QMap>
 
 #include "hwform.h"
 #include "hwconsts.h"
@@ -44,6 +46,29 @@
 {
 	QApplication app(argc, argv);
 
+    QStringList arguments = app.arguments();
+    QMap<QString, QString> parsedArgs;
+    {
+        QList<QString>::iterator i = arguments.begin();
+        while(++i != arguments.end()) {
+            QString arg = *i;
+
+            QRegExp opt("--(\\S+)=(.+)");
+            if(opt.exactMatch(arg)) {
+                parsedArgs[opt.cap(1)] = opt.cap(2);
+                arguments.erase(i);
+            }
+        }
+    }
+
+    if(parsedArgs.contains("data-dir")) {
+        QFileInfo f(parsedArgs["data-dir"]);
+        if(!f.exists()) {
+            qWarning() << "WARNING: Cannot open DATA_PATH=" << f.absoluteFilePath();
+        }
+        *cDataDir = f.absoluteFilePath();
+    }
+
 	app.setStyle(new QPlastiqueStyle);
 	
 	QDateTime now = QDateTime::currentDateTime();