NOISSUE do not crash when mmc-pack.json is corrupted or missing Minecraft

This commit is contained in:
Petr Mrázek 2024-12-21 01:14:50 +01:00
parent a026fabd20
commit c7ba800bd4
6 changed files with 47 additions and 15 deletions

View File

@ -49,7 +49,11 @@ void MinecraftUpdate::executeTask()
// add metadata update task if necessary
{
auto components = m_inst->getPackProfile();
components->reload(Net::Mode::Online);
if(!components->reload(Net::Mode::Online))
{
emitFailed(tr("Failed to load version components - mmc-pack.json is probably corrupted."));
return;
}
auto task = components->getCurrentTask();
if(task)
{

View File

@ -289,6 +289,7 @@ bool PackProfile::load()
ComponentContainer newComponents;
if(!loadPackProfile(this, filename, patchesPattern(), newComponents))
{
// FIXME: convert this to an error type?
qCritical() << "Failed to load the component config for instance" << d->m_instance->name();
return false;
}
@ -320,12 +321,12 @@ bool PackProfile::load()
}
}
void PackProfile::reload(Net::Mode netmode)
bool PackProfile::reload(Net::Mode netmode)
{
// Do not reload when the update/resolve task is running. It is in control.
if(d->m_updateTask)
{
return;
return true;
}
// flush any scheduled saves to not lose state
@ -334,10 +335,13 @@ void PackProfile::reload(Net::Mode netmode)
// FIXME: differentiate when a reapply is required by propagating state from components
invalidateLaunchProfile();
if(load())
if(!load())
{
resolve(netmode);
// FIXME: propagate reason for failure
return false;
}
resolve(netmode);
return true;
}
Task::Ptr PackProfile::getCurrentTask()

View File

@ -79,7 +79,7 @@ public:
bool revertToBase(int index);
/// reload the list, reload all components, resolve dependencies
void reload(Net::Mode netmode);
bool reload(Net::Mode netmode);
// reload all components, resolve dependencies
void resolve(Net::Mode netmode);

View File

@ -32,8 +32,18 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
bool supportsQuickPlay = false;
auto *mcInst = dynamic_cast<MinecraftInstance *>(inst);
if (mcInst && mcInst->getPackProfile()->getComponent("net.minecraft")->getReleaseDateTime() >= g_VersionFilterData.quickPlayBeginsDate)
if (mcInst)
{
auto minecraftComponent = mcInst->getPackProfile()->getComponent("net.minecraft");
if(minecraftComponent && minecraftComponent->getReleaseDateTime() >= g_VersionFilterData.quickPlayBeginsDate)
{
supportsQuickPlay = true;
}
}
if(supportsQuickPlay)
{
mcInst->worldList()->update();
for (const auto &world : mcInst->worldList()->allWorlds())

View File

@ -210,17 +210,23 @@ void VersionPage::updateRunningStatus(bool running)
void VersionPage::updateVersionControls()
{
// FIXME: This is better than the broken stuff we had before, but it would probably be better to handle this in meta somehow
auto minecraftReleaseDate = m_profile->getComponent("net.minecraft")->getReleaseDateTime();
bool supportsFabric = false;
bool supportsLiteLoader = false;
bool supportsNeoForge = false;
auto component = m_profile->getComponent("net.minecraft");
if(component)
{
// FIXME: This is better than the broken stuff we had before, but it would probably be better to handle this in meta somehow
auto minecraftReleaseDate = m_profile->getComponent("net.minecraft")->getReleaseDateTime();
supportsFabric = minecraftReleaseDate >= g_VersionFilterData.fabricBeginsDate;
supportsLiteLoader = minecraftReleaseDate <= g_VersionFilterData.liteLoaderEndsDate;
supportsNeoForge = minecraftReleaseDate >= g_VersionFilterData.neoForgeBeginsDate;
}
bool supportsFabric = minecraftReleaseDate >= g_VersionFilterData.fabricBeginsDate;
ui->actionInstall_Fabric->setEnabled(controlsEnabled && supportsFabric);
ui->actionInstall_Quilt->setEnabled((controlsEnabled) && supportsFabric);
bool supportsLiteLoader = minecraftReleaseDate <= g_VersionFilterData.liteLoaderEndsDate;
ui->actionInstall_LiteLoader->setEnabled(controlsEnabled && supportsLiteLoader);
bool supportsNeoForge = minecraftReleaseDate >= g_VersionFilterData.neoForgeBeginsDate;
ui->actionInstall_NeoForge->setEnabled(controlsEnabled && supportsNeoForge);
updateButtons();

View File

@ -314,7 +314,15 @@ void WorldListPage::mceditState(LoggedProcess::State state)
void WorldListPage::worldChanged(const QModelIndex &current, const QModelIndex &previous)
{
auto mcInst = std::dynamic_pointer_cast<MinecraftInstance>(m_inst);
bool enableJoinActions = mcInst && mcInst->getPackProfile()->getComponent("net.minecraft")->getReleaseDateTime() >= g_VersionFilterData.quickPlayBeginsDate;
bool enableJoinActions = false;
if(mcInst)
{
auto minecraftComponent = mcInst->getPackProfile()->getComponent("net.minecraft");
if(minecraftComponent)
{
enableJoinActions = minecraftComponent->getReleaseDateTime() >= g_VersionFilterData.quickPlayBeginsDate;
}
}
QModelIndex index = getSelectedWorld();
bool enable = index.isValid();