NOISSUE force saving of any outstanding instance component state on exit

This commit is contained in:
Petr Mrázek 2017-12-03 18:36:28 +01:00
parent e0bea1e46a
commit 95e6f37d39
10 changed files with 42 additions and 15 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -12,7 +12,10 @@ public:
virtual ~NullInstance() {};
virtual void init() override
{
};
}
virtual void saveNow() override
{
}
virtual QString getStatusbarDescription() override
{
return tr("Unknown instance type");

View File

@ -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();

View File

@ -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();

View File

@ -115,6 +115,11 @@ void MinecraftInstance::init()
{
}
void MinecraftInstance::saveNow()
{
m_components->saveNow();
}
QString MinecraftInstance::typeName() const
{
return "Minecraft";

View File

@ -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;

View File

@ -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;

View File

@ -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)
{