fix: handling of incomplete mods
(i.e. mods without ModDetails that may have metadata)
This commit is contained in:
parent
c4f2e3a955
commit
40ccd1a469
@ -58,8 +58,6 @@ Mod::Mod(const QFileInfo& file)
|
||||
|
||||
Mod::Mod(const QDir& mods_dir, const Metadata::ModStruct& 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_internal_id(metadata.filename)
|
||||
, m_name(metadata.name)
|
||||
{
|
||||
@ -145,16 +143,22 @@ auto Mod::enable(bool value) -> bool
|
||||
|
||||
void Mod::setStatus(ModStatus status)
|
||||
{
|
||||
if(m_localDetails.get())
|
||||
if (m_localDetails) {
|
||||
m_localDetails->status = status;
|
||||
} else {
|
||||
m_temp_status = status;
|
||||
}
|
||||
}
|
||||
void Mod::setMetadata(Metadata::ModStruct* metadata)
|
||||
{
|
||||
if(status() == ModStatus::NoMetadata)
|
||||
if (status() == ModStatus::NoMetadata)
|
||||
setStatus(ModStatus::Installed);
|
||||
|
||||
if(m_localDetails.get())
|
||||
if (m_localDetails) {
|
||||
m_localDetails->metadata.reset(metadata);
|
||||
} else {
|
||||
m_temp_metadata.reset(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
auto Mod::destroy(QDir& index_dir) -> bool
|
||||
@ -205,20 +209,36 @@ auto Mod::authors() const -> QStringList
|
||||
|
||||
auto Mod::status() const -> ModStatus
|
||||
{
|
||||
if (!m_localDetails)
|
||||
return m_temp_status;
|
||||
return details().status;
|
||||
}
|
||||
|
||||
auto Mod::metadata() -> std::shared_ptr<Metadata::ModStruct>
|
||||
{
|
||||
if (m_localDetails)
|
||||
return m_localDetails->metadata;
|
||||
return m_temp_metadata;
|
||||
}
|
||||
|
||||
auto Mod::metadata() const -> const std::shared_ptr<Metadata::ModStruct>
|
||||
{
|
||||
if (m_localDetails)
|
||||
return m_localDetails->metadata;
|
||||
return m_temp_metadata;
|
||||
}
|
||||
|
||||
void Mod::finishResolvingWithDetails(std::shared_ptr<ModDetails> details)
|
||||
{
|
||||
m_resolving = false;
|
||||
m_resolved = true;
|
||||
m_localDetails = details;
|
||||
|
||||
if (status() != ModStatus::NoMetadata
|
||||
&& m_temp_metadata.get()
|
||||
&& m_temp_metadata->isValid() &&
|
||||
m_localDetails.get()) {
|
||||
|
||||
m_localDetails->metadata.swap(m_temp_metadata);
|
||||
if (m_localDetails && m_temp_metadata && m_temp_metadata->isValid()) {
|
||||
m_localDetails->metadata = m_temp_metadata;
|
||||
if (status() == ModStatus::NoMetadata)
|
||||
setStatus(ModStatus::Installed);
|
||||
}
|
||||
|
||||
setStatus(m_temp_status);
|
||||
}
|
||||
|
@ -73,8 +73,8 @@ public:
|
||||
auto authors() const -> QStringList;
|
||||
auto status() const -> ModStatus;
|
||||
|
||||
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct> { return details().metadata; };
|
||||
auto metadata() -> std::shared_ptr<Metadata::ModStruct> { return m_localDetails->metadata; };
|
||||
auto metadata() -> std::shared_ptr<Metadata::ModStruct>;
|
||||
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>;
|
||||
|
||||
void setStatus(ModStatus status);
|
||||
void setMetadata(Metadata::ModStruct* metadata);
|
||||
@ -109,6 +109,10 @@ protected:
|
||||
/* 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;
|
||||
|
||||
/* Set the mod status while it doesn't have local details just yet */
|
||||
ModStatus m_temp_status = ModStatus::NotInstalled;
|
||||
|
||||
std::shared_ptr<ModDetails> m_localDetails;
|
||||
|
||||
bool m_enabled = true;
|
||||
|
Loading…
Reference in New Issue
Block a user