NOISSUE force saving of any outstanding instance component state on exit
This commit is contained in:
parent
e0bea1e46a
commit
95e6f37d39
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -12,7 +12,10 @@ public:
|
||||
virtual ~NullInstance() {};
|
||||
virtual void init() override
|
||||
{
|
||||
};
|
||||
}
|
||||
virtual void saveNow() override
|
||||
{
|
||||
}
|
||||
virtual QString getStatusbarDescription() override
|
||||
{
|
||||
return tr("Unknown instance type");
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -115,6 +115,11 @@ void MinecraftInstance::init()
|
||||
{
|
||||
}
|
||||
|
||||
void MinecraftInstance::saveNow()
|
||||
{
|
||||
m_components->saveNow();
|
||||
}
|
||||
|
||||
QString MinecraftInstance::typeName() const
|
||||
{
|
||||
return "Minecraft";
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user