From 95e6f37d3942d4ab681e2f2484f17bbf8489c332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 3 Dec 2017 18:36:28 +0100 Subject: [PATCH] NOISSUE force saving of any outstanding instance component state on exit --- api/logic/BaseInstance.h | 1 + api/logic/InstanceList.cpp | 8 +++++++ api/logic/InstanceList.h | 1 + api/logic/NullInstance.h | 5 ++++- api/logic/minecraft/ComponentList.cpp | 24 +++++++++++---------- api/logic/minecraft/ComponentList.h | 6 +++++- api/logic/minecraft/MinecraftInstance.cpp | 5 +++++ api/logic/minecraft/MinecraftInstance.h | 1 + api/logic/minecraft/legacy/LegacyInstance.h | 3 ++- application/MultiMC.cpp | 3 ++- 10 files changed, 42 insertions(+), 15 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 &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; diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 2c443d6a..7fce31d0 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -644,7 +644,8 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) connect(this, &MultiMC::aboutToQuit, [this](){ if(m_instances) { - // m_instances->saveGroupList(); + // save any remaining instance state + m_instances->saveNow(); } if(logFile) {