From 4340068a84d1532d9f5ca4de4d12cbf1b7a7bd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 31 Dec 2017 01:37:50 +0100 Subject: NOISSUE add button for creating empty, properly registered, components --- api/logic/minecraft/ComponentList.cpp | 28 ++++++++++++++++++++++++++++ api/logic/minecraft/ComponentList.h | 2 ++ 2 files changed, 30 insertions(+) (limited to 'api/logic') diff --git a/api/logic/minecraft/ComponentList.cpp b/api/logic/minecraft/ComponentList.cpp index 3fb04255..b4ab2151 100644 --- a/api/logic/minecraft/ComponentList.cpp +++ b/api/logic/minecraft/ComponentList.cpp @@ -971,6 +971,34 @@ void ComponentList::installCustomJar(QString selectedFile) installCustomJar_internal(selectedFile); } +bool ComponentList::installEmpty(const QString& uid, const QString& name) +{ + QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches"); + if(!FS::ensureFolderPathExists(patchDir)) + { + return false; + } + auto f = std::make_shared(); + f->name = name; + f->uid = uid; + f->version = "1"; + QString patchFileName = FS::PathCombine(patchDir, uid + ".json"); + QFile file(patchFileName); + if (!file.open(QFile::WriteOnly)) + { + qCritical() << "Error opening" << file.fileName() + << "for reading:" << file.errorString(); + return false; + } + file.write(OneSixVersionFormat::versionFileToJson(f).toJson()); + file.close(); + + appendComponent(new Component(this, f->uid, f)); + scheduleSave(); + invalidateLaunchProfile(); + return true; +} + bool ComponentList::removeComponent_internal(ComponentPtr patch) { bool ok = true; diff --git a/api/logic/minecraft/ComponentList.h b/api/logic/minecraft/ComponentList.h index b66b3417..3b53a9fe 100644 --- a/api/logic/minecraft/ComponentList.h +++ b/api/logic/minecraft/ComponentList.h @@ -103,6 +103,8 @@ public: bool setComponentVersion(const QString &uid, const QString &version, bool important = false); + bool installEmpty(const QString &uid, const QString &name); + QString patchFilePathForUid(const QString &uid) const; /// if there is a save scheduled, do it now. -- cgit v1.2.3