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.
This commit is contained in:
Petr Mrázek 2016-10-02 00:26:10 +02:00
parent 69f3ab019d
commit 6e80f03409
13 changed files with 180 additions and 45 deletions

View File

@ -55,18 +55,23 @@ struct GradleSpecifier
}
return retval;
}
QString getFileName() const
{
QString filename = m_artifactId + '-' + m_version;
if(!m_classifier.isEmpty())
{
filename += "-" + m_classifier;
}
filename += "." + m_extension;
return filename;
}
QString toPath() const
{
if(!m_valid)
return "INVALID";
QString path = m_groupId;
path.replace('.', '/');
path += '/' + m_artifactId + '/' + m_version + '/' + m_artifactId + '-' + m_version;
if(!m_classifier.isEmpty())
{
path += "-" + m_classifier;
}
path += "." + m_extension;
path += '/' + m_artifactId + '/' + m_version + '/' + getFileName();
return path;
}
inline bool valid() const

View File

@ -1,15 +1,31 @@
#include "Library.h"
#include "MinecraftInstance.h"
#include <net/Download.h>
#include <net/ChecksumValidator.h>
#include <minecraft/forge/ForgeXzDownload.h>
#include <Env.h>
#include <FileSystem.h>
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<NetActionPtr> 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<NetActionPtr> out;
bool isAlwaysStale = (hint() == "always-stale");
@ -87,6 +104,25 @@ QList<NetActionPtr> 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())
{

View File

@ -18,6 +18,7 @@
#include "multimc_logic_export.h"
class Library;
class MinecraftInstance;
typedef std::shared_ptr<Library> LibraryPtr;
@ -99,7 +100,8 @@ public: /* methods */
m_repositoryURL = base_url;
}
void getApplicableFiles(OpSys system, QStringList & jar, QStringList & native, QStringList & native32, QStringList & native64) const;
void getApplicableFiles(OpSys system, QStringList & jar, QStringList & native,
QStringList & native32, QStringList & native64, const QString & overridePath) const;
void setAbsoluteUrl(const QString &absolute_url)
{
@ -126,7 +128,8 @@ public: /* methods */
bool isActive() const;
// Get a list of downloads for this library
QList<NetActionPtr> getDownloads(OpSys system, class HttpMetaCache * cache, QStringList &failedFiles) const;
QList<NetActionPtr> getDownloads(OpSys system, class HttpMetaCache * cache,
QStringList & failedFiles, const QString & overridePath) const;
private: /* methods */
/// the default storage prefix used by MultiMC

View File

@ -31,6 +31,7 @@ slots:
{
cache.reset(new HttpMetaCache());
cache->addBase("libraries", QDir("libraries").absolutePath());
dataDir = QDir("data").absolutePath();
}
void test_legacy()
{
@ -39,7 +40,7 @@ slots:
QCOMPARE(test.isNative(), false);
QStringList jar, native, native32, native64;
test.getApplicableFiles(currentSystem, jar, native, native32, native64);
test.getApplicableFiles(currentSystem, jar, native, native32, native64, QString());
QCOMPARE(jar, getStorage("test/package/testname/testversion/testname-testversion.jar"));
QCOMPARE(native, {});
QCOMPARE(native32, {});
@ -50,7 +51,7 @@ slots:
QStringList failedFiles;
Library test("test.package:testname:testversion");
test.setRepositoryURL("file://foo/bar");
auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles);
auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QString());
QCOMPARE(downloads.size(), 1);
QCOMPARE(failedFiles, {});
NetActionPtr dl = downloads[0];
@ -62,10 +63,27 @@ slots:
QCOMPARE(test.isNative(), false);
QStringList failedFiles;
test.setHint("local");
auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles);
auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QString());
QCOMPARE(downloads.size(), 0);
QCOMPARE(failedFiles, getStorage("test/package/testname/testversion/testname-testversion.jar"));
}
void test_legacy_url_local_override()
{
Library test("com.paulscode:codecwav:20101023");
QCOMPARE(test.isNative(), false);
QStringList failedFiles;
test.setHint("local");
auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QString("data"));
QCOMPARE(downloads.size(), 0);
QCOMPARE(failedFiles.size(), 0);
QStringList jar, native, native32, native64;
test.getApplicableFiles(currentSystem, jar, native, native32, native64, QString("data"));
QCOMPARE(jar, {QFileInfo("data/codecwav-20101023.jar").absoluteFilePath()});
QCOMPARE(native, {});
QCOMPARE(native32, {});
QCOMPARE(native64, {});
}
void test_legacy_native()
{
Library test("test.package:testname:testversion");
@ -74,13 +92,13 @@ slots:
test.setRepositoryURL("file://foo/bar");
{
QStringList jar, native, native32, native64;
test.getApplicableFiles(Os_Linux, jar, native, native32, native64);
test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QString());
QCOMPARE(jar, {});
QCOMPARE(native, getStorage("test/package/testname/testversion/testname-testversion-linux.jar"));
QCOMPARE(native32, {});
QCOMPARE(native64, {});
QStringList failedFiles;
auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles);
auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QString());
QCOMPARE(dls.size(), 1);
QCOMPARE(failedFiles, {});
auto dl = dls[0];
@ -97,13 +115,13 @@ slots:
test.setRepositoryURL("file://foo/bar");
{
QStringList jar, native, native32, native64;
test.getApplicableFiles(Os_Linux, jar, native, native32, native64);
test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QString());
QCOMPARE(jar, {});
QCOMPARE(native, {});
QCOMPARE(native32, getStorage("test/package/testname/testversion/testname-testversion-linux-32.jar"));
QCOMPARE(native64, getStorage("test/package/testname/testversion/testname-testversion-linux-64.jar"));
QStringList failedFiles;
auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles);
auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QString());
QCOMPARE(dls.size(), 2);
QCOMPARE(failedFiles, {});
QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux-32.jar"));
@ -111,13 +129,13 @@ slots:
}
{
QStringList jar, native, native32, native64;
test.getApplicableFiles(Os_Windows, jar, native, native32, native64);
test.getApplicableFiles(Os_Windows, jar, native, native32, native64, QString());
QCOMPARE(jar, {});
QCOMPARE(native, {});
QCOMPARE(native32, getStorage("test/package/testname/testversion/testname-testversion-windows-32.jar"));
QCOMPARE(native64, getStorage("test/package/testname/testversion/testname-testversion-windows-64.jar"));
QStringList failedFiles;
auto dls = test.getDownloads(Os_Windows, cache.get(), failedFiles);
auto dls = test.getDownloads(Os_Windows, cache.get(), failedFiles, QString());
QCOMPARE(dls.size(), 2);
QCOMPARE(failedFiles, {});
QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-windows-32.jar"));
@ -125,45 +143,103 @@ slots:
}
{
QStringList jar, native, native32, native64;
test.getApplicableFiles(Os_OSX, jar, native, native32, native64);
test.getApplicableFiles(Os_OSX, jar, native, native32, native64, QString());
QCOMPARE(jar, {});
QCOMPARE(native, {});
QCOMPARE(native32, getStorage("test/package/testname/testversion/testname-testversion-osx-32.jar"));
QCOMPARE(native64, getStorage("test/package/testname/testversion/testname-testversion-osx-64.jar"));
QStringList failedFiles;
auto dls = test.getDownloads(Os_OSX, cache.get(), failedFiles);
auto dls = test.getDownloads(Os_OSX, cache.get(), failedFiles, QString());
QCOMPARE(dls.size(), 2);
QCOMPARE(failedFiles, {});
QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-32.jar"));
QCOMPARE(dls[1]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-64.jar"));
}
}
void test_legacy_native_arch_local_override()
{
Library test("test.package:testname:testversion");
test.m_nativeClassifiers[OpSys::Os_Linux]="linux-${arch}";
test.setHint("local");
QCOMPARE(test.isNative(), true);
test.setRepositoryURL("file://foo/bar");
{
QStringList jar, native, native32, native64;
test.getApplicableFiles(Os_Linux, jar, native, native32, native64, QString("data"));
QCOMPARE(jar, {});
QCOMPARE(native, {});
QCOMPARE(native32, {QFileInfo("data/testname-testversion-linux-32.jar").absoluteFilePath()});
QCOMPARE(native64, getStorage("test/package/testname/testversion/testname-testversion-linux-64.jar"));
QStringList failedFiles;
auto dls = test.getDownloads(Os_Linux, cache.get(), failedFiles, QString("data"));
QCOMPARE(dls.size(), 0);
QCOMPARE(failedFiles, {getStorage("test/package/testname/testversion/testname-testversion-linux-64.jar")});
}
}
void test_onenine()
{
auto test = readMojangJson("data/lib-simple.json");
{
QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64);
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString());
QCOMPARE(jar, getStorage("com/paulscode/codecwav/20101023/codecwav-20101023.jar"));
QCOMPARE(native, {});
QCOMPARE(native32, {});
QCOMPARE(native64, {});
}
{
QStringList failedFiles;
auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles);
auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QString());
QCOMPARE(dls.size(), 1);
QCOMPARE(failedFiles, {});
QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/com/paulscode/codecwav/20101023/codecwav-20101023.jar"));
}
test->setHint("local");
{
QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString("data"));
QCOMPARE(jar, {QFileInfo("data/codecwav-20101023.jar").absoluteFilePath()});
QCOMPARE(native, {});
QCOMPARE(native32, {});
QCOMPARE(native64, {});
}
{
QStringList failedFiles;
auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QString("data"));
QCOMPARE(dls.size(), 0);
QCOMPARE(failedFiles, {});
}
}
void test_onenine_local_override()
{
auto test = readMojangJson("data/lib-simple.json");
test->setHint("local");
{
QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString("data"));
QCOMPARE(jar, {QFileInfo("data/codecwav-20101023.jar").absoluteFilePath()});
QCOMPARE(native, {});
QCOMPARE(native32, {});
QCOMPARE(native64, {});
}
{
QStringList failedFiles;
auto dls = test->getDownloads(Os_Linux, cache.get(), failedFiles, QString("data"));
QCOMPARE(dls.size(), 0);
QCOMPARE(failedFiles, {});
}
}
void test_onenine_native()
{
auto test = readMojangJson("data/lib-native.json");
QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_OSX, jar, native, native32, native64);
test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString());
QCOMPARE(jar, getStorage("org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209.jar"));
QCOMPARE(native, getStorage("org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar"));
QCOMPARE(native32, {});
QCOMPARE(native64, {});
QStringList failedFiles;
auto dls = test->getDownloads(Os_OSX, cache.get(), failedFiles);
auto dls = test->getDownloads(Os_OSX, cache.get(), failedFiles, QString());
QCOMPARE(dls.size(), 2);
QCOMPARE(failedFiles, {});
QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209.jar"));
@ -173,13 +249,13 @@ slots:
{
auto test = readMojangJson("data/lib-native-arch.json");
QStringList jar, native, native32, native64;
test->getApplicableFiles(Os_Windows, jar, native, native32, native64);
test->getApplicableFiles(Os_Windows, jar, native, native32, native64, QString());
QCOMPARE(jar, {});
QCOMPARE(native, {});
QCOMPARE(native32, getStorage("tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-32.jar"));
QCOMPARE(native64, getStorage("tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-64.jar"));
QStringList failedFiles;
auto dls = test->getDownloads(Os_Windows, cache.get(), failedFiles);
auto dls = test->getDownloads(Os_Windows, cache.get(), failedFiles, QString());
QCOMPARE(dls.size(), 2);
QCOMPARE(failedFiles, {});
QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-32.jar"));
@ -187,7 +263,7 @@ slots:
}
private:
std::unique_ptr<HttpMetaCache> cache;
QString workDir;
QString dataDir;
};
QTEST_GUILESS_MAIN(LibraryTest)

View File

@ -69,6 +69,8 @@ public:
virtual QString getNativePath() const = 0;
virtual QString getLocalLibraryPath() const = 0;
virtual QStringList processMinecraftArgs(AuthSessionPtr account) const = 0;
virtual JavaVersion getJavaVersion() const;

View File

@ -581,14 +581,14 @@ const QList<LibraryPtr> & MinecraftProfile::getLibraries() const
return m_libraries;
}
void MinecraftProfile::getLibraryFiles(const QString& architecture, QStringList& jars, QStringList& nativeJars) const
void MinecraftProfile::getLibraryFiles(const QString& architecture, QStringList& jars, QStringList& nativeJars, const QString& overridePath) const
{
QStringList native32, native64;
jars.clear();
nativeJars.clear();
for (auto lib : getLibraries())
{
lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64);
lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath);
}
if(architecture == "32")
{

View File

@ -111,7 +111,7 @@ public: /* getters for profile variables */
const QStringList & getTweakers() const;
const QList<JarmodPtr> & getJarMods() const;
const QList<LibraryPtr> & getLibraries() const;
void getLibraryFiles(const QString & architecture, QStringList & jars, QStringList & nativeJars) const;
void getLibraryFiles(const QString & architecture, QStringList & jars, QStringList & nativeJars, const QString & overridePath) const;
QString getMainJarUrl() const;
bool hasTrait(const QString & trait) const;
ProblemSeverity getProblemSeverity() const;

View File

@ -132,6 +132,11 @@ public:
QStringList getNativeJars() const override;
QString getNativePath() const override;
QString getLocalLibraryPath() const override
{
return QString();
}
QStringList processMinecraftArgs(AuthSessionPtr account) const override;
QStringList verboseDescription(AuthSessionPtr session) override;

View File

@ -145,6 +145,12 @@ QString OneSixInstance::getNativePath() const
return natives_dir.absolutePath();
}
QString OneSixInstance::getLocalLibraryPath() const
{
QDir libraries_dir(FS::PathCombine(instanceRoot(), "libraries/"));
return libraries_dir.absolutePath();
}
QString OneSixInstance::mainJarPath() const
{
auto jarMods = getJarMods();
@ -207,7 +213,7 @@ QString OneSixInstance::createLaunchScript(AuthSessionPtr session)
{
QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString();
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars);
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath());
for(auto file: jars)
{
launchScript += "cp " + file + "\n";
@ -251,7 +257,7 @@ QStringList OneSixInstance::verboseDescription(AuthSessionPtr session)
out << "Libraries:";
QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString();
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars);
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath());
auto printLibFile = [&](const QString & path)
{
QFileInfo info(path);
@ -654,7 +660,7 @@ QStringList OneSixInstance::getClassPath() const
{
QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString();
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars);
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath());
jars.append(mainJarPath());
return jars;
}
@ -668,6 +674,6 @@ QStringList OneSixInstance::getNativeJars() const
{
QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString();
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars);
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath());
return nativeJars;
}

View File

@ -104,6 +104,8 @@ public:
QStringList getNativeJars() const override;
QString getNativePath() const override;
QString getLocalLibraryPath() const override;
QStringList processMinecraftArgs(AuthSessionPtr account) const override;
protected:

View File

@ -42,7 +42,7 @@ void LibrariesTask::executeTask()
QStringList failedFiles;
for (auto lib : libs)
{
auto dls = lib->getDownloads(currentSystem, metacache.get(), failedFiles);
auto dls = lib->getDownloads(currentSystem, metacache.get(), failedFiles, inst->getLocalLibraryPath());
for(auto dl : dls)
{
downloadJob->addNetAction(dl);

Binary file not shown.

Binary file not shown.