From acf25d8a33ef67b79d8e8a8859f5559e011373a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 26 Dec 2013 05:14:32 +0100 Subject: Disable/enable mods with checkboxes. Needs testing. A lot of testing! --- logic/Mod.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 10 deletions(-) (limited to 'logic/Mod.cpp') diff --git a/logic/Mod.cpp b/logic/Mod.cpp index cff9467e..8e880be1 100644 --- a/logic/Mod.cpp +++ b/logic/Mod.cpp @@ -35,20 +35,40 @@ Mod::Mod(const QFileInfo &file) void Mod::repath(const QFileInfo &file) { m_file = file; - m_name = file.completeBaseName(); - m_id = file.fileName(); + QString name_base = file.fileName(); m_type = Mod::MOD_UNKNOWN; + if (m_file.isDir()) + { m_type = MOD_FOLDER; + m_name = name_base; + m_mmc_id = name_base; + } else if (m_file.isFile()) { - QString ext = m_file.suffix().toLower(); - if (ext == "zip" || ext == "jar") + if(name_base.endsWith(".disabled")) + { + m_enabled = false; + name_base.chop(9); + } + else + { + m_enabled = true; + } + m_mmc_id = name_base; + if (name_base.endsWith(".zip") || name_base.endsWith(".jar")) + { m_type = MOD_ZIPFILE; + name_base.chop(4); + } else + { m_type = MOD_SINGLEFILE; + } + m_name = name_base; } + if (m_type == MOD_ZIPFILE) { QuaZip zip(m_file.filePath()); @@ -114,7 +134,7 @@ void Mod::ReadMCModInfo(QByteArray contents) if (!arr.at(0).isObject()) return; auto firstObj = arr.at(0).toObject(); - m_id = firstObj.value("modid").toString(); + m_mod_id = firstObj.value("modid").toString(); m_name = firstObj.value("name").toString(); m_version = firstObj.value("version").toString(); m_homeurl = firstObj.value("url").toString(); @@ -163,7 +183,7 @@ void Mod::ReadForgeInfo(QByteArray contents) { // Read the data m_name = "Minecraft Forge"; - m_id = "Forge"; + m_mod_id = "Forge"; m_homeurl = "http://www.minecraftforge.net/forum/"; INIFile ini; if (!ini.loadFile(contents)) @@ -183,9 +203,11 @@ bool Mod::replace(Mod &with) return false; bool success = false; auto t = with.type(); + if (t == MOD_ZIPFILE || t == MOD_SINGLEFILE) { - success = QFile::copy(with.m_file.filePath(), m_file.path()); + QLOG_DEBUG() << "Copy: " << with.m_file.filePath() << " to " << m_file.filePath(); + success = QFile::copy(with.m_file.filePath(), m_file.filePath()); } if (t == MOD_FOLDER) { @@ -193,11 +215,17 @@ bool Mod::replace(Mod &with) } if (success) { - m_id = with.m_id; - m_mcversion = with.m_mcversion; - m_type = with.m_type; m_name = with.m_name; + m_mmc_id = with.m_mmc_id; + m_mod_id = with.m_mod_id; m_version = with.m_version; + m_mcversion = with.m_mcversion; + m_description = with.m_description; + m_authors = with.m_authors; + m_credits = with.m_credits; + m_homeurl = with.m_homeurl; + m_type = with.m_type; + m_file.refresh(); } return success; } @@ -241,3 +269,42 @@ QString Mod::version() const return "VOID"; } } + +bool Mod::enable(bool value) +{ + if(m_type == Mod::MOD_UNKNOWN || m_type == Mod::MOD_FOLDER) + return false; + + if(m_enabled == value) + return false; + + QString path = m_file.absoluteFilePath(); + if(value) + { + QFile foo(path); + if(!path.endsWith(".disabled")) + return false; + path.chop(9); + if(!foo.rename(path)) + return false; + } + else + { + QFile foo(path); + path += ".disabled"; + if(!foo.rename(path)) + return false; + } + m_file = QFileInfo(path); + m_enabled = value; + return true; +} +bool Mod::operator==(const Mod &other) const +{ + return mmc_id() == other.mmc_id(); +} +bool Mod::strongCompare(const Mod &other) const +{ + return mmc_id() == other.mmc_id() && + version() == other.version() && type() == other.type(); +} -- cgit v1.2.3 From 8549e5317f708e71c2dead9d84cc27d6185b523e Mon Sep 17 00:00:00 2001 From: robotbrainify Date: Sat, 28 Dec 2013 20:28:24 -0500 Subject: Litemod version info. --- logic/Mod.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 13 deletions(-) (limited to 'logic/Mod.cpp') 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(); } -- cgit v1.2.3 From 654f444f55de58f5cf0477e3b08b8f18e8d60831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 29 Dec 2013 04:17:52 +0100 Subject: Fix various LiteLoader related bugs. --- logic/Mod.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'logic/Mod.cpp') diff --git a/logic/Mod.cpp b/logic/Mod.cpp index 009a32a4..6732446d 100644 --- a/logic/Mod.cpp +++ b/logic/Mod.cpp @@ -227,11 +227,18 @@ 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("name")) + { + m_mod_id = m_name = 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(); -- cgit v1.2.3