From f83119ce7ec3d11a903901b8eff762d2b0a9f635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 6 Oct 2013 01:13:40 +0200 Subject: Added file logger --- logic/BaseInstance.cpp | 2 +- logic/BaseInstance.h | 6 +- logic/BaseInstance_p.h | 2 +- logic/BaseVersion.h | 4 +- logic/ForgeInstaller.cpp | 4 +- logic/ForgeInstaller.h | 6 +- logic/InstanceFactory.cpp | 5 +- logic/InstanceLauncher.cpp | 2 +- logic/LegacyInstance.cpp | 8 +- logic/LegacyInstance.h | 8 +- logic/LegacyInstance_p.h | 8 +- logic/LegacyUpdate.cpp | 213 ++++++++++++++++++---------------- logic/LegacyUpdate.h | 2 +- logic/Mod.cpp | 7 +- logic/ModList.cpp | 16 +-- logic/OneSixAssets.cpp | 13 ++- logic/OneSixInstance.cpp | 9 +- logic/OneSixInstance.h | 6 +- logic/OneSixInstance_p.h | 6 +- logic/OneSixLibrary.cpp | 2 +- logic/OneSixLibrary.h | 6 +- logic/OneSixRule.cpp | 6 +- logic/OneSixRule.h | 10 +- logic/OneSixUpdate.cpp | 25 ++-- logic/OneSixUpdate.h | 2 +- logic/OneSixVersion.cpp | 28 ++--- logic/OneSixVersion.h | 12 +- logic/lists/ForgeVersionList.cpp | 20 ++-- logic/lists/ForgeVersionList.h | 2 +- logic/lists/InstanceList.cpp | 218 ++++++++++++++++++----------------- logic/lists/LwjglVersionList.cpp | 62 +++++----- logic/lists/LwjglVersionList.h | 6 +- logic/lists/MinecraftVersionList.cpp | 10 +- logic/net/ByteArrayDownload.cpp | 13 ++- logic/net/ByteArrayDownload.h | 2 +- logic/net/CacheDownload.cpp | 10 +- logic/net/CacheDownload.h | 2 +- logic/net/Download.h | 18 +-- logic/net/DownloadJob.cpp | 22 ++-- logic/net/DownloadJob.h | 2 +- logic/net/FileDownload.cpp | 12 +- logic/net/FileDownload.h | 2 +- logic/net/ForgeXzDownload.cpp | 26 ++--- logic/net/ForgeXzDownload.h | 2 +- logic/net/HttpMetaCache.cpp | 6 +- logic/net/HttpMetaCache.h | 2 +- logic/net/LoginTask.cpp | 4 +- logic/tasks/Task.cpp | 2 + 48 files changed, 441 insertions(+), 420 deletions(-) (limited to 'logic') diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index ec86596a..6a6b195b 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -132,7 +132,7 @@ InstanceList *BaseInstance::instList() const return NULL; } -QSharedPointer BaseInstance::versionList() const +std::shared_ptr BaseInstance::versionList() const { return MMC->minecraftlist(); } diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index 0056327a..e360d3ae 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -135,7 +135,7 @@ public: * \brief Gets a pointer to this instance's version list. * \return A pointer to the available version list for this instance. */ - virtual QSharedPointer versionList() const; + virtual std::shared_ptr versionList() const; /*! * \brief Gets this instance's settings object. @@ -179,9 +179,9 @@ signals: void nuked(BaseInstance * inst); protected: - QSharedPointer inst_d; + std::shared_ptr inst_d; }; // pointer for lazy people -typedef QSharedPointer InstancePtr; +typedef std::shared_ptr InstancePtr; diff --git a/logic/BaseInstance_p.h b/logic/BaseInstance_p.h index a30916a4..06c0c0ba 100644 --- a/logic/BaseInstance_p.h +++ b/logic/BaseInstance_p.h @@ -4,7 +4,7 @@ class BaseInstance; -#define I_D(Class) Class##Private * const d = (Class##Private * const) inst_d.data() +#define I_D(Class) Class##Private * const d = (Class##Private * const) inst_d.get() struct BaseInstancePrivate { diff --git a/logic/BaseVersion.h b/logic/BaseVersion.h index be717fee..01745c46 100644 --- a/logic/BaseVersion.h +++ b/logic/BaseVersion.h @@ -14,7 +14,7 @@ */ #pragma once -#include +#include /*! * An abstract base class for versions. @@ -40,6 +40,6 @@ struct BaseVersion virtual QString typeString() const = 0; }; -typedef QSharedPointer BaseVersionPtr; +typedef std::shared_ptr BaseVersionPtr; Q_DECLARE_METATYPE( BaseVersionPtr ) \ No newline at end of file diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 9ae3f1e1..a946dd44 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -10,7 +10,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) { - QSharedPointer newVersion; + std::shared_ptr newVersion; m_universal_url = universal_url; QuaZip zip(filename); @@ -88,7 +88,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); } -bool ForgeInstaller::apply(QSharedPointer to) +bool ForgeInstaller::apply(std::shared_ptr to) { if (!m_forge_version) return false; diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index f4ceaaef..f6f22a2a 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include class OneSixVersion; @@ -9,11 +9,11 @@ class ForgeInstaller public: ForgeInstaller(QString filename, QString universal_url); - bool apply(QSharedPointer to); + bool apply(std::shared_ptr to); private: // the version, read from the installer - QSharedPointer m_forge_version; + std::shared_ptr m_forge_version; QString internalPath; QString finalPath; QString realVersionId; diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index b5832ce5..0da62803 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -30,6 +30,7 @@ #include #include "pathutils.h" +#include InstanceFactory InstanceFactory::loader; @@ -72,12 +73,12 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& { QDir rootDir(instDir); - qDebug(instDir.toUtf8()); + QLOG_DEBUG() << instDir.toUtf8(); if (!rootDir.exists() && !rootDir.mkpath(".")) { return InstanceFactory::CantCreateDir; } - auto mcVer = version.dynamicCast(); + auto mcVer = std::dynamic_pointer_cast(version); if(!mcVer) return InstanceFactory::NoSuchVersion; diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp index 93b87f23..720052a3 100644 --- a/logic/InstanceLauncher.cpp +++ b/logic/InstanceLauncher.cpp @@ -61,7 +61,7 @@ int InstanceLauncher::launch() { std::cout << "Launching Instance '" << qPrintable ( instId ) << "'" << std::endl; auto instance = MMC->instances()->getInstanceById(instId); - if ( instance.isNull() ) + if ( !instance ) { std::cout << "Could not find instance requested. note that you have to specify the ID, not the NAME" << std::endl; return 1; diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index 4f367980..2ffcb075 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -92,7 +92,7 @@ void LegacyInstance::cleanupAfterRun() //FIXME: delete the launcher and icons and whatnot. } -QSharedPointer< ModList > LegacyInstance::coreModList() +std::shared_ptr< ModList > LegacyInstance::coreModList() { I_D(LegacyInstance); if(!d->core_mod_list) @@ -104,7 +104,7 @@ QSharedPointer< ModList > LegacyInstance::coreModList() return d->core_mod_list; } -QSharedPointer< ModList > LegacyInstance::jarModList() +std::shared_ptr< ModList > LegacyInstance::jarModList() { I_D(LegacyInstance); if(!d->jar_mod_list) @@ -124,7 +124,7 @@ void LegacyInstance::jarModsChanged() } -QSharedPointer< ModList > LegacyInstance::loaderModList() +std::shared_ptr< ModList > LegacyInstance::loaderModList() { I_D(LegacyInstance); if(!d->loader_mod_list) @@ -136,7 +136,7 @@ QSharedPointer< ModList > LegacyInstance::loaderModList() return d->loader_mod_list; } -QSharedPointer< ModList > LegacyInstance::texturePackList() +std::shared_ptr< ModList > LegacyInstance::texturePackList() { I_D(LegacyInstance); if(!d->texture_pack_list) diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h index 2eab9035..d7438cca 100644 --- a/logic/LegacyInstance.h +++ b/logic/LegacyInstance.h @@ -19,10 +19,10 @@ public: QString modListFile() const; ////// Mod Lists ////// - QSharedPointer jarModList(); - QSharedPointer coreModList(); - QSharedPointer loaderModList(); - QSharedPointer texturePackList(); + std::shared_ptr jarModList(); + std::shared_ptr coreModList(); + std::shared_ptr loaderModList(); + std::shared_ptr texturePackList(); ////// Directories ////// QString savesDir() const; diff --git a/logic/LegacyInstance_p.h b/logic/LegacyInstance_p.h index d1f417fe..0809b8d2 100644 --- a/logic/LegacyInstance_p.h +++ b/logic/LegacyInstance_p.h @@ -9,8 +9,8 @@ class ModList; struct LegacyInstancePrivate: public BaseInstancePrivate { - QSharedPointer jar_mod_list; - QSharedPointer core_mod_list; - QSharedPointer loader_mod_list; - QSharedPointer texture_pack_list; + std::shared_ptr jar_mod_list; + std::shared_ptr core_mod_list; + std::shared_ptr loader_mod_list; + std::shared_ptr texture_pack_list; }; \ No newline at end of file diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index d8e622dd..5f5a2e52 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -9,9 +9,11 @@ #include #include #include +#include - -LegacyUpdate::LegacyUpdate ( BaseInstance* inst, QObject* parent ) : BaseUpdate ( inst, parent ) {} +LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : BaseUpdate(inst, parent) +{ +} void LegacyUpdate::executeTask() { @@ -20,35 +22,35 @@ void LegacyUpdate::executeTask() void LegacyUpdate::lwjglStart() { - LegacyInstance * inst = (LegacyInstance *) m_inst; + LegacyInstance *inst = (LegacyInstance *)m_inst; + + lwjglVersion = inst->lwjglVersion(); + lwjglTargetPath = PathCombine("lwjgl", lwjglVersion); + lwjglNativesPath = PathCombine(lwjglTargetPath, "natives"); - lwjglVersion = inst->lwjglVersion(); - lwjglTargetPath = PathCombine("lwjgl", lwjglVersion ); - lwjglNativesPath = PathCombine( lwjglTargetPath, "natives"); - // if the 'done' file exists, we don't have to download this again QFileInfo doneFile(PathCombine(lwjglTargetPath, "done")); - if(doneFile.exists()) + if (doneFile.exists()) { jarStart(); return; } - + auto list = MMC->lwjgllist(); - if(!list->isLoaded()) + if (!list->isLoaded()) { emitFailed("Too soon! Let the LWJGL list load :)"); return; } - + setStatus("Downloading new LWJGL."); auto version = list->getVersion(lwjglVersion); - if(!version) + if (!version) { emitFailed("Game update failed: the selected LWJGL version is invalid."); return; } - + QString url = version->url(); QUrl realUrl(url); QString hostname = realUrl.host(); @@ -56,39 +58,42 @@ void LegacyUpdate::lwjglStart() QNetworkRequest req(realUrl); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker->get ( req ); - - m_reply = QSharedPointer (rep, &QObject::deleteLater); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); - connect(worker.data(), SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); - //connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); + QNetworkReply *rep = worker->get(req); + + m_reply = std::shared_ptr(rep); + connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); + connect(worker.get(), SIGNAL(finished(QNetworkReply *)), + SLOT(lwjglFinished(QNetworkReply *))); + // connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), + // SLOT(downloadError(QNetworkReply::NetworkError))); } -void LegacyUpdate::lwjglFinished(QNetworkReply* reply) +void LegacyUpdate::lwjglFinished(QNetworkReply *reply) { - if(m_reply != reply) + if (m_reply.get() != reply) { return; } - if(reply->error() != QNetworkReply::NoError) + if (reply->error() != QNetworkReply::NoError) { - emitFailed( "Failed to download: "+ - reply->errorString()+ - "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV"); + emitFailed("Failed to download: " + reply->errorString() + + "\nSometimes you have to wait a bit if you download many LWJGL versions in " + "a row. YMMV"); return; } auto worker = MMC->qnam(); - //Here i check if there is a cookie for me in the reply and extract it - QList cookies = qvariant_cast>(reply->header(QNetworkRequest::SetCookieHeader)); - if(cookies.count() != 0) + // Here i check if there is a cookie for me in the reply and extract it + QList cookies = + qvariant_cast>(reply->header(QNetworkRequest::SetCookieHeader)); + if (cookies.count() != 0) { - //you must tell which cookie goes with which url + // you must tell which cookie goes with which url worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); } - //here you can check for the 302 or whatever other header i need + // here you can check for the 302 or whatever other header i need QVariant newLoc = reply->header(QNetworkRequest::LocationHeader); - if(newLoc.isValid()) + if (newLoc.isValid()) { QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString(); QUrl realUrl(redirectedTo); @@ -96,9 +101,10 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply) QNetworkRequest req(redirectedTo); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker->get(req); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); - m_reply = QSharedPointer (rep, &QObject::deleteLater); + QNetworkReply *rep = worker->get(req); + connect(rep, SIGNAL(downloadProgress(qint64, qint64)), + SIGNAL(progress(qint64, qint64))); + m_reply = std::shared_ptr(rep); return; } QFile saveMe("lwjgl.zip"); @@ -114,26 +120,26 @@ void LegacyUpdate::extractLwjgl() // make sure the directories are there bool success = ensureFolderPathExists(lwjglNativesPath); - - if(!success) + + if (!success) { emitFailed("Failed to extract the lwjgl libs - error when creating required folders."); return; } - + QuaZip zip("lwjgl.zip"); - if(!zip.open(QuaZip::mdUnzip)) + if (!zip.open(QuaZip::mdUnzip)) { emitFailed("Failed to extract the lwjgl libs - not a valid archive."); return; } - + // and now we are going to access files inside it QuaZipFile file(&zip); - const QString jarNames[] = { "jinput.jar", "lwjgl_util.jar", "lwjgl.jar" }; - for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) + const QString jarNames[] = {"jinput.jar", "lwjgl_util.jar", "lwjgl.jar"}; + for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { - if(!file.open(QIODevice::ReadOnly)) + if (!file.open(QIODevice::ReadOnly)) { zip.close(); emitFailed("Failed to extract the lwjgl libs - error while reading archive."); @@ -141,7 +147,7 @@ void LegacyUpdate::extractLwjgl() } QuaZipFileInfo info; QString name = file.getActualFileName(); - if(name.endsWith('/')) + if (name.endsWith('/')) { file.close(); continue; @@ -156,25 +162,25 @@ void LegacyUpdate::extractLwjgl() } } // Not found? look for the natives - if(destFileName.isEmpty()) + if (destFileName.isEmpty()) { #ifdef Q_OS_WIN32 QString nativesDir = "windows"; #else - #ifdef Q_OS_MAC +#ifdef Q_OS_MAC QString nativesDir = "macosx"; - #else +#else QString nativesDir = "linux"; - #endif +#endif #endif if (name.contains(nativesDir)) { int lastSlash = name.lastIndexOf('/'); int lastBackSlash = name.lastIndexOf('\\'); - if(lastSlash != -1) - name = name.mid(lastSlash+1); - else if(lastBackSlash != -1) - name = name.mid(lastBackSlash+1); + if (lastSlash != -1) + name = name.mid(lastSlash + 1); + else if (lastBackSlash != -1) + name = name.mid(lastBackSlash + 1); destFileName = PathCombine(lwjglNativesPath, name); } } @@ -190,7 +196,7 @@ void LegacyUpdate::extractLwjgl() file.close(); // do not forget to close! } zip.close(); - m_reply.clear(); + m_reply.reset(); QFile doneFile(PathCombine(lwjglTargetPath, "done")); doneFile.open(QIODevice::WriteOnly); doneFile.write("done."); @@ -204,13 +210,13 @@ void LegacyUpdate::lwjglFailed() void LegacyUpdate::jarStart() { - LegacyInstance * inst = (LegacyInstance *) m_inst; - if(!inst->shouldUpdate() || inst->shouldUseCustomBaseJar()) + LegacyInstance *inst = (LegacyInstance *)m_inst; + if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar()) { ModTheJar(); return; } - + setStatus("Checking for jar updates..."); // Make directories QDir binDir(inst->binDir()); @@ -226,13 +232,13 @@ void LegacyUpdate::jarStart() QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); QString intended_version_id = inst->intendedVersionId(); urlstr += intended_version_id + "/" + intended_version_id + ".jar"; - + auto dljob = new DownloadJob("Minecraft.jar for version " + intended_version_id); dljob->addFileDownload(QUrl(urlstr), inst->defaultBaseJar()); legacyDownloadJob.reset(dljob); connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); - connect(dljob, SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); + connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); legacyDownloadJob->start(); } @@ -248,34 +254,36 @@ void LegacyUpdate::jarFailed() emitFailed("Failed to download the minecraft jar. Try again later."); } -bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& contained, MetainfAction metainf ) +bool LegacyUpdate::MergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, + MetainfAction metainf) { setStatus("Installing mods - Adding " + from.fileName()); - + QuaZip modZip(from.filePath()); modZip.open(QuaZip::mdUnzip); - + QuaZipFile fileInsideMod(&modZip); - QuaZipFile zipOutFile( into ); - for(bool more=modZip.goToFirstFile(); more; more=modZip.goToNextFile()) + QuaZipFile zipOutFile(into); + for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile()) { QString filename = modZip.getCurrentFileName(); - if(filename.contains("META-INF") && metainf == LegacyUpdate::IgnoreMetainf) + if (filename.contains("META-INF") && metainf == LegacyUpdate::IgnoreMetainf) { - qDebug() << "Skipping META-INF " << filename << " from " << from.fileName(); + QLOG_INFO() << "Skipping META-INF " << filename << " from " << from.fileName(); continue; } - if(contained.contains(filename)) + if (contained.contains(filename)) { - qDebug() << "Skipping already contained file " << filename << " from " << from.fileName(); + QLOG_INFO() << "Skipping already contained file " << filename << " from " + << from.fileName(); continue; } contained.insert(filename); - qDebug() << "Adding file " << filename << " from " << from.fileName(); - - if(!fileInsideMod.open(QIODevice::ReadOnly)) + QLOG_INFO() << "Adding file " << filename << " from " << from.fileName(); + + if (!fileInsideMod.open(QIODevice::ReadOnly)) { - qDebug() << "Failed to open " << filename << " from " << from.fileName(); + QLOG_ERROR() << "Failed to open " << filename << " from " << from.fileName(); return false; } /* @@ -286,17 +294,17 @@ bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& /* info_out.externalAttr = old_info.externalAttr; */ - if(!zipOutFile.open(QIODevice::WriteOnly, info_out)) + if (!zipOutFile.open(QIODevice::WriteOnly, info_out)) { - qDebug() << "Failed to open " << filename << " in the jar"; + QLOG_ERROR() << "Failed to open " << filename << " in the jar"; fileInsideMod.close(); return false; } - if(!JlCompress::copyData(fileInsideMod, zipOutFile)) + if (!JlCompress::copyData(fileInsideMod, zipOutFile)) { zipOutFile.close(); fileInsideMod.close(); - qDebug() << "Failed to copy data of " << filename << " into the jar"; + QLOG_ERROR() << "Failed to copy data of " << filename << " into the jar"; return false; } zipOutFile.close(); @@ -307,34 +315,34 @@ bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& void LegacyUpdate::ModTheJar() { - LegacyInstance * inst = (LegacyInstance *) m_inst; - - if(!inst->shouldRebuild()) + LegacyInstance *inst = (LegacyInstance *)m_inst; + + if (!inst->shouldRebuild()) { emitSucceeded(); return; } - + // Get the mod list auto modList = inst->jarModList(); - - QFileInfo runnableJar (inst->runnableJar()); - QFileInfo baseJar (inst->baseJar()); + + QFileInfo runnableJar(inst->runnableJar()); + QFileInfo baseJar(inst->baseJar()); bool base_is_custom = inst->shouldUseCustomBaseJar(); - + // Nothing to do if there are no jar mods to install, no backup and just the mc jar - if(base_is_custom) + if (base_is_custom) { // yes, this can happen if the instance only has the runnable jar and not the base jar // it *could* be assumed that such an instance is vanilla, but that wouldn't be safe // because that's not something mmc4 guarantees - if(runnableJar.isFile() && !baseJar.exists() && modList->empty()) + if (runnableJar.isFile() && !baseJar.exists() && modList->empty()) { inst->setShouldRebuild(false); emitSucceeded(); return; } - + setStatus("Installing mods - backing up minecraft.jar..."); if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath())) { @@ -342,24 +350,24 @@ void LegacyUpdate::ModTheJar() return; } } - + if (!baseJar.exists()) { emitFailed("The base jar " + baseJar.filePath() + " does not exist"); return; } - + if (runnableJar.exists() && !QFile::remove(runnableJar.filePath())) { emitFailed("Failed to delete old minecraft.jar"); return; } - - //TaskStep(); // STEP 1 + + // TaskStep(); // STEP 1 setStatus("Installing mods - Opening minecraft.jar"); QuaZip zipOut(runnableJar.filePath()); - if(!zipOut.open(QuaZip::mdCreate)) + if (!zipOut.open(QuaZip::mdCreate)) { QFile::remove(runnableJar.filePath()); emitFailed("Failed to open the minecraft.jar for modding"); @@ -376,7 +384,7 @@ void LegacyUpdate::ModTheJar() auto &mod = modList->operator[](i); if (mod.type() == Mod::MOD_ZIPFILE) { - if(!MergeZipFiles(&zipOut, mod.filename(), addedFiles, LegacyUpdate::KeepMetainf)) + if (!MergeZipFiles(&zipOut, mod.filename(), addedFiles, LegacyUpdate::KeepMetainf)) { zipOut.close(); QFile::remove(runnableJar.filePath()); @@ -387,7 +395,8 @@ void LegacyUpdate::ModTheJar() else if (mod.type() == Mod::MOD_SINGLEFILE) { auto filename = mod.filename(); - if(!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) + if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), + filename.fileName())) { zipOut.close(); QFile::remove(runnableJar.filePath()); @@ -395,7 +404,8 @@ void LegacyUpdate::ModTheJar() return; } addedFiles.insert(filename.fileName()); - qDebug() << "Adding file " << filename.fileName() << " from " << filename.absoluteFilePath(); + QLOG_INFO() << "Adding file " << filename.fileName() << " from " + << filename.absoluteFilePath(); } else if (mod.type() == Mod::MOD_FOLDER) { @@ -404,35 +414,36 @@ void LegacyUpdate::ModTheJar() QDir dir(what_to_zip); dir.cdUp(); QString parent_dir = dir.absolutePath(); - if(!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, true, addedFiles)) + if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, true, addedFiles)) { zipOut.close(); QFile::remove(runnableJar.filePath()); emitFailed("Failed to add " + filename.fileName() + " to the jar"); return; } - qDebug() << "Adding folder " << filename.fileName() << " from " << filename.absoluteFilePath(); + QLOG_INFO() << "Adding folder " << filename.fileName() << " from " + << filename.absoluteFilePath(); } } - - if(!MergeZipFiles(&zipOut, baseJar, addedFiles, LegacyUpdate::IgnoreMetainf)) + + if (!MergeZipFiles(&zipOut, baseJar, addedFiles, LegacyUpdate::IgnoreMetainf)) { zipOut.close(); QFile::remove(runnableJar.filePath()); emitFailed("Failed to insert minecraft.jar contents."); return; } - + // Recompress the jar zipOut.close(); - if(zipOut.getZipError()!=0) + if (zipOut.getZipError() != 0) { QFile::remove(runnableJar.filePath()); emitFailed("Failed to finalize minecraft.jar!"); return; - } + } inst->setShouldRebuild(false); - //inst->UpdateVersion(true); + // inst->UpdateVersion(true); emitSucceeded(); return; } \ No newline at end of file diff --git a/logic/LegacyUpdate.h b/logic/LegacyUpdate.h index 05c00495..e84ec56a 100644 --- a/logic/LegacyUpdate.h +++ b/logic/LegacyUpdate.h @@ -56,7 +56,7 @@ private: bool MergeZipFiles(QuaZip *into, QFileInfo from, QSet& contained, MetainfAction metainf); private: - QSharedPointer m_reply; + std::shared_ptr m_reply; // target version, determined during this task // MinecraftVersion *targetVersion; diff --git a/logic/Mod.cpp b/logic/Mod.cpp index 38faa760..75e0a3a9 100644 --- a/logic/Mod.cpp +++ b/logic/Mod.cpp @@ -20,14 +20,13 @@ #include #include #include -#include #include #include #include "Mod.h" #include #include - +#include Mod::Mod( const QFileInfo& file ) { @@ -134,8 +133,8 @@ void Mod::ReadMCModInfo(QByteArray contents) int version = val.toDouble(); if(version != 2) { - qDebug() << "BAD stuff happened to mod json:"; - qDebug() << contents; + QLOG_ERROR() << "BAD stuff happened to mod json:"; + QLOG_ERROR() << contents; return; } auto arrVal = jsonDoc.object().value("modlist"); diff --git a/logic/ModList.cpp b/logic/ModList.cpp index 84511e4c..a600afff 100644 --- a/logic/ModList.cpp +++ b/logic/ModList.cpp @@ -19,9 +19,9 @@ #include #include #include -#include #include #include +#include ModList::ModList ( const QString& dir, const QString& list_file ) : QAbstractListModel(), m_dir(dir), m_list_file(list_file) @@ -39,18 +39,18 @@ void ModList::startWatching() { is_watching = m_watcher->addPath(m_dir.absolutePath()); if(is_watching) - qDebug() << "Started watching " << m_dir.absolutePath(); + QLOG_INFO() << "Started watching " << m_dir.absolutePath(); else - qDebug() << "Failed to start watching " << m_dir.absolutePath(); + QLOG_INFO() << "Failed to start watching " << m_dir.absolutePath(); } void ModList::stopWatching() { is_watching = !m_watcher->removePath(m_dir.absolutePath()); if(!is_watching) - qDebug() << "Stopped watching " << m_dir.absolutePath(); + QLOG_INFO() << "Stopped watching " << m_dir.absolutePath(); else - qDebug() << "Failed to stop watching " << m_dir.absolutePath(); + QLOG_INFO() << "Failed to stop watching " << m_dir.absolutePath(); } @@ -436,7 +436,7 @@ bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int r row = rowCount(); if (column == -1) column = 0; - qDebug() << "Drop row: " << row << " column: " << column; + QLOG_INFO() << "Drop row: " << row << " column: " << column; // files dropped from outside? if(data->hasUrls()) @@ -452,7 +452,7 @@ bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int r continue; QString filename = url.toLocalFile(); installMod(filename, row); - qDebug() << "installing: " << filename; + QLOG_INFO() << "installing: " << filename; } if(was_watching) startWatching(); @@ -466,7 +466,7 @@ bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int r return false; QString remoteId = list[0]; int remoteIndex = list[1].toInt(); - qDebug() << "move: " << sourcestr; + QLOG_INFO() << "move: " << sourcestr; // no moving of things between two lists if(remoteId != m_list_id) return false; diff --git a/logic/OneSixAssets.cpp b/logic/OneSixAssets.cpp index ca7a5534..6aa0a207 100644 --- a/logic/OneSixAssets.cpp +++ b/logic/OneSixAssets.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include "OneSixAssets.h" #include "net/DownloadJob.h" @@ -21,6 +21,7 @@ class ThreadedDeleter : public QThread public: void run() { + QLOG_INFO() << "Cleaning up assets folder..."; QDirIterator iter ( m_base, QDirIterator::Subdirectories ); int base_length = m_base.length(); while ( iter.hasNext() ) @@ -34,12 +35,12 @@ public: trimmedf.remove ( 0, base_length + 1 ); if ( m_whitelist.contains ( trimmedf ) ) { - // qDebug() << trimmedf << " gets to live"; + QLOG_TRACE() << trimmedf << " gets to live"; } else { // DO NOT TOLERATE JUNK - // qDebug() << trimmedf << " dies"; + QLOG_TRACE() << trimmedf << " dies"; QFile f ( filename ); f.remove(); } @@ -67,13 +68,15 @@ void OneSixAssets::fetchXMLFinished() nuke_whitelist.clear(); auto firstJob = index_job->first(); - QByteArray ba = firstJob.dynamicCast()->m_data; + QByteArray ba = std::dynamic_pointer_cast(firstJob)->m_data; QString xmlErrorMsg; QDomDocument doc; if ( !doc.setContent ( ba, false, &xmlErrorMsg ) ) { - qDebug() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" << xmlErrorMsg << ba; + QLOG_ERROR() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" << xmlErrorMsg << ba; + emit failed(); + return; } //QRegExp etag_match(".*([a-f0-9]{32}).*"); QDomNodeList contents = doc.elementsByTagName ( "Contents" ); diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 6e39b5b5..c5d546a3 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -9,6 +9,7 @@ #include #include #include +#include OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj, QObject *parent) @@ -102,7 +103,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(LoginResponse response) for (auto lib : libs_to_extract) { QString path = "libraries/" + lib->storagePath(); - qDebug() << "Will extract " << path.toLocal8Bit(); + QLOG_INFO() << "Will extract " << path.toLocal8Bit(); if (JlCompress::extractWithExceptions(path, natives_dir_raw, lib->extract_excludes) .isEmpty()) { @@ -156,7 +157,7 @@ void OneSixInstance::cleanupAfterRun() dir.removeRecursively(); } -QSharedPointer OneSixInstance::loaderModList() +std::shared_ptr OneSixInstance::loaderModList() { I_D(OneSixInstance); if (!d->loader_mod_list) @@ -168,7 +169,7 @@ QSharedPointer OneSixInstance::loaderModList() return d->loader_mod_list; } -QSharedPointer OneSixInstance::resourcePackList() +std::shared_ptr OneSixInstance::resourcePackList() { I_D(OneSixInstance); if (!d->resource_pack_list) @@ -271,7 +272,7 @@ bool OneSixInstance::reloadFullVersion() return false; } -QSharedPointer OneSixInstance::getFullVersion() +std::shared_ptr OneSixInstance::getFullVersion() { I_D(OneSixInstance); return d->version; diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 33091188..8f5c22e6 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -14,8 +14,8 @@ public: ////// Mod Lists ////// - QSharedPointer loaderModList(); - QSharedPointer resourcePackList(); + std::shared_ptr loaderModList(); + std::shared_ptr resourcePackList(); ////// Directories ////// QString resourcePacksDir() const; @@ -40,7 +40,7 @@ public: /// reload the full version json file. return true on success! bool reloadFullVersion(); /// get the current full version info - QSharedPointer getFullVersion(); + std::shared_ptr getFullVersion(); /// revert the current custom version back to base bool revertCustomVersion(); /// customize the current base version diff --git a/logic/OneSixInstance_p.h b/logic/OneSixInstance_p.h index 7b1ca82e..06737b6f 100644 --- a/logic/OneSixInstance_p.h +++ b/logic/OneSixInstance_p.h @@ -7,7 +7,7 @@ struct OneSixInstancePrivate: public BaseInstancePrivate { - QSharedPointer version; - QSharedPointer loader_mod_list; - QSharedPointer resource_pack_list; + std::shared_ptr version; + std::shared_ptr loader_mod_list; + std::shared_ptr resource_pack_list; }; \ No newline at end of file diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index 63d42646..0643abe3 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -72,7 +72,7 @@ void OneSixLibrary::addNative(OpSys os, QString suffix) m_is_native = true; m_native_suffixes[os] = suffix; } -void OneSixLibrary::setRules(QList> rules) +void OneSixLibrary::setRules(QList> rules) { m_rules = rules; } diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index 2a16d8e1..a8bcc364 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "OpSys.h" @@ -14,7 +14,7 @@ private: // basic values used internally (so far) QString m_name; QString m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/"; - QList > m_rules; + QList > m_rules; // custom values /// absolute URL. takes precedence over m_download_path, if defined @@ -83,7 +83,7 @@ public: /// Attach a name suffix to the specified OS native void addNative(OpSys os, QString suffix); /// Set the load rules - void setRules(QList > rules); + void setRules(QList > rules); /// Returns true if the library should be loaded (or extracted, in case of natives) bool isActive(); diff --git a/logic/OneSixRule.cpp b/logic/OneSixRule.cpp index 545cd641..cb64c9ba 100644 --- a/logic/OneSixRule.cpp +++ b/logic/OneSixRule.cpp @@ -2,9 +2,9 @@ #include #include -QList> rulesFromJsonV4(QJsonObject &objectWithRules) +QList> rulesFromJsonV4(QJsonObject &objectWithRules) { - QList> rules; + QList> rules; auto rulesVal = objectWithRules.value("rules"); if (!rulesVal.isArray()) return rules; @@ -12,7 +12,7 @@ QList> rulesFromJsonV4(QJsonObject &objectWithRules) QJsonArray ruleList = rulesVal.toArray(); for (auto ruleVal : ruleList) { - QSharedPointer rule; + std::shared_ptr rule; if (!ruleVal.isObject()) continue; auto ruleObj = ruleVal.toObject(); diff --git a/logic/OneSixRule.h b/logic/OneSixRule.h index 23d20ff4..6be01f1b 100644 --- a/logic/OneSixRule.h +++ b/logic/OneSixRule.h @@ -11,7 +11,7 @@ enum RuleAction }; RuleAction RuleAction_fromString(QString); -QList> rulesFromJsonV4(QJsonObject &objectWithRules); +QList> rulesFromJsonV4(QJsonObject &objectWithRules); class Rule { @@ -48,9 +48,9 @@ protected: : Rule(result), m_system(system), m_version_regexp(version_regexp) {} public: virtual QJsonObject toJson(); - static QSharedPointer create(RuleAction result, OpSys system, QString version_regexp) + static std::shared_ptr create(RuleAction result, OpSys system, QString version_regexp) { - return QSharedPointer (new OsRule(result, system, version_regexp)); + return std::shared_ptr (new OsRule(result, system, version_regexp)); } }; @@ -65,8 +65,8 @@ protected: : Rule(result) {} public: virtual QJsonObject toJson(); - static QSharedPointer create(RuleAction result) + static std::shared_ptr create(RuleAction result) { - return QSharedPointer (new ImplicitRule(result)); + return std::shared_ptr (new ImplicitRule(result)); } }; diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index 41d8f599..008995ae 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -22,8 +22,6 @@ #include #include -#include - #include "BaseInstance.h" #include "lists/MinecraftVersionList.h" #include "OneSixVersion.h" @@ -49,8 +47,8 @@ void OneSixUpdate::executeTask() } // Get a pointer to the version object that corresponds to the instance's version. - targetVersion = - MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast(); + targetVersion = std::dynamic_pointer_cast( + MMC->minecraftlist()->findVersion(intendedVersion)); if (targetVersion == nullptr) { // don't do anything if it was invalid @@ -77,10 +75,9 @@ void OneSixUpdate::versionFileStart() auto job = new DownloadJob("Version index"); job->addByteArrayDownload(QUrl(urlstr)); specificVersionDownloadJob.reset(job); - connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), - SLOT(versionFileFinished())); - connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); - connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64, qint64)), + connect(specificVersionDownloadJob.get(), SIGNAL(succeeded()), SLOT(versionFileFinished())); + connect(specificVersionDownloadJob.get(), SIGNAL(failed()), SLOT(versionFileFailed())); + connect(specificVersionDownloadJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); specificVersionDownloadJob->start(); } @@ -103,7 +100,7 @@ void OneSixUpdate::versionFileFinished() emitFailed("Can't open " + version1 + " for writing."); return; } - auto data = DlJob.dynamicCast()->m_data; + auto data = std::dynamic_pointer_cast(DlJob)->m_data; qint64 actual = 0; if ((actual = vfile1.write(data)) != data.size()) { @@ -149,7 +146,7 @@ void OneSixUpdate::jarlibStart() return; } - QSharedPointer version = inst->getFullVersion(); + std::shared_ptr version = inst->getFullVersion(); // download the right jar, save it in versions/$version/$version.jar QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); @@ -171,15 +168,15 @@ void OneSixUpdate::jarlibStart() auto entry = metacache->resolveEntry("libraries", lib->storagePath()); if (entry->stale) { - if(lib->hint() == "forge-pack-xz") + if (lib->hint() == "forge-pack-xz") jarlibDownloadJob->addForgeXzDownload(download_path, entry); else jarlibDownloadJob->addCacheDownload(download_path, entry); } } - connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished())); - connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed())); - connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64, qint64)), + connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(jarlibFinished())); + connect(jarlibDownloadJob.get(), SIGNAL(failed()), SLOT(jarlibFailed())); + connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); jarlibDownloadJob->start(); diff --git a/logic/OneSixUpdate.h b/logic/OneSixUpdate.h index 7314a6d1..ed8dcbcd 100644 --- a/logic/OneSixUpdate.h +++ b/logic/OneSixUpdate.h @@ -47,7 +47,7 @@ private: DownloadJobPtr jarlibDownloadJob; // target version, determined during this task - QSharedPointer targetVersion; + std::shared_ptr targetVersion; }; diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 64a47562..f7efedf9 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -2,8 +2,8 @@ #include "OneSixLibrary.h" #include "OneSixRule.h" -QSharedPointer fromJsonV4(QJsonObject root, - QSharedPointer fullVersion) +std::shared_ptr fromJsonV4(QJsonObject root, + std::shared_ptr fullVersion) { fullVersion->id = root.value("id").toString(); @@ -64,7 +64,7 @@ QSharedPointer fromJsonV4(QJsonObject root, auto nameVal = libObj.value("name"); if (!nameVal.isString()) continue; - QSharedPointer library(new OneSixLibrary(nameVal.toString())); + std::shared_ptr library(new OneSixLibrary(nameVal.toString())); auto urlVal = libObj.value("url"); if (urlVal.isString()) @@ -129,9 +129,9 @@ QSharedPointer fromJsonV4(QJsonObject root, return fullVersion; } -QSharedPointer OneSixVersion::fromJson(QJsonObject root) +std::shared_ptr OneSixVersion::fromJson(QJsonObject root) { - QSharedPointer readVersion(new OneSixVersion()); + std::shared_ptr readVersion(new OneSixVersion()); int launcher_ver = readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble(); @@ -140,16 +140,16 @@ QSharedPointer OneSixVersion::fromJson(QJsonObject root) return fromJsonV4(root, readVersion); else { - return QSharedPointer(); + return std::shared_ptr(); } } -QSharedPointer OneSixVersion::fromFile(QString filepath) +std::shared_ptr OneSixVersion::fromFile(QString filepath) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { - return QSharedPointer(); + return std::shared_ptr(); } auto data = file.readAll(); @@ -158,12 +158,12 @@ QSharedPointer OneSixVersion::fromFile(QString filepath) if (jsonError.error != QJsonParseError::NoError) { - return QSharedPointer(); + return std::shared_ptr(); } if (!jsonDoc.isObject()) { - return QSharedPointer(); + return std::shared_ptr(); } QJsonObject root = jsonDoc.object(); auto version = fromJson(root); @@ -202,9 +202,9 @@ bool OneSixVersion::toOriginalFile() return file.commit(); } -QList> OneSixVersion::getActiveNormalLibs() +QList> OneSixVersion::getActiveNormalLibs() { - QList> output; + QList> output; for (auto lib : libraries) { if (lib->isActive() && !lib->isNative()) @@ -215,9 +215,9 @@ QList> OneSixVersion::getActiveNormalLibs() return output; } -QList> OneSixVersion::getActiveNativeLibs() +QList> OneSixVersion::getActiveNativeLibs() { - QList> output; + QList> output; for (auto lib : libraries) { if (lib->isActive() && lib->isNative()) diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 69268ecf..3529138c 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -1,5 +1,7 @@ #pragma once #include +#include + class OneSixLibrary; class OneSixVersion : public QAbstractListModel @@ -16,12 +18,12 @@ public: // serialization/deserialization public: bool toOriginalFile(); - static QSharedPointer fromJson(QJsonObject root); - static QSharedPointer fromFile(QString filepath); + static std::shared_ptr fromJson(QJsonObject root); + static std::shared_ptr fromFile(QString filepath); public: - QList> getActiveNormalLibs(); - QList> getActiveNativeLibs(); + QList> getActiveNormalLibs(); + QList> getActiveNativeLibs(); // called when something starts/stops messing with the object // FIXME: these are ugly in every possible way. void externalUpdateStart(); @@ -62,7 +64,7 @@ public: QString mainClass; /// the list of libs - both active and inactive, native and java - QList> libraries; + QList> libraries; /* FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index ac1a4ef5..9b698135 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -18,11 +18,11 @@ #include "MultiMC.h" #include - #include - #include +#include + #define JSON_URL "http://files.minecraftforge.net/minecraftforge/json" ForgeVersionList::ForgeVersionList(QObject *parent) : BaseVersionList(parent) @@ -62,7 +62,7 @@ QVariant ForgeVersionList::data(const QModelIndex &index, int role) const if (index.row() > count()) return QVariant(); - auto version = m_vlist[index.row()].dynamicCast(); + auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); switch (role) { case Qt::DisplayRole: @@ -164,9 +164,9 @@ void ForgeListLoadTask::executeTask() auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json"); job->addCacheDownload(QUrl(JSON_URL), forgeListEntry); listJob.reset(job); - connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded())); - connect(listJob.data(), SIGNAL(failed()), SLOT(list_failed())); - connect(listJob.data(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); + connect(listJob.get(), SIGNAL(succeeded()), SLOT(list_downloaded())); + connect(listJob.get(), SIGNAL(failed()), SLOT(list_failed())); + connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); listJob->start(); } @@ -176,10 +176,10 @@ void ForgeListLoadTask::list_failed() auto reply = DlJob->m_reply; if(reply) { - qDebug() << "Getting forge version list failed: " << reply->errorString(); + QLOG_ERROR() << "Getting forge version list failed: " << reply->errorString(); } else - qDebug() << "Getting forge version list failed for reasons unknown."; + QLOG_ERROR() << "Getting forge version list failed for reasons unknown."; } void ForgeListLoadTask::list_downloaded() @@ -187,7 +187,7 @@ void ForgeListLoadTask::list_downloaded() QByteArray data; { auto DlJob = listJob->first(); - auto filename = DlJob.dynamicCast()->m_target_path; + auto filename = std::dynamic_pointer_cast(DlJob)->m_target_path; QFile listFile(filename); if(!listFile.open(QIODevice::ReadOnly)) return; @@ -272,7 +272,7 @@ void ForgeListLoadTask::list_downloaded() if (valid) { // Now, we construct the version object and add it to the list. - QSharedPointer fVersion(new ForgeVersion()); + std::shared_ptr fVersion(new ForgeVersion()); fVersion->universal_url = url; fVersion->changelog_url = changelog_url; fVersion->installer_url = installer_url; diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h index 4abfe9ce..56a207c8 100644 --- a/logic/lists/ForgeVersionList.h +++ b/logic/lists/ForgeVersionList.h @@ -26,7 +26,7 @@ #include "logic/net/DownloadJob.h" class ForgeVersion; -typedef QSharedPointer ForgeVersionPtr; +typedef std::shared_ptr ForgeVersionPtr; struct ForgeVersion : public BaseVersion { diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index b930f781..ac054267 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -3,7 +3,7 @@ * 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 @@ -29,13 +29,13 @@ #include "logic/lists/IconList.h" #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" +#include const static int GROUP_FILE_FORMAT_VERSION = 1; -InstanceList::InstanceList(const QString &instDir, QObject *parent) : - QAbstractListModel ( parent ), m_instDir("instances") +InstanceList::InstanceList(const QString &instDir, QObject *parent) + : QAbstractListModel(parent), m_instDir("instances") { - } InstanceList::~InstanceList() @@ -43,32 +43,32 @@ InstanceList::~InstanceList() saveGroupList(); } -int InstanceList::rowCount ( const QModelIndex& parent ) const +int InstanceList::rowCount(const QModelIndex &parent) const { - Q_UNUSED ( parent ); + Q_UNUSED(parent); return m_instances.count(); } -QModelIndex InstanceList::index ( int row, int column, const QModelIndex& parent ) const +QModelIndex InstanceList::index(int row, int column, const QModelIndex &parent) const { - Q_UNUSED ( parent ); - if ( row < 0 || row >= m_instances.size() ) + Q_UNUSED(parent); + if (row < 0 || row >= m_instances.size()) return QModelIndex(); - return createIndex ( row, column, ( void* ) m_instances.at ( row ).data() ); + return createIndex(row, column, (void *)m_instances.at(row).get()); } -QVariant InstanceList::data ( const QModelIndex& index, int role ) const +QVariant InstanceList::data(const QModelIndex &index, int role) const { - if ( !index.isValid() ) + if (!index.isValid()) { return QVariant(); } - BaseInstance *pdata = static_cast ( index.internalPointer() ); - switch ( role ) + BaseInstance *pdata = static_cast(index.internalPointer()); + switch (role) { case InstancePointerRole: { - QVariant v = qVariantFromValue((void *) pdata); + QVariant v = qVariantFromValue((void *)pdata); return v; } case Qt::DisplayRole: @@ -96,12 +96,12 @@ QVariant InstanceList::data ( const QModelIndex& index, int role ) const return QVariant(); } -Qt::ItemFlags InstanceList::flags ( const QModelIndex& index ) const +Qt::ItemFlags InstanceList::flags(const QModelIndex &index) const { Qt::ItemFlags f; - if ( index.isValid() ) + if (index.isValid()) { - f |= ( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); + f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable); } return f; } @@ -116,23 +116,23 @@ void InstanceList::saveGroupList() { QString groupFileName = m_instDir + "/instgroups.json"; QFile groupFile(groupFileName); - + // if you can't open the file, fail - if (!groupFile.open(QIODevice::WriteOnly| QIODevice::Truncate)) + if (!groupFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { // An error occurred. Ignore it. - qDebug("Failed to read instance group file."); + QLOG_ERROR() << "Failed to read instance group file."; return; } QTextStream out(&groupFile); - QMap > groupMap; - for(auto instance: m_instances) + QMap> groupMap; + for (auto instance : m_instances) { QString id = instance->id(); QString group = instance->group(); - if(group.isEmpty()) + if (group.isEmpty()) continue; - if(!groupMap.count(group)) + if (!groupMap.count(group)) { QSet set; set.insert(id); @@ -145,109 +145,114 @@ void InstanceList::saveGroupList() } } QJsonObject toplevel; - toplevel.insert("formatVersion",QJsonValue(QString("1"))); + toplevel.insert("formatVersion", QJsonValue(QString("1"))); QJsonObject groupsArr; - for(auto iter = groupMap.begin(); iter != groupMap.end(); iter++) + for (auto iter = groupMap.begin(); iter != groupMap.end(); iter++) { auto list = iter.value(); auto name = iter.key(); QJsonObject groupObj; QJsonArray instanceArr; - groupObj.insert("hidden",QJsonValue(QString("false"))); - for(auto item: list) + groupObj.insert("hidden", QJsonValue(QString("false"))); + for (auto item : list) { instanceArr.append(QJsonValue(item)); } - groupObj.insert("instances",instanceArr); - groupsArr.insert(name,groupObj); + groupObj.insert("instances", instanceArr); + groupsArr.insert(name, groupObj); } - toplevel.insert("groups",groupsArr); + toplevel.insert("groups", groupsArr); QJsonDocument doc(toplevel); groupFile.write(doc.toJson()); groupFile.close(); } -void InstanceList::loadGroupList(QMap & groupMap) +void InstanceList::loadGroupList(QMap &groupMap) { QString groupFileName = m_instDir + "/instgroups.json"; - + // if there's no group file, fail - if(!QFileInfo(groupFileName).exists()) + if (!QFileInfo(groupFileName).exists()) return; - + QFile groupFile(groupFileName); - + // if you can't open the file, fail if (!groupFile.open(QIODevice::ReadOnly)) { // An error occurred. Ignore it. - qDebug("Failed to read instance group file."); + QLOG_ERROR() << "Failed to read instance group file."; return; } - + QTextStream in(&groupFile); QString jsonStr = in.readAll(); groupFile.close(); - + QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &error); - + // if the json was bad, fail if (error.error != QJsonParseError::NoError) { - qWarning(QString("Failed to parse instance group file: %1 at offset %2"). - arg(error.errorString(), QString::number(error.offset)).toUtf8()); + QLOG_ERROR() << QString("Failed to parse instance group file: %1 at offset %2") + .arg(error.errorString(), QString::number(error.offset)) + .toUtf8(); return; } - + // if the root of the json wasn't an object, fail if (!jsonDoc.isObject()) { qWarning("Invalid group file. Root entry should be an object."); return; } - + QJsonObject rootObj = jsonDoc.object(); - + // Make sure the format version matches, otherwise fail. if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION) return; - + // Get the groups. if it's not an object, fail if (!rootObj.value("groups").isObject()) { qWarning("Invalid group list JSON: 'groups' should be an object."); return; } - + // Iterate through all the groups. QJsonObject groupMapping = rootObj.value("groups").toObject(); for (QJsonObject::iterator iter = groupMapping.begin(); iter != groupMapping.end(); iter++) { QString groupName = iter.key(); - + // If not an object, complain and skip to the next one. if (!iter.value().isObject()) { qWarning(QString("Group '%1' in the group list should " - "be an object.").arg(groupName).toUtf8()); + "be an object.") + .arg(groupName) + .toUtf8()); continue; } - + QJsonObject groupObj = iter.value().toObject(); if (!groupObj.value("instances").isArray()) { qWarning(QString("Group '%1' in the group list is invalid. " - "It should contain an array " - "called 'instances'.").arg(groupName).toUtf8()); + "It should contain an array " + "called 'instances'.") + .arg(groupName) + .toUtf8()); continue; } - + // Iterate through the list of instances in the group. QJsonArray instancesArray = groupObj.value("instances").toArray(); - - for (QJsonArray::iterator iter2 = instancesArray.begin(); - iter2 != instancesArray.end(); iter2++) + + for (QJsonArray::iterator iter2 = instancesArray.begin(); iter2 != instancesArray.end(); + iter2++) { groupMap[(*iter2).toString()] = groupName; } @@ -259,9 +264,9 @@ InstanceList::InstListError InstanceList::loadList() // load the instance groups QMap groupMap; loadGroupList(groupMap); - + beginResetModel(); - + m_instances.clear(); QDir dir(m_instDir); QDirIterator iter(dir); @@ -270,53 +275,55 @@ InstanceList::InstListError InstanceList::loadList() QString subDir = iter.next(); if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists()) continue; - + BaseInstance *instPtr = NULL; auto &loader = InstanceFactory::get(); auto error = loader.loadInstance(instPtr, subDir); - - switch(error) + + switch (error) { - case InstanceFactory::NoLoadError: - break; - case InstanceFactory::NotAnInstance: - break; + case InstanceFactory::NoLoadError: + break; + case InstanceFactory::NotAnInstance: + break; } - - if (error != InstanceFactory::NoLoadError && - error != InstanceFactory::NotAnInstance) + + if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance) { - QString errorMsg = QString("Failed to load instance %1: "). - arg(QFileInfo(subDir).baseName()).toUtf8(); - + QString errorMsg = QString("Failed to load instance %1: ") + .arg(QFileInfo(subDir).baseName()) + .toUtf8(); + switch (error) { default: - errorMsg += QString("Unknown instance loader error %1"). - arg(error); + errorMsg += QString("Unknown instance loader error %1").arg(error); break; } - qDebug(errorMsg.toUtf8()); + QLOG_ERROR() << errorMsg.toUtf8(); } else if (!instPtr) { - qDebug(QString("Error loading instance %1. Instance loader returned null."). - arg(QFileInfo(subDir).baseName()).toUtf8()); + QLOG_ERROR() << QString("Error loading instance %1. Instance loader returned null.") + .arg(QFileInfo(subDir).baseName()) + .toUtf8(); } else { - QSharedPointer inst(instPtr); + std::shared_ptr inst(instPtr); auto iter = groupMap.find(inst->id()); - if(iter != groupMap.end()) + if (iter != groupMap.end()) { inst->setGroupInitial((*iter)); } - qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); + QLOG_INFO() << QString("Loaded instance %1").arg(inst->name()).toUtf8(); inst->setParent(this); m_instances.append(inst); - connect(instPtr, SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*))); - connect(instPtr, SIGNAL(groupChanged()),this, SLOT(groupChanged())); - connect(instPtr, SIGNAL(nuked(BaseInstance*)), this, SLOT(instanceNuked(BaseInstance*))); + connect(instPtr, SIGNAL(propertiesChanged(BaseInstance *)), this, + SLOT(propertiesChanged(BaseInstance *))); + connect(instPtr, SIGNAL(groupChanged()), this, SLOT(groupChanged())); + connect(instPtr, SIGNAL(nuked(BaseInstance *)), this, + SLOT(instanceNuked(BaseInstance *))); } } endResetModel(); @@ -332,7 +339,8 @@ void InstanceList::clear() m_instances.clear(); endResetModel(); emit dataIsInvalid(); -}; +} +; /// Add an instance. Triggers notifications, returns the new index int InstanceList::add(InstancePtr t) @@ -340,9 +348,10 @@ int InstanceList::add(InstancePtr t) beginInsertRows(QModelIndex(), m_instances.size(), m_instances.size()); m_instances.append(t); t->setParent(this); - connect(t.data(), SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*))); - connect(t.data(), SIGNAL(groupChanged()),this, SLOT(groupChanged())); - connect(t.data(), SIGNAL(nuked(BaseInstance*)), this, SLOT(instanceNuked(BaseInstance*))); + connect(t.get(), SIGNAL(propertiesChanged(BaseInstance *)), this, + SLOT(propertiesChanged(BaseInstance *))); + connect(t.get(), SIGNAL(groupChanged()), this, SLOT(groupChanged())); + connect(t.get(), SIGNAL(nuked(BaseInstance *)), this, SLOT(instanceNuked(BaseInstance *))); endInsertRows(); return count() - 1; } @@ -351,7 +360,7 @@ InstancePtr InstanceList::getInstanceById(QString instId) { QListIterator iter(m_instances); InstancePtr inst; - while(iter.hasNext()) + while (iter.hasNext()) { inst = iter.next(); if (inst->id() == instId) @@ -363,11 +372,11 @@ InstancePtr InstanceList::getInstanceById(QString instId) return iter.peekPrevious(); } -int InstanceList::getInstIndex ( BaseInstance* inst ) +int InstanceList::getInstIndex(BaseInstance *inst) { - for(int i = 0; i < m_instances.count(); i++) + for (int i = 0; i < m_instances.count(); i++) { - if(inst == m_instances[i].data()) + if (inst == m_instances[i].get()) { return i; } @@ -375,40 +384,39 @@ int InstanceList::getInstIndex ( BaseInstance* inst ) return -1; } - -void InstanceList::instanceNuked ( BaseInstance* inst ) +void InstanceList::instanceNuked(BaseInstance *inst) { int i = getInstIndex(inst); - if(i != -1) + if (i != -1) { - beginRemoveRows(QModelIndex(),i,i); + beginRemoveRows(QModelIndex(), i, i); m_instances.removeAt(i); endRemoveRows(); } } - -void InstanceList::propertiesChanged(BaseInstance * inst) +void InstanceList::propertiesChanged(BaseInstance *inst) { int i = getInstIndex(inst); - if(i != -1) + if (i != -1) { emit dataChanged(index(i), index(i)); } } -InstanceProxyModel::InstanceProxyModel ( QObject *parent ) - : KCategorizedSortFilterProxyModel ( parent ) +InstanceProxyModel::InstanceProxyModel(QObject *parent) + : KCategorizedSortFilterProxyModel(parent) { // disable since by default we are globally sorting by date: setCategorizedModel(true); } -bool InstanceProxyModel::subSortLessThan (const QModelIndex& left, const QModelIndex& right ) const +bool InstanceProxyModel::subSortLessThan(const QModelIndex &left, + const QModelIndex &right) const { - BaseInstance *pdataLeft = static_cast ( left.internalPointer() ); - BaseInstance *pdataRight = static_cast ( right.internalPointer() ); - //kDebug() << *pdataLeft << *pdataRight; + BaseInstance *pdataLeft = static_cast(left.internalPointer()); + BaseInstance *pdataRight = static_cast(right.internalPointer()); + // kDebug() << *pdataLeft << *pdataRight; return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0; - //return pdataLeft->name() < pdataRight->name(); + // return pdataLeft->name() < pdataRight->name(); } diff --git a/logic/lists/LwjglVersionList.cpp b/logic/lists/LwjglVersionList.cpp index b3e2dab4..6bf401ec 100644 --- a/logic/lists/LwjglVersionList.cpp +++ b/logic/lists/LwjglVersionList.cpp @@ -3,7 +3,7 @@ * 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 @@ -17,15 +17,14 @@ #include "MultiMC.h" #include - #include - #include +#include + #define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss" -LWJGLVersionList::LWJGLVersionList(QObject *parent) : - QAbstractListModel(parent) +LWJGLVersionList::LWJGLVersionList(QObject *parent) : QAbstractListModel(parent) { setLoading(false); } @@ -34,20 +33,20 @@ QVariant LWJGLVersionList::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); - + if (index.row() > count()) return QVariant(); - + const PtrLWJGLVersion version = at(index.row()); - + switch (role) { case Qt::DisplayRole: return version->name(); - + case Qt::ToolTipRole: return version->url(); - + default: return QVariant(); } @@ -59,10 +58,10 @@ QVariant LWJGLVersionList::headerData(int section, Qt::Orientation orientation, { case Qt::DisplayRole: return "Version"; - + case Qt::ToolTipRole: return "LWJGL version name."; - + default: return QVariant(); } @@ -81,7 +80,7 @@ bool LWJGLVersionList::isLoading() const void LWJGLVersionList::loadList() { Q_ASSERT_X(!m_loading, "loadList", "list is already loading (m_loading is true)"); - + setLoading(true); auto worker = MMC->qnam(); reply = worker->get(QNetworkRequest(QUrl(RSS_URL))); @@ -102,68 +101,68 @@ void LWJGLVersionList::netRequestComplete() if (reply->error() == QNetworkReply::NoError) { QRegExp lwjglRegex("lwjgl-(([0-9]\\.?)+)\\.zip"); - Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list", - "LWJGL regex is invalid"); - + Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list", "LWJGL regex is invalid"); + QDomDocument doc; - + QString xmlErrorMsg; int errorLine; if (!doc.setContent(reply->readAll(), false, &xmlErrorMsg, &errorLine)) { - failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + QString::number(errorLine)); + failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + + QString::number(errorLine)); setLoading(false); return; } - + QDomNodeList items = doc.elementsByTagName("item"); - + QList tempList; - + for (int i = 0; i < items.length(); i++) { Q_ASSERT_X(items.at(i).isElement(), "load LWJGL list", "XML element isn't an element... wat?"); - + QDomElement linkElement = getDomElementByTagName(items.at(i).toElement(), "link"); if (linkElement.isNull()) { qWarning() << "Link element" << i << "in RSS feed doesn't exist! Skipping."; continue; } - + QString link = linkElement.text(); - + // Make sure it's a download link. if (link.endsWith("/download") && link.contains(lwjglRegex)) { QString name = link.mid(lwjglRegex.indexIn(link) + 6); // Subtract 4 here to remove the .zip file extension. name = name.left(lwjglRegex.matchedLength() - 10); - + QUrl url(link); if (!url.isValid()) { qWarning() << "LWJGL version URL isn't valid:" << link << "Skipping."; continue; } - + tempList.append(LWJGLVersion::Create(name, link)); } } - + beginResetModel(); m_vlist.swap(tempList); endResetModel(); - - qDebug("Loaded LWJGL list."); + + QLOG_INFO() << "Loaded LWJGL list."; finished(); } else { failed("Failed to load LWJGL list. Network error: " + reply->errorString()); } - + setLoading(false); reply->deleteLater(); } @@ -173,13 +172,12 @@ const PtrLWJGLVersion LWJGLVersionList::getVersion(const QString &versionName) for (int i = 0; i < count(); i++) { QString name = at(i)->name(); - if ( name == versionName) + if (name == versionName) return at(i); } return PtrLWJGLVersion(); } - void LWJGLVersionList::failed(QString msg) { qWarning() << msg; diff --git a/logic/lists/LwjglVersionList.h b/logic/lists/LwjglVersionList.h index 23e92a1a..99712292 100644 --- a/logic/lists/LwjglVersionList.h +++ b/logic/lists/LwjglVersionList.h @@ -17,13 +17,13 @@ #include #include -#include #include - #include +#include + class LWJGLVersion; -typedef QSharedPointer PtrLWJGLVersion; +typedef std::shared_ptr PtrLWJGLVersion; class LWJGLVersion : public QObject { diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index 35f7251e..36611165 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -16,8 +16,6 @@ #include "MinecraftVersionList.h" #include -#include - #include #include @@ -62,8 +60,8 @@ int MinecraftVersionList::count() const bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) { - auto left = first.dynamicCast(); - auto right = second.dynamicCast(); + auto left = std::dynamic_pointer_cast(first); + auto right = std::dynamic_pointer_cast(second); return left->timestamp > right->timestamp; } @@ -78,7 +76,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const { for (int i = 0; i < m_vlist.length(); i++) { - auto ver = m_vlist.at(i).dynamicCast(); + auto ver =std::dynamic_pointer_cast(m_vlist.at(i)); if (ver->is_latest && !ver->is_snapshot) { return m_vlist.at(i); @@ -272,7 +270,7 @@ void MCVListLoadTask::list_downloaded() QString dlUrl = QString(MCVLIST_URLBASE) + versionID + "/"; // Now, we construct the version object and add it to the list. - QSharedPointer mcVersion(new MinecraftVersion()); + std::shared_ptr mcVersion(new MinecraftVersion()); mcVersion->m_name = mcVersion->m_descriptor = versionID; mcVersion->timestamp = versionTime.toMSecsSinceEpoch(); mcVersion->download_url = dlUrl; diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp index b7a68c60..ba771eef 100644 --- a/logic/net/ByteArrayDownload.cpp +++ b/logic/net/ByteArrayDownload.cpp @@ -1,6 +1,6 @@ #include "ByteArrayDownload.h" #include "MultiMC.h" -#include +#include ByteArrayDownload::ByteArrayDownload(QUrl url) : Download() { @@ -10,13 +10,13 @@ ByteArrayDownload::ByteArrayDownload(QUrl url) : Download() void ByteArrayDownload::start() { - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); auto worker = MMC->qnam(); QNetworkReply *rep = worker->get(request); - m_reply = QSharedPointer(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); @@ -33,7 +33,8 @@ void ByteArrayDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error) { // error happened during download. - qDebug() << "URL:" << m_url.toString().toLocal8Bit() << "Network error: " << error; + QLOG_ERROR() << "Error getting URL:" << m_url.toString().toLocal8Bit() + << "Network error: " << error; m_status = Job_Failed; } @@ -45,14 +46,14 @@ void ByteArrayDownload::downloadFinished() // nothing went wrong... m_status = Job_Finished; m_data = m_reply->readAll(); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); return; } // else the download failed else { - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } diff --git a/logic/net/ByteArrayDownload.h b/logic/net/ByteArrayDownload.h index 428b21db..cfc6a8d0 100644 --- a/logic/net/ByteArrayDownload.h +++ b/logic/net/ByteArrayDownload.h @@ -21,4 +21,4 @@ protected slots: void downloadReadyRead(); }; -typedef QSharedPointer ByteArrayDownloadPtr; +typedef std::shared_ptr ByteArrayDownloadPtr; diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp index 9fc1f127..0e653e05 100644 --- a/logic/net/CacheDownload.cpp +++ b/logic/net/CacheDownload.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry) : Download(), md5sum(QCryptographicHash::Md5) @@ -31,7 +31,7 @@ void CacheDownload::start() emit failed(index_within_job); return; } - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request(m_url); request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)"); @@ -39,7 +39,7 @@ void CacheDownload::start() auto worker = MMC->qnam(); QNetworkReply *rep = worker->get(request); - m_reply = QSharedPointer(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); @@ -92,7 +92,7 @@ void CacheDownload::downloadFinished() m_entry->stale = false; MMC->metacache()->updateEntry(m_entry); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); return; } @@ -101,7 +101,7 @@ void CacheDownload::downloadFinished() { m_output_file.close(); m_output_file.remove(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } diff --git a/logic/net/CacheDownload.h b/logic/net/CacheDownload.h index f95dabd5..295391b1 100644 --- a/logic/net/CacheDownload.h +++ b/logic/net/CacheDownload.h @@ -31,4 +31,4 @@ public slots: virtual void start(); }; -typedef QSharedPointer CacheDownloadPtr; +typedef std::shared_ptr CacheDownloadPtr; diff --git a/logic/net/Download.h b/logic/net/Download.h index 91f09dec..ca4bee9f 100644 --- a/logic/net/Download.h +++ b/logic/net/Download.h @@ -2,10 +2,9 @@ #include #include -#include +#include #include - enum JobStatus { Job_NotStarted, @@ -18,20 +17,21 @@ class Download : public QObject { Q_OBJECT protected: - explicit Download(): QObject(0){}; + explicit Download() : QObject(0) {}; + public: virtual ~Download() {}; public: /// the network reply - QSharedPointer m_reply; - + std::shared_ptr m_reply; + /// source URL QUrl m_url; - + /// The file's status JobStatus m_status; - + /// index within the parent job int index_within_job = 0; @@ -46,9 +46,9 @@ protected slots: virtual void downloadError(QNetworkReply::NetworkError error) = 0; virtual void downloadFinished() = 0; virtual void downloadReadyRead() = 0; - + public slots: virtual void start() = 0; }; -typedef QSharedPointer DownloadPtr; +typedef std::shared_ptr DownloadPtr; diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp index 03a69555..f6275b7a 100644 --- a/logic/net/DownloadJob.cpp +++ b/logic/net/DownloadJob.cpp @@ -5,7 +5,7 @@ #include "ByteArrayDownload.h" #include "CacheDownload.h" -#include +#include ByteArrayDownloadPtr DownloadJob::addByteArrayDownload(QUrl url) { @@ -54,18 +54,18 @@ void DownloadJob::partSucceeded(int index) partProgress(index, slot.total_progress, slot.total_progress); num_succeeded++; - qDebug() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/" + QLOG_INFO() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/" << downloads.size(); if (num_failed + num_succeeded == downloads.size()) { if (num_failed) { - qDebug() << m_job_name.toLocal8Bit() << " failed."; + QLOG_ERROR() << m_job_name.toLocal8Bit() << " failed."; emit failed(); } else { - qDebug() << m_job_name.toLocal8Bit() << " succeeded."; + QLOG_INFO() << m_job_name.toLocal8Bit() << " succeeded."; emit succeeded(); } } @@ -76,17 +76,17 @@ void DownloadJob::partFailed(int index) auto &slot = parts_progress[index]; if (slot.failures == 3) { - qDebug() << "Part " << index << " failed 3 times (" << downloads[index]->m_url << ")"; + QLOG_ERROR() << "Part " << index << " failed 3 times (" << downloads[index]->m_url << ")"; num_failed++; if (num_failed + num_succeeded == downloads.size()) { - qDebug() << m_job_name.toLocal8Bit() << " failed."; + QLOG_ERROR() << m_job_name.toLocal8Bit() << " failed."; emit failed(); } } else { - qDebug() << "Part " << index << " failed, restarting (" << downloads[index]->m_url + QLOG_ERROR() << "Part " << index << " failed, restarting (" << downloads[index]->m_url << ")"; // restart the job slot.failures++; @@ -110,12 +110,12 @@ void DownloadJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTota void DownloadJob::start() { - qDebug() << m_job_name.toLocal8Bit() << " started."; + QLOG_INFO() << m_job_name.toLocal8Bit() << " started."; for (auto iter : downloads) { - connect(iter.data(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); - connect(iter.data(), SIGNAL(failed(int)), SLOT(partFailed(int))); - connect(iter.data(), SIGNAL(progress(int, qint64, qint64)), + connect(iter.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); + connect(iter.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); + connect(iter.get(), SIGNAL(progress(int, qint64, qint64)), SLOT(partProgress(int, qint64, qint64))); iter->start(); } diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h index 8c32950a..91b014ad 100644 --- a/logic/net/DownloadJob.h +++ b/logic/net/DownloadJob.h @@ -9,7 +9,7 @@ #include "logic/tasks/ProgressProvider.h" class DownloadJob; -typedef QSharedPointer DownloadJobPtr; +typedef std::shared_ptr DownloadJobPtr; /** * A single file for the downloader/cache to process. diff --git a/logic/net/FileDownload.cpp b/logic/net/FileDownload.cpp index 353fd58b..3f38b0fa 100644 --- a/logic/net/FileDownload.cpp +++ b/logic/net/FileDownload.cpp @@ -2,7 +2,7 @@ #include "FileDownload.h" #include #include -#include +#include FileDownload::FileDownload ( QUrl url, QString target_path ) @@ -28,7 +28,7 @@ void FileDownload::start() // skip this file if they match if ( m_check_md5 && hash == m_expected_md5 ) { - qDebug() << "Skipping " << m_url.toString() << ": md5 match."; + QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match."; emit succeeded(index_within_job); return; } @@ -43,7 +43,7 @@ void FileDownload::start() return; } - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request ( m_url ); request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1()); request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Uncached)"); @@ -51,7 +51,7 @@ void FileDownload::start() auto worker = MMC->qnam(); QNetworkReply * rep = worker->get ( request ); - m_reply = QSharedPointer ( rep, &QObject::deleteLater ); + m_reply = std::shared_ptr ( 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 ) ) ); @@ -79,7 +79,7 @@ void FileDownload::downloadFinished() m_status = Job_Finished; m_output_file.close(); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); return; } @@ -87,7 +87,7 @@ void FileDownload::downloadFinished() else { m_output_file.close(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } diff --git a/logic/net/FileDownload.h b/logic/net/FileDownload.h index 190bee58..9abb590d 100644 --- a/logic/net/FileDownload.h +++ b/logic/net/FileDownload.h @@ -32,4 +32,4 @@ public slots: virtual void start(); }; -typedef QSharedPointer FileDownloadPtr; +typedef std::shared_ptr FileDownloadPtr; diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp index 6d66abce..3ec2155b 100644 --- a/logic/net/ForgeXzDownload.cpp +++ b/logic/net/ForgeXzDownload.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include ForgeXzDownload::ForgeXzDownload(QUrl url, MetaEntryPtr entry) : Download() @@ -32,7 +32,7 @@ void ForgeXzDownload::start() emit failed(index_within_job); return; } - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request(m_url); request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)"); @@ -40,7 +40,7 @@ void ForgeXzDownload::start() auto worker = MMC->qnam(); QNetworkReply *rep = worker->get(request); - m_reply = QSharedPointer(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); @@ -78,7 +78,7 @@ void ForgeXzDownload::downloadFinished() { // something bad happened m_pack200_xz_file.remove(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } @@ -88,7 +88,7 @@ void ForgeXzDownload::downloadFinished() { m_pack200_xz_file.close(); m_pack200_xz_file.remove(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } @@ -198,38 +198,38 @@ void ForgeXzDownload::decompressAndInstall() break; case XZ_MEM_ERROR: - qDebug() << "Memory allocation failed\n"; + QLOG_ERROR() << "Memory allocation failed\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_MEMLIMIT_ERROR: - qDebug() << "Memory usage limit reached\n"; + QLOG_ERROR() << "Memory usage limit reached\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_FORMAT_ERROR: - qDebug() << "Not a .xz file\n"; + QLOG_ERROR() << "Not a .xz file\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_OPTIONS_ERROR: - qDebug() << "Unsupported options in the .xz headers\n"; + QLOG_ERROR() << "Unsupported options in the .xz headers\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_DATA_ERROR: case XZ_BUF_ERROR: - qDebug() << "File is corrupt\n"; + QLOG_ERROR() << "File is corrupt\n"; xz_dec_end(s); emit failed(index_within_job); return; default: - qDebug() << "Bug!\n"; + QLOG_ERROR() << "Bug!\n"; xz_dec_end(s); emit failed(index_within_job); return; @@ -246,7 +246,7 @@ void ForgeXzDownload::decompressAndInstall() } catch(std::runtime_error & err) { - qDebug() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what(); + QLOG_ERROR() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what(); QFile f(m_target_path); if(f.exists()) f.remove(); @@ -274,6 +274,6 @@ void ForgeXzDownload::decompressAndInstall() m_entry->stale = false; MMC->metacache()->updateEntry(m_entry); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); } diff --git a/logic/net/ForgeXzDownload.h b/logic/net/ForgeXzDownload.h index 8cb47783..5d677947 100644 --- a/logic/net/ForgeXzDownload.h +++ b/logic/net/ForgeXzDownload.h @@ -32,4 +32,4 @@ private: void decompressAndInstall(); }; -typedef QSharedPointer ForgeXzDownloadPtr; +typedef std::shared_ptr ForgeXzDownloadPtr; diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp index 46801ab3..9c642a0f 100644 --- a/logic/net/HttpMetaCache.cpp +++ b/logic/net/HttpMetaCache.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -105,12 +105,12 @@ bool HttpMetaCache::updateEntry ( MetaEntryPtr stale_entry ) { if(!m_entries.contains(stale_entry->base)) { - qDebug() << "Cannot add entry with unknown base: " << stale_entry->base.toLocal8Bit(); + QLOG_ERROR() << "Cannot add entry with unknown base: " << stale_entry->base.toLocal8Bit(); return false; } if(stale_entry->stale) { - qDebug() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit(); + QLOG_ERROR() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit(); return false; } m_entries[stale_entry->base].entry_list[stale_entry->path] = stale_entry; diff --git a/logic/net/HttpMetaCache.h b/logic/net/HttpMetaCache.h index daf6c43f..8107839e 100644 --- a/logic/net/HttpMetaCache.h +++ b/logic/net/HttpMetaCache.h @@ -15,7 +15,7 @@ struct MetaEntry QString getFullPath(); }; -typedef QSharedPointer MetaEntryPtr; +typedef std::shared_ptr MetaEntryPtr; class HttpMetaCache : public QObject { diff --git a/logic/net/LoginTask.cpp b/logic/net/LoginTask.cpp index 2a45400e..5de8efa9 100644 --- a/logic/net/LoginTask.cpp +++ b/logic/net/LoginTask.cpp @@ -40,7 +40,7 @@ void LoginTask::legacyLogin() { setStatus(tr("Logging in...")); auto worker = MMC->qnam(); - connect(worker.data(), SIGNAL(finished(QNetworkReply *)), this, + connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this, SLOT(processLegacyReply(QNetworkReply *))); QUrl loginURL("https://login.minecraft.net/"); @@ -134,7 +134,7 @@ void LoginTask::yggdrasilLogin() { setStatus(tr("Logging in...")); auto worker = MMC->qnam(); - connect(worker.data(), SIGNAL(finished(QNetworkReply *)), this, + connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this, SLOT(processYggdrasilReply(QNetworkReply *))); /* diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp index c75bcb8f..2f137c55 100644 --- a/logic/tasks/Task.cpp +++ b/logic/tasks/Task.cpp @@ -14,6 +14,7 @@ */ #include "Task.h" +#include Task::Task(QObject *parent) : ProgressProvider(parent) @@ -55,6 +56,7 @@ void Task::start() void Task::emitFailed(QString reason) { m_running = false; + QLOG_ERROR() << "Task failed: " << reason; emit failed(reason); } -- cgit v1.2.3