From 2dc8e8cdaf2e8f767dfd3c0e9e3d107d1f3f4108 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Mon, 25 May 2015 07:20:42 +0200 Subject: [PATCH] Add settings Class Singleton class that keeps track of settings. First thing it has a RuntimeDirectory to place things like sockets into. --- CMakeLists.txt | 2 ++ src/core/Settings.cxx | 24 ++++++++++++++++++++++++ src/core/Settings.hxx | 21 +++++++++++++++++++++ src/main.cxx | 2 ++ 4 files changed, 49 insertions(+) create mode 100644 src/core/Settings.cxx create mode 100644 src/core/Settings.hxx diff --git a/CMakeLists.txt b/CMakeLists.txt index dfa4112..b793c67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..eee4ff3 --- /dev/null +++ b/src/core/Settings.cxx @@ -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 index 0000000..6e40c4d --- /dev/null +++ b/src/core/Settings.hxx @@ -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 */ diff --git a/src/main.cxx b/src/main.cxx index 24ddf7a..ccb2c52 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -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"); -- 2.39.5