summaryrefslogtreecommitdiffstats
path: root/logic/net
diff options
context:
space:
mode:
authorForkk <forkk@forkk.net>2014-01-02 13:38:20 -0600
committerForkk <forkk@forkk.net>2014-01-02 13:38:20 -0600
commit17f1864a71b69b9df14d8e06ed48a65e678d09c9 (patch)
tree4d98a2b3493a26017150d6ba8c5ae0419de3de7d /logic/net
parent4495e20cd7f7f2ab062f3b60f19ac4b79f32c350 (diff)
parentaa5f2c8120cc23de0d57c9f0280512adb9a531b3 (diff)
downloadMultiMC-17f1864a71b69b9df14d8e06ed48a65e678d09c9.tar
MultiMC-17f1864a71b69b9df14d8e06ed48a65e678d09c9.tar.gz
MultiMC-17f1864a71b69b9df14d8e06ed48a65e678d09c9.tar.lz
MultiMC-17f1864a71b69b9df14d8e06ed48a65e678d09c9.tar.xz
MultiMC-17f1864a71b69b9df14d8e06ed48a65e678d09c9.zip
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into feature_news
Conflicts: CMakeLists.txt gui/MainWindow.h
Diffstat (limited to 'logic/net')
-rw-r--r--logic/net/ForgeXzDownload.cpp44
-rw-r--r--logic/net/MD5EtagDownload.cpp38
-rw-r--r--logic/net/MD5EtagDownload.h8
-rw-r--r--logic/net/URLConstants.h2
4 files changed, 72 insertions, 20 deletions
diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp
index 1771d304..359ad858 100644
--- a/logic/net/ForgeXzDownload.cpp
+++ b/logic/net/ForgeXzDownload.cpp
@@ -20,6 +20,7 @@
#include <QCryptographicHash>
#include <QFileInfo>
#include <QDateTime>
+#include <QDir>
#include "logger/QsLog.h"
ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : NetAction()
@@ -310,16 +311,51 @@ void ForgeXzDownload::decompressAndInstall()
m_pack200_xz_file.remove();
// revert pack200
- pack200_file.close();
- QString pack_name = pack200_file.fileName();
+ pack200_file.seek(0);
+ int handle_in = pack200_file.handle();
+ // FIXME: dispose of file handles, pointers and the like. Ideally wrap in objects.
+ if(handle_in == -1)
+ {
+ QLOG_ERROR() << "Error reopening " << pack200_file.fileName();
+ failAndTryNextMirror();
+ return;
+ }
+ FILE * file_in = fdopen(handle_in,"r");
+ if(!file_in)
+ {
+ QLOG_ERROR() << "Error reopening " << pack200_file.fileName();
+ failAndTryNextMirror();
+ return;
+ }
+ QFile qfile_out(m_target_path);
+ if(!qfile_out.open(QIODevice::WriteOnly))
+ {
+ QLOG_ERROR() << "Error opening " << qfile_out.fileName();
+ failAndTryNextMirror();
+ return;
+ }
+ int handle_out = qfile_out.handle();
+ if(handle_out == -1)
+ {
+ QLOG_ERROR() << "Error opening " << qfile_out.fileName();
+ failAndTryNextMirror();
+ return;
+ }
+ FILE * file_out = fdopen(handle_out,"w");
+ if(!file_out)
+ {
+ QLOG_ERROR() << "Error opening " << qfile_out.fileName();
+ failAndTryNextMirror();
+ return;
+ }
try
{
- unpack_200(pack_name.toStdString(), m_target_path.toStdString());
+ unpack_200(file_in, file_out);
}
catch (std::runtime_error &err)
{
m_status = Job_Failed;
- QLOG_ERROR() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what();
+ QLOG_ERROR() << "Error unpacking " << pack200_file.fileName() << " : " << err.what();
QFile f(m_target_path);
if (f.exists())
f.remove();
diff --git a/logic/net/MD5EtagDownload.cpp b/logic/net/MD5EtagDownload.cpp
index 435e854e..63583e8d 100644
--- a/logic/net/MD5EtagDownload.cpp
+++ b/logic/net/MD5EtagDownload.cpp
@@ -23,7 +23,6 @@ MD5EtagDownload::MD5EtagDownload(QUrl url, QString target_path) : NetAction()
{
m_url = url;
m_target_path = target_path;
- m_check_md5 = false;
m_status = Job_NotStarted;
}
@@ -34,22 +33,26 @@ void MD5EtagDownload::start()
// if there already is a file and md5 checking is in effect and it can be opened
if (m_output_file.exists() && m_output_file.open(QIODevice::ReadOnly))
{
- // check the md5 against the expected one
- QString hash =
+ // get the md5 of the local file.
+ m_local_md5 =
QCryptographicHash::hash(m_output_file.readAll(), QCryptographicHash::Md5)
.toHex()
.constData();
m_output_file.close();
- // skip this file if they match
- if (m_check_md5 && hash == m_expected_md5)
+ // if we are expecting some md5sum, compare it with the local one
+ if (!m_expected_md5.isEmpty())
{
- QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match.";
- emit succeeded(m_index_within_job);
- return;
+ // skip if they match
+ if(m_local_md5 == m_expected_md5)
+ {
+ QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match.";
+ emit succeeded(m_index_within_job);
+ return;
+ }
}
else
{
- m_expected_md5 = hash;
+ // no expected md5. we use the local md5sum as an ETag
}
}
if (!ensureFilePathExists(filename))
@@ -58,9 +61,18 @@ void MD5EtagDownload::start()
return;
}
- QLOG_INFO() << "Downloading " << m_url.toString() << " expecting " << m_expected_md5;
QNetworkRequest request(m_url);
- request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1());
+
+ QLOG_INFO() << "Downloading " << m_url.toString() << " got " << m_local_md5;
+
+ if(!m_local_md5.isEmpty())
+ {
+ QLOG_INFO() << "Got " << m_local_md5;
+ request.setRawHeader(QString("If-None-Match").toLatin1(), m_local_md5.toLatin1());
+ }
+ if(!m_expected_md5.isEmpty())
+ QLOG_INFO() << "Expecting " << m_expected_md5;
+
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
// Go ahead and try to open the file.
@@ -107,7 +119,10 @@ void MD5EtagDownload::downloadFinished()
m_status = Job_Finished;
m_output_file.close();
+ // FIXME: compare with the real written data md5sum
+ // this is just an ETag
QLOG_INFO() << "Finished " << m_url.toString() << " got " << m_reply->rawHeader("ETag").constData();
+
m_reply.reset();
emit succeeded(m_index_within_job);
return;
@@ -116,6 +131,7 @@ void MD5EtagDownload::downloadFinished()
else
{
m_output_file.close();
+ m_output_file.remove();
m_reply.reset();
emit failed(m_index_within_job);
return;
diff --git a/logic/net/MD5EtagDownload.h b/logic/net/MD5EtagDownload.h
index 416ab9de..d5aed0ca 100644
--- a/logic/net/MD5EtagDownload.h
+++ b/logic/net/MD5EtagDownload.h
@@ -23,12 +23,10 @@ class MD5EtagDownload : public NetAction
{
Q_OBJECT
public:
- /// if true, check the md5sum against a provided md5sum
- /// also, if a file exists, perform an md5sum first and don't download only if they don't
- /// match
- bool m_check_md5;
- /// the expected md5 checksum
+ /// the expected md5 checksum. Only set from outside
QString m_expected_md5;
+ /// the md5 checksum of a file that already exists.
+ QString m_local_md5;
/// if saving to file, use the one specified in this string
QString m_target_path;
/// this is the output file, if any
diff --git a/logic/net/URLConstants.h b/logic/net/URLConstants.h
index dcd5c2b1..9579198d 100644
--- a/logic/net/URLConstants.h
+++ b/logic/net/URLConstants.h
@@ -29,4 +29,6 @@ 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 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");
}