From 6e80f03409054293bdbbcd0ce87b607a811016d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 2 Oct 2016 00:26:10 +0200 Subject: NOISSUE add instance-local library storage Any libraries stored in $instanceroot/libraries/ will override the libraries from MultiMC's global folders, as long as they are marked 'local' in the json patch. --- api/logic/minecraft/Library.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'api/logic/minecraft/Library.cpp') diff --git a/api/logic/minecraft/Library.cpp b/api/logic/minecraft/Library.cpp index c516edb7..8bbd5503 100644 --- a/api/logic/minecraft/Library.cpp +++ b/api/logic/minecraft/Library.cpp @@ -1,15 +1,31 @@ #include "Library.h" +#include "MinecraftInstance.h" + #include #include #include #include #include -void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32, QStringList& native64) const + +void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32, + QStringList& native64, const QString &overridePath) const { + bool isLocal = (hint() == "local"); auto actualPath = [&](QString relPath) { QFileInfo out(FS::PathCombine(storagePrefix(), relPath)); + if(isLocal && !overridePath.isEmpty()) + { + QString fileName = out.fileName(); + auto fullPath = FS::PathCombine(overridePath, fileName); + qDebug() << fullPath; + QFileInfo fileinfo(fullPath); + if(fileinfo.exists()) + { + return fileinfo.absoluteFilePath(); + } + } return out.absoluteFilePath(); }; if(m_mojangDownloads) @@ -69,7 +85,8 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na } } -QList Library::getDownloads(OpSys system, HttpMetaCache * cache, QStringList &failedFiles) const +QList< std::shared_ptr< NetAction > > Library::getDownloads(OpSys system, class HttpMetaCache* cache, + QStringList& failedFiles, const QString & overridePath) const { QList out; bool isAlwaysStale = (hint() == "always-stale"); @@ -87,6 +104,25 @@ QList Library::getDownloads(OpSys system, HttpMetaCache * cache, Q return true; if(isLocal) { + if(!overridePath.isEmpty()) + { + QString fileName; + int position = storage.lastIndexOf('/'); + if(position == -1) + { + fileName = storage; + } + else + { + fileName = storage.mid(position); + } + auto fullPath = FS::PathCombine(overridePath, fileName); + QFileInfo fileinfo(fullPath); + if(fileinfo.exists()) + { + return true; + } + } QFileInfo fileinfo(entry->getFullPath()); if(!fileinfo.exists()) { -- cgit v1.2.3