From 4d9c1db885bd3ab230440b25e70dcd8049cf4650 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Wed, 11 Sep 2019 11:45:32 -0500 Subject: Add portable lock feature If the file "portable.txt" is present in the application directory, MO will force itself to be launched as a portable instance. The change game button and menu item are hidden to prevent the user from changing out of the portable instance. --- src/instancemanager.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/instancemanager.cpp') diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp index fdc30e22..c0d343de 100644 --- a/src/instancemanager.cpp +++ b/src/instancemanager.cpp @@ -186,6 +186,10 @@ QString InstanceManager::queryInstanceName(const QStringList &instanceList) cons QString InstanceManager::chooseInstance(const QStringList &instanceList) const { + if (portableInstallIsLocked()) { + return QString(); + } + enum class Special : uint8_t { NewInstance, Portable, @@ -266,6 +270,19 @@ bool InstanceManager::portableInstall() const } +bool InstanceManager::portableInstallIsLocked() const +{ + return QFile::exists(qApp->applicationDirPath() + "/" + + QString::fromStdWString(AppConfig::portableLockFileName())); +} + + +bool InstanceManager::allowedToChangeInstance() const +{ + return !portableInstallIsLocked(); +} + + void InstanceManager::createDataPath(const QString &dataPath) const { if (!QDir(dataPath).exists()) { @@ -286,6 +303,10 @@ void InstanceManager::createDataPath(const QString &dataPath) const QString InstanceManager::determineDataPath() { QString instanceId = currentInstance(); + if (portableInstallIsLocked()) + { + instanceId.clear(); + } if (instanceId.isEmpty() && !m_Reset && (m_overrideInstance || portableInstall())) { // startup, apparently using portable mode before -- cgit v1.3.1