[Scummvm-cvs-logs] SF.net SVN: scummvm:[47383] tools/trunk/engines/mohawk
mthreepwood at users.sourceforge.net
mthreepwood at users.sourceforge.net
Tue Jan 19 17:57:43 CET 2010
Revision: 47383
http://scummvm.svn.sourceforge.net/scummvm/?rev=47383&view=rev
Author: mthreepwood
Date: 2010-01-19 16:57:36 +0000 (Tue, 19 Jan 2010)
Log Message:
-----------
Add autodetection of the Mohawk archive format (old vs new) and remove the command line options for specifying that. Some minor cleanup too.
Modified Paths:
--------------
tools/trunk/engines/mohawk/extract_mohawk.cpp
tools/trunk/engines/mohawk/mohawk_file.cpp
tools/trunk/engines/mohawk/mohawk_file.h
Modified: tools/trunk/engines/mohawk/extract_mohawk.cpp
===================================================================
--- tools/trunk/engines/mohawk/extract_mohawk.cpp 2010-01-19 15:20:29 UTC (rev 47382)
+++ tools/trunk/engines/mohawk/extract_mohawk.cpp 2010-01-19 16:57:36 UTC (rev 47383)
@@ -109,11 +109,11 @@
// File output naming format preserves all archive information...
char *strBuf = (char *)malloc(256);
sprintf(strBuf, "%04d_%s_%d", output.index, tag2str(output.tag), output.id);
- if(!output.name.empty())
- sprintf(strBuf+strlen(strBuf), "_%s", output.name.c_str());
+ if (!output.name.empty())
+ sprintf(strBuf + strlen(strBuf), "_%s", output.name.c_str());
output.name = strBuf;
- if(doConversion) {
+ if (doConversion) {
// Intercept the sound tags
if (output.tag == ID_TWAV || output.tag == ID_MSND || output.tag == ID_SND) {
convertSoundResource(output);
@@ -141,15 +141,12 @@
void printUsage(const char *appName) {
printf("Usage: %s [options] <mohawk archive> [tag id]\n", appName);
- printf("Options : --raw : Dump Resources as raw binary dump (default)");
- printf(" --convert : Dump Resources as converted files");
- printf(" --new : Load Mohawk Archive assuming new file format (default)");
- printf(" --old : Load Mohawk Archive assuming old file format");
+ printf("Options : --raw Dump Resources as raw binary dump (default)\n");
+ printf(" --convert Dump Resources as converted files\n");
}
int main(int argc, char *argv[]) {
bool doConversion = false;
- bool oldMohawkFormat = false;
int archiveArg;
// Parse parameters
@@ -160,14 +157,10 @@
break;
// Decode options
- if(current.equals("--raw"))
+ if (current.equals("--raw"))
doConversion = false;
- else if(current.equals("--convert"))
+ else if (current.equals("--convert"))
doConversion = true;
- else if(current.equals("--new"))
- oldMohawkFormat = false;
- else if(current.equals("--old"))
- oldMohawkFormat = true;
else {
printf("Unknown argument : \"%s\"\n", argv[archiveArg]);
printUsage(argv[0]);
@@ -175,8 +168,7 @@
}
}
- if(! (archiveArg == argc - 1) || // No tag and id
- (archiveArg == argc - 2 - 1)) { // tag and id
+ if (archiveArg != argc - 1 && archiveArg != argc - 2 - 1) { // No tag and id or tag and id present
printUsage(argv[0]);
return 1;
}
@@ -188,19 +180,20 @@
}
// Open the file as a Mohawk archive
- MohawkFile *mohawkFile;
- if(oldMohawkFormat)
- mohawkFile = new OldMohawkFile();
- else
- mohawkFile = new MohawkFile();
- mohawkFile->open(new Common::File(file));
+ MohawkFile *mohawkFile = MohawkFile::createMohawkFile(new Common::File(file));
+
+ if (!mohawkFile) {
+ printf("\'%s\' is not a valid Mohawk archive\n", argv[1]);
+ fclose(file);
+ return 1;
+ }
// Allocate a buffer for the output
outputBuffer = (byte *)malloc(MAX_BUF_SIZE);
if (argc == archiveArg - 2 - 1) {
- uint32 tag = READ_BE_UINT32(argv[archiveArg+1]);
- uint16 id = (uint16)atoi(argv[archiveArg+2]);
+ uint32 tag = READ_BE_UINT32(argv[archiveArg + 1]);
+ uint16 id = (uint16)atoi(argv[archiveArg + 2]);
MohawkOutputStream output = mohawkFile->getRawData(tag, id);
@@ -219,9 +212,7 @@
}
}
- printf ("Done!\n");
-
+ printf("Done!\n");
free(outputBuffer);
-
return 0;
}
Modified: tools/trunk/engines/mohawk/mohawk_file.cpp
===================================================================
--- tools/trunk/engines/mohawk/mohawk_file.cpp 2010-01-19 15:20:29 UTC (rev 47382)
+++ tools/trunk/engines/mohawk/mohawk_file.cpp 2010-01-19 16:57:36 UTC (rev 47383)
@@ -394,3 +394,26 @@
_curExTypeIndex++;
return output;
}
+
+MohawkFile *MohawkFile::createMohawkFile(Common::SeekableReadStream *stream) {
+ uint32 headerTag = stream->readUint32BE();
+
+ MohawkFile *mohawkFile = 0;
+
+ if (headerTag == ID_MHWK) {
+ stream->readUint32BE(); // File size, ignore
+ headerTag = stream->readUint32BE();
+ if (headerTag == ID_RSRC)
+ mohawkFile = new MohawkFile();
+ } else if (headerTag == 6 || SWAP_BYTES_32(headerTag) == 6) {
+ // Assume the old archive format
+ mohawkFile = new OldMohawkFile();
+ }
+
+ stream->seek(0);
+
+ if (mohawkFile)
+ mohawkFile->open(stream);
+
+ return mohawkFile;
+}
Modified: tools/trunk/engines/mohawk/mohawk_file.h
===================================================================
--- tools/trunk/engines/mohawk/mohawk_file.h 2010-01-19 15:20:29 UTC (rev 47382)
+++ tools/trunk/engines/mohawk/mohawk_file.h 2010-01-19 16:57:36 UTC (rev 47383)
@@ -178,6 +178,9 @@
public:
MohawkFile();
virtual ~MohawkFile() { close(); }
+
+ // Detect new/old Mohawk archive format. Return NULL if the file is neither.
+ static MohawkFile *createMohawkFile(Common::SeekableReadStream *stream);
virtual void open(Common::SeekableReadStream *stream);
void close();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list