From d96da9e2205f0b81e1088a7ce78a7fe76c4db369 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 2 Oct 2017 06:28:43 +0200 Subject: options: enable portable installation mode --- options/group.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ options/group.hpp | 1 + 2 files changed, 39 insertions(+), 6 deletions(-) (limited to 'options') diff --git a/options/group.cpp b/options/group.cpp index 60e8a7b4..545ea99f 100644 --- a/options/group.cpp +++ b/options/group.cpp @@ -10,9 +10,11 @@ #include "defs.hpp" #include "compat/timer.hpp" +#include "opentrack-library-path.h" #include +#include #include #include #include @@ -63,14 +65,44 @@ bool group::contains(const QString &s) const return kvs.find(s) != kvs.cend(); } +bool group::is_portable_installation() +{ +#if defined _WIN32 + if (QFile::exists(OPENTRACK_BASE_PATH + "/portable.txt")) + return true; +#endif + return false; +} + QString group::ini_directory() { - const auto dirs = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); - if (dirs.size() == 0) - return ""; - if (QDir(dirs[0]).mkpath(OPENTRACK_ORG)) - return dirs[0] + "/" OPENTRACK_ORG; - return ""; + + QString dir; + + if (is_portable_installation()) + { + dir = OPENTRACK_BASE_PATH; + + static const QString subdir = "ini"; + + if (!QDir(dir).mkpath(subdir)) + return QString(); + + return dir + '/' + subdir; + } + else + { + dir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).value(0, QString()); + if (dir.isEmpty()) + return QString(); + if (!QDir(dir).mkpath(OPENTRACK_ORG)) + return QString(); + + dir += '/'; + dir += OPENTRACK_ORG; + } + + return dir; } QString group::ini_filename() diff --git a/options/group.hpp b/options/group.hpp index 93806193..c07fe576 100644 --- a/options/group.hpp +++ b/options/group.hpp @@ -49,6 +49,7 @@ public: static QString ini_pathname(); static QString ini_combine(const QString& filename); static QStringList ini_list(); + static bool is_portable_installation(); static void mark_ini_modified(); -- cgit v1.2.3