change: mod metadata improvements
- Use slug instead of name - Keep temporary status before having local details Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
@ -37,9 +37,9 @@ class Metadata {
|
||||
return Packwiz::V1::createModFormat(index_dir, mod_pack, mod_version);
|
||||
}
|
||||
|
||||
static auto create(QDir& index_dir, Mod& internal_mod) -> ModStruct
|
||||
static auto create(QDir& index_dir, Mod& internal_mod, QString mod_slug) -> ModStruct
|
||||
{
|
||||
return Packwiz::V1::createModFormat(index_dir, internal_mod);
|
||||
return Packwiz::V1::createModFormat(index_dir, internal_mod, mod_slug);
|
||||
}
|
||||
|
||||
static void update(QDir& index_dir, ModStruct& mod)
|
||||
@ -47,9 +47,9 @@ class Metadata {
|
||||
Packwiz::V1::updateModIndex(index_dir, mod);
|
||||
}
|
||||
|
||||
static void remove(QDir& index_dir, QString& mod_name)
|
||||
static void remove(QDir& index_dir, QString mod_slug)
|
||||
{
|
||||
Packwiz::V1::deleteModIndex(index_dir, mod_name);
|
||||
Packwiz::V1::deleteModIndex(index_dir, mod_slug);
|
||||
}
|
||||
|
||||
static void remove(QDir& index_dir, QVariant& mod_id)
|
||||
@ -57,9 +57,9 @@ class Metadata {
|
||||
Packwiz::V1::deleteModIndex(index_dir, mod_id);
|
||||
}
|
||||
|
||||
static auto get(QDir& index_dir, QString& mod_name) -> ModStruct
|
||||
static auto get(QDir& index_dir, QString mod_slug) -> ModStruct
|
||||
{
|
||||
return Packwiz::V1::getIndexForMod(index_dir, mod_name);
|
||||
return Packwiz::V1::getIndexForMod(index_dir, mod_slug);
|
||||
}
|
||||
|
||||
static auto get(QDir& index_dir, QVariant& mod_id) -> ModStruct
|
||||
|
@ -147,25 +147,36 @@ void Mod::setStatus(ModStatus status)
|
||||
if (m_localDetails) {
|
||||
m_localDetails->status = status;
|
||||
} else {
|
||||
m_temp_status = status;
|
||||
if (!m_temp_status.get())
|
||||
m_temp_status.reset(new ModStatus());
|
||||
|
||||
*m_temp_status = status;
|
||||
}
|
||||
}
|
||||
void Mod::setMetadata(Metadata::ModStruct* metadata)
|
||||
void Mod::setMetadata(const Metadata::ModStruct& metadata)
|
||||
{
|
||||
if (status() == ModStatus::NoMetadata)
|
||||
setStatus(ModStatus::Installed);
|
||||
|
||||
if (m_localDetails) {
|
||||
m_localDetails->metadata.reset(metadata);
|
||||
m_localDetails->metadata = std::make_shared<Metadata::ModStruct>(std::move(metadata));
|
||||
} else {
|
||||
m_temp_metadata.reset(metadata);
|
||||
m_temp_metadata = std::make_shared<Metadata::ModStruct>(std::move(metadata));
|
||||
}
|
||||
}
|
||||
|
||||
auto Mod::destroy(QDir& index_dir, bool preserve_metadata) -> bool
|
||||
{
|
||||
if (!preserve_metadata && status() != ModStatus::NoMetadata)
|
||||
Metadata::remove(index_dir, metadata()->mod_id());
|
||||
if (!preserve_metadata) {
|
||||
qDebug() << QString("Destroying metadata for '%1' on purpose").arg(name());
|
||||
|
||||
if (metadata()) {
|
||||
Metadata::remove(index_dir, metadata()->slug);
|
||||
} else {
|
||||
auto n = name();
|
||||
Metadata::remove(index_dir, n);
|
||||
}
|
||||
}
|
||||
|
||||
m_type = MOD_UNKNOWN;
|
||||
return FS::deletePath(m_file.filePath());
|
||||
@ -182,7 +193,7 @@ auto Mod::name() const -> QString
|
||||
if (!d_name.isEmpty())
|
||||
return d_name;
|
||||
|
||||
if (status() != ModStatus::NoMetadata)
|
||||
if (metadata())
|
||||
return metadata()->name;
|
||||
|
||||
return m_name;
|
||||
@ -211,7 +222,7 @@ auto Mod::authors() const -> QStringList
|
||||
auto Mod::status() const -> ModStatus
|
||||
{
|
||||
if (!m_localDetails)
|
||||
return m_temp_status;
|
||||
return m_temp_status ? *m_temp_status : ModStatus::NoMetadata;
|
||||
return details().status;
|
||||
}
|
||||
|
||||
@ -235,11 +246,10 @@ void Mod::finishResolvingWithDetails(std::shared_ptr<ModDetails> details)
|
||||
m_resolved = true;
|
||||
m_localDetails = details;
|
||||
|
||||
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 ? *m_temp_status : ModStatus::NoMetadata);
|
||||
|
||||
setStatus(m_temp_status);
|
||||
if (m_localDetails && m_temp_metadata && m_temp_metadata->isValid()) {
|
||||
setMetadata(*m_temp_metadata);
|
||||
m_temp_metadata.reset();
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>;
|
||||
|
||||
void setStatus(ModStatus status);
|
||||
void setMetadata(Metadata::ModStruct* metadata);
|
||||
void setMetadata(const Metadata::ModStruct& metadata);
|
||||
|
||||
auto enable(bool value) -> bool;
|
||||
|
||||
@ -111,7 +111,7 @@ protected:
|
||||
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<ModStatus> m_temp_status;
|
||||
|
||||
std::shared_ptr<ModDetails> m_localDetails;
|
||||
|
||||
|
@ -65,15 +65,21 @@ void ModFolderModel::startWatching()
|
||||
|
||||
update();
|
||||
|
||||
// Watch the mods folder
|
||||
is_watching = m_watcher->addPath(m_dir.absolutePath());
|
||||
if (is_watching)
|
||||
{
|
||||
if (is_watching) {
|
||||
qDebug() << "Started watching " << m_dir.absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
qDebug() << "Failed to start watching " << m_dir.absolutePath();
|
||||
}
|
||||
|
||||
// Watch the mods index folder
|
||||
is_watching = m_watcher->addPath(indexDir().absolutePath());
|
||||
if (is_watching) {
|
||||
qDebug() << "Started watching " << indexDir().absolutePath();
|
||||
} else {
|
||||
qDebug() << "Failed to start watching " << indexDir().absolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
void ModFolderModel::stopWatching()
|
||||
@ -82,14 +88,18 @@ void ModFolderModel::stopWatching()
|
||||
return;
|
||||
|
||||
is_watching = !m_watcher->removePath(m_dir.absolutePath());
|
||||
if (!is_watching)
|
||||
{
|
||||
if (!is_watching) {
|
||||
qDebug() << "Stopped watching " << m_dir.absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
qDebug() << "Failed to stop watching " << m_dir.absolutePath();
|
||||
}
|
||||
|
||||
is_watching = !m_watcher->removePath(indexDir().absolutePath());
|
||||
if (!is_watching) {
|
||||
qDebug() << "Stopped watching " << indexDir().absolutePath();
|
||||
} else {
|
||||
qDebug() << "Failed to stop watching " << indexDir().absolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
bool ModFolderModel::update()
|
||||
|
@ -47,12 +47,18 @@ void LocalModUpdateTask::executeTask()
|
||||
auto old_metadata = Metadata::get(m_index_dir, m_mod.addonId);
|
||||
if (old_metadata.isValid()) {
|
||||
emit hasOldMod(old_metadata.name, old_metadata.filename);
|
||||
if (m_mod.slug.isEmpty())
|
||||
m_mod.slug = old_metadata.slug;
|
||||
}
|
||||
|
||||
auto pw_mod = Metadata::create(m_index_dir, m_mod, m_mod_version);
|
||||
Metadata::update(m_index_dir, pw_mod);
|
||||
|
||||
emitSucceeded();
|
||||
if (pw_mod.isValid()) {
|
||||
Metadata::update(m_index_dir, pw_mod);
|
||||
emitSucceeded();
|
||||
} else {
|
||||
qCritical() << "Tried to update an invalid mod!";
|
||||
emitFailed(tr("Invalid metadata"));
|
||||
}
|
||||
}
|
||||
|
||||
auto LocalModUpdateTask::abort() -> bool
|
||||
|
@ -71,7 +71,7 @@ void ModFolderLoadTask::run()
|
||||
|
||||
auto metadata = m_result->mods[chopped_id].metadata();
|
||||
if (metadata) {
|
||||
mod.setMetadata(new Metadata::ModStruct(*metadata));
|
||||
mod.setMetadata(*metadata);
|
||||
|
||||
m_result->mods[mod.internal_id()].setStatus(ModStatus::Installed);
|
||||
m_result->mods.remove(chopped_id);
|
||||
|
Reference in New Issue
Block a user