Merge pull request #759 from flowln/mod_perma_3

This commit is contained in:
Sefa Eyeoglu 2022-06-12 19:17:08 +02:00 committed by GitHub
commit d08815bbc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 19 deletions

View File

@ -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)
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()) {
if (m_localDetails && m_temp_metadata && m_temp_metadata->isValid()) {
m_localDetails->metadata = m_temp_metadata;
if (status() == ModStatus::NoMetadata)
setStatus(ModStatus::Installed);
}
m_localDetails->metadata.swap(m_temp_metadata);
}
setStatus(m_temp_status);
}

View File

@ -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;

View File

@ -53,6 +53,8 @@ void ModFolderLoadTask::run()
m_mods_dir.refresh();
for (auto entry : m_mods_dir.entryInfoList()) {
Mod mod(entry);
if (mod.enabled()) {
if (m_result->mods.contains(mod.internal_id())) {
m_result->mods[mod.internal_id()].setStatus(ModStatus::Installed);
}
@ -61,6 +63,25 @@ void ModFolderLoadTask::run()
m_result->mods[mod.internal_id()].setStatus(ModStatus::NoMetadata);
}
}
else {
QString chopped_id = mod.internal_id().chopped(9);
if (m_result->mods.contains(chopped_id)) {
m_result->mods[mod.internal_id()] = mod;
auto metadata = m_result->mods[chopped_id].metadata();
if (metadata) {
mod.setMetadata(new Metadata::ModStruct(*metadata));
m_result->mods[mod.internal_id()].setStatus(ModStatus::Installed);
m_result->mods.remove(chopped_id);
}
}
else {
m_result->mods[mod.internal_id()] = mod;
m_result->mods[mod.internal_id()].setStatus(ModStatus::NoMetadata);
}
}
}
emit succeeded();
}