summaryrefslogtreecommitdiffstats
path: root/logic/minecraft/Library.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-03-26 16:56:57 +0100
committerPetr Mrázek <peterix@gmail.com>2016-03-27 22:35:06 +0200
commitf032e32133023ed8396fc2b6ead7eadc2816a25b (patch)
tree10ce52261bf06dd9f000896b4e993fb45cd7e3fc /logic/minecraft/Library.cpp
parentd587720010036e3335e321f192449808a75e958b (diff)
downloadMultiMC-f032e32133023ed8396fc2b6ead7eadc2816a25b.tar
MultiMC-f032e32133023ed8396fc2b6ead7eadc2816a25b.tar.gz
MultiMC-f032e32133023ed8396fc2b6ead7eadc2816a25b.tar.lz
MultiMC-f032e32133023ed8396fc2b6ead7eadc2816a25b.tar.xz
MultiMC-f032e32133023ed8396fc2b6ead7eadc2816a25b.zip
NOISSUE finalize support for new mojang version format
Diffstat (limited to 'logic/minecraft/Library.cpp')
-rw-r--r--logic/minecraft/Library.cpp205
1 files changed, 157 insertions, 48 deletions
diff --git a/logic/minecraft/Library.cpp b/logic/minecraft/Library.cpp
index 9a1d2cc7..922db84e 100644
--- a/logic/minecraft/Library.cpp
+++ b/logic/minecraft/Library.cpp
@@ -1,57 +1,176 @@
#include "Library.h"
+#include <net/CacheDownload.h>
+#include <minecraft/forge/ForgeXzDownload.h>
+#include <Env.h>
#include <FileSystem.h>
-QStringList Library::files() const
+void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32, QStringList& native64) const
{
- QStringList retval;
- QString storage = storageSuffix();
- if (storage.contains("${arch}"))
+ auto actualPath = [&](QString relPath)
{
- QString cooked_storage = storage;
- cooked_storage.replace("${arch}", "32");
- retval.append(cooked_storage);
- cooked_storage = storage;
- cooked_storage.replace("${arch}", "64");
- retval.append(cooked_storage);
+ QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
+ return out.absoluteFilePath();
+ };
+ if(m_mojangDownloads)
+ {
+ if(m_mojangDownloads->artifact)
+ {
+ auto artifact = m_mojangDownloads->artifact;
+ jar += actualPath(artifact->path);
+ }
+ if(!isNative())
+ return;
+ if(m_nativeClassifiers.contains(system))
+ {
+ auto nativeClassifier = m_nativeClassifiers[system];
+ if(nativeClassifier.contains("${arch}"))
+ {
+ auto nat32Classifier = nativeClassifier;
+ nat32Classifier.replace("${arch}", "32");
+ auto nat64Classifier = nativeClassifier;
+ nat64Classifier.replace("${arch}", "64");
+ auto nat32info = m_mojangDownloads->getDownloadInfo(nat32Classifier);
+ if(nat32info)
+ native32 += actualPath(nat32info->path);
+ auto nat64info = m_mojangDownloads->getDownloadInfo(nat64Classifier);
+ if(nat64info)
+ native64 += actualPath(nat64info->path);
+ }
+ else
+ {
+ native += actualPath(m_mojangDownloads->getDownloadInfo(nativeClassifier)->path);
+ }
+ }
}
else
- retval.append(storage);
- return retval;
-}
-
-bool Library::filesExist(const QDir &base) const
-{
- auto libFiles = files();
- for(auto file: libFiles)
{
- QFileInfo info(base, file);
- qWarning() << info.absoluteFilePath() << "doesn't exist";
- if (!info.exists())
- return false;
+ QString raw_storage = storageSuffix(system);
+ if(isNative())
+ {
+ if (raw_storage.contains("${arch}"))
+ {
+ auto nat32Storage = raw_storage;
+ nat32Storage.replace("${arch}", "32");
+ auto nat64Storage = raw_storage;
+ nat64Storage.replace("${arch}", "64");
+ native32 += actualPath(nat32Storage);
+ native64 += actualPath(nat64Storage);
+ }
+ else
+ {
+ native += actualPath(raw_storage);
+ }
+ }
+ else
+ {
+ jar += actualPath(raw_storage);
+ }
}
- return true;
}
-QString Library::url() const
+QList<NetActionPtr> Library::getDownloads(OpSys system, HttpMetaCache * cache, QStringList &failedFiles) const
{
- if (!m_absolute_url.isEmpty())
- {
- return m_absolute_url;
- }
+ QList<NetActionPtr> out;
+ bool isLocal = (hint() == "local");
+ bool isForge = (hint() == "forge-pack-xz");
- if (m_base_url.isEmpty())
+ auto add_download = [&](QString storage, QString dl)
{
- return QString("https://" + URLConstants::LIBRARY_BASE) + storageSuffix();
- }
+ auto entry = cache->resolveEntry("libraries", storage);
+ if (!entry->isStale())
+ return true;
+ if(isLocal)
+ {
+ QFileInfo fileinfo(entry->getFullPath());
+ if(!fileinfo.exists())
+ {
+ failedFiles.append(entry->getFullPath());
+ return false;
+ }
+ return true;
+ }
+ if (isForge)
+ {
+ out.append(ForgeXzDownload::make(storage, entry));
+ }
+ else
+ {
+ out.append(CacheDownload::make(dl, entry));
+ }
+ return true;
+ };
- if(m_base_url.endsWith('/'))
+ if(m_mojangDownloads)
{
- return m_base_url + storageSuffix();
+ if(m_mojangDownloads->artifact)
+ {
+ auto artifact = m_mojangDownloads->artifact;
+ add_download(artifact->path, artifact->url);
+ }
+ if(m_nativeClassifiers.contains(system))
+ {
+ auto nativeClassifier = m_nativeClassifiers[system];
+ if(nativeClassifier.contains("${arch}"))
+ {
+ auto nat32Classifier = nativeClassifier;
+ nat32Classifier.replace("${arch}", "32");
+ auto nat64Classifier = nativeClassifier;
+ nat64Classifier.replace("${arch}", "64");
+ auto nat32info = m_mojangDownloads->getDownloadInfo(nat32Classifier);
+ if(nat32info)
+ add_download(nat32info->path, nat32info->url);
+ auto nat64info = m_mojangDownloads->getDownloadInfo(nat64Classifier);
+ if(nat64info)
+ add_download(nat64info->path, nat64info->url);
+ }
+ else
+ {
+ auto info = m_mojangDownloads->getDownloadInfo(nativeClassifier);
+ if(info)
+ {
+ add_download(info->path, info->url);
+ }
+ }
+ }
}
else
{
- return m_base_url + QChar('/') + storageSuffix();
+ QString raw_storage = storageSuffix(system);
+ auto raw_dl = [&](){
+ if (!m_absoluteURL.isEmpty())
+ {
+ return m_absoluteURL;
+ }
+
+ if (m_repositoryURL.isEmpty())
+ {
+ return QString("https://" + URLConstants::LIBRARY_BASE) + raw_storage;
+ }
+
+ if(m_repositoryURL.endsWith('/'))
+ {
+ return m_repositoryURL + raw_storage;
+ }
+ else
+ {
+ return m_repositoryURL + QChar('/') + raw_storage;
+ }
+ }();
+ if (raw_storage.contains("${arch}"))
+ {
+ QString cooked_storage = raw_storage;
+ QString cooked_dl = raw_dl;
+ add_download(cooked_storage.replace("${arch}", "32"), cooked_dl.replace("${arch}", "32"));
+ cooked_storage = raw_storage;
+ cooked_dl = raw_dl;
+ add_download(cooked_storage.replace("${arch}", "64"), cooked_dl.replace("${arch}", "64"));
+ }
+ else
+ {
+ add_download(raw_storage, raw_dl);
+ }
}
+ return out;
}
bool Library::isActive() const
@@ -74,7 +193,7 @@ bool Library::isActive() const
}
if (isNative())
{
- result = result && m_native_classifiers.contains(currentSystem);
+ result = result && m_nativeClassifiers.contains(currentSystem);
}
return result;
}
@@ -98,7 +217,7 @@ QString Library::storagePrefix() const
return m_storagePrefix;
}
-QString Library::storageSuffix() const
+QString Library::storageSuffix(OpSys system) const
{
// non-native? use only the gradle specifier
if (!isNative())
@@ -108,9 +227,9 @@ QString Library::storageSuffix() const
// otherwise native, override classifiers. Mojang HACK!
GradleSpecifier nativeSpec = m_name;
- if (m_native_classifiers.contains(currentSystem))
+ if (m_nativeClassifiers.contains(system))
{
- nativeSpec.setClassifier(m_native_classifiers[currentSystem]);
+ nativeSpec.setClassifier(m_nativeClassifiers[system]);
}
else
{
@@ -118,13 +237,3 @@ QString Library::storageSuffix() const
}
return nativeSpec.toPath();
}
-
-QString Library::storagePath() const
-{
- return FS::PathCombine(storagePrefix(), storageSuffix());
-}
-
-bool Library::storagePathIsDefault() const
-{
- return m_storagePrefix.isEmpty();
-}