diff options
author | flow <flowlnlnln@gmail.com> | 2022-06-11 17:19:34 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-07-17 11:33:43 -0300 |
commit | 91a5c4bdcbd3ae18139b85899f051fb3d9cbd1fc (patch) | |
tree | 2845daddf22f1f17a56ace9b4945c7a91d0c477b /launcher/modplatform | |
parent | 9a07ede615869e3df87c41a689ebbba16a433849 (diff) | |
download | PrismLauncher-91a5c4bdcbd3ae18139b85899f051fb3d9cbd1fc.tar.gz PrismLauncher-91a5c4bdcbd3ae18139b85899f051fb3d9cbd1fc.tar.bz2 PrismLauncher-91a5c4bdcbd3ae18139b85899f051fb3d9cbd1fc.zip |
feat: add metadata get/delete via mod id
This is, in many cases, more reliable than name comparisons, so it's
useful specially in cases where a mod changes name between versions
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/modplatform')
-rw-r--r-- | launcher/modplatform/packwiz/Packwiz.cpp | 33 | ||||
-rw-r--r-- | launcher/modplatform/packwiz/Packwiz.h | 8 |
2 files changed, 38 insertions, 3 deletions
diff --git a/launcher/modplatform/packwiz/Packwiz.cpp b/launcher/modplatform/packwiz/Packwiz.cpp index 0782b9f4..8bd66088 100644 --- a/launcher/modplatform/packwiz/Packwiz.cpp +++ b/launcher/modplatform/packwiz/Packwiz.cpp @@ -144,6 +144,9 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod) QFile index_file(index_dir.absoluteFilePath(real_fname)); + if (real_fname != normalized_fname) + index_file.rename(normalized_fname); + // There's already data on there! // TODO: We should do more stuff here, as the user is likely trying to // override a file. In this case, check versions and ask the user what @@ -196,16 +199,28 @@ void V1::deleteModIndex(QDir& index_dir, QString& mod_name) QFile index_file(index_dir.absoluteFilePath(real_fname)); - if(!index_file.exists()){ + if (!index_file.exists()) { qWarning() << QString("Tried to delete non-existent mod metadata for %1!").arg(mod_name); return; } - if(!index_file.remove()){ + if (!index_file.remove()) { qWarning() << QString("Failed to remove metadata for mod %1!").arg(mod_name); } } +void V1::deleteModIndex(QDir& index_dir, QVariant& mod_id) +{ + for (auto& file_name : index_dir.entryList(QDir::Filter::Files)) { + auto mod = getIndexForMod(index_dir, file_name); + + if (mod.mod_id() == mod_id) { + deleteModIndex(index_dir, mod.name); + break; + } + } +} + auto V1::getIndexForMod(QDir& index_dir, QString& index_file_name) -> Mod { Mod mod; @@ -286,4 +301,16 @@ auto V1::getIndexForMod(QDir& index_dir, QString& index_file_name) -> Mod return mod; } -} // namespace Packwiz +auto V1::getIndexForMod(QDir& index_dir, QVariant& mod_id) -> Mod +{ + for (auto& file_name : index_dir.entryList(QDir::Filter::Files)) { + auto mod = getIndexForMod(index_dir, file_name); + + if (mod.mod_id() == mod_id) + return mod; + } + + return {}; +} + +} // namespace Packwiz diff --git a/launcher/modplatform/packwiz/Packwiz.h b/launcher/modplatform/packwiz/Packwiz.h index 3c99769c..9d643703 100644 --- a/launcher/modplatform/packwiz/Packwiz.h +++ b/launcher/modplatform/packwiz/Packwiz.h @@ -84,10 +84,18 @@ class V1 { /* Deletes the metadata for the mod with the given name. If the metadata doesn't exist, it does nothing. */ static void deleteModIndex(QDir& index_dir, QString& mod_name); + /* Deletes the metadata for the mod with the given id. If the metadata doesn't exist, it does nothing. */ + static void deleteModIndex(QDir& index_dir, QVariant& mod_id); + /* Gets the metadata for a mod with a particular name. * If the mod doesn't have a metadata, it simply returns an empty Mod object. * */ static auto getIndexForMod(QDir& index_dir, QString& index_file_name) -> Mod; + + /* Gets the metadata for a mod with a particular id. + * If the mod doesn't have a metadata, it simply returns an empty Mod object. + * */ + static auto getIndexForMod(QDir& index_dir, QVariant& mod_id) -> Mod; }; } // namespace Packwiz |