diff options
author | flow <thiagodonato300@gmail.com> | 2022-04-17 09:30:32 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-05-23 14:42:28 -0300 |
commit | 23febc6d94bcc5903a9863ba7b854b5091b0813b (patch) | |
tree | 102512acb5c2ec7fefdec089ae4c7829fcbee62b /launcher | |
parent | fab4a7a6029beb60bade312ee89e649202d178de (diff) | |
download | PrismLauncher-23febc6d94bcc5903a9863ba7b854b5091b0813b.tar.gz PrismLauncher-23febc6d94bcc5903a9863ba7b854b5091b0813b.tar.bz2 PrismLauncher-23febc6d94bcc5903a9863ba7b854b5091b0813b.zip |
feat: cache metadata in ModDetails
Allows for more easy access to the metadata by outside entities
Diffstat (limited to 'launcher')
-rw-r--r-- | launcher/minecraft/mod/Mod.cpp | 14 | ||||
-rw-r--r-- | launcher/minecraft/mod/Mod.h | 14 | ||||
-rw-r--r-- | launcher/minecraft/mod/ModDetails.h | 7 |
3 files changed, 29 insertions, 6 deletions
diff --git a/launcher/minecraft/mod/Mod.cpp b/launcher/minecraft/mod/Mod.cpp index 5b35156d..46776239 100644 --- a/launcher/minecraft/mod/Mod.cpp +++ b/launcher/minecraft/mod/Mod.cpp @@ -55,6 +55,8 @@ Mod::Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata) m_from_metadata = true; m_enabled = true; m_changedDateTime = m_file.lastModified(); + + m_temp_metadata = std::make_shared<Metadata::ModStruct>(std::move(metadata)); } void Mod::repath(const QFileInfo& file) @@ -161,3 +163,15 @@ QStringList Mod::authors() const { return details().authors; } + +void Mod::finishResolvingWithDetails(std::shared_ptr<ModDetails> details) +{ + m_resolving = false; + m_resolved = true; + m_localDetails = details; + + if (fromMetadata() && m_temp_metadata->isValid()) { + m_localDetails->metadata = m_temp_metadata; + m_temp_metadata.reset(); + } +} diff --git a/launcher/minecraft/mod/Mod.h b/launcher/minecraft/mod/Mod.h index fef8cbe4..0d49d94b 100644 --- a/launcher/minecraft/mod/Mod.h +++ b/launcher/minecraft/mod/Mod.h @@ -18,7 +18,6 @@ #include <QDateTime> #include <QFileInfo> #include <QList> -#include <memory> #include "ModDetails.h" #include "minecraft/mod/MetadataHandler.h" @@ -55,6 +54,9 @@ public: QString description() const; QStringList authors() const; + const std::shared_ptr<Metadata::ModStruct> metadata() const { return details().metadata; }; + std::shared_ptr<Metadata::ModStruct> metadata() { return m_localDetails->metadata; }; + bool enable(bool value); // delete all the files of this mod @@ -71,11 +73,7 @@ public: m_resolving = resolving; m_resolutionTicket = resolutionTicket; } - void finishResolvingWithDetails(std::shared_ptr<ModDetails> details){ - m_resolving = false; - m_resolved = true; - m_localDetails = details; - } + void finishResolvingWithDetails(std::shared_ptr<ModDetails> details); protected: QFileInfo m_file; @@ -86,6 +84,10 @@ protected: QString m_name; ModType m_type = MOD_UNKNOWN; bool m_from_metadata = false; + + /* If the mod has metadata, this will be filled in the constructor, and passed to + * the ModDetails when calling finishResolvingWithDetails */ + std::shared_ptr<Metadata::ModStruct> m_temp_metadata; std::shared_ptr<ModDetails> m_localDetails; bool m_enabled = true; diff --git a/launcher/minecraft/mod/ModDetails.h b/launcher/minecraft/mod/ModDetails.h index d8d4f66f..f9973fc2 100644 --- a/launcher/minecraft/mod/ModDetails.h +++ b/launcher/minecraft/mod/ModDetails.h @@ -1,8 +1,12 @@ #pragma once +#include <memory> + #include <QString> #include <QStringList> +#include "minecraft/mod/MetadataHandler.h" + struct ModDetails { /* Mod ID as defined in the ModLoader-specific metadata */ @@ -25,4 +29,7 @@ struct ModDetails /* List of the author's names */ QStringList authors; + + /* Metadata information, if any */ + std::shared_ptr<Metadata::ModStruct> metadata; }; |