summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-10-02 06:28:43 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-10-02 06:28:43 +0200
commitd96da9e2205f0b81e1088a7ce78a7fe76c4db369 (patch)
tree0da192cedc3e3ba0330d9fbd48444a90d47f20b6
parent86a8b67400d42270839ddce946dbc2f49dd4c855 (diff)
options: enable portable installation mode
-rw-r--r--options/group.cpp44
-rw-r--r--options/group.hpp1
2 files changed, 39 insertions, 6 deletions
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 <cmath>
+#include <QFile>
#include <QStandardPaths>
#include <QDir>
#include <QDebug>
@@ -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();