diff --git a/launcher/ResourceDownloadTask.cpp b/launcher/ResourceDownloadTask.cpp index 0fe082ac4..c5d9a7c67 100644 --- a/launcher/ResourceDownloadTask.cpp +++ b/launcher/ResourceDownloadTask.cpp @@ -21,9 +21,11 @@ #include "Application.h" +#include "FileSystem.h" #include "minecraft/mod/ModFolderModel.h" #include "minecraft/mod/ResourceFolderModel.h" +#include "minecraft/mod/ShaderPackFolderModel.h" #include "modplatform/helpers/HashUtils.h" #include "net/ApiDownload.h" #include "net/ChecksumValidator.h" @@ -55,7 +57,9 @@ ResourceDownloadTask::ResourceDownloadTask(ModPlatform::IndexedPack::Ptr pack, } } - auto action = Net::ApiDownload::makeFile(m_pack_version.downloadUrl, dir.absoluteFilePath(getFilename())); + m_targetPath = dir.absoluteFilePath(getFilename()); + + auto action = Net::ApiDownload::makeFile(m_pack_version.downloadUrl, m_targetPath); if (!m_pack_version.hash_type.isEmpty() && !m_pack_version.hash.isEmpty()) { switch (Hashing::algorithmFromString(m_pack_version.hash_type)) { case Hashing::Algorithm::Md4: @@ -91,8 +95,25 @@ void ResourceDownloadTask::downloadSucceeded() m_filesNetJob.reset(); auto name = std::get<0>(to_delete); auto filename = std::get<1>(to_delete); - if (!name.isEmpty() && filename != m_pack_version.fileName) - m_pack_model->uninstallResource(filename, true); + + if (name.isEmpty() || filename == m_pack_version.fileName) + return; + + m_pack_model->uninstallResource(filename, true); + + // also rename the shader config file + if (dynamic_cast(m_pack_model.get()) != nullptr) { + QFileInfo config(m_pack_model->dir(), filename + ".txt"); + + if (config.exists()) { + QString src = config.filePath(); + QString dest = m_targetPath + ".txt"; + bool success = QFile::rename(src, dest); + + if (!success) + emit logWarning(tr("Failed to rename shader config '%1' to '%2'").arg(src, dest)); + } + } } void ResourceDownloadTask::downloadFailed(QString reason) diff --git a/launcher/ResourceDownloadTask.h b/launcher/ResourceDownloadTask.h index a10e0ac2c..de599c501 100644 --- a/launcher/ResourceDownloadTask.h +++ b/launcher/ResourceDownloadTask.h @@ -48,6 +48,7 @@ class ResourceDownloadTask : public SequentialTask { ModPlatform::IndexedVersion m_pack_version; const std::shared_ptr m_pack_model; QString m_custom_target_folder; + QString m_targetPath; NetJob::Ptr m_filesNetJob; LocalResourceUpdateTask::Ptr m_update_task; diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index e8b4c862c..785d3f7e5 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -204,7 +204,7 @@ void ResourceFolderModel::installResourceWithFlameMetadata(QString path, ModPlat } } -bool ResourceFolderModel::uninstallResource(QString file_name, bool preserve_metadata) +bool ResourceFolderModel::uninstallResource(const QString& file_name, bool preserve_metadata) { for (auto& resource : m_resources) { if (resource->fileinfo().fileName() == file_name) { diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h index 391c5c0c0..5c41fc520 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.h +++ b/launcher/minecraft/mod/ResourceFolderModel.h @@ -99,7 +99,7 @@ class ResourceFolderModel : public QAbstractListModel { * * Returns whether the removal was successful. */ - virtual bool uninstallResource(QString file_name, bool preserve_metadata = false); + virtual bool uninstallResource(const QString& file_name, bool preserve_metadata = false); virtual bool deleteResources(const QModelIndexList&); virtual void deleteMetadata(const QModelIndexList&);