From f5f2d33f930674e03f8c81c1eaa3d35ddabc2886 Mon Sep 17 00:00:00 2001 From: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> Date: Sat, 11 Feb 2023 17:35:08 -0500 Subject: parse nil metadata Signed-off-by: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> --- launcher/InstancePageProvider.h | 2 +- launcher/minecraft/mod/tasks/LocalModParseTask.cpp | 72 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) (limited to 'launcher') diff --git a/launcher/InstancePageProvider.h b/launcher/InstancePageProvider.h index 5d8beca9..286298cc 100644 --- a/launcher/InstancePageProvider.h +++ b/launcher/InstancePageProvider.h @@ -36,7 +36,7 @@ public: values.append(new VersionPage(onesix.get())); values.append(ManagedPackPage::createPage(onesix.get())); auto modsPage = new ModFolderPage(onesix.get(), onesix->loaderModList()); - modsPage->setFilter("%1 (*.zip *.jar *.litemod)"); + modsPage->setFilter("%1 (*.zip *.jar *.litemod *.nilmod)"); values.append(modsPage); values.append(new CoreModFolderPage(onesix.get(), onesix->coreModList())); values.append(new ResourcePackPage(onesix.get(), onesix->resourcePackList())); diff --git a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp index 91cb747f..03b599ea 100644 --- a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp @@ -285,6 +285,48 @@ ModDetails ReadLiteModInfo(QByteArray contents) return details; } +// https://git.sleeping.town/unascribed/NilLoader/src/commit/d7fc87b255fc31019ff90f80d45894927fac6efc/src/main/java/nilloader/api/NilMetadata.java#L64 +ModDetails ReadNilModInfo(QByteArray contents, QString fname) +{ + ModDetails details; + + // this is a css file (why) but we only care about a couple key/value pairs from it + // hence this instead of a css parser lib + // could be made a lot better but it works(tm) + // (does css require properties to be on their own lines? if so, the code can get less horrible looking) + QString contentStr = QString(contents).trimmed(); + int firstidx = contentStr.indexOf("@nilmod"); + firstidx = contentStr.indexOf("{", firstidx); + int lastidx = contentStr.indexOf("}", firstidx); + int nameidx = contentStr.indexOf("name:", firstidx); + int descidx = contentStr.indexOf("description:", firstidx); + int authorsidx = contentStr.indexOf("authors:", firstidx); + int versionidx = contentStr.indexOf("version:", firstidx); + + if (nameidx != -1 && nameidx < lastidx) { + nameidx = contentStr.indexOf('"', nameidx); + details.name = contentStr.mid(nameidx + 1, contentStr.indexOf('"', nameidx + 1) - nameidx - 1); + } + if (descidx != -1 && descidx < lastidx) { + descidx = contentStr.indexOf('"', descidx); + details.description = contentStr.mid(descidx + 1, contentStr.indexOf('"', descidx + 1) - descidx - 1); + } + if (authorsidx != -1 && authorsidx < lastidx) { + authorsidx = contentStr.indexOf('"', authorsidx); + details.authors.append(contentStr.mid(authorsidx + 1, contentStr.indexOf('"', authorsidx + 1) - authorsidx - 1)); + } + if (versionidx != -1 && versionidx < lastidx) { + versionidx = contentStr.indexOf('"', versionidx); + details.version = contentStr.mid(versionidx + 1, contentStr.indexOf('"', versionidx + 1) - versionidx - 1); + } else { + details.version = "?"; + } + + details.mod_id = fname.remove(".nilmod.css"); + + return details; +} + bool process(Mod& mod, ProcessingLevel level) { switch (mod.type()) { @@ -401,6 +443,36 @@ bool processZIP(Mod& mod, ProcessingLevel level) mod.setDetails(details); return true; + } else if (zip.setCurrentFile("META-INF/nil/mappings.json")) { + // nilloader uses the filename of the metadata file for the modid, so we can't know the exact filename + // thankfully, there is a good file to use as a canary so we don't look for nil meta all the time + + QStringList foundNilMetas; + for (auto& fname : zip.getFileNameList()) { + if (fname.endsWith(".nilmod.css")) { + foundNilMetas.append(fname); + } + } + + if (foundNilMetas.size() > 1 && foundNilMetas.at(0) == "nilloader.nilmod.css") { + // nilmods can shade nilloader to be able to run as a standalone agent - which includes nilloader's own meta file + // so if there is more than one meta file, ignore nilloader's meta, since it's not the actual mod + foundNilMetas.removeFirst(); + } + + if (zip.setCurrentFile(foundNilMetas.at(0))) { + if (!file.open(QIODevice::ReadOnly)) { + zip.close(); + return false; + } + + details = ReadNilModInfo(file.readAll(), foundNilMetas.at(0)); + file.close(); + zip.close(); + + mod.setDetails(details); + return true; + } } zip.close(); -- cgit From 7896dd19c12c0276551ba188adc6184dcf0a3184 Mon Sep 17 00:00:00 2001 From: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> Date: Sat, 11 Feb 2023 17:36:06 -0500 Subject: nilmods instance page mostly copied from the coremod page impl Signed-off-by: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> --- launcher/InstancePageProvider.h | 1 + launcher/minecraft/MinecraftInstance.cpp | 17 +++++++++++++++++ launcher/minecraft/MinecraftInstance.h | 3 +++ launcher/minecraft/launch/ScanModFolders.cpp | 14 +++++++++++++- launcher/minecraft/launch/ScanModFolders.h | 2 ++ launcher/ui/pages/instance/ModFolderPage.cpp | 9 +++++++++ launcher/ui/pages/instance/ModFolderPage.h | 13 +++++++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) (limited to 'launcher') diff --git a/launcher/InstancePageProvider.h b/launcher/InstancePageProvider.h index 286298cc..b4b6e739 100644 --- a/launcher/InstancePageProvider.h +++ b/launcher/InstancePageProvider.h @@ -39,6 +39,7 @@ public: modsPage->setFilter("%1 (*.zip *.jar *.litemod *.nilmod)"); values.append(modsPage); values.append(new CoreModFolderPage(onesix.get(), onesix->coreModList())); + values.append(new NilModFolderPage(onesix.get(), onesix->nilModList())); values.append(new ResourcePackPage(onesix.get(), onesix->resourcePackList())); values.append(new TexturePackPage(onesix.get(), onesix->texturePackList())); values.append(new ShaderPackPage(onesix.get(), onesix->shaderPackList())); diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 4fe234c4..0737a648 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -290,6 +290,11 @@ QString MinecraftInstance::coreModsDir() const return FS::PathCombine(gameRoot(), "coremods"); } +QString MinecraftInstance::nilModsDir() const +{ + return FS::PathCombine(gameRoot(), "nilmods"); +} + QString MinecraftInstance::resourcePacksDir() const { return FS::PathCombine(gameRoot(), "resourcepacks"); @@ -1125,6 +1130,18 @@ std::shared_ptr MinecraftInstance::coreModList() const return m_core_mod_list; } +std::shared_ptr MinecraftInstance::nilModList() const +{ + if (!m_nil_mod_list) + { + bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool(); + m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), is_indexed)); + m_nil_mod_list->disableInteraction(isRunning()); + connect(this, &BaseInstance::runningStatusChanged, m_nil_mod_list.get(), &ModFolderModel::disableInteraction); + } + return m_nil_mod_list; +} + std::shared_ptr MinecraftInstance::resourcePackList() const { if (!m_resource_pack_list) diff --git a/launcher/minecraft/MinecraftInstance.h b/launcher/minecraft/MinecraftInstance.h index 1bbd7b83..a75fa481 100644 --- a/launcher/minecraft/MinecraftInstance.h +++ b/launcher/minecraft/MinecraftInstance.h @@ -84,6 +84,7 @@ public: QString shaderPacksDir() const; QString modsRoot() const override; QString coreModsDir() const; + QString nilModsDir() const; QString modsCacheLocation() const; QString libDir() const; QString worldDir() const; @@ -116,6 +117,7 @@ public: ////// Mod Lists ////// std::shared_ptr loaderModList() const; std::shared_ptr coreModList() const; + std::shared_ptr nilModList() const; std::shared_ptr resourcePackList() const; std::shared_ptr texturePackList() const; std::shared_ptr shaderPackList() const; @@ -170,6 +172,7 @@ protected: // data std::shared_ptr m_components; mutable std::shared_ptr m_loader_mod_list; mutable std::shared_ptr m_core_mod_list; + mutable std::shared_ptr m_nil_mod_list; mutable std::shared_ptr m_resource_pack_list; mutable std::shared_ptr m_shader_pack_list; mutable std::shared_ptr m_texture_pack_list; diff --git a/launcher/minecraft/launch/ScanModFolders.cpp b/launcher/minecraft/launch/ScanModFolders.cpp index bdffeadd..71e7638c 100644 --- a/launcher/minecraft/launch/ScanModFolders.cpp +++ b/launcher/minecraft/launch/ScanModFolders.cpp @@ -55,6 +55,12 @@ void ScanModFolders::executeTask() if(!cores->update()) { m_coreModsDone = true; } + + auto nils = m_inst->nilModList(); + connect(nils.get(), &ModFolderModel::updateFinished, this, &ScanModFolders::nilModsDone); + if(!nils->update()) { + m_nilModsDone = true; + } checkDone(); } @@ -70,9 +76,15 @@ void ScanModFolders::coreModsDone() checkDone(); } +void ScanModFolders::nilModsDone() +{ + m_nilModsDone = true; + checkDone(); +} + void ScanModFolders::checkDone() { - if(m_modsDone && m_coreModsDone) { + if(m_modsDone && m_coreModsDone && m_nilModsDone) { emitSucceeded(); } } diff --git a/launcher/minecraft/launch/ScanModFolders.h b/launcher/minecraft/launch/ScanModFolders.h index d5989170..111a5850 100644 --- a/launcher/minecraft/launch/ScanModFolders.h +++ b/launcher/minecraft/launch/ScanModFolders.h @@ -33,10 +33,12 @@ public: private slots: void coreModsDone(); void modsDone(); + void nilModsDone(); private: void checkDone(); private: // DATA bool m_modsDone = false; + bool m_nilModsDone = false; bool m_coreModsDone = false; }; diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index d9069915..8c87a8a0 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -273,3 +273,12 @@ bool CoreModFolderPage::shouldDisplay() const } return false; } + +NilModFolderPage::NilModFolderPage(BaseInstance* inst, std::shared_ptr mods, QWidget* parent) + : ModFolderPage(inst, mods, parent) +{} + +bool NilModFolderPage::shouldDisplay() const +{ + return !m_model->dir().isEmpty(); +} diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h index ff58b38a..cad240bd 100644 --- a/launcher/ui/pages/instance/ModFolderPage.h +++ b/launcher/ui/pages/instance/ModFolderPage.h @@ -81,3 +81,16 @@ class CoreModFolderPage : public ModFolderPage { virtual bool shouldDisplay() const override; }; + +class NilModFolderPage : public ModFolderPage { + public: + explicit NilModFolderPage(BaseInstance* inst, std::shared_ptr mods, QWidget* parent = 0); + virtual ~NilModFolderPage() = default; + + virtual QString displayName() const override { return tr("Nilmods"); } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("coremods"); } + virtual QString id() const override { return "nilmods"; } + virtual QString helpPage() const override { return "Nil-mods"; } + + virtual bool shouldDisplay() const override; +}; -- cgit From c07fff750354e23149470d493a7c96624fe2ab26 Mon Sep 17 00:00:00 2001 From: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> Date: Sun, 12 Feb 2023 17:23:15 -0500 Subject: switch to qdcss for parsing make it not horrible to look at Signed-off-by: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> --- CMakeLists.txt | 1 + launcher/CMakeLists.txt | 1 + launcher/minecraft/mod/tasks/LocalModParseTask.cpp | 41 ++++++------------ libraries/README.md | 8 ++++ libraries/qdcss/CMakeLists.txt | 18 ++++++++ libraries/qdcss/include/qdcss.h | 21 ++++++++++ libraries/qdcss/src/qdcss.cpp | 49 ++++++++++++++++++++++ 7 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 libraries/qdcss/CMakeLists.txt create mode 100644 libraries/qdcss/include/qdcss.h create mode 100644 libraries/qdcss/src/qdcss.cpp (limited to 'launcher') diff --git a/CMakeLists.txt b/CMakeLists.txt index 37bb49ba..6ce8143c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -448,6 +448,7 @@ if (NOT ghc_filesystem_FOUND) else() message(STATUS "Using system ghc_filesystem") endif() +add_subdirectory(libraries/qdcss) # css parser ############################### Built Artifacts ############################### diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 1bfe9cbc..c6b9e380 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1025,6 +1025,7 @@ target_link_libraries(Launcher_logic nbt++ ${ZLIB_LIBRARIES} tomlplusplus::tomlplusplus + qdcss BuildConfig Katabasis Qt${QT_VERSION_MAJOR}::Widgets diff --git a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp index 03b599ea..2263f8ec 100644 --- a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -290,37 +291,21 @@ ModDetails ReadNilModInfo(QByteArray contents, QString fname) { ModDetails details; - // this is a css file (why) but we only care about a couple key/value pairs from it - // hence this instead of a css parser lib - // could be made a lot better but it works(tm) - // (does css require properties to be on their own lines? if so, the code can get less horrible looking) - QString contentStr = QString(contents).trimmed(); - int firstidx = contentStr.indexOf("@nilmod"); - firstidx = contentStr.indexOf("{", firstidx); - int lastidx = contentStr.indexOf("}", firstidx); - int nameidx = contentStr.indexOf("name:", firstidx); - int descidx = contentStr.indexOf("description:", firstidx); - int authorsidx = contentStr.indexOf("authors:", firstidx); - int versionidx = contentStr.indexOf("version:", firstidx); - - if (nameidx != -1 && nameidx < lastidx) { - nameidx = contentStr.indexOf('"', nameidx); - details.name = contentStr.mid(nameidx + 1, contentStr.indexOf('"', nameidx + 1) - nameidx - 1); - } - if (descidx != -1 && descidx < lastidx) { - descidx = contentStr.indexOf('"', descidx); - details.description = contentStr.mid(descidx + 1, contentStr.indexOf('"', descidx + 1) - descidx - 1); + QDCSS cssData = QDCSS(contents); + auto name = cssData.get("@nilmod.name"); + auto desc = cssData.get("@nilmod.description"); + auto authors = cssData.get("@nilmod.authors"); + + if (name->has_value()) { + details.name = name->value(); } - if (authorsidx != -1 && authorsidx < lastidx) { - authorsidx = contentStr.indexOf('"', authorsidx); - details.authors.append(contentStr.mid(authorsidx + 1, contentStr.indexOf('"', authorsidx + 1) - authorsidx - 1)); + if (desc->has_value()) { + details.description = desc->value(); } - if (versionidx != -1 && versionidx < lastidx) { - versionidx = contentStr.indexOf('"', versionidx); - details.version = contentStr.mid(versionidx + 1, contentStr.indexOf('"', versionidx + 1) - versionidx - 1); - } else { - details.version = "?"; + if (authors->has_value()) { + details.authors.append(authors->value()); } + details.version = cssData.get("@nilmod.version")->value_or("?"); details.mod_id = fname.remove(".nilmod.css"); diff --git a/libraries/README.md b/libraries/README.md index 95be8740..4da11314 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -140,3 +140,11 @@ A TOML language parser. Used by Forge 1.14+ to store mod metadata. See [github repo](https://github.com/marzer/tomlplusplus). Licenced under the MIT licence. + +## qdcss + +A quick and dirty css parser, used by NilLoader to store mod metadata. + +Translated (and heavily trimmed down) from [the original Java code](https://github.com/unascribed/NilLoader/blob/trunk/src/main/java/nilloader/api/lib/qdcss/QDCSS.java) from NilLoader + +Licensed under LGPL version 3. diff --git a/libraries/qdcss/CMakeLists.txt b/libraries/qdcss/CMakeLists.txt new file mode 100644 index 00000000..0afdef32 --- /dev/null +++ b/libraries/qdcss/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.9.4) +project(qdcss) + +if(QT_VERSION_MAJOR EQUAL 5) + find_package(Qt5 COMPONENTS Core REQUIRED) +elseif(Launcher_QT_VERSION_MAJOR EQUAL 6) + find_package(Qt6 COMPONENTS Core Core5Compat REQUIRED) + list(APPEND qdcss_LIBS Qt${QT_VERSION_MAJOR}::Core5Compat) +endif() + +set(QDCSS_SOURCES + include/qdcss.h + src/qdcss.cpp +) + +add_library(qdcss STATIC ${QDCSS_SOURCES}) +target_include_directories(qdcss PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_link_libraries(qdcss Qt${QT_VERSION_MAJOR}::Core ${qdcss_LIBS}) diff --git a/libraries/qdcss/include/qdcss.h b/libraries/qdcss/include/qdcss.h new file mode 100644 index 00000000..2bcac36f --- /dev/null +++ b/libraries/qdcss/include/qdcss.h @@ -0,0 +1,21 @@ +#ifndef QDCSS_H +#define QDCSS_H + +#include +#include +#include +#include + +class QDCSS { + // these are all we need to parse a couple string values out of a css string + // lots more in the original code, yet to be ported + // https://github.com/unascribed/NilLoader/blob/trunk/src/main/java/nilloader/api/lib/qdcss/QDCSS.java + public: + QDCSS(QString); + std::optional* get(QString); + + private: + QMap m_data; +}; + +#endif // QDCSS_H diff --git a/libraries/qdcss/src/qdcss.cpp b/libraries/qdcss/src/qdcss.cpp new file mode 100644 index 00000000..4426dcae --- /dev/null +++ b/libraries/qdcss/src/qdcss.cpp @@ -0,0 +1,49 @@ +#include "qdcss.h" + +#include +#include +#include + +QRegularExpression ruleset_re = QRegularExpression(R"([#.]?(@?\w+?)\s*\{(.*?)\})", QRegularExpression::DotMatchesEverythingOption); +QRegularExpression rule_re = QRegularExpression(R"((\S+?)\s*:\s*(?:\"(.*?)(?append(value); + } + } +} + +std::optional* QDCSS::get(QString key) +{ + auto found = m_data.find(key); + + if (found == m_data.end() || found->empty()) { + return new std::optional; + } + + return new std::optional(found->back()); +} -- cgit From 9c2a3231c5ee1b15b09bae9b064827ad3dcb86e0 Mon Sep 17 00:00:00 2001 From: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> Date: Mon, 13 Feb 2023 01:45:23 -0500 Subject: do not create nilmods folder "it cant be that easy" - me, clueless Signed-off-by: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> --- launcher/minecraft/MinecraftInstance.cpp | 2 +- launcher/minecraft/mod/ModFolderModel.cpp | 2 +- launcher/minecraft/mod/ModFolderModel.h | 2 +- launcher/minecraft/mod/ResourceFolderModel.cpp | 6 ++++-- launcher/minecraft/mod/ResourceFolderModel.h | 3 ++- launcher/ui/pages/instance/ModFolderPage.cpp | 2 +- launcher/ui/pages/instance/ModFolderPage.h | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) (limited to 'launcher') diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 0737a648..af4da5d0 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -1135,7 +1135,7 @@ std::shared_ptr MinecraftInstance::nilModList() const if (!m_nil_mod_list) { bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool(); - m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), is_indexed)); + m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), is_indexed, false)); m_nil_mod_list->disableInteraction(isRunning()); connect(this, &BaseInstance::runningStatusChanged, m_nil_mod_list.get(), &ModFolderModel::disableInteraction); } diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index f258ad69..2d777656 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -50,7 +50,7 @@ #include "minecraft/mod/tasks/ModFolderLoadTask.h" #include "modplatform/ModIndex.h" -ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(QDir(dir)), m_is_indexed(is_indexed) +ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed, bool create_dir) : ResourceFolderModel(QDir(dir), create_dir), m_is_indexed(is_indexed) { m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER }; } diff --git a/launcher/minecraft/mod/ModFolderModel.h b/launcher/minecraft/mod/ModFolderModel.h index 6898f6eb..84e70db9 100644 --- a/launcher/minecraft/mod/ModFolderModel.h +++ b/launcher/minecraft/mod/ModFolderModel.h @@ -75,7 +75,7 @@ public: Enable, Toggle }; - ModFolderModel(const QString &dir, bool is_indexed = false); + ModFolderModel(const QString &dir, bool is_indexed = false, bool create_dir = true); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index fdfb434b..b8353133 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -12,9 +12,11 @@ #include "tasks/Task.h" -ResourceFolderModel::ResourceFolderModel(QDir dir, QObject* parent) : QAbstractListModel(parent), m_dir(dir), m_watcher(this) +ResourceFolderModel::ResourceFolderModel(QDir dir, bool create_dir, QObject* parent) : QAbstractListModel(parent), m_dir(dir), m_watcher(this) { - FS::ensureFolderPathExists(m_dir.absolutePath()); + if (create_dir) { + FS::ensureFolderPathExists(m_dir.absolutePath()); + } m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h index f1bc2dd7..e4227a33 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.h +++ b/launcher/minecraft/mod/ResourceFolderModel.h @@ -24,7 +24,8 @@ class QSortFilterProxyModel; class ResourceFolderModel : public QAbstractListModel { Q_OBJECT public: - ResourceFolderModel(QDir, QObject* parent = nullptr); + ResourceFolderModel(QDir, bool, QObject* parent = nullptr); + ResourceFolderModel(QDir dir, QObject* parent = nullptr) : ResourceFolderModel(dir, true, parent) {}; ~ResourceFolderModel() override; /** Starts watching the paths for changes. diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 8c87a8a0..4548af59 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -280,5 +280,5 @@ NilModFolderPage::NilModFolderPage(BaseInstance* inst, std::shared_ptrdir().isEmpty(); + return m_model->dir().exists(); } diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h index cad240bd..2fc7b574 100644 --- a/launcher/ui/pages/instance/ModFolderPage.h +++ b/launcher/ui/pages/instance/ModFolderPage.h @@ -90,7 +90,7 @@ class NilModFolderPage : public ModFolderPage { virtual QString displayName() const override { return tr("Nilmods"); } virtual QIcon icon() const override { return APPLICATION->getThemedIcon("coremods"); } virtual QString id() const override { return "nilmods"; } - virtual QString helpPage() const override { return "Nil-mods"; } + virtual QString helpPage() const override { return "Nilmods"; } virtual bool shouldDisplay() const override; }; -- cgit From 256fc322a8decfd113ea73bf61ec15ce31a6f474 Mon Sep 17 00:00:00 2001 From: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> Date: Thu, 16 Feb 2023 12:57:35 -0500 Subject: minor cleanup Signed-off-by: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> --- launcher/minecraft/mod/tasks/LocalModParseTask.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'launcher') diff --git a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp index 2263f8ec..945ccda7 100644 --- a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp @@ -434,17 +434,12 @@ bool processZIP(Mod& mod, ProcessingLevel level) QStringList foundNilMetas; for (auto& fname : zip.getFileNameList()) { - if (fname.endsWith(".nilmod.css")) { + // nilmods can shade nilloader to be able to run as a standalone agent - which includes nilloader's own meta file + if (fname.endsWith(".nilmod.css") && fname != "nilloader.nilmod.css") { foundNilMetas.append(fname); } } - if (foundNilMetas.size() > 1 && foundNilMetas.at(0) == "nilloader.nilmod.css") { - // nilmods can shade nilloader to be able to run as a standalone agent - which includes nilloader's own meta file - // so if there is more than one meta file, ignore nilloader's meta, since it's not the actual mod - foundNilMetas.removeFirst(); - } - if (zip.setCurrentFile(foundNilMetas.at(0))) { if (!file.open(QIODevice::ReadOnly)) { zip.close(); -- cgit From 7973b01e81af29f0de7c6873ef119f15a2fb0791 Mon Sep 17 00:00:00 2001 From: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> Date: Sun, 19 Feb 2023 17:21:53 -0500 Subject: fix metadata for mods with `.nilmod` extension Signed-off-by: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> --- launcher/minecraft/mod/Resource.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'launcher') diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 7c572d92..0d35d755 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -37,6 +37,9 @@ void Resource::parseFile() if (file_name.endsWith(".zip") || file_name.endsWith(".jar")) { m_type = ResourceType::ZIPFILE; file_name.chop(4); + } else if (file_name.endsWith(".nilmod")) { + m_type = ResourceType::ZIPFILE; + file_name.chop(7); } else if (file_name.endsWith(".litemod")) { m_type = ResourceType::LITEMOD; file_name.chop(8); -- cgit From dc8109658c3c178e91acfc316467d1bdffe0bf40 Mon Sep 17 00:00:00 2001 From: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> Date: Wed, 22 Feb 2023 13:20:13 -0500 Subject: review fixes Signed-off-by: kumquat-ir <66188216+kumquat-ir@users.noreply.github.com> --- launcher/minecraft/mod/ModFolderModel.cpp | 2 +- launcher/minecraft/mod/ResourceFolderModel.cpp | 2 +- launcher/minecraft/mod/ResourceFolderModel.h | 3 +-- launcher/minecraft/mod/tasks/LocalModParseTask.cpp | 9 +++++---- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'launcher') diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index 2d777656..3f31b93c 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -50,7 +50,7 @@ #include "minecraft/mod/tasks/ModFolderLoadTask.h" #include "modplatform/ModIndex.h" -ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed, bool create_dir) : ResourceFolderModel(QDir(dir), create_dir), m_is_indexed(is_indexed) +ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed, bool create_dir) : ResourceFolderModel(QDir(dir), nullptr, create_dir), m_is_indexed(is_indexed) { m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER }; } diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index b8353133..f2a77c12 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -12,7 +12,7 @@ #include "tasks/Task.h" -ResourceFolderModel::ResourceFolderModel(QDir dir, bool create_dir, QObject* parent) : QAbstractListModel(parent), m_dir(dir), m_watcher(this) +ResourceFolderModel::ResourceFolderModel(QDir dir, QObject* parent, bool create_dir) : QAbstractListModel(parent), m_dir(dir), m_watcher(this) { if (create_dir) { FS::ensureFolderPathExists(m_dir.absolutePath()); diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h index e4227a33..3bd78870 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.h +++ b/launcher/minecraft/mod/ResourceFolderModel.h @@ -24,8 +24,7 @@ class QSortFilterProxyModel; class ResourceFolderModel : public QAbstractListModel { Q_OBJECT public: - ResourceFolderModel(QDir, bool, QObject* parent = nullptr); - ResourceFolderModel(QDir dir, QObject* parent = nullptr) : ResourceFolderModel(dir, true, parent) {}; + ResourceFolderModel(QDir, QObject* parent = nullptr, bool create_dir = true); ~ResourceFolderModel() override; /** Starts watching the paths for changes. diff --git a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp index 945ccda7..da27a505 100644 --- a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp @@ -432,21 +432,22 @@ bool processZIP(Mod& mod, ProcessingLevel level) // nilloader uses the filename of the metadata file for the modid, so we can't know the exact filename // thankfully, there is a good file to use as a canary so we don't look for nil meta all the time - QStringList foundNilMetas; + QString foundNilMeta; for (auto& fname : zip.getFileNameList()) { // nilmods can shade nilloader to be able to run as a standalone agent - which includes nilloader's own meta file if (fname.endsWith(".nilmod.css") && fname != "nilloader.nilmod.css") { - foundNilMetas.append(fname); + foundNilMeta = fname; + break; } } - if (zip.setCurrentFile(foundNilMetas.at(0))) { + if (zip.setCurrentFile(foundNilMeta)) { if (!file.open(QIODevice::ReadOnly)) { zip.close(); return false; } - details = ReadNilModInfo(file.readAll(), foundNilMetas.at(0)); + details = ReadNilModInfo(file.readAll(), foundNilMeta); file.close(); zip.close(); -- cgit