Merge pull request #5163 from arthomnix/feature/mrpack-export-optional-files

GH-5146 mrpack exporter: add option to treat disabled files as optional
This commit is contained in:
Petr Mrázek 2023-05-24 10:02:48 +02:00 committed by GitHub
commit 35783d9dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 5 deletions

View File

@ -29,15 +29,24 @@ void InstanceExportTask::executeTask()
QDir modsDir(m_instance->gameRoot() + "/mods");
modsDir.setFilter(QDir::Files);
modsDir.setNameFilters(QStringList() << "*.jar");
QStringList modsFilter = { "*.jar" };
if (m_settings.treatDisabledAsOptional) {
modsFilter << "*.jar.disabled";
}
modsDir.setNameFilters(modsFilter);
QStringList zipFilter = { "*.zip" };
if (m_settings.treatDisabledAsOptional) {
zipFilter << "*.zip.disabled";
}
QDir resourcePacksDir(m_instance->gameRoot() + "/resourcepacks");
resourcePacksDir.setFilter(QDir::Files);
resourcePacksDir.setNameFilters(QStringList() << "*.zip");
resourcePacksDir.setNameFilters(zipFilter);
QDir shaderPacksDir(m_instance->gameRoot() + "/shaderpacks");
shaderPacksDir.setFilter(QDir::Files);
shaderPacksDir.setNameFilters(QStringList() << "*.zip");
shaderPacksDir.setNameFilters(zipFilter);
QStringList filesToResolve;
@ -132,7 +141,13 @@ void InstanceExportTask::lookupSucceeded()
QDir gameDir(m_instance->gameRoot());
fileData.path = gameDir.relativeFilePath(file.fileInfo.absoluteFilePath());
QString path = file.fileInfo.absoluteFilePath();
if (path.endsWith(".disabled")) {
fileData.optional = true;
path = path.left(path.length() - QString(".disabled").length());
}
fileData.path = gameDir.relativeFilePath(path);
fileData.download = url;
fileData.sha512 = sha512Hash;
fileData.sha1 = sha1Hash;
@ -175,6 +190,13 @@ void InstanceExportTask::lookupSucceeded()
fileObj.insert("fileSize", QJsonValue(file.fileSize));
if (file.optional) {
QJsonObject env;
env.insert("client", "optional");
env.insert("server", "optional");
fileObj.insert("env", env);
}
files.append(fileObj);
}

View File

@ -26,6 +26,7 @@ struct ExportSettings
bool includeModConfigs;
bool includeResourcePacks;
bool includeShaderPacks;
bool treatDisabledAsOptional;
QString datapacksPath;
QString gameVersion;
@ -44,6 +45,7 @@ struct ExportFile
QString sha1;
QString download;
qint64 fileSize;
bool optional = false;
};
class InstanceExportTask : public Task

View File

@ -81,6 +81,7 @@ void ModrinthExportDialog::accept()
settings.includeModConfigs = ui->includeModConfigs->isChecked();
settings.includeResourcePacks = ui->includeResourcePacks->isChecked();
settings.includeShaderPacks = ui->includeShaderPacks->isChecked();
settings.treatDisabledAsOptional = ui->treatDisabledAsOptional->isChecked();
if (ui->includeDatapacks->isChecked()) {
settings.datapacksPath = ui->datapacksPath->text();

View File

@ -112,7 +112,7 @@
<x>9</x>
<y>29</y>
<width>801</width>
<height>221</height>
<height>227</height>
</rect>
</property>
<layout class="QVBoxLayout" name="optionsLayout">
@ -174,6 +174,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="treatDisabledAsOptional">
<property name="toolTip">
<string>If enabled, all mods, shaders and resource packs that are available on Modrinth will be treated as optional on both client and server. Files that are unavailable on Modrinth will simply retain the &quot;.disabled&quot; extension as Modrinth packs don't support optional overrides.</string>
</property>
<property name="text">
<string>Treat disabled mods, shaders and resource packs as optional</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>