aboutsummaryrefslogtreecommitdiff
path: root/engines/m4/m4.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2010-11-02 00:13:04 +0000
committerPaul Gilbert2010-11-02 00:13:04 +0000
commit997625c3b3189c2f76c8be74727b288b5e789699 (patch)
treee0574f299bfe3617b1f7ceecebebbc1e7e1a9e5c /engines/m4/m4.cpp
parent8252fc30ce600960dc855dcecfa29092c5d6ef57 (diff)
downloadscummvm-rg350-997625c3b3189c2f76c8be74727b288b5e789699.tar.gz
scummvm-rg350-997625c3b3189c2f76c8be74727b288b5e789699.tar.bz2
scummvm-rg350-997625c3b3189c2f76c8be74727b288b5e789699.zip
M4: Reworked dumpFile to use Common::DumpFile
svn-id: r54033
Diffstat (limited to 'engines/m4/m4.cpp')
-rw-r--r--engines/m4/m4.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/engines/m4/m4.cpp b/engines/m4/m4.cpp
index 34fcef7c88..718daa571a 100644
--- a/engines/m4/m4.cpp
+++ b/engines/m4/m4.cpp
@@ -266,20 +266,23 @@ void MadsM4Engine::loadMenu(MenuType menuType, bool loadSaveFromHotkey, bool cal
_viewManager->moveToFront(view);
}
+#define DUMP_BUFFER_SIZE 1024
+
void MadsM4Engine::dumpFile(const char* filename, bool uncompress) {
-#if 0
- // FIXME: The following code is not portable and hence has been disabled.
- // Try replacing FILE by Common::DumpFile.
+ Common::DumpFile f;
+ byte buffer[DUMP_BUFFER_SIZE];
Common::SeekableReadStream *fileS = res()->get(filename);
- byte buffer[256];
- FILE *destFile = fopen(filename, "wb");
+
+ if (!f.open(filename))
+ error("Could not open '%s' for writing", filename);
+
int bytesRead = 0;
- printf("Dumping %s, size: %i\n", filename, fileS->size());
+ warning("Dumping %s, size: %i\n", filename, fileS->size());
if (!uncompress) {
while (!fileS->eos()) {
- bytesRead = fileS->read(buffer, 256);
- fwrite(buffer, bytesRead, 1, destFile);
+ bytesRead = fileS->read(buffer, DUMP_BUFFER_SIZE);
+ f.write(buffer, bytesRead);
}
} else {
MadsPack packData(fileS);
@@ -288,17 +291,16 @@ void MadsM4Engine::dumpFile(const char* filename, bool uncompress) {
sourceUnc = packData.getItemStream(i);
printf("Dumping compressed chunk %i of %i, size is %i\n", i + 1, packData.getCount(), sourceUnc->size());
while (!sourceUnc->eos()) {
- bytesRead = sourceUnc->read(buffer, 256);
- fwrite(buffer, bytesRead, 1, destFile);
+ bytesRead = sourceUnc->read(buffer, DUMP_BUFFER_SIZE);
+ f.write(buffer, bytesRead);
}
delete sourceUnc;
}
}
- fclose(destFile);
+ f.close();
res()->toss(filename);
res()->purge();
-#endif
}
/*--------------------------------------------------------------------------*/