This commit is contained in:
Petr Mrázek 2013-12-29 03:36:47 +01:00
commit fbf1cc2848
3 changed files with 57 additions and 14 deletions

View File

@ -62,6 +62,11 @@ void Mod::repath(const QFileInfo &file)
m_type = MOD_ZIPFILE; m_type = MOD_ZIPFILE;
name_base.chop(4); name_base.chop(4);
} }
else if (name_base.endsWith(".litemod"))
{
m_type = MOD_LITEMOD;
name_base.chop(8);
}
else else
{ {
m_type = MOD_SINGLEFILE; m_type = MOD_SINGLEFILE;
@ -120,6 +125,27 @@ void Mod::repath(const QFileInfo &file)
ReadMCModInfo(data); ReadMCModInfo(data);
} }
} }
else if (m_type == MOD_LITEMOD)
{
QuaZip zip(m_file.filePath());
if (!zip.open(QuaZip::mdUnzip))
return;
QuaZipFile file(&zip);
if (zip.setCurrentFile("litemod.json"))
{
if (!file.open(QIODevice::ReadOnly))
{
zip.close();
return;
}
ReadLiteModInfo(file.readAll());
file.close();
}
zip.close();
}
} }
// NEW format // NEW format
@ -152,8 +178,7 @@ void Mod::ReadMCModInfo(QByteArray contents)
} }
m_credits = firstObj.value("credits").toString(); m_credits = firstObj.value("credits").toString();
return; return;
} };
;
QJsonParseError jsonError; QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
// this is the very old format that had just the array // this is the very old format that had just the array
@ -197,6 +222,22 @@ void Mod::ReadForgeInfo(QByteArray contents)
m_version = major + "." + minor + "." + revision + "." + build; m_version = major + "." + minor + "." + revision + "." + build;
} }
void Mod::ReadLiteModInfo(QByteArray contents)
{
QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
auto object = jsonDoc.object();
m_mod_id = object.value("name").toString();
if(object.contains("version"))
m_version=object.value("version").toString("");
else
m_version=object.value("revision").toString("");
m_mcversion = object.value("mcversion").toString();
m_authors = object.value("author").toString();
m_description = object.value("description").toString();
m_homeurl = object.value("url").toString();
}
bool Mod::replace(Mod &with) bool Mod::replace(Mod &with)
{ {
if (!destroy()) if (!destroy())
@ -260,6 +301,7 @@ QString Mod::version() const
switch (type()) switch (type())
{ {
case MOD_ZIPFILE: case MOD_ZIPFILE:
case MOD_LITEMOD:
return m_version; return m_version;
case MOD_FOLDER: case MOD_FOLDER:
return "Folder"; return "Folder";
@ -305,6 +347,5 @@ bool Mod::operator==(const Mod &other) const
} }
bool Mod::strongCompare(const Mod &other) const bool Mod::strongCompare(const Mod &other) const
{ {
return mmc_id() == other.mmc_id() && return mmc_id() == other.mmc_id() && version() == other.version() && type() == other.type();
version() == other.version() && type() == other.type();
} }

View File

@ -25,6 +25,7 @@ public:
MOD_ZIPFILE, //!< The mod is a zip file containing the mod's class files. MOD_ZIPFILE, //!< The mod is a zip file containing the mod's class files.
MOD_SINGLEFILE, //!< The mod is a single file (not a zip file). MOD_SINGLEFILE, //!< The mod is a single file (not a zip file).
MOD_FOLDER, //!< The mod is in a folder on the filesystem. MOD_FOLDER, //!< The mod is in a folder on the filesystem.
MOD_LITEMOD, //!< The mod is a litemod
}; };
Mod(const QFileInfo &file); Mod(const QFileInfo &file);
@ -102,6 +103,7 @@ public:
private: private:
void ReadMCModInfo(QByteArray contents); void ReadMCModInfo(QByteArray contents);
void ReadForgeInfo(QByteArray contents); void ReadForgeInfo(QByteArray contents);
void ReadLiteModInfo(QByteArray contents);
protected: protected:

View File

@ -255,7 +255,7 @@ bool ModList::installMod(const QFileInfo &filename, int index)
auto type = m.type(); auto type = m.type();
if (type == Mod::MOD_UNKNOWN) if (type == Mod::MOD_UNKNOWN)
return false; return false;
if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE) if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD)
{ {
QString newpath = PathCombine(m_dir.path(), filename.fileName()); QString newpath = PathCombine(m_dir.path(), filename.fileName());
if (!QFile::copy(filename.filePath(), newpath)) if (!QFile::copy(filename.filePath(), newpath))