From 8cf88ffc580310e2e814d097358ff783cd5c4416 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 7 Aug 2017 00:46:29 +0200 Subject: GH-1314 add UI for custom minecraft jar addition Also changes the text of the jar mod addition button. It should be clearer what it does and hopefully will not confuse as many people. --- .../minecraft/onesix/OneSixProfileStrategy.cpp | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'api/logic/minecraft/onesix/OneSixProfileStrategy.cpp') diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp index ef2a7294..39dd8343 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -405,3 +405,67 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths) return true; } +bool OneSixProfileStrategy::installCustomJar(QString filepath) +{ + QString patchDir = FS::PathCombine(m_instance->instanceRoot(), "patches"); + if(!FS::ensureFolderPathExists(patchDir)) + { + return false; + } + + QString libDir = m_instance->customLibrariesDir(); + if (!FS::ensureFolderPathExists(libDir)) + { + return false; + } + + auto specifier = GradleSpecifier("org.multimc:customjar:1"); + QFileInfo sourceInfo(filepath); + QString target_filename = specifier.getFileName(); + QString target_id = specifier.artifactId(); + QString target_name = sourceInfo.completeBaseName() + " (custom jar)"; + QString finalPath = FS::PathCombine(libDir, target_filename); + + QFileInfo jarInfo(finalPath); + if (jarInfo.exists()) + { + if(!QFile::remove(finalPath)) + { + return false; + } + } + if (!QFile::copy(filepath, finalPath)) + { + return false; + } + + auto f = std::make_shared(); + auto jarMod = std::make_shared(); + jarMod->setRawName(specifier); + jarMod->setDisplayName(sourceInfo.completeBaseName()); + jarMod->setHint("local"); + f->mainJar = jarMod; + f->name = target_name; + f->uid = target_id; + f->order = profile->getFreeOrderNumber(); + QString patchFileName = FS::PathCombine(patchDir, target_id + ".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, true).toJson()); + file.close(); + + auto patch = std::make_shared(f, patchFileName); + patch->setMovable(true); + patch->setRemovable(true); + profile->appendPatch(patch); + + profile->saveCurrentOrder(); + profile->reapplyPatches(); + return true; +} -- cgit