mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-04 04:16:57 +03:00
ensure that save lock isunlocked on success
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
(cherry picked from commit 464a04a2cb)
This commit is contained in:
parent
7842174e5e
commit
add722b8d3
3 changed files with 166 additions and 162 deletions
|
|
@ -134,76 +134,78 @@ void PackInstallTask::install()
|
|||
|
||||
QString instanceConfigPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
||||
MinecraftInstance instance(m_globalSettings, std::make_unique<INISettingsObject>(instanceConfigPath), m_stagingPath);
|
||||
SettingsObject::Lock lock(instance.settings());
|
||||
{
|
||||
SettingsObject::Lock lock(instance.settings());
|
||||
|
||||
auto components = instance.getPackProfile();
|
||||
components->buildingFromScratch();
|
||||
components->setComponentVersion("net.minecraft", m_pack.mcVersion, true);
|
||||
auto components = instance.getPackProfile();
|
||||
components->buildingFromScratch();
|
||||
components->setComponentVersion("net.minecraft", m_pack.mcVersion, true);
|
||||
|
||||
bool fallback = true;
|
||||
bool fallback = true;
|
||||
|
||||
// handle different versions
|
||||
QFile packJson(m_stagingPath + "/minecraft/pack.json");
|
||||
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
||||
if (packJson.exists()) {
|
||||
if (packJson.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
||||
packJson.close();
|
||||
// handle different versions
|
||||
QFile packJson(m_stagingPath + "/minecraft/pack.json");
|
||||
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
||||
if (packJson.exists()) {
|
||||
if (packJson.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
||||
packJson.close();
|
||||
|
||||
// we only care about the libs
|
||||
QJsonArray libs = doc.object().value("libraries").toArray();
|
||||
// we only care about the libs
|
||||
QJsonArray libs = doc.object().value("libraries").toArray();
|
||||
|
||||
for (const auto& value : libs) {
|
||||
QString nameValue = value.toObject().value("name").toString();
|
||||
if (!nameValue.startsWith("net.minecraftforge")) {
|
||||
continue;
|
||||
for (const auto& value : libs) {
|
||||
QString nameValue = value.toObject().value("name").toString();
|
||||
if (!nameValue.startsWith("net.minecraftforge")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GradleSpecifier forgeVersion(nameValue);
|
||||
|
||||
components->setComponentVersion("net.minecraftforge",
|
||||
forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
|
||||
packJson.remove();
|
||||
fallback = false;
|
||||
break;
|
||||
}
|
||||
|
||||
GradleSpecifier forgeVersion(nameValue);
|
||||
|
||||
components->setComponentVersion("net.minecraftforge",
|
||||
forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
|
||||
packJson.remove();
|
||||
fallback = false;
|
||||
break;
|
||||
} else {
|
||||
qWarning() << "Failed to open file '" << packJson.fileName() << "' for reading!";
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Failed to open file '" << packJson.fileName() << "' for reading!";
|
||||
}
|
||||
}
|
||||
|
||||
if (jarmodDir.exists()) {
|
||||
qDebug() << "Found jarmods, installing...";
|
||||
|
||||
QStringList jarmods;
|
||||
for (auto info : jarmodDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files)) {
|
||||
qDebug() << "Jarmod:" << info.fileName();
|
||||
jarmods.push_back(info.absoluteFilePath());
|
||||
}
|
||||
|
||||
components->installJarMods(jarmods);
|
||||
fallback = false;
|
||||
if (jarmodDir.exists()) {
|
||||
qDebug() << "Found jarmods, installing...";
|
||||
|
||||
QStringList jarmods;
|
||||
for (auto info : jarmodDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files)) {
|
||||
qDebug() << "Jarmod:" << info.fileName();
|
||||
jarmods.push_back(info.absoluteFilePath());
|
||||
}
|
||||
|
||||
components->installJarMods(jarmods);
|
||||
fallback = false;
|
||||
}
|
||||
|
||||
// just nuke unzip directory, it s not needed anymore
|
||||
FS::deletePath(m_stagingPath + "/unzip");
|
||||
|
||||
if (fallback) {
|
||||
// TODO: Some fallback mechanism... or just keep failing!
|
||||
emitFailed(tr("No installation method found!"));
|
||||
return;
|
||||
}
|
||||
|
||||
components->saveNow();
|
||||
|
||||
progress(4, 4);
|
||||
|
||||
instance.setName(name());
|
||||
if (m_instIcon == "default") {
|
||||
m_instIcon = "ftb_logo";
|
||||
}
|
||||
instance.setIconKey(m_instIcon);
|
||||
}
|
||||
|
||||
// just nuke unzip directory, it s not needed anymore
|
||||
FS::deletePath(m_stagingPath + "/unzip");
|
||||
|
||||
if (fallback) {
|
||||
// TODO: Some fallback mechanism... or just keep failing!
|
||||
emitFailed(tr("No installation method found!"));
|
||||
return;
|
||||
}
|
||||
|
||||
components->saveNow();
|
||||
|
||||
progress(4, 4);
|
||||
|
||||
instance.setName(name());
|
||||
if (m_instIcon == "default") {
|
||||
m_instIcon = "ftb_logo";
|
||||
}
|
||||
instance.setIconKey(m_instIcon);
|
||||
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue