summaryrefslogtreecommitdiffstats
path: root/logic/net
diff options
context:
space:
mode:
Diffstat (limited to 'logic/net')
-rw-r--r--logic/net/CacheDownload.cpp21
-rw-r--r--logic/net/HttpMetaCache.cpp34
-rw-r--r--logic/net/HttpMetaCache.h54
-rw-r--r--logic/net/URLConstants.cpp34
-rw-r--r--logic/net/URLConstants.h38
5 files changed, 109 insertions, 72 deletions
diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp
index 1d48170a..d79feb14 100644
--- a/logic/net/CacheDownload.cpp
+++ b/logic/net/CacheDownload.cpp
@@ -34,7 +34,7 @@ CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry)
void CacheDownload::start()
{
m_status = Job_InProgress;
- if (!m_entry->stale)
+ if (!m_entry->isStale())
{
m_status = Job_Finished;
emit succeeded(m_index_within_job);
@@ -65,11 +65,11 @@ void CacheDownload::start()
QFile current(m_target_path);
if(current.exists() && current.size() != 0)
{
- if (m_entry->remote_changed_timestamp.size())
+ if (m_entry->getRemoteChangedTimestamp().size())
request.setRawHeader(QString("If-Modified-Since").toLatin1(),
- m_entry->remote_changed_timestamp.toLatin1());
- if (m_entry->etag.size())
- request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
+ m_entry->getRemoteChangedTimestamp().toLatin1());
+ if (m_entry->getETag().size())
+ request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->getETag().toLatin1());
}
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
@@ -138,7 +138,7 @@ void CacheDownload::downloadFinished()
if (m_output_file->commit())
{
m_status = Job_Finished;
- m_entry->md5sum = md5sum.result().toHex().constData();
+ m_entry->setMD5Sum(md5sum.result().toHex().constData());
}
else
{
@@ -160,14 +160,13 @@ void CacheDownload::downloadFinished()
QFileInfo output_file_info(m_target_path);
- m_entry->etag = m_reply->rawHeader("ETag").constData();
+ m_entry->setETag(m_reply->rawHeader("ETag").constData());
if (m_reply->hasRawHeader("Last-Modified"))
{
- m_entry->remote_changed_timestamp = m_reply->rawHeader("Last-Modified").constData();
+ m_entry->setRemoteChangedTimestamp(m_reply->rawHeader("Last-Modified").constData());
}
- m_entry->local_changed_timestamp =
- output_file_info.lastModified().toUTC().toMSecsSinceEpoch();
- m_entry->stale = false;
+ m_entry->setLocalChangedTimestamp(output_file_info.lastModified().toUTC().toMSecsSinceEpoch());
+ m_entry->setStale(false);
ENV.metacache()->updateEntry(m_entry);
m_reply.reset();
diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp
index 3d6aef0d..68bfa89c 100644
--- a/logic/net/HttpMetaCache.cpp
+++ b/logic/net/HttpMetaCache.cpp
@@ -32,7 +32,7 @@
QString MetaEntry::getFullPath()
{
// FIXME: make local?
- return FS::PathCombine(ENV.metacache()->getBasePath(base), path);
+ return FS::PathCombine(basePath, relativePath);
}
HttpMetaCache::HttpMetaCache(QString path) : QObject()
@@ -65,8 +65,7 @@ MetaEntryPtr HttpMetaCache::getEntry(QString base, QString resource_path)
return MetaEntryPtr();
}
-MetaEntryPtr HttpMetaCache::resolveEntry(QString base, QString resource_path,
- QString expected_etag)
+MetaEntryPtr HttpMetaCache::resolveEntry(QString base, QString resource_path, QString expected_etag)
{
auto entry = getEntry(base, resource_path);
// it's not present? generate a default stale entry
@@ -114,15 +113,16 @@ MetaEntryPtr HttpMetaCache::resolveEntry(QString base, QString resource_path,
}
// entry passed all the checks we cared about.
+ entry->basePath = getBasePath(base);
return entry;
}
bool HttpMetaCache::updateEntry(MetaEntryPtr stale_entry)
{
- if (!m_entries.contains(stale_entry->base))
+ if (!m_entries.contains(stale_entry->baseId))
{
qCritical() << "Cannot add entry with unknown base: "
- << stale_entry->base.toLocal8Bit();
+ << stale_entry->baseId.toLocal8Bit();
return false;
}
if (stale_entry->stale)
@@ -130,7 +130,7 @@ bool HttpMetaCache::updateEntry(MetaEntryPtr stale_entry)
qCritical() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit();
return false;
}
- m_entries[stale_entry->base].entry_list[stale_entry->path] = stale_entry;
+ m_entries[stale_entry->baseId].entry_list[stale_entry->relativePath] = stale_entry;
SaveEventually();
return true;
}
@@ -148,9 +148,10 @@ bool HttpMetaCache::evictEntry(MetaEntryPtr entry)
MetaEntryPtr HttpMetaCache::staleEntry(QString base, QString resource_path)
{
- auto foo = new MetaEntry;
- foo->base = base;
- foo->path = resource_path;
+ auto foo = new MetaEntry();
+ foo->baseId = base;
+ foo->basePath = getBasePath(base);
+ foo->relativePath = resource_path;
foo->stale = true;
return MetaEntryPtr(foo);
}
@@ -177,6 +178,9 @@ QString HttpMetaCache::getBasePath(QString base)
void HttpMetaCache::Load()
{
+ if(m_index_file.isNull())
+ return;
+
QFile index(m_index_file);
if (!index.open(QIODevice::ReadOnly))
return;
@@ -206,9 +210,9 @@ void HttpMetaCache::Load()
if (!m_entries.contains(base))
continue;
auto &entrymap = m_entries[base];
- auto foo = new MetaEntry;
- foo->base = base;
- QString path = foo->path = element_obj.value("path").toString();
+ auto foo = new MetaEntry();
+ foo->baseId = base;
+ QString path = foo->relativePath = element_obj.value("path").toString();
foo->md5sum = element_obj.value("md5sum").toString();
foo->etag = element_obj.value("etag").toString();
foo->local_changed_timestamp = element_obj.value("last_changed_timestamp").toDouble();
@@ -229,6 +233,8 @@ void HttpMetaCache::SaveEventually()
void HttpMetaCache::SaveNow()
{
+ if(m_index_file.isNull())
+ return;
QJsonObject toplevel;
toplevel.insert("version", QJsonValue(QString("1")));
QJsonArray entriesArr;
@@ -242,8 +248,8 @@ void HttpMetaCache::SaveNow()
continue;
}
QJsonObject entryObj;
- entryObj.insert("base", QJsonValue(entry->base));
- entryObj.insert("path", QJsonValue(entry->path));
+ entryObj.insert("base", QJsonValue(entry->baseId));
+ entryObj.insert("path", QJsonValue(entry->relativePath));
entryObj.insert("md5sum", QJsonValue(entry->md5sum));
entryObj.insert("etag", QJsonValue(entry->etag));
entryObj.insert("last_changed_timestamp",
diff --git a/logic/net/HttpMetaCache.h b/logic/net/HttpMetaCache.h
index fba3fe5a..7b626c70 100644
--- a/logic/net/HttpMetaCache.h
+++ b/logic/net/HttpMetaCache.h
@@ -23,16 +23,58 @@
class HttpMetaCache;
-struct MULTIMC_LOGIC_EXPORT MetaEntry
+class MULTIMC_LOGIC_EXPORT MetaEntry
{
- QString base;
- QString path;
+friend class HttpMetaCache;
+protected:
+ MetaEntry() {}
+public:
+ bool isStale()
+ {
+ return stale;
+ }
+ void setStale(bool stale)
+ {
+ this->stale = stale;
+ }
+ QString getFullPath();
+ QString getRemoteChangedTimestamp()
+ {
+ return remote_changed_timestamp;
+ }
+ void setRemoteChangedTimestamp(QString remote_changed_timestamp)
+ {
+ this->remote_changed_timestamp = remote_changed_timestamp;
+ }
+ void setLocalChangedTimestamp(qint64 timestamp)
+ {
+ local_changed_timestamp = timestamp;
+ }
+ QString getETag()
+ {
+ return etag;
+ }
+ void setETag(QString etag)
+ {
+ this->etag = etag;
+ }
+ QString getMD5Sum()
+ {
+ return md5sum;
+ }
+ void setMD5Sum(QString md5sum)
+ {
+ this->md5sum = md5sum;
+ }
+protected:
+ QString baseId;
+ QString basePath;
+ QString relativePath;
QString md5sum;
QString etag;
qint64 local_changed_timestamp = 0;
QString remote_changed_timestamp; // QString for now, RFC 2822 encoded time
bool stale = true;
- QString getFullPath();
};
typedef std::shared_ptr<MetaEntry> MetaEntryPtr;
@@ -42,7 +84,7 @@ class MULTIMC_LOGIC_EXPORT HttpMetaCache : public QObject
Q_OBJECT
public:
// supply path to the cache index file
- HttpMetaCache(QString path);
+ HttpMetaCache(QString path = QString());
~HttpMetaCache();
// get the entry solely from the cache
@@ -80,4 +122,4 @@ private:
QMap<QString, EntryMap> m_entries;
QString m_index_file;
QTimer saveBatchingTimer;
-}; \ No newline at end of file
+};
diff --git a/logic/net/URLConstants.cpp b/logic/net/URLConstants.cpp
index 85224767..bd476b2c 100644
--- a/logic/net/URLConstants.cpp
+++ b/logic/net/URLConstants.cpp
@@ -1,24 +1,16 @@
#include "URLConstants.h"
-namespace URLConstants
+
+namespace URLConstants {
+
+QString getLegacyJarUrl(QString version)
{
-const QString AWS_DOWNLOAD_BASE("s3.amazonaws.com/Minecraft.Download/");
-const QString AWS_DOWNLOAD_VERSIONS(AWS_DOWNLOAD_BASE + "versions/");
-const QString AWS_DOWNLOAD_LIBRARIES(AWS_DOWNLOAD_BASE + "libraries/");
-const QString AWS_DOWNLOAD_INDEXES(AWS_DOWNLOAD_BASE + "indexes/");
-const QString ASSETS_BASE("assets.minecraft.net/");
-const QString RESOURCE_BASE("resources.download.minecraft.net/");
-const QString LIBRARY_BASE("libraries.minecraft.net/");
-//const QString SKINS_BASE("skins.minecraft.net/MinecraftSkins/");
-const QString SKINS_BASE("crafatar.com/skins/");
-const QString AUTH_BASE("authserver.mojang.com/");
-const QString FORGE_LEGACY_URL("http://files.minecraftforge.net/minecraftforge/json");
-const QString
- FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json");
-const QString MOJANG_STATUS_URL("http://status.mojang.com/check");
-const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news");
-const QString LITELOADER_URL("http://dl.liteloader.com/versions/versions.json");
-const QString IMGUR_BASE_URL("https://api.imgur.com/3/");
-const QString FMLLIBS_OUR_BASE_URL("http://files.multimc.org/fmllibs/");
-const QString FMLLIBS_FORGE_BASE_URL("http://files.minecraftforge.net/fmllibs/");
-const QString TRANSLATIONS_BASE_URL("http://files.multimc.org/translations/");
+ return "http://" + AWS_DOWNLOAD_VERSIONS + getJarPath(version);
+}
+
+QString getJarPath(QString version)
+{
+ return version + "/" + version + ".jar";
+}
+
+
}
diff --git a/logic/net/URLConstants.h b/logic/net/URLConstants.h
index b04f44ba..8923ef54 100644
--- a/logic/net/URLConstants.h
+++ b/logic/net/URLConstants.h
@@ -17,26 +17,24 @@
#include <QString>
-#include "multimc_logic_export.h"
-
namespace URLConstants
{
-extern const QString AWS_DOWNLOAD_BASE;
-extern const QString AWS_DOWNLOAD_VERSIONS;
-extern const QString AWS_DOWNLOAD_LIBRARIES;
-extern const QString AWS_DOWNLOAD_INDEXES;
-extern const QString ASSETS_BASE;
-extern const QString RESOURCE_BASE;
-extern const QString LIBRARY_BASE;
-MULTIMC_LOGIC_EXPORT extern const QString SKINS_BASE;
-extern const QString AUTH_BASE;
-extern const QString FORGE_LEGACY_URL;
-extern const QString FORGE_GRADLE_URL;
-extern const QString MOJANG_STATUS_URL;
-extern const QString MOJANG_STATUS_NEWS_URL;
-extern const QString LITELOADER_URL;
-extern const QString IMGUR_BASE_URL;
-extern const QString FMLLIBS_OUR_BASE_URL;
-extern const QString FMLLIBS_FORGE_BASE_URL;
-extern const QString TRANSLATIONS_BASE_URL;
+const QString AWS_DOWNLOAD_VERSIONS("s3.amazonaws.com/Minecraft.Download/versions/");
+const QString RESOURCE_BASE("resources.download.minecraft.net/");
+const QString LIBRARY_BASE("libraries.minecraft.net/");
+//const QString SKINS_BASE("skins.minecraft.net/MinecraftSkins/");
+const QString SKINS_BASE("crafatar.com/skins/");
+const QString AUTH_BASE("authserver.mojang.com/");
+const QString FORGE_LEGACY_URL("http://files.minecraftforge.net/minecraftforge/json");
+const QString FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json");
+const QString MOJANG_STATUS_URL("http://status.mojang.com/check");
+const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news");
+const QString LITELOADER_URL("http://dl.liteloader.com/versions/versions.json");
+const QString IMGUR_BASE_URL("https://api.imgur.com/3/");
+const QString FMLLIBS_OUR_BASE_URL("http://files.multimc.org/fmllibs/");
+const QString FMLLIBS_FORGE_BASE_URL("http://files.minecraftforge.net/fmllibs/");
+const QString TRANSLATIONS_BASE_URL("http://files.multimc.org/translations/");
+
+QString getJarPath(QString version);
+QString getLegacyJarUrl(QString version);
}