fix: apply client overrides in mrpacks
another oopsie x.x
This commit is contained in:
parent
b3c8f9d508
commit
54144154f9
@ -454,4 +454,47 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList listFolderPaths(QDir root)
|
||||||
|
{
|
||||||
|
auto createAbsPath = [](QFileInfo const& entry) { return FS::PathCombine(entry.path(), entry.fileName()); };
|
||||||
|
|
||||||
|
QStringList entries;
|
||||||
|
|
||||||
|
root.refresh();
|
||||||
|
for (auto entry : root.entryInfoList(QDir::Filter::Files)) {
|
||||||
|
entries.append(createAbsPath(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto entry : root.entryInfoList(QDir::Filter::AllDirs | QDir::Filter::NoDotAndDotDot)) {
|
||||||
|
entries.append(listFolderPaths(createAbsPath(entry)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool overrideFolder(QString overwritten_path, QString override_path)
|
||||||
|
{
|
||||||
|
if (!FS::ensureFolderPathExists(overwritten_path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QStringList paths_to_override;
|
||||||
|
QDir root_override (override_path);
|
||||||
|
for (auto file : listFolderPaths(root_override)) {
|
||||||
|
QString destination = file;
|
||||||
|
destination.replace(override_path, overwritten_path);
|
||||||
|
|
||||||
|
qDebug() << QString("Applying override %1 in %2").arg(file, destination);
|
||||||
|
|
||||||
|
if (QFile::exists(destination))
|
||||||
|
QFile::remove(destination);
|
||||||
|
if (!QFile::rename(file, destination)) {
|
||||||
|
qCritical() << QString("Failed to apply override from %1 to %2").arg(file, destination);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -124,4 +124,8 @@ QString getDesktopDir();
|
|||||||
// call it *name* and assign it the icon *icon*
|
// call it *name* and assign it the icon *icon*
|
||||||
// return true if operation succeeded
|
// return true if operation succeeded
|
||||||
bool createShortCut(QString location, QString dest, QStringList args, QString name, QString iconLocation);
|
bool createShortCut(QString location, QString dest, QStringList args, QString name, QString iconLocation);
|
||||||
|
|
||||||
|
// Overrides one folder with the contents of another, preserving items exclusive to the first folder
|
||||||
|
// Equivalent to doing QDir::rename, but allowing for overrides
|
||||||
|
bool overrideFolder(QString overwritten_path, QString override_path);
|
||||||
}
|
}
|
||||||
|
@ -697,15 +697,25 @@ void InstanceImportTask::processModrinth()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString overridePath = FS::PathCombine(m_stagingPath, "overrides");
|
auto mcPath = FS::PathCombine(m_stagingPath, ".minecraft");
|
||||||
if (QFile::exists(overridePath)) {
|
|
||||||
QString mcPath = FS::PathCombine(m_stagingPath, ".minecraft");
|
auto override_path = FS::PathCombine(m_stagingPath, "overrides");
|
||||||
if (!QFile::rename(overridePath, mcPath)) {
|
if (QFile::exists(override_path)) {
|
||||||
|
if (!QFile::rename(override_path, mcPath)) {
|
||||||
emitFailed(tr("Could not rename the overrides folder:\n") + "overrides");
|
emitFailed(tr("Could not rename the overrides folder:\n") + "overrides");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do client overrides
|
||||||
|
auto client_override_path = FS::PathCombine(m_stagingPath, "client-overrides");
|
||||||
|
if (QFile::exists(client_override_path)) {
|
||||||
|
if (!FS::overrideFolder(mcPath, client_override_path)) {
|
||||||
|
emitFailed(tr("Could not rename the client overrides folder:\n") + "client overrides");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
||||||
auto instanceSettings = std::make_shared<INISettingsObject>(configPath);
|
auto instanceSettings = std::make_shared<INISettingsObject>(configPath);
|
||||||
MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
|
MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
|
||||||
|
Loading…
Reference in New Issue
Block a user