From 8ca1c89872453ad077d05a09420303f32e8ebf10 Mon Sep 17 00:00:00 2001 From: Joshua Snyder Date: Sun, 29 Apr 2018 13:47:50 -0400 Subject: [PATCH] Fix for changed download URL. --- Schticker-Book-Rewritten.pro | 8 ++--- globaldefines.h | 2 +- hashworker.cpp | 60 ------------------------------------ hashworker.h | 38 ----------------------- updateworker.cpp | 15 +++++---- updateworker.h | 2 -- utilities.cpp | 35 +++++++++++++++++++++ utilities.h | 8 +++++ 8 files changed, 55 insertions(+), 113 deletions(-) delete mode 100644 hashworker.cpp delete mode 100644 hashworker.h create mode 100644 utilities.cpp create mode 100644 utilities.h diff --git a/Schticker-Book-Rewritten.pro b/Schticker-Book-Rewritten.pro index 2e9dc4c..e1aba82 100644 --- a/Schticker-Book-Rewritten.pro +++ b/Schticker-Book-Rewritten.pro @@ -38,8 +38,8 @@ SOURCES += main.cpp\ loginworker.cpp \ twofactorwindow.cpp \ patchworker.cpp \ - hashworker.cpp \ - filelocationchooser.cpp + filelocationchooser.cpp \ + utilities.cpp HEADERS += launcherwindow.h \ globaldefines.h \ @@ -50,8 +50,8 @@ HEADERS += launcherwindow.h \ loginworker.h \ twofactorwindow.h \ patchworker.h \ - hashworker.h \ - filelocationchooser.h + filelocationchooser.h \ + utilities.h FORMS += launcherwindow.ui \ twofactorwindow.ui \ diff --git a/globaldefines.h b/globaldefines.h index 453382f..f9e42b2 100644 --- a/globaldefines.h +++ b/globaldefines.h @@ -50,4 +50,4 @@ #define PATCH_MANIFEST_URL "https://cdn.toontownrewritten.com/content/patchmanifest.txt" //content distribution URL -#define CDN_URL "https://cdn.toontownrewritten.com/content/patches/" +#define CDN_URL "http://s3.amazonaws.com/download.toontownrewritten.com/patches/" diff --git a/hashworker.cpp b/hashworker.cpp deleted file mode 100644 index d2c3875..0000000 --- a/hashworker.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2015-2016 Joshua Snyder - * Distributed under the GNU GPL v3. For full terms see the file LICENSE - * - * This file is part of Shticker Book Rewritten. - * - * Shticker Book Rewritten is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Shticker Book Rewritten is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Shticker Book Rewritten. If not, see . - */ - -#include "hashworker.h" - -#include -#include -#include - -HashWorker::HashWorker(QObject *parent) : QObject(parent) -{ - -} - -//Generates the SHA1 checksum of the passed file -QByteArray HashWorker::getHash(QString fileName) -{ - QString hashString; - QFile file(fileName); - QByteArray hashArray; - QCryptographicHash *sha1Hash; - - //Attempt to open the file - if(!file.open(QFile::ReadOnly)) - { - qDebug() << "Unable to read file:" << fileName << ". Error:" << file.errorString() << "\n"; - } - else - { - //Load the file's data to process - QByteArray fileContents = file.readAll(); - - hashArray = sha1Hash->hash(fileContents, QCryptographicHash::Sha1); - } - - //clean up the file since we are done with it - file.flush(); - file.close(); - file.deleteLater(); - - //return the checksum in hexidecimal format since that is what the manifest requires - return hashArray.toHex(); -} diff --git a/hashworker.h b/hashworker.h deleted file mode 100644 index 861cd6d..0000000 --- a/hashworker.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2015-2016 Joshua Snyder - * Distributed under the GNU GPL v3. For full terms see the file LICENSE - * - * This file is part of Shticker Book Rewritten. - * - * Shticker Book Rewritten is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Shticker Book Rewritten is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Shticker Book Rewritten. If not, see . - */ - -#ifndef HASHWORKER_H -#define HASHWORKER_H - -#include - -class HashWorker : public QObject -{ - Q_OBJECT -public: - explicit HashWorker(QObject *parent = 0); - QByteArray getHash(QString); - -signals: - -public slots: -}; - -#endif // HASHWORKER_H diff --git a/updateworker.cpp b/updateworker.cpp index b654fac..f9e621f 100644 --- a/updateworker.cpp +++ b/updateworker.cpp @@ -23,6 +23,7 @@ #include "extractionworker.h" #include "downloadworker.h" #include "patchworker.h" +#include "utilities.h" #include #include @@ -35,8 +36,6 @@ UpdateWorker::UpdateWorker(QObject *parent) : QObject(parent) { - hashWorker = new HashWorker(this); - QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten"); settings.beginGroup("FilesPath"); @@ -96,7 +95,7 @@ void UpdateWorker::patchManifestReady(QJsonDocument patchManifest) if(file.exists()) { //generate the SHA1 hash of the file to compare with the patch manifest - fileHash = hashWorker->getHash(localFileName); + fileHash = getHash(localFileName); qDebug() << "Local file's hash is:" << fileHash; //Check if the hash matches the patch manifest @@ -129,7 +128,7 @@ void UpdateWorker::patchManifestReady(QJsonDocument patchManifest) getNewFile(patchObject["filename"].toString(), patchFileName, extractedFileName, patchObject["compPatchHash"].toString()); //verify the downloaded patch is good - if(hashWorker->getHash(extractedFileName) == patchObject["patchHash"].toString()) + if(getHash(extractedFileName) == patchObject["patchHash"].toString()) { qDebug() << "Downloaded patch matches manifest"; } @@ -144,7 +143,7 @@ void UpdateWorker::patchManifestReady(QJsonDocument patchManifest) hasBeenPatched = true; //check if the patch updated the file fully - if(hashWorker->getHash(localFileName) == fileObject["hash"].toString()) + if(getHash(localFileName) == fileObject["hash"].toString()) { qDebug() << "File has been patched fully\n"; fileIsOld = false; @@ -167,7 +166,7 @@ void UpdateWorker::patchManifestReady(QJsonDocument patchManifest) getNewFile(fileObject["dl"].toString(), localBz2FileName, localFileName, fileObject["compHash"].toString()); //check to make sure it is up to date - fileHash = hashWorker->getHash(localFileName); + fileHash = getHash(localFileName); if(fileHash == fileObject["hash"].toString()) { qDebug() << "Downloaded file's integrity has been verified\n"; @@ -188,7 +187,7 @@ void UpdateWorker::patchManifestReady(QJsonDocument patchManifest) getNewFile(fileObject["dl"].toString(), localBz2FileName, localFileName, fileObject["compHash"].toString()); //check to make sure it is up to date - fileHash = hashWorker->getHash(localFileName); + fileHash = getHash(localFileName); if(fileHash == fileObject["hash"].toString()) { qDebug() << "Downloaded file's integrity has been verified\n"; @@ -269,7 +268,7 @@ void UpdateWorker::getNewFile(QString dlFile, QString localBz2FileName, QString startDownload(dlFile); //make sure download succeeded, logging for debugging purposes but still extracting because TTR has been known to not update hashes - QByteArray fileHash = hashWorker->getHash(localBz2FileName); + QByteArray fileHash = getHash(localBz2FileName); if(fileHash == compHash) { diff --git a/updateworker.h b/updateworker.h index 3eb4485..2a534b7 100644 --- a/updateworker.h +++ b/updateworker.h @@ -22,7 +22,6 @@ #define UPDATEWORKER_H #include "jsonworker.h" -#include "hashworker.h" #include #include @@ -52,7 +51,6 @@ private slots: private: JsonWorker *jsonWorker; - HashWorker *hashWorker; QString filePath; QString cachePath; diff --git a/utilities.cpp b/utilities.cpp new file mode 100644 index 0000000..0cc39de --- /dev/null +++ b/utilities.cpp @@ -0,0 +1,35 @@ +#include "utilities.h" + +#include +#include +#include +#include + +QByteArray getHash(QString fileName) +{ + QString hashString; + QFile file(fileName); + QByteArray hashArray; + QCryptographicHash *sha1Hash; + + //Attempt to open the file + if(!file.open(QFile::ReadOnly)) + { + qDebug() << "Unable to read file:" << fileName << ". Error:" << file.errorString() << "\n"; + } + else + { + //Load the file's data to process + QByteArray fileContents = file.readAll(); + + hashArray = sha1Hash->hash(fileContents, QCryptographicHash::Sha1); + } + + //clean up the file since we are done with it + file.flush(); + file.close(); + file.deleteLater(); + + //return the checksum in hexidecimal format since that is what the manifest requires + return hashArray.toHex(); +} diff --git a/utilities.h b/utilities.h new file mode 100644 index 0000000..0289d63 --- /dev/null +++ b/utilities.h @@ -0,0 +1,8 @@ +#ifndef UTILITIES_H +#define UTILITIES_H + +#include + +QByteArray getHash(QString); + +#endif // UTILITIES_H