summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-02-25 16:36:27 -0600
committerAndrew <forkk@forkk.net>2013-02-25 16:36:27 -0600
commitbd64cda6726e088ebc860c3fc3ee220ed00121bd (patch)
tree135a1784cf2b7910dd7e258f52129b31a4f4244e
parent4ca35a760dfc53fd69f0f2030868ebeda250ed59 (diff)
downloadMultiMC-bd64cda6726e088ebc860c3fc3ee220ed00121bd.tar
MultiMC-bd64cda6726e088ebc860c3fc3ee220ed00121bd.tar.gz
MultiMC-bd64cda6726e088ebc860c3fc3ee220ed00121bd.tar.lz
MultiMC-bd64cda6726e088ebc860c3fc3ee220ed00121bd.tar.xz
MultiMC-bd64cda6726e088ebc860c3fc3ee220ed00121bd.zip
Added instance setting overrides.
-rw-r--r--libinstance/include/instance.h64
-rw-r--r--libinstance/src/instance.cpp46
-rw-r--r--libsettings/CMakeLists.txt4
-rw-r--r--libsettings/include/inisettingsobject.h59
-rw-r--r--libsettings/include/overridesetting.h43
-rw-r--r--libsettings/src/inisettingsobject.cpp49
-rw-r--r--libsettings/src/overridesetting.cpp30
-rw-r--r--plugins/stdinstance/stdinstance.cpp3
-rw-r--r--plugins/stdinstance/stdinstance.h4
9 files changed, 241 insertions, 61 deletions
diff --git a/libinstance/include/instance.h b/libinstance/include/instance.h
index 5a9a7b02..9c89fbc3 100644
--- a/libinstance/include/instance.h
+++ b/libinstance/include/instance.h
@@ -76,13 +76,7 @@ public:
virtual InstanceList *instList() const;
- //////// FIELDS AND SETTINGS ////////
- // Fields are options stored in the instance's config file that are specific
- // to instances (not a part of SettingsBase). Settings are things overridden
- // from SettingsBase.
-
-
- ////// Fields //////
+ //////// INSTANCE INFO ////////
//// General Info ////
@@ -92,39 +86,39 @@ public:
* \return The instance's name.
* \sa setName
*/
- virtual QString name() { return getField("name", "Unnamed Instance").value<QString>(); }
+ virtual QString name() { return settings().get("name").toString(); }
/*!
* \brief Sets the instance's name
* \param val The instance's new name.
*/
- virtual void setName(QString val) { setField("name", val); }
+ virtual void setName(QString val) { settings().set("name", val); }
/*!
* \brief Gets the instance's icon key.
* \return The instance's icon key.
* \sa setIconKey()
*/
- virtual QString iconKey() const { return getField("iconKey", "default").value<QString>(); }
+ virtual QString iconKey() const { return settings().get("iconKey").toString(); }
/*!
* \brief Sets the instance's icon key.
* \param val The new icon key.
*/
- virtual void setIconKey(QString val) { setField("iconKey", val); }
+ virtual void setIconKey(QString val) { settings().set("iconKey", val); }
/*!
* \brief Gets the instance's notes.
* \return The instances notes.
*/
- virtual QString notes() const { return getField("notes", "").value<QString>(); }
+ virtual QString notes() const { return settings().get("notes").toString(); }
/*!
* \brief Sets the instance's notes.
* \param val The instance's new notes.
*/
- virtual void setNotes(QString val) { setField("notes", val); }
+ virtual void setNotes(QString val) { settings().set("notes", val); }
/*!
@@ -134,13 +128,13 @@ public:
* the jar mod list changes.
* \return Whether or not the instance's jar file should be rebuilt.
*/
- virtual bool shouldRebuild() const { return getField("NeedsRebuild", false).value<bool>(); }
+ virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); }
/*!
* \brief Sets whether or not the instance's minecraft.jar needs to be rebuilt.
* \param val Whether the instance's minecraft needs to be rebuilt or not.
*/
- virtual void setShouldRebuild(bool val) { setField("NeedsRebuild", val); }
+ virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
//// Version Stuff ////
@@ -152,7 +146,7 @@ public:
* This value is updated by the updateCurrentVersion() function.
* \return A string representing the instance's current version.
*/
- virtual QString currentVersion() { return getField("JarVersion", "Unknown").value<QString>(); }
+ virtual QString currentVersion() { return settings().get("JarVersion").toString(); }
/*!
* \brief Sets the instance's current version.
@@ -160,7 +154,7 @@ public:
* mess with this unless you know what you're doing.
* \param val The new value.
*/
- virtual void setCurrentVersion(QString val) { setField("JarVersion", val); }
+ virtual void setCurrentVersion(QString val) { settings().set("JarVersion", val); }
/*!
@@ -169,13 +163,13 @@ public:
* defaults to "Mojang"
* \return The instance's LWJGL version.
*/
- virtual QString lwjglVersion() { return getField("LwjglVersion", "Mojang").value<QString>(); }
+ virtual QString lwjglVersion() { return settings().get("LwjglVersion").toString(); }
/*!
* \brief Sets the version of LWJGL that this instance should use.
* \param val The LWJGL version to use
*/
- virtual void setLWJGLVersion(QString val) { setField("LwjglVersion", val); }
+ virtual void setLWJGLVersion(QString val) { settings().set("LwjglVersion", val); }
/*!
@@ -184,13 +178,13 @@ public:
* download the intended version when it launches.
* \return The instance's intended version.
*/
- virtual QString intendedVersion() { return getField("IntendedJarVersion", currentVersion()).value<QString>(); }
+ virtual QString intendedVersion() { return settings().get("IntendedJarVersion").toString(); }
/*!
* \brief Sets the version that this instance should try to update to.
* \param val The instance's new intended version.
*/
- virtual void setIntendedVersion(QString val) { setField("IntendedJarVersion", val); }
+ virtual void setIntendedVersion(QString val) { settings().set("IntendedJarVersion", val); }
@@ -201,14 +195,14 @@ public:
* Measured in milliseconds since epoch. QDateTime::currentMSecsSinceEpoch()
* \return The time that the instance was last launched.
*/
- virtual qint64 lastLaunch() { return getField("lastLaunchTime", 0).value<qint64>(); }
+ virtual qint64 lastLaunch() { return settings().get("lastLaunchTime").value<qint64>(); }
/*!
* \brief Sets the time that the instance was last launched.
* \param val The time to set. Defaults to QDateTime::currentMSecsSinceEpoch()
*/
virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
- { setField("lastLaunchTime", val); }
+ { settings().set("lastLaunchTime", val); }
////// Directories //////
@@ -290,31 +284,11 @@ public:
* This settings object stores instance-specific settings.
* \return A pointer to this instance's settings object.
*/
- virtual SettingsObject &settings();
-
-protected:
- /*!
- * \brief Gets the value of the given field in the instance's config file.
- * If the value isn't in the config file, defVal is returned instead.
- * \param name The name of the field in the config file.
- * \param defVal The default value.
- * \return The value of the given field or defVal if the field doesn't exist.
- * \sa setField()
- */
- virtual QVariant getField(const QString &name, QVariant defVal = QVariant()) const;
-
- /*!
- * \brief Sets the value of the given field in the config file.
- * \param name The name of the field in the config file.
- * \param val The value to set the field to.
- * \sa getField()
- */
- virtual void setField(const QString &name, QVariant val);
-
- INIFile config;
+ virtual SettingsObject &settings() const;
private:
QString m_rootDir;
+ SettingsObject *m_settings;
};
// pointer for lazy people
diff --git a/libinstance/src/instance.cpp b/libinstance/src/instance.cpp
index 85b43640..377acd32 100644
--- a/libinstance/src/instance.cpp
+++ b/libinstance/src/instance.cpp
@@ -17,7 +17,9 @@
#include <QFileInfo>
-#include "settingsobject.h"
+#include "inisettingsobject.h"
+#include "setting.h"
+#include "overridesetting.h"
#include "pathutils.h"
@@ -25,7 +27,33 @@ Instance::Instance(const QString &rootDir, QObject *parent) :
QObject(parent)
{
m_rootDir = rootDir;
- config.loadFile(PathCombine(rootDir, "instance.cfg"));
+ m_settings = new INISettingsObject(PathCombine(rootDir, "instance.cfg"), this);
+
+ settings().registerSetting(new Setting("name", "Unnamed Instance"));
+ settings().registerSetting(new Setting("iconKey", "default"));
+ settings().registerSetting(new Setting("notes", ""));
+ settings().registerSetting(new Setting("NeedsRebuild", true));
+ settings().registerSetting(new Setting("JarVersion", "Unknown"));
+ settings().registerSetting(new Setting("LwjglVersion", "Mojang"));
+ settings().registerSetting(new Setting("IntendedJarVersion", ""));
+ settings().registerSetting(new Setting("lastLaunchTime", 0));
+
+ // Java Settings
+ settings().registerSetting(new OverrideSetting("JavaPath", globalSettings->getSetting("JavaPath")));
+ settings().registerSetting(new OverrideSetting("JvmArgs", globalSettings->getSetting("JvmArgs")));
+
+ // Custom Commands
+ settings().registerSetting(new OverrideSetting("PreLaunchCommand",
+ globalSettings->getSetting("PreLaunchCommand")));
+ settings().registerSetting(new OverrideSetting("PostExitCommand",
+ globalSettings->getSetting("PostExitCommand")));
+
+ // Memory
+ settings().registerSetting(new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc")));
+ settings().registerSetting(new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc")));
+
+ // Auto login
+ settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin")));
}
QString Instance::id() const
@@ -97,17 +125,7 @@ QString Instance::mcJar() const
return PathCombine(binDir(), "minecraft.jar");
}
-QVariant Instance::getField(const QString &name, QVariant defVal) const
-{
- return config.get(name, defVal);
-}
-
-void Instance::setField(const QString &name, QVariant val)
-{
- config.set(name, val);
-}
-
-SettingsObject &Instance::settings()
+SettingsObject &Instance::settings() const
{
- return *globalSettings;
+ return *m_settings;
}
diff --git a/libsettings/CMakeLists.txt b/libsettings/CMakeLists.txt
index 4040032d..4ec019a5 100644
--- a/libsettings/CMakeLists.txt
+++ b/libsettings/CMakeLists.txt
@@ -15,15 +15,19 @@ include/libsettings_config.h
include/settingsobject.h
include/setting.h
+include/overridesetting.h
include/basicsettingsobject.h
+include/inisettingsobject.h
)
SET(LIBSETTINGS_SOURCES
src/settingsobject.cpp
src/setting.cpp
+src/overridesetting.cpp
src/basicsettingsobject.cpp
+src/inisettingsobject.cpp
)
# Set the include dir path.
diff --git a/libsettings/include/inisettingsobject.h b/libsettings/include/inisettingsobject.h
new file mode 100644
index 00000000..6eead951
--- /dev/null
+++ b/libsettings/include/inisettingsobject.h
@@ -0,0 +1,59 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INISETTINGSOBJECT_H
+#define INISETTINGSOBJECT_H
+
+#include <QObject>
+
+#include <inifile.h>
+
+#include "settingsobject.h"
+
+#include "libutil_config.h"
+
+/*!
+ * \brief A settings object that stores its settings in an INIFile.
+ */
+class LIBMMCSETTINGS_EXPORT INISettingsObject : public SettingsObject
+{
+ Q_OBJECT
+public:
+ explicit INISettingsObject(const QString &path, QObject *parent = 0);
+
+ /*!
+ * \brief Gets the path to the INI file.
+ * \return The path to the INI file.
+ */
+ virtual QString filePath() const { return m_filePath; }
+
+ /*!
+ * \brief Sets the path to the INI file and reloads it.
+ * \param filePath The INI file's new path.
+ */
+ virtual void setFilePath(const QString &filePath);
+
+protected slots:
+ virtual void changeSetting(const Setting &setting, QVariant value);
+
+protected:
+ virtual QVariant retrieveValue(const Setting &setting);
+
+ INIFile m_ini;
+
+ QString m_filePath;
+};
+
+#endif // INISETTINGSOBJECT_H
diff --git a/libsettings/include/overridesetting.h b/libsettings/include/overridesetting.h
new file mode 100644
index 00000000..e7bf2c32
--- /dev/null
+++ b/libsettings/include/overridesetting.h
@@ -0,0 +1,43 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OVERRIDESETTING_H
+#define OVERRIDESETTING_H
+
+#include <QObject>
+
+#include "setting.h"
+
+#include "libsettings_config.h"
+
+/*!
+ * \brief A setting that 'overrides another.'
+ * This means that the setting's default value will be the value of another setting.
+ * The other setting can be (and usually is) a part of a different SettingsObject
+ * than this one.
+ */
+class LIBMMCSETTINGS_EXPORT OverrideSetting : public Setting
+{
+ Q_OBJECT
+public:
+ explicit OverrideSetting(const QString &name, Setting *other, QObject *parent = 0);
+
+ virtual QVariant defValue() const;
+
+protected:
+ Setting *m_other;
+};
+
+#endif // OVERRIDESETTING_H
diff --git a/libsettings/src/inisettingsobject.cpp b/libsettings/src/inisettingsobject.cpp
new file mode 100644
index 00000000..75228865
--- /dev/null
+++ b/libsettings/src/inisettingsobject.cpp
@@ -0,0 +1,49 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/inisettingsobject.h"
+#include "include/setting.h"
+
+INISettingsObject::INISettingsObject(const QString &path, QObject *parent) :
+ SettingsObject(parent)
+{
+ m_filePath = path;
+ m_ini.loadFile(path);
+}
+
+void INISettingsObject::setFilePath(const QString &filePath)
+{
+ m_filePath = filePath;
+}
+
+void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
+{
+ if (contains(setting.id()))
+ {
+ m_ini.set(setting.configKey(), value);
+ }
+}
+
+QVariant INISettingsObject::retrieveValue(const Setting &setting)
+{
+ if (contains(setting.id()))
+ {
+ return m_ini.get(setting.configKey(), QVariant());
+ }
+ else
+ {
+ return QVariant();
+ }
+}
diff --git a/libsettings/src/overridesetting.cpp b/libsettings/src/overridesetting.cpp
new file mode 100644
index 00000000..eafb298f
--- /dev/null
+++ b/libsettings/src/overridesetting.cpp
@@ -0,0 +1,30 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/overridesetting.h"
+
+OverrideSetting::OverrideSetting(const QString &name, Setting *other, QObject *parent) :
+ Setting(name, QVariant(), parent)
+{
+ m_other = other;
+}
+
+QVariant OverrideSetting::defValue() const
+{
+ if (m_other)
+ return m_other->get();
+ else
+ return QVariant();
+}
diff --git a/plugins/stdinstance/stdinstance.cpp b/plugins/stdinstance/stdinstance.cpp
index 12d86bbc..217514a3 100644
--- a/plugins/stdinstance/stdinstance.cpp
+++ b/plugins/stdinstance/stdinstance.cpp
@@ -17,11 +17,14 @@
#include <QFileInfo>
+#include <setting.h>
+
#include <javautils.h>
StdInstance::StdInstance(const QString &rootDir, QObject *parent) :
Instance(rootDir, parent)
{
+ settings().registerSetting(new Setting("lastVersionUpdate", 0));
}
diff --git a/plugins/stdinstance/stdinstance.h b/plugins/stdinstance/stdinstance.h
index d812a9b0..d657d9aa 100644
--- a/plugins/stdinstance/stdinstance.h
+++ b/plugins/stdinstance/stdinstance.h
@@ -29,8 +29,8 @@ public:
virtual void updateCurrentVersion(bool keepCurrent);
////// TIMESTAMPS //////
- virtual qint64 lastVersionUpdate() { return getField("lastVersionUpdate", 0).value<qint64>(); }
- virtual void setLastVersionUpdate(qint64 val) { setField("lastVersionUpdate", val); }
+ virtual qint64 lastVersionUpdate() { return settings().get("lastVersionUpdate").value<qint64>(); }
+ virtual void setLastVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); }
};
#endif // STDINSTANCE_H