feat: use mod metadata for getting mod information
For now this doesn't mean much, but it will help when we need data exclusive from the metadata, such as addon id and mod provider. Also removes the metadata when the mod is deleted, and make the Mod.h file a little more pleasing to look at :)
This commit is contained in:
parent
e93b9560b5
commit
fcfb2cfc3d
@ -33,6 +33,30 @@ Mod::Mod(const QFileInfo &file)
|
|||||||
m_changedDateTime = file.lastModified();
|
m_changedDateTime = file.lastModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mod::Mod(const QDir& mods_dir, const Packwiz::Mod& 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_mmc_id(metadata.filename)
|
||||||
|
, m_name(metadata.name)
|
||||||
|
{
|
||||||
|
if(m_file.isDir()){
|
||||||
|
m_type = MOD_FOLDER;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (metadata.filename.endsWith(".zip") || metadata.filename.endsWith(".jar"))
|
||||||
|
m_type = MOD_ZIPFILE;
|
||||||
|
else if (metadata.filename.endsWith(".litemod"))
|
||||||
|
m_type = MOD_LITEMOD;
|
||||||
|
else
|
||||||
|
m_type = MOD_SINGLEFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_from_metadata = true;
|
||||||
|
m_enabled = true;
|
||||||
|
m_changedDateTime = m_file.lastModified();
|
||||||
|
}
|
||||||
|
|
||||||
void Mod::repath(const QFileInfo &file)
|
void Mod::repath(const QFileInfo &file)
|
||||||
{
|
{
|
||||||
m_file = file;
|
m_file = file;
|
||||||
@ -101,13 +125,18 @@ bool Mod::enable(bool value)
|
|||||||
if (!foo.rename(path))
|
if (!foo.rename(path))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(!fromMetadata())
|
||||||
repath(QFileInfo(path));
|
repath(QFileInfo(path));
|
||||||
|
|
||||||
m_enabled = value;
|
m_enabled = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mod::destroy()
|
bool Mod::destroy(QDir& index_dir)
|
||||||
{
|
{
|
||||||
|
// Delete metadata
|
||||||
|
Packwiz::deleteModIndex(index_dir, m_name);
|
||||||
|
|
||||||
m_type = MOD_UNKNOWN;
|
m_type = MOD_UNKNOWN;
|
||||||
return FS::deletePath(m_file.filePath());
|
return FS::deletePath(m_file.filePath());
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "ModDetails.h"
|
#include "ModDetails.h"
|
||||||
|
#include "modplatform/packwiz/Packwiz.h"
|
||||||
|
|
||||||
|
|
||||||
class Mod
|
class Mod
|
||||||
{
|
{
|
||||||
@ -37,36 +37,18 @@ public:
|
|||||||
|
|
||||||
Mod() = default;
|
Mod() = default;
|
||||||
Mod(const QFileInfo &file);
|
Mod(const QFileInfo &file);
|
||||||
|
explicit Mod(const QDir& mods_dir, const Packwiz::Mod& metadata);
|
||||||
|
|
||||||
QFileInfo filename() const
|
QFileInfo filename() const { return m_file; }
|
||||||
{
|
QDateTime dateTimeChanged() const { return m_changedDateTime; }
|
||||||
return m_file;
|
QString mmc_id() const { return m_mmc_id; }
|
||||||
}
|
ModType type() const { return m_type; }
|
||||||
QString mmc_id() const
|
bool fromMetadata() const { return m_from_metadata; }
|
||||||
{
|
bool enabled() const { return m_enabled; }
|
||||||
return m_mmc_id;
|
|
||||||
}
|
|
||||||
ModType type() const
|
|
||||||
{
|
|
||||||
return m_type;
|
|
||||||
}
|
|
||||||
bool valid()
|
|
||||||
{
|
|
||||||
return m_type != MOD_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDateTime dateTimeChanged() const
|
bool valid() const { return m_type != MOD_UNKNOWN; }
|
||||||
{
|
|
||||||
return m_changedDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool enabled() const
|
|
||||||
{
|
|
||||||
return m_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ModDetails &details() const;
|
|
||||||
|
|
||||||
|
const ModDetails& details() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QString version() const;
|
QString version() const;
|
||||||
QString homeurl() const;
|
QString homeurl() const;
|
||||||
@ -76,21 +58,15 @@ public:
|
|||||||
bool enable(bool value);
|
bool enable(bool value);
|
||||||
|
|
||||||
// delete all the files of this mod
|
// delete all the files of this mod
|
||||||
bool destroy();
|
bool destroy(QDir& index_dir);
|
||||||
|
|
||||||
// change the mod's filesystem path (used by mod lists for *MAGIC* purposes)
|
// change the mod's filesystem path (used by mod lists for *MAGIC* purposes)
|
||||||
void repath(const QFileInfo &file);
|
void repath(const QFileInfo &file);
|
||||||
|
|
||||||
bool shouldResolve() {
|
bool shouldResolve() const { return !m_resolving && !m_resolved; }
|
||||||
return !m_resolving && !m_resolved;
|
bool isResolving() const { return m_resolving; }
|
||||||
}
|
int resolutionTicket() const { return m_resolutionTicket; }
|
||||||
bool isResolving() {
|
|
||||||
return m_resolving;
|
|
||||||
}
|
|
||||||
int resolutionTicket()
|
|
||||||
{
|
|
||||||
return m_resolutionTicket;
|
|
||||||
}
|
|
||||||
void setResolving(bool resolving, int resolutionTicket) {
|
void setResolving(bool resolving, int resolutionTicket) {
|
||||||
m_resolving = resolving;
|
m_resolving = resolving;
|
||||||
m_resolutionTicket = resolutionTicket;
|
m_resolutionTicket = resolutionTicket;
|
||||||
@ -104,12 +80,15 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
QFileInfo m_file;
|
QFileInfo m_file;
|
||||||
QDateTime m_changedDateTime;
|
QDateTime m_changedDateTime;
|
||||||
|
|
||||||
QString m_mmc_id;
|
QString m_mmc_id;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
ModType m_type = MOD_UNKNOWN;
|
||||||
|
bool m_from_metadata = false;
|
||||||
|
std::shared_ptr<ModDetails> m_localDetails;
|
||||||
|
|
||||||
bool m_enabled = true;
|
bool m_enabled = true;
|
||||||
bool m_resolving = false;
|
bool m_resolving = false;
|
||||||
bool m_resolved = false;
|
bool m_resolved = false;
|
||||||
int m_resolutionTicket = 0;
|
int m_resolutionTicket = 0;
|
||||||
ModType m_type = MOD_UNKNOWN;
|
|
||||||
std::shared_ptr<ModDetails> m_localDetails;
|
|
||||||
};
|
};
|
||||||
|
@ -1,18 +1,35 @@
|
|||||||
#include "ModFolderLoadTask.h"
|
#include "ModFolderLoadTask.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
ModFolderLoadTask::ModFolderLoadTask(QDir dir) :
|
#include "modplatform/packwiz/Packwiz.h"
|
||||||
m_dir(dir), m_result(new Result())
|
|
||||||
|
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir) :
|
||||||
|
m_mods_dir(mods_dir), m_index_dir(index_dir), m_result(new Result())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModFolderLoadTask::run()
|
void ModFolderLoadTask::run()
|
||||||
{
|
{
|
||||||
m_dir.refresh();
|
// Read metadata first
|
||||||
for (auto entry : m_dir.entryInfoList())
|
m_index_dir.refresh();
|
||||||
{
|
for(auto entry : m_index_dir.entryList()){
|
||||||
Mod m(entry);
|
// QDir::Filter::NoDotAndDotDot seems to exclude all files for some reason...
|
||||||
m_result->mods[m.mmc_id()] = m;
|
if(entry == "." || entry == "..")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
entry.chop(5); // Remove .toml at the end
|
||||||
|
Mod mod(m_mods_dir, Packwiz::getIndexForMod(m_index_dir, entry));
|
||||||
|
m_result->mods[mod.mmc_id()] = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read JAR files that don't have metadata
|
||||||
|
m_mods_dir.refresh();
|
||||||
|
for (auto entry : m_mods_dir.entryInfoList())
|
||||||
|
{
|
||||||
|
Mod mod(entry);
|
||||||
|
if(!m_result->mods.contains(mod.mmc_id()))
|
||||||
|
m_result->mods[mod.mmc_id()] = mod;
|
||||||
|
}
|
||||||
|
|
||||||
emit succeeded();
|
emit succeeded();
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModFolderLoadTask(QDir dir);
|
ModFolderLoadTask(QDir& mods_dir, QDir& index_dir);
|
||||||
void run();
|
void run();
|
||||||
signals:
|
signals:
|
||||||
void succeeded();
|
void succeeded();
|
||||||
private:
|
private:
|
||||||
QDir m_dir;
|
QDir& m_mods_dir, m_index_dir;
|
||||||
ResultPtr m_result;
|
ResultPtr m_result;
|
||||||
};
|
};
|
||||||
|
@ -79,10 +79,14 @@ bool ModFolderModel::update()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto task = new ModFolderLoadTask(m_dir);
|
auto index_dir = indexDir();
|
||||||
|
auto task = new ModFolderLoadTask(dir(), index_dir);
|
||||||
|
|
||||||
m_update = task->result();
|
m_update = task->result();
|
||||||
|
|
||||||
QThreadPool *threadPool = QThreadPool::globalInstance();
|
QThreadPool *threadPool = QThreadPool::globalInstance();
|
||||||
connect(task, &ModFolderLoadTask::succeeded, this, &ModFolderModel::finishUpdate);
|
connect(task, &ModFolderLoadTask::succeeded, this, &ModFolderModel::finishUpdate);
|
||||||
|
|
||||||
threadPool->start(task);
|
threadPool->start(task);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -334,7 +338,8 @@ bool ModFolderModel::deleteMods(const QModelIndexList& indexes)
|
|||||||
for (auto i: indexes)
|
for (auto i: indexes)
|
||||||
{
|
{
|
||||||
Mod &m = mods[i.row()];
|
Mod &m = mods[i.row()];
|
||||||
m.destroy();
|
auto index_dir = indexDir();
|
||||||
|
m.destroy(index_dir);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user