From d6c71488b34a2854461feee3296c11568542ecbe Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 17 Dec 2013 02:09:58 +0100 Subject: Some test madness --- logic/net/ForgeXzDownload.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'logic/net') diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp index 1771d304..83cbabd0 100644 --- a/logic/net/ForgeXzDownload.cpp +++ b/logic/net/ForgeXzDownload.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "logger/QsLog.h" ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : NetAction() @@ -312,9 +313,11 @@ void ForgeXzDownload::decompressAndInstall() // revert pack200 pack200_file.close(); QString pack_name = pack200_file.fileName(); + QString source_native = QDir::toNativeSeparators(pack_name); + QString target_native = QDir::toNativeSeparators(m_target_path); try { - unpack_200(pack_name.toStdString(), m_target_path.toStdString()); + unpack_200(source_native.toStdString(), target_native.toStdString()); } catch (std::runtime_error &err) { -- cgit From 01dbebdfc81abab00048f48e68a4e04d391bc50e Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 21 Dec 2013 14:25:16 +0100 Subject: Fix issues with the updater * Bad URLs used for downloading update files * MD5ETagDownload resetting the expected ETag after failure to the failed file MD5 checksum * Delete MD5ETagDownload downloaded files if the download fails. --- logic/net/MD5EtagDownload.cpp | 38 +++++++++++++++++++++++++----------- logic/net/MD5EtagDownload.h | 8 +++----- logic/updater/DownloadUpdateTask.cpp | 11 +++++++---- 3 files changed, 37 insertions(+), 20 deletions(-) (limited to 'logic/net') 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/updater/DownloadUpdateTask.cpp b/logic/updater/DownloadUpdateTask.cpp index cc06104a..b017afeb 100644 --- a/logic/updater/DownloadUpdateTask.cpp +++ b/logic/updater/DownloadUpdateTask.cpp @@ -396,7 +396,6 @@ DownloadUpdateTask::processFileLists(NetJob *job, // We need to download the file to the updatefiles folder and add a task // to copy it to its install path. auto download = MD5EtagDownload::make(source.url, dlPath); - download->m_check_md5 = true; download->m_expected_md5 = entry.md5; job->addNetAction(download); } @@ -487,9 +486,13 @@ bool DownloadUpdateTask::writeInstallScript(UpdateOperationList &opsList, QStrin QString DownloadUpdateTask::preparePath(const QString &path) { - QString foo = path; - foo.replace("$PWD", qApp->applicationDirPath()); - return QUrl::fromLocalFile(foo).toString(QUrl::FullyEncoded); + if(path.startsWith("$PWD")) + { + QString foo = path; + foo.replace("$PWD", qApp->applicationDirPath()); + return QUrl::fromLocalFile(foo).toString(QUrl::FullyEncoded); + } + return path; } void DownloadUpdateTask::fileDownloadFinished() -- cgit From 3051d0d3283656baafe6021e5036fdca9db0c4aa Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 22 Dec 2013 18:49:52 +0100 Subject: Make pack200 use QFile by proxy, eliminating some unicode issues. --- depends/pack200/anti200.cpp | 43 +++++++++++++++++++++++------------ depends/pack200/include/unpack200.h | 2 +- depends/pack200/src/unpack200.cpp | 13 +---------- logic/net/ForgeXzDownload.cpp | 45 ++++++++++++++++++++++++++++++++----- mmc_updater/src/Platform.h | 4 +++- 5 files changed, 73 insertions(+), 34 deletions(-) (limited to 'logic/net') diff --git a/depends/pack200/anti200.cpp b/depends/pack200/anti200.cpp index 3dfdb5dc..1e1ec0c8 100644 --- a/depends/pack200/anti200.cpp +++ b/depends/pack200/anti200.cpp @@ -8,21 +8,36 @@ int main(int argc, char **argv) { - if (argc == 3) + if (argc != 3) { - try - { - unpack_200(argv[1], argv[2]); - } - catch (std::runtime_error &e) - { - std::cerr << "Bad things happened: " << e.what() << std::endl; - return EXIT_FAILURE; - } - return EXIT_SUCCESS; - } - else std::cerr << "Simple pack200 unpacker!" << std::endl << "Run like this:" << std::endl << " " << argv[0] << " input.jar.lzma output.jar" << std::endl; - return EXIT_FAILURE; + return EXIT_FAILURE; + } + + FILE *input = fopen(argv[1], "rb"); + FILE *output = fopen(argv[2], "wb"); + if (!input) + { + std::cerr << "Can't open input file"; + return EXIT_FAILURE; + } + if (!output) + { + fclose(output); + std::cerr << "Can't open output file"; + return EXIT_FAILURE; + } + try + { + unpack_200(input, output); + } + catch (std::runtime_error &e) + { + std::cerr << "Bad things happened: " << e.what() << std::endl; + fclose(input); + fclose(output); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; } diff --git a/depends/pack200/include/unpack200.h b/depends/pack200/include/unpack200.h index bcee8009..f9239488 100644 --- a/depends/pack200/include/unpack200.h +++ b/depends/pack200/include/unpack200.h @@ -34,4 +34,4 @@ * @return void * @throw std::runtime_error for any error encountered */ -void unpack_200(std::string input_path, std::string output_path); +void unpack_200(FILE * input, FILE * output); diff --git a/depends/pack200/src/unpack200.cpp b/depends/pack200/src/unpack200.cpp index 0a9d2714..22b7f3b0 100644 --- a/depends/pack200/src/unpack200.cpp +++ b/depends/pack200/src/unpack200.cpp @@ -94,20 +94,9 @@ static int read_magic(unpacker *u, char peek[], int peeklen) return magic; } -void unpack_200(std::string input_path, std::string output_path) +void unpack_200(FILE *input, FILE *output) { unpacker u; - FILE *input = fopen(input_path.c_str(), "rb"); - if (!input) - { - throw std::runtime_error("Can't open input file" + input_path); - } - FILE *output = fopen(output_path.c_str(), "wb"); - if (!output) - { - fclose(output); - throw std::runtime_error("Can't open output file" + output_path); - } u.init(read_input_via_stdio); // initialize jar output diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp index 83cbabd0..359ad858 100644 --- a/logic/net/ForgeXzDownload.cpp +++ b/logic/net/ForgeXzDownload.cpp @@ -311,18 +311,51 @@ void ForgeXzDownload::decompressAndInstall() m_pack200_xz_file.remove(); // revert pack200 - pack200_file.close(); - QString pack_name = pack200_file.fileName(); - QString source_native = QDir::toNativeSeparators(pack_name); - QString target_native = QDir::toNativeSeparators(m_target_path); + 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(source_native.toStdString(), target_native.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/mmc_updater/src/Platform.h b/mmc_updater/src/Platform.h index 6d9afdfb..97867d6a 100644 --- a/mmc_updater/src/Platform.h +++ b/mmc_updater/src/Platform.h @@ -13,7 +13,9 @@ // disable warnings about exception specifications, // which are not implemented in Visual C++ - #pragma warning(disable:4290) + #ifdef MSVC + #pragma warning(disable:4290) + #endif #endif #ifdef __APPLE__ -- cgit From f402001453c4053d1c8c56b63896796d63df0388 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 23 Dec 2013 00:43:29 +0100 Subject: Use the central URL list for forge URLs --- logic/lists/ForgeVersionList.cpp | 43 ++++++++++++++++++++-------------------- logic/net/URLConstants.h | 2 ++ 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'logic/net') diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index b6e06e77..78cb0de0 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -15,6 +15,7 @@ #include "ForgeVersionList.h" #include +#include #include "MultiMC.h" #include @@ -23,9 +24,6 @@ #include "logger/QsLog.h" -#define JSON_URL "http://files.minecraftforge.net/minecraftforge/json" -#define GRADLE_JSON_URL "http://files.minecraftforge.net/maven/net/minecraftforge/forge/json" - ForgeVersionList::ForgeVersionList(QObject *parent) : BaseVersionList(parent) { } @@ -170,8 +168,10 @@ void ForgeListLoadTask::executeTask() forgeListEntry->stale = true; gradleForgeListEntry->stale = true; - job->addNetAction(listDownload = CacheDownload::make(QUrl(JSON_URL), forgeListEntry)); - job->addNetAction(gradleListDownload = CacheDownload::make(QUrl(GRADLE_JSON_URL), gradleForgeListEntry)); + job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::FORGE_LEGACY_URL), + forgeListEntry)); + job->addNetAction(gradleListDownload = CacheDownload::make( + QUrl(URLConstants::FORGE_GRADLE_URL), gradleForgeListEntry)); connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed())); connect(gradleListDownload.get(), SIGNAL(failed(int)), SLOT(gradleListFailed())); @@ -355,33 +355,32 @@ bool ForgeListLoadTask::parseForgeGradleList(QList &out) } if (file.at(1).toString() == "installer") { - fVersion->installer_url = - QString("%1/%2-%3/%4-%2-%3-installer.%5") - .arg(webpath, fVersion->mcver, fVersion->jobbuildver, artifact, file.at(0).toString()); - installer_filename = QString("%1-%2-%3-installer.%4") - .arg(artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); + fVersion->installer_url = QString("%1/%2-%3/%4-%2-%3-installer.%5").arg( + webpath, fVersion->mcver, fVersion->jobbuildver, artifact, + file.at(0).toString()); + installer_filename = QString("%1-%2-%3-installer.%4").arg( + artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); } else if (file.at(1).toString() == "universal") { - fVersion->universal_url = - QString("%1/%2-%3/%4-%2-%3-universal.%5") - .arg(webpath, fVersion->mcver, fVersion->jobbuildver, artifact, file.at(0).toString()); - filename = QString("%1-%2-%3-universal.%4") - .arg(artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); + fVersion->universal_url = QString("%1/%2-%3/%4-%2-%3-universal.%5").arg( + webpath, fVersion->mcver, fVersion->jobbuildver, artifact, + file.at(0).toString()); + filename = QString("%1-%2-%3-universal.%4").arg( + artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); } else if (file.at(1).toString() == "changelog") { - fVersion->changelog_url = - QString("%1/%2-%3/%4-%2-%3-changelog.%5") - .arg(webpath, fVersion->mcver, fVersion->jobbuildver, artifact, file.at(0).toString()); + fVersion->changelog_url = QString("%1/%2-%3/%4-%2-%3-changelog.%5").arg( + webpath, fVersion->mcver, fVersion->jobbuildver, artifact, + file.at(0).toString()); } } if (fVersion->installer_url.isEmpty() && fVersion->universal_url.isEmpty()) { continue; } - fVersion->filename = fVersion->installer_url.isEmpty() ? - filename : installer_filename; + fVersion->filename = fVersion->installer_url.isEmpty() ? filename : installer_filename; out.append(fVersion); } @@ -406,8 +405,8 @@ void ForgeListLoadTask::listDownloaded() return; } - qSort(list.begin(), list.end(), - [](const BaseVersionPtr &p1, const BaseVersionPtr &p2) { + qSort(list.begin(), list.end(), [](const BaseVersionPtr & p1, const BaseVersionPtr & p2) + { // TODO better comparison (takes major/minor/build number into account) return p1->name() > p2->name(); }); 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"); } -- cgit