]> git.siccegge.de Git - frida/frida.git/commitdiff
Add settings Class
authorChristoph Egger <christoph@christoph-egger.org>
Mon, 25 May 2015 05:20:42 +0000 (07:20 +0200)
committerChristoph Egger <christoph@christoph-egger.org>
Mon, 25 May 2015 05:21:38 +0000 (07:21 +0200)
Singleton class that keeps track of settings. First thing it has a
RuntimeDirectory to place things like sockets into.

CMakeLists.txt
src/core/Settings.cxx [new file with mode: 0644]
src/core/Settings.hxx [new file with mode: 0644]
src/main.cxx

index dfa41120b60602dcc546568b432cbe6f373b2277..b793c67a3137e7d33f655ad18af9e6db4385b504 100644 (file)
@@ -55,6 +55,7 @@ SET(frida_SOURCES
   src/core/BasicBlock.cxx
   src/core/Comment.cxx
   src/core/Function.cxx
+  src/core/Settings.cxx
   src/gui/Mainwindow.cxx
   src/gui/widgets/BasicBlockWidget.cxx
   src/gui/widgets/CFGScene.cxx
@@ -71,6 +72,7 @@ SET(frida_SOURCES
 SET(frida_HEADERS
   src/include_llvm.hxx
   src/core/InformationManager.hxx
+  src/core/Settings.hxx
   src/qt.hxx
   src/gui/Mainwindow.hxx
   src/gui/widgets/BasicBlockWidget.hxx
diff --git a/src/core/Settings.cxx b/src/core/Settings.cxx
new file mode 100644 (file)
index 0000000..eee4ff3
--- /dev/null
@@ -0,0 +1,24 @@
+#include "Settings.hxx"
+
+Settings* Settings::instance = NULL;
+
+Settings::Settings()
+       : QSettings("frida")
+       , logger(log4cxx::Logger::getLogger("core.Settings")) {
+       setIniCodec("UTF-8");
+       instance = this;
+
+       QStringList runtimePaths = QStandardPaths::standardLocations(QStandardPaths::RuntimeLocation);
+       if (! runtimePaths.empty() && (*runtimePaths.begin()) != "") {
+               LOG4CXX_DEBUG(logger, "Using runtime Path \"" << runtimePaths.begin()->toStdString() << "\" from list of length " << runtimePaths.length());
+               runtimeDirectory = new QDir(*runtimePaths.begin());
+       } else {
+               QTemporaryDir* dir = new QTemporaryDir();
+               if (dir->isValid()) {
+                       runtimeDirectory = new QDir(dir->path());
+                       LOG4CXX_INFO(logger, "Using custom runtime Path " << dir->path().toStdString());
+               } else {
+                       LOG4CXX_ERROR(logger, "Could not create Runtime directory!");
+               }
+       }
+}
diff --git a/src/core/Settings.hxx b/src/core/Settings.hxx
new file mode 100644 (file)
index 0000000..6e40c4d
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef INCLUDE__Settings_hxx
+#define INCLUDE__Settings_hxx
+
+#include "qt.hxx"
+#include "log4cxx/logger.h"
+
+class Settings : public QSettings {
+public:
+       QDir* getRuntimeDirectory() const {return runtimeDirectory;}
+       static Settings* get() {return instance;}
+private:
+       Settings();
+
+       static Settings* instance;
+       log4cxx::LoggerPtr logger;
+       QDir* runtimeDirectory;
+
+       friend int main(int argc, char** argv);
+};
+
+#endif /* INCLUDE__Settings_hxx */
index 24ddf7a2ad24aca695601d0d6b8d0906b4a5350e..ccb2c52951ccd9639866f507f7c064c954ada0bd 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "gui/Mainwindow.hxx"
 #include "core/InformationManager.hxx"
+#include "core/Settings.hxx"
 #include "disassembler/llvm/LLVMDisassembler.hxx"
 #include "Config.hxx"
 
@@ -67,6 +68,7 @@ int main(int argc, char** argv)
 #endif
        log4cxx::Logger::getRootLogger()->setLevel(level);
 
+       Settings settings;
        InformationManager iman;
 
        LOG4CXX_DEBUG(_logger, "Initializing LLVM");