refactor: make mod metadata presence (or lack of) easier to find out

This commit is contained in:
flow 2022-04-20 18:45:39 -03:00 committed by flow
parent a99858c64d
commit 96e36f0604
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
6 changed files with 49 additions and 13 deletions

View File

@ -54,7 +54,6 @@ Mod::Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata)
m_type = MOD_SINGLEFILE;
}
m_from_metadata = true;
m_enabled = true;
m_changedDateTime = m_file.lastModified();
@ -117,13 +116,27 @@ auto Mod::enable(bool value) -> bool
return false;
}
if (!fromMetadata())
if (status() == ModStatus::NoMetadata)
repath(QFileInfo(path));
m_enabled = value;
return true;
}
void Mod::setStatus(ModStatus status)
{
if(m_localDetails.get())
m_localDetails->status = status;
}
void Mod::setMetadata(Metadata::ModStruct* metadata)
{
if(status() == ModStatus::NoMetadata)
setStatus(ModStatus::Installed);
if(m_localDetails.get())
m_localDetails->metadata.reset(metadata);
}
auto Mod::destroy(QDir& index_dir) -> bool
{
auto n = name();
@ -170,13 +183,22 @@ auto Mod::authors() const -> QStringList
return details().authors;
}
auto Mod::status() const -> ModStatus
{
return details().status;
}
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.get()) {
if (status() != ModStatus::NoMetadata
&& m_temp_metadata.get()
&& m_temp_metadata->isValid() &&
m_localDetails.get()) {
m_localDetails->metadata.swap(m_temp_metadata);
}
}

View File

@ -41,7 +41,6 @@ public:
auto dateTimeChanged() const -> QDateTime { return m_changedDateTime; }
auto internal_id() const -> QString { return m_internal_id; }
auto type() const -> ModType { return m_type; }
auto fromMetadata() const -> bool { return m_from_metadata; }
auto enabled() const -> bool { return m_enabled; }
auto valid() const -> bool { return m_type != MOD_UNKNOWN; }
@ -52,10 +51,14 @@ public:
auto homeurl() const -> QString;
auto description() const -> QString;
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; };
void setStatus(ModStatus status);
void setMetadata(Metadata::ModStruct* metadata);
auto enable(bool value) -> bool;
// delete all the files of this mod
@ -82,7 +85,6 @@ protected:
/* Name as reported via the file name */
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 */

View File

@ -7,6 +7,12 @@
#include "minecraft/mod/MetadataHandler.h"
enum class ModStatus {
Installed, // Both JAR and Metadata are present
NotInstalled, // Only the Metadata is present
NoMetadata, // Only the JAR is present
};
struct ModDetails
{
/* Mod ID as defined in the ModLoader-specific metadata */
@ -30,6 +36,9 @@ struct ModDetails
/* List of the author's names */
QStringList authors;
/* Installation status of the mod */
ModStatus status;
/* Metadata information, if any */
std::shared_ptr<Metadata::ModStruct> metadata;
};

View File

@ -19,8 +19,13 @@ void ModFolderLoadTask::run()
m_mods_dir.refresh();
for (auto entry : m_mods_dir.entryInfoList()) {
Mod mod(entry);
if (!m_result->mods.contains(mod.internal_id()))
if(m_result->mods.contains(mod.internal_id())){
m_result->mods[mod.internal_id()].setStatus(ModStatus::Installed);
}
else {
m_result->mods[mod.internal_id()] = mod;
m_result->mods[mod.internal_id()].setStatus(ModStatus::NoMetadata);
}
}
emit succeeded();
@ -42,6 +47,7 @@ void ModFolderLoadTask::getFromMetadata()
}
Mod mod(m_mods_dir, metadata);
mod.setStatus(ModStatus::NotInstalled);
m_result->mods[mod.internal_id()] = mod;
}
}

View File

@ -10,6 +10,7 @@ auto ProviderCapabilities::name(Provider p) -> const char*
case Provider::FLAME:
return "curseforge";
}
return {};
}
auto ProviderCapabilities::hashType(Provider p) -> QString
{
@ -19,6 +20,7 @@ auto ProviderCapabilities::hashType(Provider p) -> QString
case Provider::FLAME:
return "murmur2";
}
return {};
}
} // namespace ModPlatform

View File

@ -48,14 +48,9 @@ auto V1::createModFormat(QDir& index_dir, ::Mod& internal_mod) -> Mod
if(mod.isValid())
return mod;
// Manually construct packwiz mod
mod.name = internal_mod.name();
mod.filename = internal_mod.fileinfo().fileName();
qWarning() << QString("Tried to create mod metadata with a Mod without metadata!");
// TODO: Have a mechanism for telling the UI subsystem that we want to gather user information
// (i.e. which mod provider we want to use). Maybe an object parameter with a signal for that?
return mod;
return {};
}
void V1::updateModIndex(QDir& index_dir, Mod& mod)