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 ~BaseInstance() {};
|
||||||
|
|
||||||
virtual void init() = 0;
|
virtual void init() = 0;
|
||||||
|
virtual void saveNow() = 0;
|
||||||
|
|
||||||
/// nuke thoroughly - deletes the instance contents, notifies the list/model which is
|
/// nuke thoroughly - deletes the instance contents, notifies the list/model which is
|
||||||
/// responsible of cleaning up the husk
|
/// responsible of cleaning up the husk
|
||||||
|
@ -241,6 +241,14 @@ InstanceList::InstListError InstanceList::loadList(bool complete)
|
|||||||
return NoError;
|
return NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InstanceList::saveNow()
|
||||||
|
{
|
||||||
|
for(auto & item: m_instances)
|
||||||
|
{
|
||||||
|
item->saveNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InstanceList::add(const QList<InstancePtr> &t)
|
void InstanceList::add(const QList<InstancePtr> &t)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), m_instances.count(), m_instances.count() + t.size() - 1);
|
beginInsertRows(QModelIndex(), m_instances.count(), m_instances.count() + t.size() - 1);
|
||||||
|
@ -73,6 +73,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstListError loadList(bool complete = false);
|
InstListError loadList(bool complete = false);
|
||||||
|
void saveNow();
|
||||||
|
|
||||||
/// Add an instance provider. Takes ownership of it. Should only be done before the first load.
|
/// Add an instance provider. Takes ownership of it. Should only be done before the first load.
|
||||||
void addInstanceProvider(BaseInstanceProvider * provider);
|
void addInstanceProvider(BaseInstanceProvider * provider);
|
||||||
|
@ -12,7 +12,10 @@ public:
|
|||||||
virtual ~NullInstance() {};
|
virtual ~NullInstance() {};
|
||||||
virtual void init() override
|
virtual void init() override
|
||||||
{
|
{
|
||||||
};
|
}
|
||||||
|
virtual void saveNow() override
|
||||||
|
{
|
||||||
|
}
|
||||||
virtual QString getStatusbarDescription() override
|
virtual QString getStatusbarDescription() override
|
||||||
{
|
{
|
||||||
return tr("Unknown instance type");
|
return tr("Unknown instance type");
|
||||||
|
@ -43,16 +43,12 @@ ComponentList::ComponentList(MinecraftInstance * instance)
|
|||||||
d->m_instance = instance;
|
d->m_instance = instance;
|
||||||
d->m_saveTimer.setSingleShot(true);
|
d->m_saveTimer.setSingleShot(true);
|
||||||
d->m_saveTimer.setInterval(5000);
|
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()
|
ComponentList::~ComponentList()
|
||||||
{
|
{
|
||||||
if(saveIsScheduled())
|
saveNow();
|
||||||
{
|
|
||||||
d->m_saveTimer.stop();
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BEGIN: component file format
|
// BEGIN: component file format
|
||||||
@ -212,6 +208,15 @@ static bool loadComponentList(ComponentList * parent, const QString & filename,
|
|||||||
|
|
||||||
// BEGIN: save/load logic
|
// BEGIN: save/load logic
|
||||||
|
|
||||||
|
void ComponentList::saveNow()
|
||||||
|
{
|
||||||
|
if(saveIsScheduled())
|
||||||
|
{
|
||||||
|
d->m_saveTimer.stop();
|
||||||
|
save_internal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ComponentList::saveIsScheduled() const
|
bool ComponentList::saveIsScheduled() const
|
||||||
{
|
{
|
||||||
return d->dirty;
|
return d->dirty;
|
||||||
@ -253,7 +258,7 @@ QString ComponentList::patchFilePathForUid(const QString& uid) const
|
|||||||
return patchesPattern().arg(uid);
|
return patchesPattern().arg(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComponentList::save()
|
void ComponentList::save_internal()
|
||||||
{
|
{
|
||||||
qDebug() << "Component list save performed now for" << d->m_instance->name();
|
qDebug() << "Component list save performed now for" << d->m_instance->name();
|
||||||
auto filename = componentsFilePath();
|
auto filename = componentsFilePath();
|
||||||
@ -321,10 +326,7 @@ void ComponentList::reload(Net::Mode netmode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// flush any scheduled saves to not lose state
|
// flush any scheduled saves to not lose state
|
||||||
if(saveIsScheduled())
|
saveNow();
|
||||||
{
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: differentiate when a reapply is required by propagating state from components
|
// FIXME: differentiate when a reapply is required by propagating state from components
|
||||||
invalidateLaunchProfile();
|
invalidateLaunchProfile();
|
||||||
|
@ -104,6 +104,10 @@ public:
|
|||||||
bool setComponentVersion(const QString &uid, const QString &version, bool important = false);
|
bool setComponentVersion(const QString &uid, const QString &version, bool important = false);
|
||||||
|
|
||||||
QString patchFilePathForUid(const QString &uid) const;
|
QString patchFilePathForUid(const QString &uid) const;
|
||||||
|
|
||||||
|
/// if there is a save scheduled, do it now.
|
||||||
|
void saveNow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// get the profile component by id
|
/// get the profile component by id
|
||||||
ComponentPtr getComponent(const QString &id);
|
ComponentPtr getComponent(const QString &id);
|
||||||
@ -127,7 +131,7 @@ private:
|
|||||||
QString patchesPattern() const;
|
QString patchesPattern() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void save();
|
void save_internal();
|
||||||
void updateSucceeded();
|
void updateSucceeded();
|
||||||
void updateFailed(const QString & error);
|
void updateFailed(const QString & error);
|
||||||
void componentDataChanged();
|
void componentDataChanged();
|
||||||
|
@ -115,6 +115,11 @@ void MinecraftInstance::init()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MinecraftInstance::saveNow()
|
||||||
|
{
|
||||||
|
m_components->saveNow();
|
||||||
|
}
|
||||||
|
|
||||||
QString MinecraftInstance::typeName() const
|
QString MinecraftInstance::typeName() const
|
||||||
{
|
{
|
||||||
return "Minecraft";
|
return "Minecraft";
|
||||||
|
@ -18,6 +18,7 @@ public:
|
|||||||
MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
|
MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
|
||||||
virtual ~MinecraftInstance() {};
|
virtual ~MinecraftInstance() {};
|
||||||
virtual void init() override;
|
virtual void init() override;
|
||||||
|
virtual void saveNow();
|
||||||
|
|
||||||
// FIXME: remove
|
// FIXME: remove
|
||||||
QString typeName() const override;
|
QString typeName() const override;
|
||||||
|
@ -34,7 +34,8 @@ public:
|
|||||||
|
|
||||||
explicit LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
|
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
|
/// Path to the instance's minecraft.jar
|
||||||
QString runnableJar() const;
|
QString runnableJar() const;
|
||||||
|
@ -644,7 +644,8 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
connect(this, &MultiMC::aboutToQuit, [this](){
|
connect(this, &MultiMC::aboutToQuit, [this](){
|
||||||
if(m_instances)
|
if(m_instances)
|
||||||
{
|
{
|
||||||
// m_instances->saveGroupList();
|
// save any remaining instance state
|
||||||
|
m_instances->saveNow();
|
||||||
}
|
}
|
||||||
if(logFile)
|
if(logFile)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user