diff options
Diffstat (limited to 'api/logic/minecraft/onesix')
-rw-r--r-- | api/logic/minecraft/onesix/OneSixInstance.cpp | 7 | ||||
-rw-r--r-- | api/logic/minecraft/onesix/OneSixInstance.h | 3 | ||||
-rw-r--r-- | api/logic/minecraft/onesix/OneSixProfileStrategy.cpp | 64 | ||||
-rw-r--r-- | api/logic/minecraft/onesix/OneSixProfileStrategy.h | 15 | ||||
-rw-r--r-- | api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp | 6 |
5 files changed, 83 insertions, 12 deletions
diff --git a/api/logic/minecraft/onesix/OneSixInstance.cpp b/api/logic/minecraft/onesix/OneSixInstance.cpp index 107da04f..34253f02 100644 --- a/api/logic/minecraft/onesix/OneSixInstance.cpp +++ b/api/logic/minecraft/onesix/OneSixInstance.cpp @@ -637,11 +637,16 @@ QString OneSixInstance::jarModsDir() const return FS::PathCombine(instanceRoot(), "jarmods"); } -QString OneSixInstance::libDir() const +QString OneSixInstance::FMLlibDir() const { return FS::PathCombine(minecraftRoot(), "lib"); } +QString OneSixInstance::customLibrariesDir() const +{ + return FS::PathCombine(instanceRoot(), "libraries"); +} + QString OneSixInstance::worldDir() const { return FS::PathCombine(minecraftRoot(), "saves"); diff --git a/api/logic/minecraft/onesix/OneSixInstance.h b/api/logic/minecraft/onesix/OneSixInstance.h index bf12160e..0cb4340b 100644 --- a/api/logic/minecraft/onesix/OneSixInstance.h +++ b/api/logic/minecraft/onesix/OneSixInstance.h @@ -48,7 +48,8 @@ public: QString texturePacksDir() const; QString loaderModsDir() const; QString coreModsDir() const; - QString libDir() const; + QString FMLlibDir() const; + QString customLibrariesDir() const; QString worldDir() const; virtual QString instanceConfigFolder() const override; 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; +} diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.h b/api/logic/minecraft/onesix/OneSixProfileStrategy.h index 96c1ba7b..e4eee4b2 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.h +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.h @@ -8,13 +8,14 @@ class OneSixProfileStrategy : public ProfileStrategy public: OneSixProfileStrategy(OneSixInstance * instance); virtual ~OneSixProfileStrategy() {}; - virtual void load() override; - virtual bool resetOrder() override; - virtual bool saveOrder(ProfileUtils::PatchOrder order) override; - virtual bool installJarMods(QStringList filepaths) override; - virtual bool removePatch(ProfilePatchPtr patch) override; - virtual bool customizePatch(ProfilePatchPtr patch) override; - virtual bool revertPatch(ProfilePatchPtr patch) override; + void load() override; + bool resetOrder() override; + bool saveOrder(ProfileUtils::PatchOrder order) override; + bool installJarMods(QStringList filepaths) override; + bool installCustomJar(QString filepath) override; + bool removePatch(ProfilePatchPtr patch) override; + bool customizePatch(ProfilePatchPtr patch) override; + bool revertPatch(ProfilePatchPtr patch) override; protected: virtual void loadDefaultBuiltinPatches(); diff --git a/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp b/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp index 42148e67..13310e92 100644 --- a/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp +++ b/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp @@ -45,7 +45,7 @@ void FMLLibrariesTask::executeTask() // now check the lib folder inside the instance for files. for (auto &lib : libList) { - QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename)); + QFileInfo libInfo(FS::PathCombine(inst->FMLlibDir(), lib.filename)); if (libInfo.exists()) continue; fmlLibsToProcess.append(lib); @@ -95,13 +95,13 @@ void FMLLibrariesTask::fmllibsFinished() { progress(index, fmlLibsToProcess.size()); auto entry = metacache->resolveEntry("fmllibs", lib.filename); - auto path = FS::PathCombine(inst->libDir(), lib.filename); + auto path = FS::PathCombine(inst->FMLlibDir(), lib.filename); if (!FS::ensureFilePathExists(path)) { emitFailed(tr("Failed creating FML library folder inside the instance.")); return; } - if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename))) + if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->FMLlibDir(), lib.filename))) { emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename)); return; |