Skip to content

Commit

Permalink
WINTERMUTE: Add a console command, "dump_file", to dump resource file…
Browse files Browse the repository at this point in the history
…s to disk
  • Loading branch information
bluegr committed Mar 30, 2013
1 parent 880f264 commit 4990bdf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
38 changes: 37 additions & 1 deletion engines/wintermute/debugger.cpp
Expand Up @@ -22,12 +22,15 @@

#include "engines/wintermute/debugger.h"
#include "engines/wintermute/wintermute.h"
#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/base/base_game.h"

namespace Wintermute {

Console::Console(WintermuteEngine *vm) : GUI::Debugger(), _engineRef(vm) {
DCmd_Register("show_fps", WRAP_METHOD(Console, Cmd_ShowFps));
DCmd_Register("dump_file", WRAP_METHOD(Console, Cmd_DumpFile));
}

Console::~Console(void) {
Expand All @@ -44,5 +47,38 @@ bool Console::Cmd_ShowFps(int argc, const char **argv) {
}
return true;
}


bool Console::Cmd_DumpFile(int argc, const char **argv) {
if (argc != 3) {
DebugPrintf("Usage: %s <file path> <output file name>\n", argv[0]);
return true;
}

Common::String filePath = argv[1];
Common::String outFileName = argv[2];

BaseFileManager *fileManager = BaseEngine::instance().getFileManager();
Common::SeekableReadStream *inFile = fileManager->openFile(filePath);
if (!inFile) {
DebugPrintf("File '%s' not found\n", argv[1]);
return true;
}

Common::DumpFile *outFile = new Common::DumpFile();
outFile->open(outFileName);

byte *data = new byte[inFile->size()];
inFile->read(data, inFile->size());
outFile->write(data, inFile->size());
outFile->finalize();
outFile->close();
delete[] data;

delete outFile;
delete inFile;

DebugPrintf("Resource file '%s' dumped to file '%s'\n", argv[1], argv[2]);
return true;
}

} // end of namespace Wintermute
1 change: 1 addition & 0 deletions engines/wintermute/debugger.h
Expand Up @@ -34,6 +34,7 @@ class Console : public GUI::Debugger {
virtual ~Console();

bool Cmd_ShowFps(int argc, const char **argv);
bool Cmd_DumpFile(int argc, const char **argv);
private:
WintermuteEngine *_engineRef;
};
Expand Down

0 comments on commit 4990bdf

Please sign in to comment.