summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorrobotbrainify <robotbrainify@gmail.com>2013-12-28 20:28:24 -0500
committerrobotbrainify <robotbrainify@gmail.com>2013-12-28 20:28:24 -0500
commit8549e5317f708e71c2dead9d84cc27d6185b523e (patch)
tree02e0f2c8c90501073bdb4c7912159fcc66ce7cac /logic
parent695ad1474e00a62b5afe19fb2b81974f584efeef (diff)
downloadMultiMC-8549e5317f708e71c2dead9d84cc27d6185b523e.tar
MultiMC-8549e5317f708e71c2dead9d84cc27d6185b523e.tar.gz
MultiMC-8549e5317f708e71c2dead9d84cc27d6185b523e.tar.lz
MultiMC-8549e5317f708e71c2dead9d84cc27d6185b523e.tar.xz
MultiMC-8549e5317f708e71c2dead9d84cc27d6185b523e.zip
Litemod version info.
Diffstat (limited to 'logic')
-rw-r--r--logic/Mod.cpp67
-rw-r--r--logic/Mod.h2
-rw-r--r--logic/ModList.cpp2
3 files changed, 57 insertions, 14 deletions
diff --git a/logic/Mod.cpp b/logic/Mod.cpp
index 8e880be1..009a32a4 100644
--- a/logic/Mod.cpp
+++ b/logic/Mod.cpp
@@ -47,7 +47,7 @@ void Mod::repath(const QFileInfo &file)
}
else if (m_file.isFile())
{
- if(name_base.endsWith(".disabled"))
+ if (name_base.endsWith(".disabled"))
{
m_enabled = false;
name_base.chop(9);
@@ -62,6 +62,11 @@ void Mod::repath(const QFileInfo &file)
m_type = MOD_ZIPFILE;
name_base.chop(4);
}
+ else if (name_base.endsWith(".litemod"))
+ {
+ m_type = MOD_LITEMOD;
+ name_base.chop(8);
+ }
else
{
m_type = MOD_SINGLEFILE;
@@ -79,7 +84,7 @@ void Mod::repath(const QFileInfo &file)
if (zip.setCurrentFile("mcmod.info"))
{
- if(!file.open(QIODevice::ReadOnly))
+ if (!file.open(QIODevice::ReadOnly))
{
zip.close();
return;
@@ -120,6 +125,27 @@ void Mod::repath(const QFileInfo &file)
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
@@ -152,8 +178,7 @@ void Mod::ReadMCModInfo(QByteArray contents)
}
m_credits = firstObj.value("credits").toString();
return;
- }
- ;
+ };
QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
// this is the very old format that had just the array
@@ -197,13 +222,29 @@ void Mod::ReadForgeInfo(QByteArray contents)
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)
{
if (!destroy())
return false;
bool success = false;
auto t = with.type();
-
+
if (t == MOD_ZIPFILE || t == MOD_SINGLEFILE)
{
QLOG_DEBUG() << "Copy: " << with.m_file.filePath() << " to " << m_file.filePath();
@@ -260,6 +301,7 @@ QString Mod::version() const
switch (type())
{
case MOD_ZIPFILE:
+ case MOD_LITEMOD:
return m_version;
case MOD_FOLDER:
return "Folder";
@@ -272,27 +314,27 @@ QString Mod::version() const
bool Mod::enable(bool value)
{
- if(m_type == Mod::MOD_UNKNOWN || m_type == Mod::MOD_FOLDER)
+ if (m_type == Mod::MOD_UNKNOWN || m_type == Mod::MOD_FOLDER)
return false;
- if(m_enabled == value)
+ if (m_enabled == value)
return false;
QString path = m_file.absoluteFilePath();
- if(value)
+ if (value)
{
QFile foo(path);
- if(!path.endsWith(".disabled"))
+ if (!path.endsWith(".disabled"))
return false;
path.chop(9);
- if(!foo.rename(path))
+ if (!foo.rename(path))
return false;
}
else
{
QFile foo(path);
path += ".disabled";
- if(!foo.rename(path))
+ if (!foo.rename(path))
return false;
}
m_file = QFileInfo(path);
@@ -305,6 +347,5 @@ bool Mod::operator==(const Mod &other) const
}
bool Mod::strongCompare(const Mod &other) const
{
- return mmc_id() == other.mmc_id() &&
- version() == other.version() && type() == other.type();
+ return mmc_id() == other.mmc_id() && version() == other.version() && type() == other.type();
}
diff --git a/logic/Mod.h b/logic/Mod.h
index 05d3cea2..2eb2b97a 100644
--- a/logic/Mod.h
+++ b/logic/Mod.h
@@ -25,6 +25,7 @@ public:
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_FOLDER, //!< The mod is in a folder on the filesystem.
+ MOD_LITEMOD, //!< The mod is a litemod
};
Mod(const QFileInfo &file);
@@ -102,6 +103,7 @@ public:
private:
void ReadMCModInfo(QByteArray contents);
void ReadForgeInfo(QByteArray contents);
+ void ReadLiteModInfo(QByteArray contents);
protected:
diff --git a/logic/ModList.cpp b/logic/ModList.cpp
index eb7f3128..fd41bcf7 100644
--- a/logic/ModList.cpp
+++ b/logic/ModList.cpp
@@ -255,7 +255,7 @@ bool ModList::installMod(const QFileInfo &filename, int index)
auto type = m.type();
if (type == Mod::MOD_UNKNOWN)
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());
if (!QFile::copy(filename.filePath(), newpath))