aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Turner2014-12-05 23:13:12 +0000
committerDavid Turner2014-12-05 23:13:12 +0000
commite3c5eb9afa59d59cb3415a1ddde9753035db7e89 (patch)
tree06b6b5c2d5c375fdfc1ddd682de680110f9341d2
parent665c813496f5a5b18352392d0a3d6d3a9674e872 (diff)
parent6bc36cbdf412db1ce10adcdc50eb98135908612e (diff)
downloadscummvm-rg350-e3c5eb9afa59d59cb3415a1ddde9753035db7e89.tar.gz
scummvm-rg350-e3c5eb9afa59d59cb3415a1ddde9753035db7e89.tar.bz2
scummvm-rg350-e3c5eb9afa59d59cb3415a1ddde9753035db7e89.zip
Merge pull request #497 from eriktorbjorn/md5-debug
Add "md5" command to the debugger
-rw-r--r--gui/debugger.cpp81
-rw-r--r--gui/debugger.h4
2 files changed, 85 insertions, 0 deletions
diff --git a/gui/debugger.cpp b/gui/debugger.cpp
index dcdc18d7b9..216bd626fe 100644
--- a/gui/debugger.cpp
+++ b/gui/debugger.cpp
@@ -27,6 +27,13 @@
#include "common/debug-channels.h"
#include "common/system.h"
+#ifndef DISABLE_MD5
+#include "common/md5.h"
+#include "common/archive.h"
+#include "common/macresman.h"
+#include "common/stream.h"
+#endif
+
#include "engines/engine.h"
#include "gui/debugger.h"
@@ -61,6 +68,10 @@ Debugger::Debugger() {
registerCmd("help", WRAP_METHOD(Debugger, cmdHelp));
registerCmd("openlog", WRAP_METHOD(Debugger, cmdOpenLog));
+#ifndef DISABLE_MD5
+ registerCmd("md5", WRAP_METHOD(Debugger, cmdMd5));
+ registerCmd("md5mac", WRAP_METHOD(Debugger, cmdMd5Mac));
+#endif
registerCmd("debuglevel", WRAP_METHOD(Debugger, cmdDebugLevel));
registerCmd("debugflag_list", WRAP_METHOD(Debugger, cmdDebugFlagsList));
@@ -502,6 +513,76 @@ bool Debugger::cmdOpenLog(int argc, const char **argv) {
return true;
}
+#ifndef DISABLE_MD5
+struct ArchiveMemberLess {
+ bool operator()(const Common::ArchiveMemberPtr &x, const Common::ArchiveMemberPtr &y) const {
+ return (*x).getDisplayName().compareToIgnoreCase((*y).getDisplayName()) < 0;
+ }
+};
+
+bool Debugger::cmdMd5(int argc, const char **argv) {
+ if (argc < 2) {
+ debugPrintf("md5 <filename | pattern>\n");
+ } else {
+ // Assume that spaces are part of a single filename.
+ Common::String filename = argv[1];
+ for (int i = 2; i < argc; i++) {
+ filename = filename + " " + argv[i];
+ }
+ Common::ArchiveMemberList list;
+ SearchMan.listMatchingMembers(list, filename);
+ if (list.empty()) {
+ debugPrintf("File '%s' not found\n", filename.c_str());
+ } else {
+ sort(list.begin(), list.end(), ArchiveMemberLess());
+ for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) {
+ Common::ReadStream *stream = (*iter)->createReadStream();
+ Common::String md5 = Common::computeStreamMD5AsString(*stream, 0);
+ debugPrintf("%s %s\n", md5.c_str(), (*iter)->getDisplayName().c_str());
+ delete stream;
+ }
+ }
+ }
+ return true;
+}
+
+bool Debugger::cmdMd5Mac(int argc, const char **argv) {
+ if (argc < 2) {
+ debugPrintf("md5mac <base filename>\n");
+ } else {
+ // Assume that spaces are part of a single filename.
+ Common::String filename = argv[1];
+ for (int i = 2; i < argc; i++) {
+ filename = filename + " " + argv[i];
+ }
+ Common::MacResManager macResMan;
+ // FIXME: There currently isn't any way to tell the Mac resource
+ // manager to open a specific file. Instead, it takes a "base name"
+ // and constructs a file name out of that. While usually a desirable
+ // thing, it's not ideal here.
+ if (!macResMan.open(filename)) {
+ debugPrintf("Resource file '%s' not found\n", filename.c_str());
+ } else {
+ if (!macResMan.hasResFork() && !macResMan.hasDataFork()) {
+ debugPrintf("'%s' has neither data not resource fork\n", macResMan.getBaseFileName().c_str());
+ } else {
+ // The resource fork is probably the most relevant one.
+ if (macResMan.hasResFork()) {
+ Common::String md5 = macResMan.computeResForkMD5AsString(0);
+ debugPrintf("%s %s (resource)\n", md5.c_str(), macResMan.getBaseFileName().c_str());
+ }
+ if (macResMan.hasDataFork()) {
+ Common::ReadStream *stream = macResMan.getDataFork();
+ Common::String md5 = Common::computeStreamMD5AsString(*stream, 0);
+ debugPrintf("%s %s (data)\n", md5.c_str(), macResMan.getBaseFileName().c_str());
+ }
+ }
+ macResMan.close();
+ }
+ }
+ return true;
+}
+#endif
bool Debugger::cmdDebugLevel(int argc, const char **argv) {
if (argc == 1) { // print level
diff --git a/gui/debugger.h b/gui/debugger.h
index 175eb33960..ef6f900974 100644
--- a/gui/debugger.h
+++ b/gui/debugger.h
@@ -213,6 +213,10 @@ protected:
bool cmdExit(int argc, const char **argv);
bool cmdHelp(int argc, const char **argv);
bool cmdOpenLog(int argc, const char **argv);
+#ifndef DISABLE_MD5
+ bool cmdMd5(int argc, const char **argv);
+ bool cmdMd5Mac(int argc, const char **argv);
+#endif
bool cmdDebugLevel(int argc, const char **argv);
bool cmdDebugFlagsList(int argc, const char **argv);
bool cmdDebugFlagEnable(int argc, const char **argv);