diff options
author | flow <thiagodonato300@gmail.com> | 2022-04-15 00:24:57 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-05-23 14:42:27 -0300 |
commit | fcfb2cfc3da9a8f897063db05fdf3aebc41a59ae (patch) | |
tree | 5b2de59599a0c05a23ac8aff0eec4de2c61c9469 /launcher/minecraft/mod/Mod.cpp | |
parent | e93b9560b5137a5ee7acdc34c0f74992aa02aad6 (diff) | |
download | PrismLauncher-fcfb2cfc3da9a8f897063db05fdf3aebc41a59ae.tar.gz PrismLauncher-fcfb2cfc3da9a8f897063db05fdf3aebc41a59ae.tar.bz2 PrismLauncher-fcfb2cfc3da9a8f897063db05fdf3aebc41a59ae.zip |
feat: use mod metadata for getting mod information
For now this doesn't mean much, but it will help when we need data
exclusive from the metadata, such as addon id and mod provider.
Also removes the metadata when the mod is deleted, and make the Mod.h
file a little more pleasing to look at :)
Diffstat (limited to 'launcher/minecraft/mod/Mod.cpp')
-rw-r--r-- | launcher/minecraft/mod/Mod.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/launcher/minecraft/mod/Mod.cpp b/launcher/minecraft/mod/Mod.cpp index b6bff29b..59f4d83b 100644 --- a/launcher/minecraft/mod/Mod.cpp +++ b/launcher/minecraft/mod/Mod.cpp @@ -33,6 +33,30 @@ Mod::Mod(const QFileInfo &file) m_changedDateTime = file.lastModified(); } +Mod::Mod(const QDir& mods_dir, const Packwiz::Mod& metadata) + : m_file(mods_dir.absoluteFilePath(metadata.filename)) + // It is weird, but name is not reliable for comparing with the JAR files name + // FIXME: Maybe use hash when implemented? + , m_mmc_id(metadata.filename) + , m_name(metadata.name) +{ + if(m_file.isDir()){ + m_type = MOD_FOLDER; + } + else{ + if (metadata.filename.endsWith(".zip") || metadata.filename.endsWith(".jar")) + m_type = MOD_ZIPFILE; + else if (metadata.filename.endsWith(".litemod")) + m_type = MOD_LITEMOD; + else + m_type = MOD_SINGLEFILE; + } + + m_from_metadata = true; + m_enabled = true; + m_changedDateTime = m_file.lastModified(); +} + void Mod::repath(const QFileInfo &file) { m_file = file; @@ -101,13 +125,18 @@ bool Mod::enable(bool value) if (!foo.rename(path)) return false; } - repath(QFileInfo(path)); + if(!fromMetadata()) + repath(QFileInfo(path)); + m_enabled = value; return true; } -bool Mod::destroy() +bool Mod::destroy(QDir& index_dir) { + // Delete metadata + Packwiz::deleteModIndex(index_dir, m_name); + m_type = MOD_UNKNOWN; return FS::deletePath(m_file.filePath()); } |