diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-08-07 00:46:29 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-08-07 00:46:29 +0200 |
commit | 8cf88ffc580310e2e814d097358ff783cd5c4416 (patch) | |
tree | 4ed75860253ffa667af38664b4fd10e6d7bc29de /api/logic/minecraft/onesix/OneSixProfileStrategy.cpp | |
parent | 117bfef151c2083085025c32f96461f1c97dbec3 (diff) | |
download | PrismLauncher-8cf88ffc580310e2e814d097358ff783cd5c4416.tar.gz PrismLauncher-8cf88ffc580310e2e814d097358ff783cd5c4416.tar.bz2 PrismLauncher-8cf88ffc580310e2e814d097358ff783cd5c4416.zip |
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.
Diffstat (limited to 'api/logic/minecraft/onesix/OneSixProfileStrategy.cpp')
-rw-r--r-- | api/logic/minecraft/onesix/OneSixProfileStrategy.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
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<VersionFile>(); + auto jarMod = std::make_shared<Library>(); + 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<ProfilePatch>(f, patchFileName); + patch->setMovable(true); + patch->setRemovable(true); + profile->appendPatch(patch); + + profile->saveCurrentOrder(); + profile->reapplyPatches(); + return true; +} |