Permalink
Comparing changes
Open a pull request
- 7 commits
- 2 files changed
- 0 commit comments
- 2 contributors
Commits on Sep 01, 2014
This may make it easier to ask users for the MD5 sum of a file, in case we suspect a bug report is caused by damaged files.
Commits on Sep 07, 2014
I don't know of any good way of transforming file names to base file names, so document that "md5mac" expects the base file name. Even though it currently will accept MacBinary file names.
Commits on Oct 31, 2014
Commits on Dec 05, 2014
Add "md5" command to the debugger
Unified
Split
Showing
with
85 additions
and 0 deletions.
- +81 −0 gui/debugger.cpp
- +4 −0 gui/debugger.h
| @@ -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 | ||
| @@ -213,6 +213,10 @@ class Debugger { | ||
| 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); | ||