UI: Refactor portable mode detection.

This commit is contained in:
Nodir Temirkhodjaev 2021-03-27 18:45:31 +03:00
parent dd8fef9958
commit 9f40ac34a2
3 changed files with 14 additions and 12 deletions

View File

@ -14,10 +14,15 @@
namespace { namespace {
QString pathSlash(const QString &path)
{
return FileUtil::pathSlash(FileUtil::absolutePath(path));
}
QString expandPath(const QString &path, EnvManager *envManager = nullptr) QString expandPath(const QString &path, EnvManager *envManager = nullptr)
{ {
const auto expPath = envManager ? envManager->expandString(path) : path; const auto expPath = envManager ? envManager->expandString(path) : path;
return FileUtil::pathSlash(FileUtil::absolutePath(expPath)); return pathSlash(expPath);
} }
} }
@ -25,7 +30,6 @@ QString expandPath(const QString &path, EnvManager *envManager = nullptr)
FortSettings::FortSettings(QObject *parent) : FortSettings::FortSettings(QObject *parent) :
QObject(parent), QObject(parent),
m_iniExists(false), m_iniExists(false),
m_isPortable(false),
m_noCache(false), m_noCache(false),
m_bulkUpdating(false), m_bulkUpdating(false),
m_bulkIniChanged(false) m_bulkIniChanged(false)
@ -124,9 +128,6 @@ void FortSettings::processArguments(const QStringList &args, EnvManager *envMana
parser.process(args); parser.process(args);
// Portable Mode
m_isPortable = FileUtil::fileExists(FileUtil::appBinLocation() + "/README.portable");
// No Cache // No Cache
if (parser.isSet(noCacheOption)) { if (parser.isSet(noCacheOption)) {
m_noCache = true; m_noCache = true;
@ -142,10 +143,14 @@ void FortSettings::processArguments(const QStringList &args, EnvManager *envMana
m_profilePath = parser.value(profileOption); m_profilePath = parser.value(profileOption);
} }
if (m_profilePath.isEmpty()) { if (m_profilePath.isEmpty()) {
const auto appBinLocation = FileUtil::appBinLocation();
const bool isPortable = FileUtil::fileExists(appBinLocation + "/README.portable");
m_profilePath = m_profilePath =
m_isPortable ? FileUtil::appBinLocation() + "/Data" : FileUtil::appConfigLocation(); pathSlash(isPortable ? appBinLocation + "/Data" : FileUtil::appConfigLocation());
} } else {
m_profilePath = expandPath(m_profilePath, envManager); m_profilePath = expandPath(m_profilePath, envManager);
}
// Statistics Path // Statistics Path
if (parser.isSet(statOption)) { if (parser.isSet(statOption)) {

View File

@ -66,7 +66,6 @@ class FortSettings : public QObject
public: public:
explicit FortSettings(QObject *parent = nullptr); explicit FortSettings(QObject *parent = nullptr);
bool isPortable() const { return m_isPortable; }
bool noCache() const { return m_noCache; } bool noCache() const { return m_noCache; }
bool debug() const { return iniBool("base/debug"); } bool debug() const { return iniBool("base/debug"); }
@ -326,7 +325,6 @@ private:
private: private:
bool m_iniExists : 1; bool m_iniExists : 1;
bool m_isPortable : 1;
bool m_noCache : 1; bool m_noCache : 1;
bool m_bulkUpdating : 1; bool m_bulkUpdating : 1;

View File

@ -27,9 +27,8 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
FortSettings fortSettings;
// Process global settings required before QApplication costruction // Process global settings required before QApplication costruction
FortSettings fortSettings;
fortSettings.setupGlobal(); fortSettings.setupGlobal();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -45,7 +44,7 @@ int main(int argc, char *argv[])
EnvManager envManager; EnvManager envManager;
// Initialize with command line arguments // Initialize settings from command line arguments
fortSettings.initialize(QCoreApplication::arguments(), &envManager); fortSettings.initialize(QCoreApplication::arguments(), &envManager);
#ifdef USE_CONTROL_COMMANDS #ifdef USE_CONTROL_COMMANDS