Properly rename shader config on update/version change
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@@ -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<ShaderPackFolderModel*>(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)
|
||||
|
||||
@@ -48,6 +48,7 @@ class ResourceDownloadTask : public SequentialTask {
|
||||
ModPlatform::IndexedVersion m_pack_version;
|
||||
const std::shared_ptr<ResourceFolderModel> m_pack_model;
|
||||
QString m_custom_target_folder;
|
||||
QString m_targetPath;
|
||||
|
||||
NetJob::Ptr m_filesNetJob;
|
||||
LocalResourceUpdateTask::Ptr m_update_task;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user