Skip to content

Commit

Permalink
Add portable lock feature
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LostDragonist committed Sep 11, 2019
1 parent 99fdbb2 commit 4d9c1db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/instancemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()) {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/instancemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class InstanceManager {

QString currentInstance() const;

bool allowedToChangeInstance() const;

private:

InstanceManager();
Expand All @@ -58,6 +60,7 @@ class InstanceManager {

void createDataPath(const QString &dataPath) const;
bool portableInstall() const;
bool portableInstallIsLocked() const;

private:

Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,10 @@ void MainWindow::setupToolbar()
} else {
log::warn("no separator found on the toolbar, icons won't be right-aligned");
}

if (!InstanceManager::instance().allowedToChangeInstance()) {
ui->actionChange_Game->setVisible(false);
}
}

void MainWindow::setupActionMenu(QAction* a)
Expand Down
1 change: 1 addition & 0 deletions src/shared/appconfig.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ APPPARAM(std::wstring, proxyDLLOrig, L"steam_api_orig.dll") // needs to be ident
APPPARAM(std::wstring, proxyDLLSource, L"proxy.dll")
APPPARAM(std::wstring, vfs32DLLName, L"usvfs_x86.dll")
APPPARAM(std::wstring, vfs64DLLName, L"usvfs_x64.dll")
APPPARAM(std::wstring, portableLockFileName, L"portable.txt")
APPPARAM(const wchar_t*, localSavePlaceholder, L"__MOProfileSave__\\")

APPPARAM(std::wstring, firstStepsTutorial, L"tutorial_firststeps_main.js")
Expand Down

0 comments on commit 4d9c1db

Please # to comment.