feat: cache metadata in ModDetails
Allows for more easy access to the metadata by outside entities
This commit is contained in:
parent
fab4a7a602
commit
23febc6d94
@ -55,6 +55,8 @@ Mod::Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata)
|
|||||||
m_from_metadata = true;
|
m_from_metadata = true;
|
||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
m_changedDateTime = m_file.lastModified();
|
m_changedDateTime = m_file.lastModified();
|
||||||
|
|
||||||
|
m_temp_metadata = std::make_shared<Metadata::ModStruct>(std::move(metadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mod::repath(const QFileInfo& file)
|
void Mod::repath(const QFileInfo& file)
|
||||||
@ -161,3 +163,15 @@ QStringList Mod::authors() const
|
|||||||
{
|
{
|
||||||
return details().authors;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "ModDetails.h"
|
#include "ModDetails.h"
|
||||||
#include "minecraft/mod/MetadataHandler.h"
|
#include "minecraft/mod/MetadataHandler.h"
|
||||||
@ -55,6 +54,9 @@ public:
|
|||||||
QString description() const;
|
QString description() const;
|
||||||
QStringList authors() 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);
|
bool enable(bool value);
|
||||||
|
|
||||||
// delete all the files of this mod
|
// delete all the files of this mod
|
||||||
@ -71,11 +73,7 @@ public:
|
|||||||
m_resolving = resolving;
|
m_resolving = resolving;
|
||||||
m_resolutionTicket = resolutionTicket;
|
m_resolutionTicket = resolutionTicket;
|
||||||
}
|
}
|
||||||
void finishResolvingWithDetails(std::shared_ptr<ModDetails> details){
|
void finishResolvingWithDetails(std::shared_ptr<ModDetails> details);
|
||||||
m_resolving = false;
|
|
||||||
m_resolved = true;
|
|
||||||
m_localDetails = details;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QFileInfo m_file;
|
QFileInfo m_file;
|
||||||
@ -86,6 +84,10 @@ protected:
|
|||||||
QString m_name;
|
QString m_name;
|
||||||
ModType m_type = MOD_UNKNOWN;
|
ModType m_type = MOD_UNKNOWN;
|
||||||
bool m_from_metadata = false;
|
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;
|
std::shared_ptr<ModDetails> m_localDetails;
|
||||||
|
|
||||||
bool m_enabled = true;
|
bool m_enabled = true;
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include "minecraft/mod/MetadataHandler.h"
|
||||||
|
|
||||||
struct ModDetails
|
struct ModDetails
|
||||||
{
|
{
|
||||||
/* Mod ID as defined in the ModLoader-specific metadata */
|
/* Mod ID as defined in the ModLoader-specific metadata */
|
||||||
@ -25,4 +29,7 @@ struct ModDetails
|
|||||||
|
|
||||||
/* List of the author's names */
|
/* List of the author's names */
|
||||||
QStringList authors;
|
QStringList authors;
|
||||||
|
|
||||||
|
/* Metadata information, if any */
|
||||||
|
std::shared_ptr<Metadata::ModStruct> metadata;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user