summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-07-25 22:47:34 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2020-11-03 11:39:05 -0500
commit0f0313874aa90c66acaac9082f5ba6fbd29300ef (patch)
treed9dbb5b7e479f88656379b9b4617632b20dce601 /src
parentdfbcf8ec4c6da4d2d098403a01e7ec19b587e836 (diff)
new GlobalSettings class to manage the registry
close the create instance dialog when launch is unchecked
Diffstat (limited to 'src')
-rw-r--r--src/createinstancedialog.cpp7
-rw-r--r--src/createinstancedialog.ui3
-rw-r--r--src/instancemanager.cpp30
-rw-r--r--src/instancemanager.h4
-rw-r--r--src/settings.cpp36
-rw-r--r--src/settings.h16
6 files changed, 59 insertions, 37 deletions
diff --git a/src/createinstancedialog.cpp b/src/createinstancedialog.cpp
index 63df9cd7..5a38aa50 100644
--- a/src/createinstancedialog.cpp
+++ b/src/createinstancedialog.cpp
@@ -294,8 +294,7 @@ void CreateInstanceDialog::finish()
InstanceManager::instance().setCurrentInstance(ci.instanceName);
ExitModOrganizer(Exit::Restart);
} else {
- ui->next->setEnabled(false);
- ui->cancel->setText(tr("Close"));
+ close();
}
}
catch(Failed&)
@@ -338,10 +337,6 @@ void CreateInstanceDialog::updateNavigation()
} else {
ui->next->setText(m_originalNext);
}
-
- // this may have been changed by finish() if the launch checkbox wasn't
- // checked
- ui->cancel->setText(tr("Cancel"));
}
CreateInstanceDialog::Types CreateInstanceDialog::instanceType() const
diff --git a/src/createinstancedialog.ui b/src/createinstancedialog.ui
index bcd2eb03..1f9a8ce1 100644
--- a/src/createinstancedialog.ui
+++ b/src/createinstancedialog.ui
@@ -943,6 +943,9 @@
<property name="text">
<string>Launch the new instance</string>
</property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
</widget>
</item>
</layout>
diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp
index 849cdb5e..bd35cb47 100644
--- a/src/instancemanager.cpp
+++ b/src/instancemanager.cpp
@@ -23,7 +23,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "settings.h"
#include "shared/appconfig.h"
#include "plugincontainer.h"
-#include "env.h"
#include <report.h>
#include <iplugingame.h>
#include <utility.h>
@@ -38,15 +37,9 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
using namespace MOBase;
-const QString Organization = "Mod Organizer Team";
-const QString Application = "Mod Organizer";
-const QString InstanceValue = "CurrentInstance";
-
-
InstanceManager::InstanceManager()
- : m_AppSettings(Organization, Application)
{
- updateRegistryKey();
+ GlobalSettings::updateRegistryKey();
}
InstanceManager &InstanceManager::instance()
@@ -55,23 +48,6 @@ InstanceManager &InstanceManager::instance()
return s_Instance;
}
-void InstanceManager::updateRegistryKey()
-{
- const QString OldOrganization = "Tannin";
- const QString OldApplication = "Mod Organizer";
- const QString OldInstanceValue = "CurrentInstance";
-
- const QString OldRootKey = "Software\\" + OldOrganization;
-
- if (env::registryValueExists(OldRootKey + "\\" + OldApplication, OldInstanceValue)) {
- QSettings old(OldOrganization, OldApplication);
- setCurrentInstance(old.value(OldInstanceValue).toString());
- old.remove(OldInstanceValue);
- }
-
- env::deleteRegistryKeyIfEmpty(OldRootKey);
-}
-
void InstanceManager::overrideInstance(const QString& instanceName)
{
m_overrideInstanceName = instanceName;
@@ -89,7 +65,7 @@ QString InstanceManager::currentInstance() const
if (m_overrideInstance)
return m_overrideInstanceName;
else
- return m_AppSettings.value(InstanceValue, "").toString();
+ return GlobalSettings::currentInstance();
}
void InstanceManager::clearCurrentInstance()
@@ -101,7 +77,7 @@ void InstanceManager::clearCurrentInstance()
void InstanceManager::setCurrentInstance(const QString &name)
{
- m_AppSettings.setValue(InstanceValue, name);
+ GlobalSettings::setCurrentInstance(name);
}
bool InstanceManager::deleteLocalInstance(const QString& instanceId) const
diff --git a/src/instancemanager.h b/src/instancemanager.h
index 7467e2fa..f53543df 100644
--- a/src/instancemanager.h
+++ b/src/instancemanager.h
@@ -75,11 +75,7 @@ private:
bool portableInstall() const;
bool portableInstallIsLocked() const;
- void updateRegistryKey();
-
private:
-
- QSettings m_AppSettings;
bool m_Reset {false};
bool m_overrideInstance{false};
QString m_overrideInstanceName;
diff --git a/src/settings.cpp b/src/settings.cpp
index 661cf429..76378af9 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -2165,3 +2165,39 @@ void DiagnosticsSettings::setSpawnDelay(std::chrono::seconds t)
{
set(m_Settings, "Settings", "spawn_delay", t.count());
}
+
+
+void GlobalSettings::updateRegistryKey()
+{
+ const QString OldOrganization = "Tannin";
+ const QString OldApplication = "Mod Organizer";
+ const QString OldInstanceValue = "CurrentInstance";
+
+ const QString OldRootKey = "Software\\" + OldOrganization;
+
+ if (env::registryValueExists(OldRootKey + "\\" + OldApplication, OldInstanceValue)) {
+ QSettings old(OldOrganization, OldApplication);
+ setCurrentInstance(old.value(OldInstanceValue).toString());
+ old.remove(OldInstanceValue);
+ }
+
+ env::deleteRegistryKeyIfEmpty(OldRootKey);
+}
+
+QString GlobalSettings::currentInstance()
+{
+ return settings().value("CurrentInstance", "").toString();
+}
+
+void GlobalSettings::setCurrentInstance(const QString& s)
+{
+ settings().setValue("CurrentInstance", s);
+}
+
+QSettings GlobalSettings::settings()
+{
+ const QString Organization = "Mod Organizer Team";
+ const QString Application = "Mod Organizer";
+
+ return QSettings(Organization, Application);
+}
diff --git a/src/settings.h b/src/settings.h
index c723faec..54f1bb5b 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -827,6 +827,22 @@ private:
};
+// manages global settings in the registry
+//
+class GlobalSettings
+{
+public:
+ // migrates the old settings from the Tannin key to the new one
+ static void updateRegistryKey();
+
+ static QString currentInstance();
+ static void setCurrentInstance(const QString& s);
+
+private:
+ static QSettings settings();
+};
+
+
// helper class that calls restoreGeometry() in the constructor and
// saveGeometry() in the destructor
//