[Scummvm-git-logs] scummvm master -> f06bf27950093e9476460059db52d20b6541822c
sev-
noreply at scummvm.org
Sun Apr 27 12:27:32 UTC 2025
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
065d5e6448 GUI: Fix integrity dialog freeze issue
d29c2e7581 GUI: Fix Segmentation fault on clicking cancel
68258a1ced COMMON: Add callback for progress update
b416931862 GUI: Make lastEventPoll a class member
f06bf27950 COMMON: Use optional parameter instead of overload
Commit: 065d5e64485ae2b048c6f1b36dad8f880bd7ccac
https://github.com/scummvm/scummvm/commit/065d5e64485ae2b048c6f1b36dad8f880bd7ccac
Author: ShivangNagta (shivangnag at gmail.com)
Date: 2025-04-27T20:27:27+08:00
Commit Message:
GUI: Fix integrity dialog freeze issue
Changed paths:
common/macresman.cpp
common/macresman.h
common/md5.cpp
common/md5.h
gui/integrity-dialog.cpp
gui/integrity-dialog.h
diff --git a/common/macresman.cpp b/common/macresman.cpp
index 0dad3367388..b3806b544e1 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -168,6 +168,23 @@ String MacResManager::computeResForkMD5AsString(uint32 length, bool tail) const
return computeStreamMD5AsString(resForkStream, MIN<uint32>(length, _resForkSize));
}
+String MacResManager::computeResForkMD5AsString(uint32 length, bool tail, bool (*progressUpdateCallback)(int)) const {
+ if (!hasResFork())
+ return String();
+
+ _stream->seek(_resForkOffset);
+ uint32 dataOffset = _stream->readUint32BE() + _resForkOffset;
+ /* uint32 mapOffset = */ _stream->readUint32BE();
+ uint32 dataLength = _stream->readUint32BE();
+
+
+ SeekableSubReadStream resForkStream(_stream, dataOffset, dataOffset + dataLength);
+ if (tail && dataLength > length)
+ resForkStream.seek(-(int64)length, SEEK_END);
+
+ return computeStreamMD5AsString(resForkStream, MIN<uint32>(length, _resForkSize), progressUpdateCallback);
+}
+
bool MacResManager::open(const Path &fileName) {
return open(fileName, SearchMan);
}
diff --git a/common/macresman.h b/common/macresman.h
index 5fa3a0f9049..3505c943608 100644
--- a/common/macresman.h
+++ b/common/macresman.h
@@ -268,6 +268,15 @@ public:
*/
String computeResForkMD5AsString(uint32 length = 0, bool tail = false) const;
+ /**
+ * Overloaded version for callbacks
+ * Calculate the MD5 checksum of the resource fork
+ * @param length The maximum length to compute for
+ * @param tail Calculate length from the tail
+ * @return The MD5 checksum of the resource fork
+ */
+ String computeResForkMD5AsString(uint32 length, bool tail, bool (*progressUpdateCallback)(int)) const;
+
/**
* Get the base file name of the data/resource fork pair
* @return The base file name of the data/resource fork pair
diff --git a/common/md5.cpp b/common/md5.cpp
index 4e4a1700068..a0e75674394 100644
--- a/common/md5.cpp
+++ b/common/md5.cpp
@@ -279,6 +279,48 @@ bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length) {
return true;
}
+
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, bool (*progressUpdateCallback)(int)) {
+
+#ifdef DISABLE_MD5
+ memset(digest, 0, 16);
+#else
+ md5_context ctx;
+ int i;
+ unsigned char buf[1000];
+ bool restricted = (length != 0);
+ uint32 readlen;
+
+ if (!restricted || sizeof(buf) <= length)
+ readlen = sizeof(buf);
+ else
+ readlen = length;
+
+ md5_starts(&ctx);
+
+ while ((i = stream.read(buf, readlen)) > 0) {
+
+ if (!progressUpdateCallback(i)) {
+ return false;
+ }
+
+ md5_update(&ctx, buf, i);
+
+ if (restricted) {
+ length -= i;
+ if (length == 0)
+ break;
+
+ if (sizeof(buf) > length)
+ readlen = length;
+ }
+ }
+
+ md5_finish(&ctx, digest);
+#endif
+ return true;
+}
+
String computeStreamMD5AsString(ReadStream &stream, uint32 length) {
String md5;
uint8 digest[16];
@@ -291,4 +333,17 @@ String computeStreamMD5AsString(ReadStream &stream, uint32 length) {
return md5;
}
+
+String computeStreamMD5AsString(ReadStream &stream, uint32 length, bool (*progressUpdateCallback)(int)) {
+ String md5;
+ uint8 digest[16];
+ if (computeStreamMD5(stream, digest, length, progressUpdateCallback)) {
+ for (int i = 0; i < 16; i++) {
+ md5 += String::format("%02x", (int)digest[i]);
+ }
+ }
+
+ return md5;
+}
+
} // End of namespace Common
diff --git a/common/md5.h b/common/md5.h
index 11eb06dc3c4..8624904c56a 100644
--- a/common/md5.h
+++ b/common/md5.h
@@ -49,6 +49,7 @@ class String;
* @return true on success, false if an error occurred
*/
bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length = 0);
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, bool (*progressUpdateCallback)(int));
/**
* Compute the MD5 checksum of the content of the given ReadStream.
@@ -61,6 +62,7 @@ bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length = 0);
* @return the MD5 as a hex string on success, and an empty string if an error occurred
*/
String computeStreamMD5AsString(ReadStream &stream, uint32 length = 0);
+String computeStreamMD5AsString(ReadStream &stream, uint32 length, bool (*progressUpdateCallback)(int));
/** @} */
diff --git a/gui/integrity-dialog.cpp b/gui/integrity-dialog.cpp
index eee08aedabb..ad3fb0f8cfe 100644
--- a/gui/integrity-dialog.cpp
+++ b/gui/integrity-dialog.cpp
@@ -146,6 +146,38 @@ IntegrityDialog::IntegrityDialog(Common::String endpoint, Common::String domain)
IntegrityDialog::~IntegrityDialog() {
}
+
+bool IntegrityDialog::progressUpdateCallback(int bytesProcessed) {
+ if(g_checksum_state->dialog->_close)
+ return false;
+
+ g_checksum_state->calculatedSize += bytesProcessed;
+
+ if (g_system->getMillis() > g_checksum_state->lastUpdate + 500) {
+ g_checksum_state->lastUpdate = g_system->getMillis();
+ g_checksum_state->dialog->sendCommand(kDownloadProgressCmd, 0);
+ }
+
+ Common::Event event;
+ g_checksum_state->dialog->pollEvent(event);
+
+ return true;
+};
+
+
+void IntegrityDialog::pollEvent(Common::Event &event) {
+ if (g_system->getEventManager()->pollEvent(event)) {
+ static uint32 lastEventPoll = 0;
+
+ if (g_system->getMillis() > lastEventPoll + 16) {
+ lastEventPoll = g_system->getMillis();
+ g_gui.processEvent(event, g_checksum_state->dialog);
+ g_system->updateScreen();
+ }
+ }
+}
+
+
void IntegrityDialog::open() {
Dialog::open();
reflowLayout();
@@ -337,21 +369,21 @@ Common::Array<Common::StringArray> IntegrityDialog::generateChecksums(Common::Pa
// Data fork
// Various checksizes
for (auto size : {0, 5000, 1024 * 1024}) {
- fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream, size).c_str());
+ fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream, size, progressUpdateCallback).c_str());
dataForkStream->seek(0);
}
// Tail checksums with checksize 5000
dataForkStream->seek(-5000, SEEK_END);
- fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream).c_str());
+ fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream, 0, progressUpdateCallback).c_str());
// Resource fork
if (macFile.hasResFork()) {
// Various checksizes
for (auto size : {0, 5000, 1024 * 1024}) {
- fileChecksum.push_back(macFile.computeResForkMD5AsString(size).c_str());
+ fileChecksum.push_back(macFile.computeResForkMD5AsString(size, false, progressUpdateCallback).c_str());
}
// Tail checksums with checksize 5000
- fileChecksum.push_back(macFile.computeResForkMD5AsString(5000, true).c_str());
+ fileChecksum.push_back(macFile.computeResForkMD5AsString(5000, true, progressUpdateCallback).c_str());
fileChecksums.push_back(fileChecksum);
}
@@ -365,19 +397,12 @@ Common::Array<Common::StringArray> IntegrityDialog::generateChecksums(Common::Pa
Common::Array<Common::String> fileChecksum = {filename.toString()};
// Various checksizes
for (auto size : {0, 5000, 1024 * 1024}) {
- fileChecksum.push_back(Common::computeStreamMD5AsString(file, size).c_str());
+ fileChecksum.push_back(Common::computeStreamMD5AsString(file, size, progressUpdateCallback).c_str());
file.seek(0);
}
// Tail checksums with checksize 5000
file.seek(-5000, SEEK_END);
- fileChecksum.push_back(Common::computeStreamMD5AsString(file).c_str());
-
- g_checksum_state->calculatedSize += file.size();
-
- if (g_system->getMillis() > g_checksum_state->lastUpdate + 500) {
- g_checksum_state->lastUpdate = g_system->getMillis();
- sendCommand(kDownloadProgressCmd, 0);
- }
+ fileChecksum.push_back(Common::computeStreamMD5AsString(file, 0, progressUpdateCallback).c_str());
file.close();
fileChecksums.push_back(fileChecksum);
diff --git a/gui/integrity-dialog.h b/gui/integrity-dialog.h
index 7fc4326a9b7..13c23e90062 100644
--- a/gui/integrity-dialog.h
+++ b/gui/integrity-dialog.h
@@ -70,6 +70,18 @@ public:
IntegrityDialog(Common::String endpoint, Common::String gameConfig);
~IntegrityDialog();
+
+ /**
+ * Callback funtion which updates the progress bar every 500ms
+ * It also poll events to allow mouse movements/button interactions to avoid freezing when processing large files
+ */
+ static bool progressUpdateCallback(int bytesProcessed);
+
+ /**
+ * Poll events during callback
+ */
+ void pollEvent(Common::Event &event);
+
void sendJSON();
void checksumResponseCallback(const Common::JSONValue *r);
void errorCallback(const Networking::ErrorResponse &error);
Commit: d29c2e7581180e5335e09537ce28e85a6902ad86
https://github.com/scummvm/scummvm/commit/d29c2e7581180e5335e09537ce28e85a6902ad86
Author: ShivangNagta (shivangnag at gmail.com)
Date: 2025-04-27T20:27:27+08:00
Commit Message:
GUI: Fix Segmentation fault on clicking cancel
Changed paths:
gui/integrity-dialog.cpp
diff --git a/gui/integrity-dialog.cpp b/gui/integrity-dialog.cpp
index ad3fb0f8cfe..9c9544fc48b 100644
--- a/gui/integrity-dialog.cpp
+++ b/gui/integrity-dialog.cpp
@@ -187,6 +187,13 @@ void IntegrityDialog::open() {
void IntegrityDialog::close() {
if (g_checksum_state)
g_checksum_state->dialog = nullptr;
+ delete g_checksum_state;
+ g_checksum_state = nullptr;
+
+ if (g_result) {
+ delete g_result;
+ g_result = nullptr;
+ }
Dialog::close();
}
@@ -240,13 +247,7 @@ void IntegrityDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 da
setState(kResponseReceived);
break;
case kCleanupCmd: {
- delete g_checksum_state;
- g_checksum_state = nullptr;
-
- delete g_result;
- g_result = nullptr;
-
- close();
+ _close = true;
break;
}
case kDownloadProgressCmd:
@@ -473,6 +474,9 @@ Common::JSONValue *IntegrityDialog::generateJSONRequest(Common::Path gamePath, C
}
void IntegrityDialog::checksumResponseCallback(const Common::JSONValue *r) {
+ if (!g_result || !g_checksum_state) {
+ return;
+ }
debug(3, "JSON Response: %s", r->stringify().c_str());
IntegrityDialog::parseJSON(r);
@@ -504,6 +508,9 @@ void IntegrityDialog::sendJSON() {
}
void IntegrityDialog::parseJSON(const Common::JSONValue *response) {
+ if (!g_result || !g_checksum_state) {
+ return;
+ }
Common::JSONObject responseObject = response->asObject();
int responseError = responseObject.getVal("error")->asIntegerNumber();
Commit: 68258a1cedb439a5746c14d08c763fe09f456959
https://github.com/scummvm/scummvm/commit/68258a1cedb439a5746c14d08c763fe09f456959
Author: ShivangNagta (shivangnag at gmail.com)
Date: 2025-04-27T20:27:27+08:00
Commit Message:
COMMON: Add callback for progress update
Changed paths:
common/macresman.cpp
common/macresman.h
common/md5.cpp
common/md5.h
diff --git a/common/macresman.cpp b/common/macresman.cpp
index b3806b544e1..a7b33c63a8e 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -168,7 +168,7 @@ String MacResManager::computeResForkMD5AsString(uint32 length, bool tail) const
return computeStreamMD5AsString(resForkStream, MIN<uint32>(length, _resForkSize));
}
-String MacResManager::computeResForkMD5AsString(uint32 length, bool tail, bool (*progressUpdateCallback)(int)) const {
+String MacResManager::computeResForkMD5AsString(uint32 length, bool tail, ProgressUpdateCallback progressUpdateCallback) const {
if (!hasResFork())
return String();
diff --git a/common/macresman.h b/common/macresman.h
index 3505c943608..595eac6d3ab 100644
--- a/common/macresman.h
+++ b/common/macresman.h
@@ -55,6 +55,7 @@ namespace Common {
typedef Array<uint16> MacResIDArray;
typedef Array<uint32> MacResTagArray;
+typedef bool (*ProgressUpdateCallback)(int);
/**
* Class containing the raw data bytes for a Macintosh Finder Info data block.
@@ -275,7 +276,7 @@ public:
* @param tail Calculate length from the tail
* @return The MD5 checksum of the resource fork
*/
- String computeResForkMD5AsString(uint32 length, bool tail, bool (*progressUpdateCallback)(int)) const;
+ String computeResForkMD5AsString(uint32 length, bool tail, ProgressUpdateCallback progressUpdateCallback) const;
/**
* Get the base file name of the data/resource fork pair
diff --git a/common/md5.cpp b/common/md5.cpp
index a0e75674394..876be70f052 100644
--- a/common/md5.cpp
+++ b/common/md5.cpp
@@ -280,7 +280,7 @@ bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length) {
}
-bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, bool (*progressUpdateCallback)(int)) {
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, ProgressUpdateCallback progressUpdateCallback) {
#ifdef DISABLE_MD5
memset(digest, 0, 16);
@@ -334,7 +334,7 @@ String computeStreamMD5AsString(ReadStream &stream, uint32 length) {
}
-String computeStreamMD5AsString(ReadStream &stream, uint32 length, bool (*progressUpdateCallback)(int)) {
+String computeStreamMD5AsString(ReadStream &stream, uint32 length, ProgressUpdateCallback progressUpdateCallback) {
String md5;
uint8 digest[16];
if (computeStreamMD5(stream, digest, length, progressUpdateCallback)) {
diff --git a/common/md5.h b/common/md5.h
index 8624904c56a..14fd930db51 100644
--- a/common/md5.h
+++ b/common/md5.h
@@ -24,6 +24,8 @@
#include "common/scummsys.h"
+typedef bool (*ProgressUpdateCallback)(int);
+
namespace Common {
/**
@@ -49,7 +51,7 @@ class String;
* @return true on success, false if an error occurred
*/
bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length = 0);
-bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, bool (*progressUpdateCallback)(int));
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, ProgressUpdateCallback progressUpdateCallback );
/**
* Compute the MD5 checksum of the content of the given ReadStream.
@@ -62,7 +64,7 @@ bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, bool
* @return the MD5 as a hex string on success, and an empty string if an error occurred
*/
String computeStreamMD5AsString(ReadStream &stream, uint32 length = 0);
-String computeStreamMD5AsString(ReadStream &stream, uint32 length, bool (*progressUpdateCallback)(int));
+String computeStreamMD5AsString(ReadStream &stream, uint32 length, ProgressUpdateCallback progressUpdateCallback);
/** @} */
Commit: b4169318625344495a41fb14e9bbc1a7eab085ea
https://github.com/scummvm/scummvm/commit/b4169318625344495a41fb14e9bbc1a7eab085ea
Author: ShivangNagta (shivangnag at gmail.com)
Date: 2025-04-27T20:27:27+08:00
Commit Message:
GUI: Make lastEventPoll a class member
Changed paths:
gui/integrity-dialog.cpp
gui/integrity-dialog.h
diff --git a/gui/integrity-dialog.cpp b/gui/integrity-dialog.cpp
index 9c9544fc48b..c4da6560f5e 100644
--- a/gui/integrity-dialog.cpp
+++ b/gui/integrity-dialog.cpp
@@ -167,8 +167,7 @@ bool IntegrityDialog::progressUpdateCallback(int bytesProcessed) {
void IntegrityDialog::pollEvent(Common::Event &event) {
if (g_system->getEventManager()->pollEvent(event)) {
- static uint32 lastEventPoll = 0;
-
+ lastEventPoll = 0;
if (g_system->getMillis() > lastEventPoll + 16) {
lastEventPoll = g_system->getMillis();
g_gui.processEvent(event, g_checksum_state->dialog);
diff --git a/gui/integrity-dialog.h b/gui/integrity-dialog.h
index 13c23e90062..1c58b1777ef 100644
--- a/gui/integrity-dialog.h
+++ b/gui/integrity-dialog.h
@@ -62,6 +62,8 @@ class IntegrityDialog : public Dialog, public CommandSender {
ButtonWidget *_copyEmailButton;
bool _close;
+ uint32 lastEventPoll;
+
Common::U32String getSizeLabelText();
void refreshWidgets();
Commit: f06bf27950093e9476460059db52d20b6541822c
https://github.com/scummvm/scummvm/commit/f06bf27950093e9476460059db52d20b6541822c
Author: ShivangNagta (shivangnag at gmail.com)
Date: 2025-04-27T20:27:27+08:00
Commit Message:
COMMON: Use optional parameter instead of overload
Changed paths:
common/macresman.cpp
common/macresman.h
common/md5.cpp
common/md5.h
gui/integrity-dialog.cpp
gui/integrity-dialog.h
diff --git a/common/macresman.cpp b/common/macresman.cpp
index a7b33c63a8e..2d4478855e9 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -151,7 +151,7 @@ uint32 MacResManager::getResForkDataSize() const {
return _stream->readUint32BE();
}
-String MacResManager::computeResForkMD5AsString(uint32 length, bool tail) const {
+String MacResManager::computeResForkMD5AsString(uint32 length, bool tail, ProgressUpdateCallback progressUpdateCallback, void *callbackParameter) const {
if (!hasResFork())
return String();
@@ -165,29 +165,9 @@ String MacResManager::computeResForkMD5AsString(uint32 length, bool tail) const
if (tail && dataLength > length)
resForkStream.seek(-(int64)length, SEEK_END);
- return computeStreamMD5AsString(resForkStream, MIN<uint32>(length, _resForkSize));
+ return computeStreamMD5AsString(resForkStream, MIN<uint32>(length, _resForkSize), progressUpdateCallback, callbackParameter);
}
-String MacResManager::computeResForkMD5AsString(uint32 length, bool tail, ProgressUpdateCallback progressUpdateCallback) const {
- if (!hasResFork())
- return String();
-
- _stream->seek(_resForkOffset);
- uint32 dataOffset = _stream->readUint32BE() + _resForkOffset;
- /* uint32 mapOffset = */ _stream->readUint32BE();
- uint32 dataLength = _stream->readUint32BE();
-
-
- SeekableSubReadStream resForkStream(_stream, dataOffset, dataOffset + dataLength);
- if (tail && dataLength > length)
- resForkStream.seek(-(int64)length, SEEK_END);
-
- return computeStreamMD5AsString(resForkStream, MIN<uint32>(length, _resForkSize), progressUpdateCallback);
-}
-
-bool MacResManager::open(const Path &fileName) {
- return open(fileName, SearchMan);
-}
SeekableReadStream *MacResManager::openAppleDoubleWithAppleOrOSXNaming(Archive& archive, const Path &fileName) {
SeekableReadStream *stream = archive.createReadStreamForMember(constructAppleDoubleName(fileName));
@@ -246,6 +226,10 @@ SeekableReadStream *MacResManager::openAppleDoubleWithAppleOrOSXNaming(Archive&
return nullptr;
}
+bool MacResManager::open(const Path &fileName) {
+ return open(fileName, SearchMan);
+}
+
bool MacResManager::open(const Path &fileName, Archive &archive) {
close();
diff --git a/common/macresman.h b/common/macresman.h
index 595eac6d3ab..8231ff7d63d 100644
--- a/common/macresman.h
+++ b/common/macresman.h
@@ -55,7 +55,7 @@ namespace Common {
typedef Array<uint16> MacResIDArray;
typedef Array<uint32> MacResTagArray;
-typedef bool (*ProgressUpdateCallback)(int);
+typedef bool (* ProgressUpdateCallback)(void *, int);
/**
* Class containing the raw data bytes for a Macintosh Finder Info data block.
@@ -267,16 +267,7 @@ public:
* @param tail Calculate length from the tail
* @return The MD5 checksum of the resource fork
*/
- String computeResForkMD5AsString(uint32 length = 0, bool tail = false) const;
-
- /**
- * Overloaded version for callbacks
- * Calculate the MD5 checksum of the resource fork
- * @param length The maximum length to compute for
- * @param tail Calculate length from the tail
- * @return The MD5 checksum of the resource fork
- */
- String computeResForkMD5AsString(uint32 length, bool tail, ProgressUpdateCallback progressUpdateCallback) const;
+ String computeResForkMD5AsString(uint32 length = 0, bool tail = false, ProgressUpdateCallback progressUpdateCallback = nullptr, void *callbackParameter = nullptr) const;
/**
* Get the base file name of the data/resource fork pair
diff --git a/common/md5.cpp b/common/md5.cpp
index 876be70f052..065b883e2b9 100644
--- a/common/md5.cpp
+++ b/common/md5.cpp
@@ -243,7 +243,7 @@ void md5_finish(md5_context *ctx, uint8 digest[16]) {
}
-bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length) {
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, ProgressUpdateCallback progressUpdateCallback, void *callbackParameter) {
#ifdef DISABLE_MD5
memset(digest, 0, 16);
@@ -262,45 +262,8 @@ bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length) {
md5_starts(&ctx);
while ((i = stream.read(buf, readlen)) > 0) {
- md5_update(&ctx, buf, i);
-
- if (restricted) {
- length -= i;
- if (length == 0)
- break;
-
- if (sizeof(buf) > length)
- readlen = length;
- }
- }
-
- md5_finish(&ctx, digest);
-#endif
- return true;
-}
-
-
-bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, ProgressUpdateCallback progressUpdateCallback) {
-#ifdef DISABLE_MD5
- memset(digest, 0, 16);
-#else
- md5_context ctx;
- int i;
- unsigned char buf[1000];
- bool restricted = (length != 0);
- uint32 readlen;
-
- if (!restricted || sizeof(buf) <= length)
- readlen = sizeof(buf);
- else
- readlen = length;
-
- md5_starts(&ctx);
-
- while ((i = stream.read(buf, readlen)) > 0) {
-
- if (!progressUpdateCallback(i)) {
+ if (progressUpdateCallback != nullptr && !progressUpdateCallback(callbackParameter, i)) {
return false;
}
@@ -321,23 +284,10 @@ bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, Progr
return true;
}
-String computeStreamMD5AsString(ReadStream &stream, uint32 length) {
- String md5;
- uint8 digest[16];
- if (computeStreamMD5(stream, digest, length)) {
- for (int i = 0; i < 16; i++) {
- md5 += String::format("%02x", (int)digest[i]);
- }
- }
-
- return md5;
-}
-
-
-String computeStreamMD5AsString(ReadStream &stream, uint32 length, ProgressUpdateCallback progressUpdateCallback) {
+String computeStreamMD5AsString(ReadStream &stream, uint32 length, ProgressUpdateCallback progressUpdateCallback, void *callbackParameter) {
String md5;
uint8 digest[16];
- if (computeStreamMD5(stream, digest, length, progressUpdateCallback)) {
+ if (computeStreamMD5(stream, digest, length, progressUpdateCallback, callbackParameter)) {
for (int i = 0; i < 16; i++) {
md5 += String::format("%02x", (int)digest[i]);
}
diff --git a/common/md5.h b/common/md5.h
index 14fd930db51..cbbf105123e 100644
--- a/common/md5.h
+++ b/common/md5.h
@@ -24,7 +24,7 @@
#include "common/scummsys.h"
-typedef bool (*ProgressUpdateCallback)(int);
+typedef bool (* ProgressUpdateCallback)(void *, int);
namespace Common {
@@ -50,8 +50,7 @@ class String;
* @param[in] length the number of bytes for which to compute the checksum; 0 means all
* @return true on success, false if an error occurred
*/
-bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length = 0);
-bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, ProgressUpdateCallback progressUpdateCallback );
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length = 0, ProgressUpdateCallback progressUpdateCallback = nullptr, void *callbackParameter = nullptr);
/**
* Compute the MD5 checksum of the content of the given ReadStream.
@@ -63,8 +62,7 @@ bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length, Progr
* @param[in] length the number of bytes for which to compute the checksum; 0 means all
* @return the MD5 as a hex string on success, and an empty string if an error occurred
*/
-String computeStreamMD5AsString(ReadStream &stream, uint32 length = 0);
-String computeStreamMD5AsString(ReadStream &stream, uint32 length, ProgressUpdateCallback progressUpdateCallback);
+String computeStreamMD5AsString(ReadStream &stream, uint32 length = 0, ProgressUpdateCallback progressUpdateCallback = nullptr, void *callbackParameter = nullptr);
/** @} */
diff --git a/gui/integrity-dialog.cpp b/gui/integrity-dialog.cpp
index c4da6560f5e..a969365907f 100644
--- a/gui/integrity-dialog.cpp
+++ b/gui/integrity-dialog.cpp
@@ -92,7 +92,7 @@ uint32 getCalculationProgress() {
return progress;
}
-IntegrityDialog::IntegrityDialog(Common::String endpoint, Common::String domain) : Dialog("GameOptions_IntegrityDialog"), CommandSender(this), _close(false) {
+IntegrityDialog::IntegrityDialog(Common::String endpoint, Common::String domain) : Dialog("GameOptions_IntegrityDialog"), CommandSender(this), _close(false), _lastEventPoll(0) {
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
@@ -147,8 +147,8 @@ IntegrityDialog::~IntegrityDialog() {
}
-bool IntegrityDialog::progressUpdateCallback(int bytesProcessed) {
- if(g_checksum_state->dialog->_close)
+bool IntegrityDialog::progressUpdate(int bytesProcessed) {
+ if (g_checksum_state->dialog->_close)
return false;
g_checksum_state->calculatedSize += bytesProcessed;
@@ -159,22 +159,21 @@ bool IntegrityDialog::progressUpdateCallback(int bytesProcessed) {
}
Common::Event event;
- g_checksum_state->dialog->pollEvent(event);
-
- return true;
-};
-
-
-void IntegrityDialog::pollEvent(Common::Event &event) {
if (g_system->getEventManager()->pollEvent(event)) {
- lastEventPoll = 0;
- if (g_system->getMillis() > lastEventPoll + 16) {
- lastEventPoll = g_system->getMillis();
+ if (g_system->getMillis() > g_checksum_state->dialog->_lastEventPoll + 16) {
+ g_checksum_state->dialog->_lastEventPoll = g_system->getMillis();
g_gui.processEvent(event, g_checksum_state->dialog);
g_system->updateScreen();
}
}
-}
+
+ return true;
+};
+
+static bool progressUpdateCallback(void *param, int bytesProcessed) {
+ IntegrityDialog *dialog = (IntegrityDialog *)param;
+ return dialog->progressUpdate(bytesProcessed);
+};
void IntegrityDialog::open() {
@@ -369,21 +368,21 @@ Common::Array<Common::StringArray> IntegrityDialog::generateChecksums(Common::Pa
// Data fork
// Various checksizes
for (auto size : {0, 5000, 1024 * 1024}) {
- fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream, size, progressUpdateCallback).c_str());
+ fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream, size, progressUpdateCallback, this).c_str());
dataForkStream->seek(0);
}
// Tail checksums with checksize 5000
dataForkStream->seek(-5000, SEEK_END);
- fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream, 0, progressUpdateCallback).c_str());
+ fileChecksum.push_back(Common::computeStreamMD5AsString(*dataForkStream, 0, progressUpdateCallback, this).c_str());
// Resource fork
if (macFile.hasResFork()) {
// Various checksizes
for (auto size : {0, 5000, 1024 * 1024}) {
- fileChecksum.push_back(macFile.computeResForkMD5AsString(size, false, progressUpdateCallback).c_str());
+ fileChecksum.push_back(macFile.computeResForkMD5AsString(size, false, progressUpdateCallback, this).c_str());
}
// Tail checksums with checksize 5000
- fileChecksum.push_back(macFile.computeResForkMD5AsString(5000, true, progressUpdateCallback).c_str());
+ fileChecksum.push_back(macFile.computeResForkMD5AsString(5000, true, progressUpdateCallback, this).c_str());
fileChecksums.push_back(fileChecksum);
}
@@ -397,12 +396,12 @@ Common::Array<Common::StringArray> IntegrityDialog::generateChecksums(Common::Pa
Common::Array<Common::String> fileChecksum = {filename.toString()};
// Various checksizes
for (auto size : {0, 5000, 1024 * 1024}) {
- fileChecksum.push_back(Common::computeStreamMD5AsString(file, size, progressUpdateCallback).c_str());
+ fileChecksum.push_back(Common::computeStreamMD5AsString(file, size, progressUpdateCallback, this).c_str());
file.seek(0);
}
// Tail checksums with checksize 5000
file.seek(-5000, SEEK_END);
- fileChecksum.push_back(Common::computeStreamMD5AsString(file, 0, progressUpdateCallback).c_str());
+ fileChecksum.push_back(Common::computeStreamMD5AsString(file, 0, progressUpdateCallback, this).c_str());
file.close();
fileChecksums.push_back(fileChecksum);
diff --git a/gui/integrity-dialog.h b/gui/integrity-dialog.h
index 1c58b1777ef..4cec4147342 100644
--- a/gui/integrity-dialog.h
+++ b/gui/integrity-dialog.h
@@ -62,7 +62,7 @@ class IntegrityDialog : public Dialog, public CommandSender {
ButtonWidget *_copyEmailButton;
bool _close;
- uint32 lastEventPoll;
+ uint32 _lastEventPoll;
Common::U32String getSizeLabelText();
@@ -74,15 +74,10 @@ public:
/**
- * Callback funtion which updates the progress bar every 500ms
- * It also poll events to allow mouse movements/button interactions to avoid freezing when processing large files
+ * Updates the progress bar every 500ms
+ * Includes polling to avoid freezing when processing files
*/
- static bool progressUpdateCallback(int bytesProcessed);
-
- /**
- * Poll events during callback
- */
- void pollEvent(Common::Event &event);
+ bool progressUpdate(int bytesProcessed);
void sendJSON();
void checksumResponseCallback(const Common::JSONValue *r);
More information about the Scummvm-git-logs
mailing list