summaryrefslogtreecommitdiffstats
path: root/logic/minecraft/forge
diff options
context:
space:
mode:
Diffstat (limited to 'logic/minecraft/forge')
-rw-r--r--logic/minecraft/forge/ForgeInstaller.cpp14
-rw-r--r--logic/minecraft/forge/ForgeMirror.h10
-rw-r--r--logic/minecraft/forge/ForgeMirrors.cpp118
-rw-r--r--logic/minecraft/forge/ForgeMirrors.h61
-rw-r--r--logic/minecraft/forge/ForgeVersionList.cpp4
-rw-r--r--logic/minecraft/forge/ForgeXzDownload.cpp63
-rw-r--r--logic/minecraft/forge/ForgeXzDownload.h7
7 files changed, 17 insertions, 260 deletions
diff --git a/logic/minecraft/forge/ForgeInstaller.cpp b/logic/minecraft/forge/ForgeInstaller.cpp
index 7957de0e..155a2cac 100644
--- a/logic/minecraft/forge/ForgeInstaller.cpp
+++ b/logic/minecraft/forge/ForgeInstaller.cpp
@@ -126,8 +126,8 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr
QCryptographicHash md5sum(QCryptographicHash::Md5);
md5sum.addData(data);
- cacheentry->stale = false;
- cacheentry->md5sum = md5sum.result().toHex().constData();
+ cacheentry->setStale(false);
+ cacheentry->setMD5Sum(md5sum.result().toHex().constData());
ENV.metacache()->updateEntry(cacheentry);
}
file.close();
@@ -264,8 +264,8 @@ bool ForgeInstaller::add(OneSixInstance *to)
m_forge_json->name = "Forge";
m_forge_json->fileId = id();
m_forge_json->version = m_forgeVersionString;
- m_forge_json->mcVersion = to->intendedVersionId();
- m_forge_json->id.clear();
+ m_forge_json->dependsOnMinecraftVersion = to->intendedVersionId();
+ m_forge_json->minecraftVersion.clear();
m_forge_json->order = 5;
QSaveFile file(filename(to->instanceRoot()));
@@ -378,16 +378,16 @@ protected:
* This fixes some problems with bad files acquired because of unhandled HTTP redirects
* in old versions of MultiMC.
*/
- if (!entry->stale)
+ if (!entry->isStale())
{
QFileInfo localFile(entry->getFullPath());
if (localFile.size() <= 0x4000)
{
- entry->stale = true;
+ entry->setStale(true);
}
}
- if (entry->stale)
+ if (entry->isStale())
{
NetJob *fjob = new NetJob("Forge download");
fjob->addNetAction(CacheDownload::make(forgeVersion->url(), entry));
diff --git a/logic/minecraft/forge/ForgeMirror.h b/logic/minecraft/forge/ForgeMirror.h
deleted file mode 100644
index 2518dffe..00000000
--- a/logic/minecraft/forge/ForgeMirror.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-#include <QString>
-
-struct ForgeMirror
-{
- QString name;
- QString logo_url;
- QString website_url;
- QString mirror_url;
-}; \ No newline at end of file
diff --git a/logic/minecraft/forge/ForgeMirrors.cpp b/logic/minecraft/forge/ForgeMirrors.cpp
deleted file mode 100644
index a2fc2c62..00000000
--- a/logic/minecraft/forge/ForgeMirrors.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-#include "Env.h"
-#include "ForgeMirrors.h"
-#include <QDebug>
-#include <algorithm>
-#include <random>
-
-ForgeMirrors::ForgeMirrors(QList<ForgeXzDownloadPtr> &libs, NetJobPtr parent_job,
- QString mirrorlist)
-{
- m_libs = libs;
- m_parent_job = parent_job;
- m_url = QUrl(mirrorlist);
- m_status = Job_NotStarted;
-}
-
-void ForgeMirrors::start()
-{
- qDebug() << "Downloading " << m_url.toString();
- QNetworkRequest request(m_url);
- request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
- auto worker = ENV.qnam();
- QNetworkReply *rep = worker->get(request);
-
- m_reply.reset(rep);
- connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
- SLOT(downloadProgress(qint64, qint64)));
- connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
- connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
- SLOT(downloadError(QNetworkReply::NetworkError)));
- connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
-}
-
-void ForgeMirrors::downloadError(QNetworkReply::NetworkError error)
-{
- // error happened during download.
- qCritical() << "Error getting URL:" << m_url.toString().toLocal8Bit()
- << "Network error: " << error;
- m_status = Job_Failed;
-}
-
-void ForgeMirrors::downloadFinished()
-{
- // if the download succeeded
- if (m_status != Job_Failed)
- {
- // nothing went wrong... ?
- parseMirrorList();
- return;
- }
- // else the download failed, we use a fixed list
- else
- {
- m_status = Job_Finished;
- m_reply.reset();
- deferToFixedList();
- return;
- }
-}
-
-void ForgeMirrors::deferToFixedList()
-{
- m_mirrors.clear();
- m_mirrors.append(
- {"Minecraft Forge", "http://files.minecraftforge.net/forge_logo.png",
- "http://files.minecraftforge.net/", "http://files.minecraftforge.net/maven/"});
- m_mirrors.append({"Creeper Host",
- "http://files.minecraftforge.net/forge_logo.png",
- "https://www.creeperhost.net/link.php?id=1",
- "http://new.creeperrepo.net/forge/maven/"});
- injectDownloads();
- emit succeeded(m_index_within_job);
-}
-
-void ForgeMirrors::parseMirrorList()
-{
- m_status = Job_Finished;
- auto data = m_reply->readAll();
- m_reply.reset();
- auto dataLines = data.split('\n');
- for(auto line: dataLines)
- {
- auto elements = line.split('!');
- if (elements.size() == 4)
- {
- m_mirrors.append({elements[0],elements[1],elements[2],elements[3]});
- }
- }
- if(!m_mirrors.size())
- deferToFixedList();
- injectDownloads();
- emit succeeded(m_index_within_job);
-}
-
-void ForgeMirrors::injectDownloads()
-{
- // shuffle the mirrors randomly
- std::random_device rd;
- std::mt19937 rng(rd());
- std::shuffle(m_mirrors.begin(), m_mirrors.end(), rng);
-
- // tell parent to download the libs
- for(auto lib: m_libs)
- {
- lib->setMirrors(m_mirrors);
- m_parent_job->addNetAction(lib);
- }
-}
-
-void ForgeMirrors::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
-{
- m_total_progress = bytesTotal;
- m_progress = bytesReceived;
- emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
-}
-
-void ForgeMirrors::downloadReadyRead()
-{
-}
diff --git a/logic/minecraft/forge/ForgeMirrors.h b/logic/minecraft/forge/ForgeMirrors.h
deleted file mode 100644
index 0312829b..00000000
--- a/logic/minecraft/forge/ForgeMirrors.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Copyright 2013-2015 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include "ForgeXzDownload.h"
-
-#include "net/NetAction.h"
-#include "net/HttpMetaCache.h"
-#include "net/NetJob.h"
-
-#include <QFile>
-#include <QTemporaryFile>
-
-typedef std::shared_ptr<class ForgeMirrors> ForgeMirrorsPtr;
-
-class ForgeMirrors : public NetAction
-{
- Q_OBJECT
-public:
- QList<ForgeXzDownloadPtr> m_libs;
- NetJobPtr m_parent_job;
- QList<ForgeMirror> m_mirrors;
-
-public:
- explicit ForgeMirrors(QList<ForgeXzDownloadPtr> &libs, NetJobPtr parent_job,
- QString mirrorlist);
- static ForgeMirrorsPtr make(QList<ForgeXzDownloadPtr> &libs, NetJobPtr parent_job,
- QString mirrorlist)
- {
- return ForgeMirrorsPtr(new ForgeMirrors(libs, parent_job, mirrorlist));
- }
- virtual ~ForgeMirrors(){};
-protected
-slots:
- virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
- virtual void downloadError(QNetworkReply::NetworkError error);
- virtual void downloadFinished();
- virtual void downloadReadyRead();
-
-private:
- void parseMirrorList();
- void deferToFixedList();
- void injectDownloads();
-
-public
-slots:
- virtual void start();
-};
diff --git a/logic/minecraft/forge/ForgeVersionList.cpp b/logic/minecraft/forge/ForgeVersionList.cpp
index 9b418310..907672f2 100644
--- a/logic/minecraft/forge/ForgeVersionList.cpp
+++ b/logic/minecraft/forge/ForgeVersionList.cpp
@@ -128,8 +128,8 @@ void ForgeListLoadTask::executeTask()
auto gradleForgeListEntry = ENV.metacache()->resolveEntry("minecraftforge", "json");
// verify by poking the server.
- forgeListEntry->stale = true;
- gradleForgeListEntry->stale = true;
+ forgeListEntry->setStale(true);
+ gradleForgeListEntry->setStale(true);
job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::FORGE_LEGACY_URL),
forgeListEntry));
diff --git a/logic/minecraft/forge/ForgeXzDownload.cpp b/logic/minecraft/forge/ForgeXzDownload.cpp
index 6009e31e..2a47bb26 100644
--- a/logic/minecraft/forge/ForgeXzDownload.cpp
+++ b/logic/minecraft/forge/ForgeXzDownload.cpp
@@ -30,19 +30,13 @@ ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : Ne
m_pack200_xz_file.setFileTemplate("./dl_temp.XXXXXX");
m_status = Job_NotStarted;
m_url_path = relative_path;
-}
-
-void ForgeXzDownload::setMirrors(QList<ForgeMirror> &mirrors)
-{
- m_mirror_index = 0;
- m_mirrors = mirrors;
- updateUrl();
+ m_url = "http://files.minecraftforge.net/maven/" + m_url_path + ".pack.xz";
}
void ForgeXzDownload::start()
{
m_status = Job_InProgress;
- if (!m_entry->stale)
+ if (!m_entry->isStale())
{
m_status = Job_Finished;
emit succeeded(m_index_within_job);
@@ -55,16 +49,10 @@ void ForgeXzDownload::start()
emit failed(m_index_within_job);
return;
}
- if (m_mirrors.empty())
- {
- m_status = Job_Failed;
- emit failed(m_index_within_job);
- return;
- }
qDebug() << "Downloading " << m_url.toString();
QNetworkRequest request(m_url);
- request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
+ request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->getETag().toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
auto worker = ENV.qnam();
@@ -96,44 +84,11 @@ void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error)
void ForgeXzDownload::failAndTryNextMirror()
{
m_status = Job_Failed;
- int next = m_mirror_index + 1;
- if(m_mirrors.size() == next)
- m_mirror_index = 0;
- else
- m_mirror_index = next;
-
- updateUrl();
emit failed(m_index_within_job);
}
-void ForgeXzDownload::updateUrl()
-{
- qDebug() << "Updating URL for " << m_url_path;
- for (auto possible : m_mirrors)
- {
- qDebug() << "Possible: " << possible.name << " : " << possible.mirror_url;
- }
- QString aggregate = m_mirrors[m_mirror_index].mirror_url + m_url_path + ".pack.xz";
- m_url = QUrl(aggregate);
-}
-
void ForgeXzDownload::downloadFinished()
{
- //TEST: defer to other possible mirrors (autofail the first one)
- /*
- qDebug() <<"dl " << index_within_job << " mirror " << m_mirror_index;
- if( m_mirror_index == 0)
- {
- qDebug() <<"dl " << index_within_job << " AUTOFAIL";
- m_status = Job_Failed;
- m_pack200_xz_file.close();
- m_pack200_xz_file.remove();
- m_reply.reset();
- failAndTryNextMirror();
- return;
- }
- */
-
// if the download succeeded
if (m_status != Job_Failed)
{
@@ -372,16 +327,14 @@ void ForgeXzDownload::decompressAndInstall()
failAndTryNextMirror();
return;
}
- m_entry->md5sum = QCryptographicHash::hash(jar_file.readAll(), QCryptographicHash::Md5)
- .toHex()
- .constData();
+ auto hash = QCryptographicHash::hash(jar_file.readAll(), QCryptographicHash::Md5);
+ m_entry->setMD5Sum(hash.toHex().constData());
jar_file.close();
QFileInfo output_file_info(m_target_path);
- m_entry->etag = m_reply->rawHeader("ETag").constData();
- m_entry->local_changed_timestamp =
- output_file_info.lastModified().toUTC().toMSecsSinceEpoch();
- m_entry->stale = false;
+ m_entry->setETag(m_reply->rawHeader("ETag").constData());
+ 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/minecraft/forge/ForgeXzDownload.h b/logic/minecraft/forge/ForgeXzDownload.h
index 45722812..67524405 100644
--- a/logic/minecraft/forge/ForgeXzDownload.h
+++ b/logic/minecraft/forge/ForgeXzDownload.h
@@ -19,7 +19,6 @@
#include "net/HttpMetaCache.h"
#include <QFile>
#include <QTemporaryFile>
-#include "ForgeMirror.h"
typedef std::shared_ptr<class ForgeXzDownload> ForgeXzDownloadPtr;
@@ -32,10 +31,6 @@ public:
QString m_target_path;
/// this is the output file, if any
QTemporaryFile m_pack200_xz_file;
- /// mirror index (NOT OPTICS, I SWEAR)
- int m_mirror_index = 0;
- /// list of mirrors to use. Mirror has the url base
- QList<ForgeMirror> m_mirrors;
/// path relative to the mirror base
QString m_url_path;
@@ -46,7 +41,6 @@ public:
return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry));
}
virtual ~ForgeXzDownload(){};
- void setMirrors(QList<ForgeMirror> & mirrors);
protected
slots:
@@ -62,5 +56,4 @@ slots:
private:
void decompressAndInstall();
void failAndTryNextMirror();
- void updateUrl();
};