summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-12-03 18:36:28 +0100
committerPetr Mrázek <peterix@gmail.com>2017-12-03 18:36:28 +0100
commit95e6f37d3942d4ab681e2f2484f17bbf8489c332 (patch)
tree98cc9231f0d1f2c5c935108aa075c7f0a0b65e7a /api/logic
parente0bea1e46a8086b098248ec506b71e5f4512c70f (diff)
downloadMultiMC-95e6f37d3942d4ab681e2f2484f17bbf8489c332.tar
MultiMC-95e6f37d3942d4ab681e2f2484f17bbf8489c332.tar.gz
MultiMC-95e6f37d3942d4ab681e2f2484f17bbf8489c332.tar.lz
MultiMC-95e6f37d3942d4ab681e2f2484f17bbf8489c332.tar.xz
MultiMC-95e6f37d3942d4ab681e2f2484f17bbf8489c332.zip
NOISSUE force saving of any outstanding instance component state on exit
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/BaseInstance.h1
-rw-r--r--api/logic/InstanceList.cpp8
-rw-r--r--api/logic/InstanceList.h1
-rw-r--r--api/logic/NullInstance.h5
-rw-r--r--api/logic/minecraft/ComponentList.cpp24
-rw-r--r--api/logic/minecraft/ComponentList.h6
-rw-r--r--api/logic/minecraft/MinecraftInstance.cpp5
-rw-r--r--api/logic/minecraft/MinecraftInstance.h1
-rw-r--r--api/logic/minecraft/legacy/LegacyInstance.h3
9 files changed, 40 insertions, 14 deletions
diff --git a/api/logic/BaseInstance.h b/api/logic/BaseInstance.h
index d0909031..b1a594bf 100644
--- a/api/logic/BaseInstance.h
+++ b/api/logic/BaseInstance.h
@@ -70,6 +70,7 @@ public:
virtual ~BaseInstance() {};
virtual void init() = 0;
+ virtual void saveNow() = 0;
/// nuke thoroughly - deletes the instance contents, notifies the list/model which is
/// responsible of cleaning up the husk
diff --git a/api/logic/InstanceList.cpp b/api/logic/InstanceList.cpp
index dbc111fc..96251b60 100644
--- a/api/logic/InstanceList.cpp
+++ b/api/logic/InstanceList.cpp
@@ -241,6 +241,14 @@ InstanceList::InstListError InstanceList::loadList(bool complete)
return NoError;
}
+void InstanceList::saveNow()
+{
+ for(auto & item: m_instances)
+ {
+ item->saveNow();
+ }
+}
+
void InstanceList::add(const QList<InstancePtr> &t)
{
beginInsertRows(QModelIndex(), m_instances.count(), m_instances.count() + t.size() - 1);
diff --git a/api/logic/InstanceList.h b/api/logic/InstanceList.h
index ea4717ff..89be10de 100644
--- a/api/logic/InstanceList.h
+++ b/api/logic/InstanceList.h
@@ -73,6 +73,7 @@ public:
}
InstListError loadList(bool complete = false);
+ void saveNow();
/// Add an instance provider. Takes ownership of it. Should only be done before the first load.
void addInstanceProvider(BaseInstanceProvider * provider);
diff --git a/api/logic/NullInstance.h b/api/logic/NullInstance.h
index 27a8a251..64965277 100644
--- a/api/logic/NullInstance.h
+++ b/api/logic/NullInstance.h
@@ -12,7 +12,10 @@ public:
virtual ~NullInstance() {};
virtual void init() override
{
- };
+ }
+ virtual void saveNow() override
+ {
+ }
virtual QString getStatusbarDescription() override
{
return tr("Unknown instance type");
diff --git a/api/logic/minecraft/ComponentList.cpp b/api/logic/minecraft/ComponentList.cpp
index 93deef39..6547a851 100644
--- a/api/logic/minecraft/ComponentList.cpp
+++ b/api/logic/minecraft/ComponentList.cpp
@@ -43,16 +43,12 @@ ComponentList::ComponentList(MinecraftInstance * instance)
d->m_instance = instance;
d->m_saveTimer.setSingleShot(true);
d->m_saveTimer.setInterval(5000);
- connect(&d->m_saveTimer, &QTimer::timeout, this, &ComponentList::save);
+ connect(&d->m_saveTimer, &QTimer::timeout, this, &ComponentList::save_internal);
}
ComponentList::~ComponentList()
{
- if(saveIsScheduled())
- {
- d->m_saveTimer.stop();
- save();
- }
+ saveNow();
}
// BEGIN: component file format
@@ -212,6 +208,15 @@ static bool loadComponentList(ComponentList * parent, const QString & filename,
// BEGIN: save/load logic
+void ComponentList::saveNow()
+{
+ if(saveIsScheduled())
+ {
+ d->m_saveTimer.stop();
+ save_internal();
+ }
+}
+
bool ComponentList::saveIsScheduled() const
{
return d->dirty;
@@ -253,7 +258,7 @@ QString ComponentList::patchFilePathForUid(const QString& uid) const
return patchesPattern().arg(uid);
}
-void ComponentList::save()
+void ComponentList::save_internal()
{
qDebug() << "Component list save performed now for" << d->m_instance->name();
auto filename = componentsFilePath();
@@ -321,10 +326,7 @@ void ComponentList::reload(Net::Mode netmode)
}
// flush any scheduled saves to not lose state
- if(saveIsScheduled())
- {
- save();
- }
+ saveNow();
// FIXME: differentiate when a reapply is required by propagating state from components
invalidateLaunchProfile();
diff --git a/api/logic/minecraft/ComponentList.h b/api/logic/minecraft/ComponentList.h
index 9cce111b..8e89d640 100644
--- a/api/logic/minecraft/ComponentList.h
+++ b/api/logic/minecraft/ComponentList.h
@@ -104,6 +104,10 @@ public:
bool setComponentVersion(const QString &uid, const QString &version, bool important = false);
QString patchFilePathForUid(const QString &uid) const;
+
+ /// if there is a save scheduled, do it now.
+ void saveNow();
+
public:
/// get the profile component by id
ComponentPtr getComponent(const QString &id);
@@ -127,7 +131,7 @@ private:
QString patchesPattern() const;
private slots:
- void save();
+ void save_internal();
void updateSucceeded();
void updateFailed(const QString & error);
void componentDataChanged();
diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp
index b7deed77..7a0ff6bf 100644
--- a/api/logic/minecraft/MinecraftInstance.cpp
+++ b/api/logic/minecraft/MinecraftInstance.cpp
@@ -115,6 +115,11 @@ void MinecraftInstance::init()
{
}
+void MinecraftInstance::saveNow()
+{
+ m_components->saveNow();
+}
+
QString MinecraftInstance::typeName() const
{
return "Minecraft";
diff --git a/api/logic/minecraft/MinecraftInstance.h b/api/logic/minecraft/MinecraftInstance.h
index 13a3753e..446a39d5 100644
--- a/api/logic/minecraft/MinecraftInstance.h
+++ b/api/logic/minecraft/MinecraftInstance.h
@@ -18,6 +18,7 @@ public:
MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
virtual ~MinecraftInstance() {};
virtual void init() override;
+ virtual void saveNow();
// FIXME: remove
QString typeName() const override;
diff --git a/api/logic/minecraft/legacy/LegacyInstance.h b/api/logic/minecraft/legacy/LegacyInstance.h
index ef590cae..7ff905e7 100644
--- a/api/logic/minecraft/legacy/LegacyInstance.h
+++ b/api/logic/minecraft/legacy/LegacyInstance.h
@@ -34,7 +34,8 @@ public:
explicit LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
- virtual void init() override {};
+ virtual void init() override {}
+ virtual void saveNow() override {}
/// Path to the instance's minecraft.jar
QString runnableJar() const;