Skip to content

Commit

Permalink
Genericize t-download, allow for no checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Nov 5, 2023
1 parent 6345fb3 commit c5a1dde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
31 changes: 17 additions & 14 deletions app/src/task/t-download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ void TDownload::setSha256(QString sha256) { mSha256 = sha256; }
void TDownload::perform()
{
// Setup download
QFile packFile(mDestinationPath + '/' + mDestinationFilename);
QFileInfo packFileInfo(packFile);
QFile file(mDestinationPath + '/' + mDestinationFilename);
QFileInfo fileInfo(file);
Qx::DownloadTask download{
.target = mTargetFile,
.dest = packFileInfo.absoluteFilePath()
.dest = fileInfo.absoluteFilePath()
};
mDownloadManager.appendTask(download);

// Log/label string
QString label = LOG_EVENT_DOWNLOADING_DATA_PACK.arg(packFileInfo.fileName());
QString label = LOG_EVENT_DOWNLOADING_FILE.arg(fileInfo.fileName());
emit eventOccurred(NAME, label);

// Start download
Expand All @@ -125,18 +125,21 @@ void TDownload::postDownload(Qx::DownloadManagerReport downloadReport)
emit longTaskFinished();
if(downloadReport.wasSuccessful())
{
// Confirm checksum is correct
QFile packFile(mDestinationPath + '/' + mDestinationFilename);
bool checksumMatch;
Qx::IoOpReport cr = Qx::fileMatchesChecksum(checksumMatch, packFile, mSha256, QCryptographicHash::Sha256);
if(cr.isFailure() || !checksumMatch)
// Confirm checksum is correct, if supplied
if(!mSha256.isEmpty())
{
TDownloadError err(TDownloadError::ChecksumMismatch, cr.isFailure() ? cr.outcomeInfo() : u""_s);
errorStatus = err;
emit errorOccurred(NAME, errorStatus);
QFile file(mDestinationPath + '/' + mDestinationFilename);
bool checksumMatch;
Qx::IoOpReport cr = Qx::fileMatchesChecksum(checksumMatch, file, mSha256, QCryptographicHash::Sha256);
if(cr.isFailure() || !checksumMatch)
{
TDownloadError err(TDownloadError::ChecksumMismatch, cr.isFailure() ? cr.outcomeInfo() : u""_s);
errorStatus = err;
emit errorOccurred(NAME, errorStatus);
}
}
else
emit eventOccurred(NAME, LOG_EVENT_DOWNLOAD_SUCC);

emit eventOccurred(NAME, LOG_EVENT_DOWNLOAD_SUCC);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions app/src/task/t-download.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class QX_ERROR_TYPE(TDownloadError, "TDownloadError", 1252)
private:
static inline const QHash<Type, QString> ERR_STRINGS{
{NoError, u""_s},
{ChecksumMismatch, u"The title's Data Pack checksum does not match its record!"_s},
{ChecksumMismatch, u"The file's checksum does not match its record!"_s},
{Incomeplete, u"The download could not be completed."_s}
};

Expand Down Expand Up @@ -59,9 +59,9 @@ class TDownload : public Task
static inline const QString NAME = u"TDownload"_s;

// Logging
static inline const QString LOG_EVENT_DOWNLOADING_DATA_PACK = u"Downloading Data Pack %1"_s;
static inline const QString LOG_EVENT_DOWNLOAD_SUCC = u"Data Pack downloaded successfully"_s;
static inline const QString LOG_EVENT_DOWNLOAD_AUTH = u"Data Pack download unexpectedly requires authentication (%1)"_s;
static inline const QString LOG_EVENT_DOWNLOADING_FILE = u"Downloading file %1"_s;
static inline const QString LOG_EVENT_DOWNLOAD_SUCC = u"File downloaded successfully"_s;
static inline const QString LOG_EVENT_DOWNLOAD_AUTH = u"File download unexpectedly requires authentication (%1)"_s;
static inline const QString LOG_EVENT_STOPPING_DOWNLOADS = u"Stopping current download(s)..."_s;

//-Instance Variables------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit c5a1dde

Please sign in to comment.