Skip to content

Commit

Permalink
Fix for changed download URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
madsciencecoder committed Apr 29, 2018
1 parent f7cdd6f commit 8ca1c89
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 113 deletions.
8 changes: 4 additions & 4 deletions Schticker-Book-Rewritten.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion globaldefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
60 changes: 0 additions & 60 deletions hashworker.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions hashworker.h

This file was deleted.

15 changes: 7 additions & 8 deletions updateworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "extractionworker.h"
#include "downloadworker.h"
#include "patchworker.h"
#include "utilities.h"

#include <QJsonObject>
#include <QJsonArray>
Expand All @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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";
}
Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions updateworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define UPDATEWORKER_H

#include "jsonworker.h"
#include "hashworker.h"

#include <QObject>
#include <QJsonDocument>
Expand Down Expand Up @@ -52,7 +51,6 @@ private slots:

private:
JsonWorker *jsonWorker;
HashWorker *hashWorker;
QString filePath;
QString cachePath;

Expand Down
35 changes: 35 additions & 0 deletions utilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "utilities.h"

#include<QString>
#include<QFile>
#include<QCryptographicHash>
#include<QDebug>

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();
}
8 changes: 8 additions & 0 deletions utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef UTILITIES_H
#define UTILITIES_H

#include <QByteArray>

QByteArray getHash(QString);

#endif // UTILITIES_H

0 comments on commit 8ca1c89

Please sign in to comment.