refactor: remove unused mod info and organize some stuff
This commit is contained in:
parent
5a34e8fd7c
commit
e9fb566c07
@ -13,12 +13,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Mod.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "Mod.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -26,8 +27,7 @@ ModDetails invalidDetails;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mod::Mod(const QFileInfo& file)
|
||||||
Mod::Mod(const QFileInfo &file)
|
|
||||||
{
|
{
|
||||||
repath(file);
|
repath(file);
|
||||||
m_changedDateTime = file.lastModified();
|
m_changedDateTime = file.lastModified();
|
||||||
@ -37,13 +37,12 @@ Mod::Mod(const QDir& mods_dir, const Packwiz::Mod& metadata)
|
|||||||
: m_file(mods_dir.absoluteFilePath(metadata.filename))
|
: m_file(mods_dir.absoluteFilePath(metadata.filename))
|
||||||
// It is weird, but name is not reliable for comparing with the JAR files name
|
// It is weird, but name is not reliable for comparing with the JAR files name
|
||||||
// FIXME: Maybe use hash when implemented?
|
// FIXME: Maybe use hash when implemented?
|
||||||
, m_mmc_id(metadata.filename)
|
, m_internal_id(metadata.filename)
|
||||||
, m_name(metadata.name)
|
, m_name(metadata.name)
|
||||||
{
|
{
|
||||||
if(m_file.isDir()){
|
if (m_file.isDir()) {
|
||||||
m_type = MOD_FOLDER;
|
m_type = MOD_FOLDER;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
if (metadata.filename.endsWith(".zip") || metadata.filename.endsWith(".jar"))
|
if (metadata.filename.endsWith(".zip") || metadata.filename.endsWith(".jar"))
|
||||||
m_type = MOD_ZIPFILE;
|
m_type = MOD_ZIPFILE;
|
||||||
else if (metadata.filename.endsWith(".litemod"))
|
else if (metadata.filename.endsWith(".litemod"))
|
||||||
@ -57,43 +56,32 @@ Mod::Mod(const QDir& mods_dir, const Packwiz::Mod& metadata)
|
|||||||
m_changedDateTime = m_file.lastModified();
|
m_changedDateTime = m_file.lastModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mod::repath(const QFileInfo &file)
|
void Mod::repath(const QFileInfo& file)
|
||||||
{
|
{
|
||||||
m_file = file;
|
m_file = file;
|
||||||
QString name_base = file.fileName();
|
QString name_base = file.fileName();
|
||||||
|
|
||||||
m_type = Mod::MOD_UNKNOWN;
|
m_type = Mod::MOD_UNKNOWN;
|
||||||
|
|
||||||
m_mmc_id = name_base;
|
m_internal_id = name_base;
|
||||||
|
|
||||||
if (m_file.isDir())
|
if (m_file.isDir()) {
|
||||||
{
|
|
||||||
m_type = MOD_FOLDER;
|
m_type = MOD_FOLDER;
|
||||||
m_name = name_base;
|
m_name = name_base;
|
||||||
}
|
} else if (m_file.isFile()) {
|
||||||
else if (m_file.isFile())
|
if (name_base.endsWith(".disabled")) {
|
||||||
{
|
|
||||||
if (name_base.endsWith(".disabled"))
|
|
||||||
{
|
|
||||||
m_enabled = false;
|
m_enabled = false;
|
||||||
name_base.chop(9);
|
name_base.chop(9);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
}
|
}
|
||||||
if (name_base.endsWith(".zip") || name_base.endsWith(".jar"))
|
if (name_base.endsWith(".zip") || name_base.endsWith(".jar")) {
|
||||||
{
|
|
||||||
m_type = MOD_ZIPFILE;
|
m_type = MOD_ZIPFILE;
|
||||||
name_base.chop(4);
|
name_base.chop(4);
|
||||||
}
|
} else if (name_base.endsWith(".litemod")) {
|
||||||
else if (name_base.endsWith(".litemod"))
|
|
||||||
{
|
|
||||||
m_type = MOD_LITEMOD;
|
m_type = MOD_LITEMOD;
|
||||||
name_base.chop(8);
|
name_base.chop(8);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
m_type = MOD_SINGLEFILE;
|
m_type = MOD_SINGLEFILE;
|
||||||
}
|
}
|
||||||
m_name = name_base;
|
m_name = name_base;
|
||||||
@ -109,23 +97,22 @@ bool Mod::enable(bool value)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
QString path = m_file.absoluteFilePath();
|
QString path = m_file.absoluteFilePath();
|
||||||
if (value)
|
QFile file(path);
|
||||||
{
|
if (value) {
|
||||||
QFile foo(path);
|
|
||||||
if (!path.endsWith(".disabled"))
|
if (!path.endsWith(".disabled"))
|
||||||
return false;
|
return false;
|
||||||
path.chop(9);
|
path.chop(9);
|
||||||
if (!foo.rename(path))
|
|
||||||
|
if (!file.rename(path))
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
QFile foo(path);
|
|
||||||
path += ".disabled";
|
path += ".disabled";
|
||||||
if (!foo.rename(path))
|
|
||||||
|
if (!file.rename(path))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!fromMetadata())
|
|
||||||
|
if (!fromMetadata())
|
||||||
repath(QFileInfo(path));
|
repath(QFileInfo(path));
|
||||||
|
|
||||||
m_enabled = value;
|
m_enabled = value;
|
||||||
@ -141,29 +128,25 @@ bool Mod::destroy(QDir& index_dir)
|
|||||||
return FS::deletePath(m_file.filePath());
|
return FS::deletePath(m_file.filePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ModDetails& Mod::details() const
|
||||||
const ModDetails & Mod::details() const
|
|
||||||
{
|
{
|
||||||
if(!m_localDetails)
|
return m_localDetails ? *m_localDetails : invalidDetails;
|
||||||
return invalidDetails;
|
|
||||||
return *m_localDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString Mod::version() const
|
|
||||||
{
|
|
||||||
return details().version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Mod::name() const
|
QString Mod::name() const
|
||||||
{
|
{
|
||||||
auto & d = details();
|
auto d_name = details().name;
|
||||||
if(!d.name.isEmpty()) {
|
if (!d_name.isEmpty()) {
|
||||||
return d.name;
|
return d_name;
|
||||||
}
|
}
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Mod::version() const
|
||||||
|
{
|
||||||
|
return details().version;
|
||||||
|
}
|
||||||
|
|
||||||
QString Mod::homeurl() const
|
QString Mod::homeurl() const
|
||||||
{
|
{
|
||||||
return details().homeurl;
|
return details().homeurl;
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
QFileInfo filename() const { return m_file; }
|
QFileInfo filename() const { return m_file; }
|
||||||
QDateTime dateTimeChanged() const { return m_changedDateTime; }
|
QDateTime dateTimeChanged() const { return m_changedDateTime; }
|
||||||
QString mmc_id() const { return m_mmc_id; }
|
QString internal_id() const { return m_internal_id; }
|
||||||
ModType type() const { return m_type; }
|
ModType type() const { return m_type; }
|
||||||
bool fromMetadata() const { return m_from_metadata; }
|
bool fromMetadata() const { return m_from_metadata; }
|
||||||
bool enabled() const { return m_enabled; }
|
bool enabled() const { return m_enabled; }
|
||||||
@ -81,7 +81,7 @@ protected:
|
|||||||
QFileInfo m_file;
|
QFileInfo m_file;
|
||||||
QDateTime m_changedDateTime;
|
QDateTime m_changedDateTime;
|
||||||
|
|
||||||
QString m_mmc_id;
|
QString m_internal_id;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
ModType m_type = MOD_UNKNOWN;
|
ModType m_type = MOD_UNKNOWN;
|
||||||
bool m_from_metadata = false;
|
bool m_from_metadata = false;
|
||||||
|
@ -5,13 +5,24 @@
|
|||||||
|
|
||||||
struct ModDetails
|
struct ModDetails
|
||||||
{
|
{
|
||||||
|
/* Mod ID as defined in the ModLoader-specific metadata */
|
||||||
QString mod_id;
|
QString mod_id;
|
||||||
|
|
||||||
|
/* Human-readable name */
|
||||||
QString name;
|
QString name;
|
||||||
|
|
||||||
|
/* Human-readable mod version */
|
||||||
QString version;
|
QString version;
|
||||||
|
|
||||||
|
/* Human-readable minecraft version */
|
||||||
QString mcversion;
|
QString mcversion;
|
||||||
|
|
||||||
|
/* URL for mod's home page */
|
||||||
QString homeurl;
|
QString homeurl;
|
||||||
QString updateurl;
|
|
||||||
|
/* Human-readable description */
|
||||||
QString description;
|
QString description;
|
||||||
|
|
||||||
|
/* List of the author's names */
|
||||||
QStringList authors;
|
QStringList authors;
|
||||||
QString credits;
|
|
||||||
};
|
};
|
||||||
|
@ -159,7 +159,7 @@ void ModFolderModel::finishUpdate()
|
|||||||
modsIndex.clear();
|
modsIndex.clear();
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for(auto & mod: mods) {
|
for(auto & mod: mods) {
|
||||||
modsIndex[mod.mmc_id()] = idx;
|
modsIndex[mod.internal_id()] = idx;
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ void ModFolderModel::resolveMod(Mod& m)
|
|||||||
|
|
||||||
auto task = new LocalModParseTask(nextResolutionTicket, m.type(), m.filename());
|
auto task = new LocalModParseTask(nextResolutionTicket, m.type(), m.filename());
|
||||||
auto result = task->result();
|
auto result = task->result();
|
||||||
result->id = m.mmc_id();
|
result->id = m.internal_id();
|
||||||
activeTickets.insert(nextResolutionTicket, result);
|
activeTickets.insert(nextResolutionTicket, result);
|
||||||
m.setResolving(true, nextResolutionTicket);
|
m.setResolving(true, nextResolutionTicket);
|
||||||
nextResolutionTicket++;
|
nextResolutionTicket++;
|
||||||
@ -388,7 +388,7 @@ QVariant ModFolderModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
return mods[row].mmc_id();
|
return mods[row].internal_id();
|
||||||
|
|
||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
switch (column)
|
switch (column)
|
||||||
@ -443,11 +443,11 @@ bool ModFolderModel::setModStatus(int row, ModFolderModel::ModStatusAction actio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// preserve the row, but change its ID
|
// preserve the row, but change its ID
|
||||||
auto oldId = mod.mmc_id();
|
auto oldId = mod.internal_id();
|
||||||
if(!mod.enable(!mod.enabled())) {
|
if(!mod.enable(!mod.enabled())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto newId = mod.mmc_id();
|
auto newId = mod.internal_id();
|
||||||
if(modsIndex.contains(newId)) {
|
if(modsIndex.contains(newId)) {
|
||||||
// NOTE: this could handle a corner case, where we are overwriting a file, because the same 'mod' exists both enabled and disabled
|
// NOTE: this could handle a corner case, where we are overwriting a file, because the same 'mod' exists both enabled and disabled
|
||||||
// But is it necessary?
|
// But is it necessary?
|
||||||
|
@ -35,7 +35,6 @@ std::shared_ptr<ModDetails> ReadMCModInfo(QByteArray contents)
|
|||||||
details->name = name;
|
details->name = name;
|
||||||
}
|
}
|
||||||
details->version = firstObj.value("version").toString();
|
details->version = firstObj.value("version").toString();
|
||||||
details->updateurl = firstObj.value("updateUrl").toString();
|
|
||||||
auto homeurl = firstObj.value("url").toString().trimmed();
|
auto homeurl = firstObj.value("url").toString().trimmed();
|
||||||
if(!homeurl.isEmpty())
|
if(!homeurl.isEmpty())
|
||||||
{
|
{
|
||||||
@ -57,7 +56,6 @@ std::shared_ptr<ModDetails> ReadMCModInfo(QByteArray contents)
|
|||||||
{
|
{
|
||||||
details->authors.append(author.toString());
|
details->authors.append(author.toString());
|
||||||
}
|
}
|
||||||
details->credits = firstObj.value("credits").toString();
|
|
||||||
return details;
|
return details;
|
||||||
};
|
};
|
||||||
QJsonParseError jsonError;
|
QJsonParseError jsonError;
|
||||||
@ -168,27 +166,9 @@ std::shared_ptr<ModDetails> ReadMCModTOML(QByteArray contents)
|
|||||||
}
|
}
|
||||||
if(!authors.isEmpty())
|
if(!authors.isEmpty())
|
||||||
{
|
{
|
||||||
// author information is stored as a string now, not a list
|
|
||||||
details->authors.append(authors);
|
details->authors.append(authors);
|
||||||
}
|
}
|
||||||
// is credits even used anywhere? including this for completion/parity with old data version
|
|
||||||
toml_datum_t creditsDatum = toml_string_in(tomlData, "credits");
|
|
||||||
QString credits = "";
|
|
||||||
if(creditsDatum.ok)
|
|
||||||
{
|
|
||||||
authors = creditsDatum.u.s;
|
|
||||||
free(creditsDatum.u.s);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
creditsDatum = toml_string_in(tomlModsTable0, "credits");
|
|
||||||
if(creditsDatum.ok)
|
|
||||||
{
|
|
||||||
credits = creditsDatum.u.s;
|
|
||||||
free(creditsDatum.u.s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
details->credits = credits;
|
|
||||||
toml_datum_t homeurlDatum = toml_string_in(tomlData, "displayURL");
|
toml_datum_t homeurlDatum = toml_string_in(tomlData, "displayURL");
|
||||||
QString homeurl = "";
|
QString homeurl = "";
|
||||||
if(homeurlDatum.ok)
|
if(homeurlDatum.ok)
|
||||||
|
@ -3,32 +3,30 @@
|
|||||||
|
|
||||||
#include "modplatform/packwiz/Packwiz.h"
|
#include "modplatform/packwiz/Packwiz.h"
|
||||||
|
|
||||||
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir) :
|
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir)
|
||||||
m_mods_dir(mods_dir), m_index_dir(index_dir), m_result(new Result())
|
: m_mods_dir(mods_dir), m_index_dir(index_dir), m_result(new Result())
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void ModFolderLoadTask::run()
|
void ModFolderLoadTask::run()
|
||||||
{
|
{
|
||||||
// Read metadata first
|
// Read metadata first
|
||||||
m_index_dir.refresh();
|
m_index_dir.refresh();
|
||||||
for(auto entry : m_index_dir.entryList()){
|
for (auto entry : m_index_dir.entryList()) {
|
||||||
// QDir::Filter::NoDotAndDotDot seems to exclude all files for some reason...
|
// QDir::Filter::NoDotAndDotDot seems to exclude all files for some reason...
|
||||||
if(entry == "." || entry == "..")
|
if (entry == "." || entry == "..")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
entry.chop(5); // Remove .toml at the end
|
entry.chop(5); // Remove .toml at the end
|
||||||
Mod mod(m_mods_dir, Packwiz::getIndexForMod(m_index_dir, entry));
|
Mod mod(m_mods_dir, Packwiz::getIndexForMod(m_index_dir, entry));
|
||||||
m_result->mods[mod.mmc_id()] = mod;
|
m_result->mods[mod.internal_id()] = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read JAR files that don't have metadata
|
// Read JAR files that don't have metadata
|
||||||
m_mods_dir.refresh();
|
m_mods_dir.refresh();
|
||||||
for (auto entry : m_mods_dir.entryInfoList())
|
for (auto entry : m_mods_dir.entryInfoList()) {
|
||||||
{
|
|
||||||
Mod mod(entry);
|
Mod mod(entry);
|
||||||
if(!m_result->mods.contains(mod.mmc_id()))
|
if (!m_result->mods.contains(mod.internal_id()))
|
||||||
m_result->mods[mod.mmc_id()] = mod;
|
m_result->mods[mod.internal_id()] = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit succeeded();
|
emit succeeded();
|
||||||
|
@ -32,7 +32,7 @@ void MCModInfoFrame::updateWithMod(Mod &m)
|
|||||||
QString text = "";
|
QString text = "";
|
||||||
QString name = "";
|
QString name = "";
|
||||||
if (m.name().isEmpty())
|
if (m.name().isEmpty())
|
||||||
name = m.mmc_id();
|
name = m.internal_id();
|
||||||
else
|
else
|
||||||
name = m.name();
|
name = m.name();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user