[Scummvm-cvs-logs] SF.net SVN: scummvm:[43015] tools/branches/gsoc2009-gui
Remere at users.sourceforge.net
Remere at users.sourceforge.net
Mon Aug 3 00:48:12 CEST 2009
Revision: 43015
http://scummvm.svn.sourceforge.net/scummvm/?rev=43015&view=rev
Author: Remere
Date: 2009-08-02 22:48:06 +0000 (Sun, 02 Aug 2009)
Log Message:
-----------
*Converted extract_cine, extract_t7g_mac, which were previously forgotten.
*Fixes to many tools having to do with confusion between read/readN.
*Some other small fixes...
Modified Paths:
--------------
tools/branches/gsoc2009-gui/compress_agos.cpp
tools/branches/gsoc2009-gui/compress_gob.cpp
tools/branches/gsoc2009-gui/compress_kyra.cpp
tools/branches/gsoc2009-gui/compress_saga.cpp
tools/branches/gsoc2009-gui/compress_tinsel.cpp
tools/branches/gsoc2009-gui/compress_touche.cpp
tools/branches/gsoc2009-gui/compress_tucker.cpp
tools/branches/gsoc2009-gui/extract_cine.cpp
tools/branches/gsoc2009-gui/extract_cine.h
tools/branches/gsoc2009-gui/extract_gob_stk.cpp
tools/branches/gsoc2009-gui/extract_kyra.cpp
tools/branches/gsoc2009-gui/extract_t7g_mac.cpp
tools/branches/gsoc2009-gui/tools.cpp
tools/branches/gsoc2009-gui/util.cpp
tools/branches/gsoc2009-gui/util.h
Modified: tools/branches/gsoc2009-gui/compress_agos.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_agos.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/compress_agos.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -45,12 +45,12 @@
_output_idx.open(_outputPath, "wb");
_input.open(TEMP_IDX, "rb");
- while ((size = _input.read(fbuf, 1, 2048)) > 0) {
+ while ((size = _input.readN(fbuf, 1, 2048)) > 0) {
_output_idx.write(fbuf, 1, size);
}
_input.open(TEMP_DAT, "rb");
- while ((size = _input.read(fbuf, 1, 2048)) > 0) {
+ while ((size = _input.readN(fbuf, 1, 2048)) > 0) {
_output_idx.write(fbuf, 1, size);
}
@@ -120,7 +120,7 @@
sprintf(outname, "%s", tempEncoded);
File f(outname, "rb");
tot_size = 0;
- while ((size = f.read(fbuf, 1, 2048)) > 0) {
+ while ((size = f.readN(fbuf, 1, 2048)) > 0) {
tot_size += size;
_output_snd.write(fbuf, 1, size);
}
Modified: tools/branches/gsoc2009-gui/compress_gob.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_gob.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/compress_gob.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -308,7 +308,7 @@
uint32 tmpSize = 0;
do {
- count = src.read(buffer, 1, 4096);
+ count = src.readN(buffer, 1, 4096);
stk.write(buffer, 1, count);
tmpSize += count;
} while (count == 4096);
@@ -437,7 +437,7 @@
src2.open(compChunk->name, "rb");
do {
- readCount = src1.read(buf1, 1, 4096);
+ readCount = src1.readN(buf1, 1, 4096);
src2.read(buf2, 1, 4096);
for (int i = 0; checkFl & (i < readCount); i++)
if (buf1[i] != buf2[i])
Modified: tools/branches/gsoc2009-gui/compress_kyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_kyra.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/compress_kyra.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -136,7 +136,7 @@
if (size == outSize) {
int readSize = size;
while (readSize > 0) {
- int read = in.read(outputBuffer, 1, readSize);
+ int read = in.readN(outputBuffer, 1, readSize);
if (read <= 0)
error("[1] Couldn't read data");
readSize -= read;
@@ -154,7 +154,7 @@
int readSize = size;
while (readSize > 0) {
- int read = in.read(inputBuffer, 1, readSize);
+ int read = in.readN(inputBuffer, 1, readSize);
if (read <= 0)
error("[2] Couldn't read data");
readSize -= read;
Modified: tools/branches/gsoc2009-gui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_saga.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/compress_saga.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -174,14 +174,14 @@
}
uint32 CompressSaga::copyFile(const char *fromFileName, File &outputFile) {
- uint32 size;
+ size_t size;
char fbuf[2048];
File tempf(fromFileName, "rb");
if (!tempf.isOpen())
error("Unable to open %s", fromFileName);
- while ((size = (uint32)tempf.read(fbuf, 1, sizeof(fbuf))) > 0) {
+ while ((size = tempf.readN(fbuf, 1, sizeof(fbuf))) > 0) {
outputFile.write(fbuf, 1, size);
}
size = tempf.pos();
@@ -189,14 +189,14 @@
}
void CompressSaga::copyFile(File &inputFile, uint32 inputSize, const char *toFileName) {
- uint32 size;
+ size_t size;
char fbuf[2048];
File tempf(toFileName, "wb");
if (!tempf.isOpen())
error("Unable to open %s", toFileName);
while (inputSize > 0) {
- size = (uint32)inputFile.read(fbuf, 1, inputSize > sizeof(fbuf) ? sizeof(fbuf) : inputSize);
+ size = inputFile.readN(fbuf, 1, inputSize > sizeof(fbuf) ? sizeof(fbuf) : inputSize);
if (size == 0) {
error("Unable to copy file");
}
Modified: tools/branches/gsoc2009-gui/compress_tinsel.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tinsel.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/compress_tinsel.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -75,7 +75,7 @@
curFileHandle.open(TEMP_RAW, "wb");
copyLeft = sampleSize;
while (copyLeft > 0) {
- doneRead = _input_smp.read(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft);
+ doneRead = _input_smp.readN(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft);
if (doneRead <= 0)
break;
copyLeft -= (int)doneRead;
@@ -96,7 +96,7 @@
_output_smp.writeUint32LE(copyLeft);
// Write actual data
while (copyLeft > 0) {
- doneRead = curFileHandle.read(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft);
+ doneRead = curFileHandle.readN(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft);
if (doneRead <= 0)
break;
copyLeft -= (int)doneRead;
@@ -243,7 +243,7 @@
_output_smp.writeUint32LE(copyLeft);
// Write actual data
while (copyLeft > 0) {
- doneRead = curFileHandle.read(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft);
+ doneRead = curFileHandle.readN(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft);
if (doneRead <= 0)
break;
copyLeft -= (int)doneRead;
Modified: tools/branches/gsoc2009-gui/compress_touche.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_touche.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/compress_touche.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -82,7 +82,7 @@
size_table[i] = 0;
- while ((size = temp.read(buf, 1, 2048)) > 0) {
+ while ((size = temp.readN(buf, 1, 2048)) > 0) {
output.write(buf, 1, size);
size_table[i] += size;
}
Modified: tools/branches/gsoc2009-gui/compress_tucker.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tucker.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/compress_tucker.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -55,7 +55,7 @@
int sz, compress_sz = 0;
File input_temp(tempEncoded, "rb");
- while ((sz = input_temp.read(buf, 1, sizeof(buf))) > 0) {
+ while ((sz = input_temp.readN(buf, 1, sizeof(buf))) > 0) {
if ((sz = output.write(buf, 1, sz)) > 0) {
compress_sz += sz;
}
@@ -66,7 +66,7 @@
int CompressTucker::compress_file_wav(File &input, File &output) {
char buf[8];
- if (input.read(buf, 1, 8) == 8 && memcmp(buf, "RIFF", 4) == 0) {
+ if (input.readN(buf, 1, 8) == 8 && memcmp(buf, "RIFF", 4) == 0) {
extractAndEncodeWAV(TEMP_WAV, input, _format);
return append_compress_file(output);
}
Modified: tools/branches/gsoc2009-gui/extract_cine.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_cine.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/extract_cine.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -35,8 +35,25 @@
#include "extract_cine.h"
+#include <algorithm>
+
////////////////////////////////////////////////////////////////////////////
+ExtractCine::ExtractCine(const std::string &name) : Tool(name, TOOLTYPE_EXTRACTION) {
+
+ ToolInput input;
+ input.format = "*.CNF";
+ _inputPaths.push_back(input);
+
+ _shorthelp = "Used to unpack Delphine's Cinematique engine's archive files.";
+ _helptext =
+ "Usage: " + getName() + " [params] [-o outputdir] <archivefile>\n" +
+ _shorthelp + "\n" +
+ "Supports using Operation Stealth's 'vol.cnf' file as input.\n";
+}
+
+////////////////////////////////////////////////////////////////////////////
+
uint32 CineUnpacker::readSource() {
if (_src < _srcBegin || _src + 4 > _srcEnd) {
_error = true;
@@ -155,37 +172,37 @@
////////////////////////////////////////////////////////////////////////////
-static void unpackFile(FILE *fp, const char *outDir) {
- char filePath[512], fileName[15];
+void ExtractCine::unpackFile(File &file) {
+ char fileName[15];
- unsigned int entryCount = readUint16BE(fp); // How many entries?
- unsigned int entrySize = readUint16BE(fp); // How many bytes per entry?
+ unsigned int entryCount = file.readUint16BE(); // How many entries?
+ unsigned int entrySize = file.readUint16BE(); // How many bytes per entry?
assert(entrySize == 0x1e);
while (entryCount--) {
- fp.read(fileName, 14, 1);
+ file.read(fileName, 14, 1);
fileName[14] = '\0';
- sprintf(filePath, "%s/%s", outDir, fileName);
- FILE *fpOut = fopen(filePath, "wb");
- uint32 offset = readUint32BE(fp);
- unsigned int packedSize = readUint32BE(fp);
- unsigned int unpackedSize = readUint32BE(fp);
- readUint32BE(fp);
- unsigned int savedPos = fp.pos();
+ Filename outPath(_outputPath);
+ outPath.setFullName(fileName);
+
+ uint32 offset = file.readUint32BE();
+ unsigned int packedSize = file.readUint32BE();
+ unsigned int unpackedSize = file.readUint32BE();
+ // Skip one
+ file.readUint32BE();
+ unsigned int savedPos = file.pos();
- if (!fpOut) {
- printf("ERROR: unable to open '%s' for writing\n", filePath);
- continue;
- }
- printf("unpacking '%s' ... ", filePath);
+ print("unpacking '%s' ... ", outPath.getFullName());
- fseek(fp, offset, SEEK_SET);
+ File fpOut(outPath, "wb");
+
+ file.seek(offset, SEEK_SET);
assert(unpackedSize >= packedSize);
uint8 *data = (uint8 *)calloc(unpackedSize, 1);
uint8 *packedData = (uint8 *)calloc(packedSize, 1);
assert(data);
assert(packedData);
- fp.read(packedData, packedSize, 1);
+ file.read(packedData, packedSize, 1);
bool status = true;
if (packedSize != unpackedSize) {
CineUnpacker cineUnpacker;
@@ -195,20 +212,19 @@
}
free(packedData);
fpOut.write(data, unpackedSize, 1);
- fclose(fpOut);
free(data);
if (!status) {
- printf("CRC ERROR");
+ print("CRC ERROR");
} else {
- printf("ok");
+ print("ok");
}
- printf(", packedSize %u unpackedSize %u\n", packedSize, unpackedSize);
- fseek(fp, savedPos, SEEK_SET);
+ print(", packedSize %u unpackedSize %u\n", packedSize, unpackedSize);
+ file.seek(savedPos, SEEK_SET);
}
}
-void fixVolCnfFileName(char *dst, const uint8 *src) {
+void ExtractCine::fixVolCnfFileName(char *dst, const uint8 *src) {
char *ext, *end;
memcpy(dst, src, 8);
@@ -231,87 +247,63 @@
}
}
-void unpackAllResourceFiles(const char *filename, const char *outDir) {
- FILE *fp = fopen(filename, "rb");
- if (!fp) {
- error("Unable to open file '%s'", filename);
- }
+void ExtractCine::unpackAllResourceFiles(const Filename &filename) {
+ File f(filename, "rb");
uint32 unpackedSize, packedSize;
{
char header[8];
- fp.read(header, 8, 1);
+ f.read(header, 8, 1);
if (memcmp(header, "ABASECP", 7) == 0) {
- unpackedSize = readUint32BE(fp);
- packedSize = readUint32BE(fp);
+ unpackedSize = f.readUint32BE();
+ packedSize = f.readUint32BE();
} else {
- fseek(fp, 0, SEEK_END);
- unpackedSize = packedSize = fp.pos(); /* Get file size */
- fseek(fp, 0, SEEK_SET);
+ unpackedSize = packedSize = f.pos(); /* Get file size */
+ f.seek(0, SEEK_SET);
}
}
+
assert(unpackedSize >= packedSize);
uint8 *buf = (uint8 *)calloc(unpackedSize, 1);
assert(buf);
- fp.read(buf, packedSize, 1);
- fclose(fp);
+ f.read(buf, packedSize, 1);
+
if (packedSize != unpackedSize) {
CineUnpacker cineUnpacker;
if (!cineUnpacker.unpack(buf, packedSize, buf, unpackedSize)) {
error("Failed to unpack 'vol.cnf' data");
}
}
+
unsigned int resourceFilesCount = READ_BE_UINT16(&buf[0]);
unsigned int entrySize = READ_BE_UINT16(&buf[2]);
- printf("--- Unpacking all %d resource files from 'vol.cnf' (entrySize = %d):\n", resourceFilesCount, entrySize);
+ print("--- Unpacking all %d resource files from 'vol.cnf' (entrySize = %d):\n", resourceFilesCount, entrySize);
char resourceFileName[9];
for (unsigned int i = 0; i < resourceFilesCount; ++i) {
memcpy(resourceFileName, &buf[4 + i * entrySize], 8);
resourceFileName[8] = 0;
- FILE *fpResFile = fopen(resourceFileName, "rb");
- if (fpResFile) {
- printf("--- Unpacking resource file %s:\n", resourceFileName);
- unpackFile(fpResFile, outDir);
- fclose(fpResFile);
- } else {
- printf("ERROR: Unable to open resource file %s\n", resourceFileName);
- }
+
+ File fpResFile(resourceFileName, "rb");
+ print("--- Unpacking resource file %s:\n", resourceFileName);
+ unpackFile(fpResFile);
}
free(buf);
}
-int showUsage() {
- printf("USAGE: extract_cine [input file] [output directory]\n" \
- "Supports using Operation Stealth's 'vol.cnf' file as input.\n");
- return -1;
-}
+void ExtractCine::execute() {
+ Filename infilename(_inputPaths[0].path);
-int main(int argc, char *argv[]) {
- int i;
- char tmp[512];
+ std::string fname = infilename.getFullName();
+ std::transform(fname.begin(), fname.end(), fname.begin(), toupper);
- if (argc == 3) {
- strcpy(tmp, argv[1]);
- for (i = 0; tmp[i] != 0; i++) {
- tmp[i] = toupper(tmp[i]);
- }
- if (!strcmp(tmp, "VOL.CNF")) {
- /* Unpack all archive files listed in 'vol.cnf' */
- unpackAllResourceFiles(argv[1], argv[2]);
- } else {
- /* Unpack a single archive file */
- FILE *fp = fopen(argv[1], "rb");
- if (fp) {
- unpackFile(fp, argv[2]);
- fclose(fp);
- } else {
- printf("Couldn't open input file '%s'\n", argv[1]);
- return -1;
- }
- }
+ if (fname == "VOL.CNF") {
+ /* Unpack all archive files listed in 'vol.cnf' */
+ unpackAllResourceFiles(infilename);
} else {
- return showUsage();
+ /* Unpack a single archive file */
+ File f(infilename, "rb");
+
+ unpackFile(f);
}
- return 0;
}
Modified: tools/branches/gsoc2009-gui/extract_cine.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_cine.h 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/extract_cine.h 2009-08-02 22:48:06 UTC (rev 43015)
@@ -1,7 +1,7 @@
#ifndef EXTRACT_CINE_H
#define EXTRACT_CINE_H
-#include "util.h"
+#include "tool.h"
/**
* A LZ77 style decompressor for Delphine's data files
@@ -84,4 +84,17 @@
byte *_dstEnd; //!< Destination buffer's end
};
+
+class ExtractCine : public Tool {
+public:
+ ExtractCine(const std::string &name = "extract_cine");
+
+ virtual void execute();
+
+protected:
+ void unpackFile(File &file);
+ void fixVolCnfFileName(char *dst, const uint8 *src);
+ void unpackAllResourceFiles(const Filename &filename);
+};
+
#endif
Modified: tools/branches/gsoc2009-gui/extract_gob_stk.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_gob_stk.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/extract_gob_stk.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -156,8 +156,7 @@
buffer[14] = '\0';
sprintf(debugStr, "File generated on %s by ", buffer);
- if (stk.read(buffer, 1, 8) < 8)
- throw ToolException("Unexpected EOF");
+ stk.read(buffer, 1, 8);
buffer[8] = '\0';
strcat(debugStr, buffer);
@@ -197,13 +196,11 @@
stk.seek(miscPos + (cpt * 61), SEEK_SET);
filenamePos = stk.readUint32LE();
- if (stk.read(buffer, 1, 36) < 36)
- throw ToolException("Unexpected EOF in Misc Section");
+ stk.read(buffer, 1, 36);
curChunk->size = stk.readUint32LE();
decompSize = stk.readUint32LE();
- if (stk.read(buffer, 1, 5) < 5)
- throw ToolException("Unexpected EOF in Misc Section");
+ stk.read(buffer, 1, 5);
filePos = stk.readUint32LE();
compressFlag = stk.readUint32LE();
Modified: tools/branches/gsoc2009-gui/extract_kyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_kyra.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/extract_kyra.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -39,7 +39,7 @@
_shorthelp = "Used to extract The Legend of Kyrandia series data file contents.";
_helptext =
- "Usage: " + getName() + "[params] [-o output] <archivefile> [-o output]\n" +
+ "Usage: " + getName() + " [params] [-o output] <archivefile>\n" +
_shorthelp + "\n" +
"Default output path is ./out/\n" +
"nParams:\n" +
Modified: tools/branches/gsoc2009-gui/extract_t7g_mac.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_t7g_mac.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/extract_t7g_mac.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -23,112 +23,95 @@
// Resource fork format taken from:
// http://developer.apple.com/documentation/mac/MoreToolbox/MoreToolbox-99.html
-#include "util.h"
+#include "extract_t7g_mac.h"
#define offsetResFork 128
uint32 offsetResourceData;
-char *readString(FILE *ifp) {
- byte len = readByte(ifp);
+ExtractT7GMac::ExtractT7GMac(const std::string &name) : Tool(name, TOOLTYPE_EXTRACTION) {
+
+ ToolInput input;
+ input.format = "*.*";
+ _inputPaths.push_back(input);
+
+ _shorthelp = "Used to the 7th guest data files.";
+ _helptext =
+ "Usage: " + getName() + " [params] [-o outputdir] <archivefile>\n" +
+ _shorthelp + "\n";
+}
+
+std::string ExtractT7GMac::readString(File &infile) {
+ byte len = infile.readByte();
char *name = new char[len + 1];
- ifp.read(name, len, 1);
+ infile.read(name, len, 1);
name[len] = 0;
return name;
}
-void dumpResource(FILE *ifp, char *name) {
+void ExtractT7GMac::dumpResource(File &infile, std::string name) {
// Show the resource details
- uint32 fileSize = readUint32BE(ifp);
- printf(" \"%s\" (%d bytes)\n", name, fileSize);
+ uint32 fileSize = infile.readUint32BE();
+ print(" \"%s\" (%d bytes)\n", name, fileSize);
// Read the resource contents
byte *buf = new byte[fileSize];
- if (!buf) {
- fclose(ifp);
- error("Could not allocate %ld bytes of memory", fileSize);
+
+ try {
+ // Dump the resource to the output file
+ File out(name, "wb");
+ infile.read(buf, 1, fileSize);
+ out.write(buf, 1, fileSize);
+ } catch (...) {
+ delete[] buf;
+ throw;
}
- // Dump the resource to the output file
- FILE *ofp = fopen(name, "wb");
- ifp.read(buf, 1, fileSize);
- ofp.write(buf, 1, fileSize);
- fclose(ofp);
-
// Free the resource memory
delete[] buf;
}
-void handleReferenceList(FILE *ifp, uint32 offsetRefList, uint16 numRes, uint32 offsetResNames) {
+void ExtractT7GMac::handleReferenceList(File &infile, uint32 offsetRefList, uint16 numRes, uint32 offsetResNames) {
for (int i = 0; i < numRes; i++) {
- if (fseek(ifp, offsetRefList + 12 * i + 2, SEEK_SET)) {
- fclose(ifp);
- error("Seek error");
- }
- uint32 offsetResName = offsetResNames + readUint16BE(ifp);
- uint32 offsetResData = offsetResourceData + (readUint32BE(ifp) & 0xFFFFFF);
+ infile.seek(offsetRefList + 12 * i + 2, SEEK_SET);
+ uint32 offsetResName = offsetResNames + infile.readUint16BE();
+ uint32 offsetResData = offsetResourceData + (infile.readUint32BE() & 0xFFFFFF);
// Read the resource name
- if (fseek(ifp, offsetResName, SEEK_SET)) {
- fclose(ifp);
- error("Seek error");
- }
- char *name = readString(ifp);
+ infile.seek(offsetResName, SEEK_SET);
- // Dump the resource
- if (fseek(ifp, offsetResData, SEEK_SET)) {
- fclose(ifp);
- error("Seek error");
- }
- dumpResource(ifp, name);
+ std::string name = readString(infile);
- // Free the resource name
- delete[] name;
+ // Dump the resource
+ infile.seek(offsetResData, SEEK_SET);
+ dumpResource(infile, name);
}
}
-int main(int argc, char *argv[]) {
- FILE *ifp;
+void ExtractT7GMac::execute() {
+ File infile(_inputPaths[0].path, "rb");
- if (argc != 2) {
- displayHelp("Usage: %s <file>\n", argv[0]);
- }
-
- if ((ifp = fopen(argv[1], "rb")) == NULL) {
- error("Could not open \'%s\'", argv[1]);
- }
-
// Read the resource fork header
- if (fseek(ifp, offsetResFork, SEEK_SET)) {
- fclose(ifp);
- error("Seek error");
- }
- offsetResourceData = offsetResFork + readUint32BE(ifp);
- uint32 offsetResMap = offsetResFork + readUint32BE(ifp);
+ infile.seek(offsetResFork, SEEK_SET);
+ offsetResourceData = offsetResFork + infile.readUint32BE();
+ uint32 offsetResMap = offsetResFork + infile.readUint32BE();
+
// Read the resource map
- if (fseek(ifp, offsetResMap + 24, SEEK_SET)) {
- fclose(ifp);
- error("Seek error");
- }
- uint32 offsetResTypes = offsetResMap + readUint16BE(ifp);
- uint32 offsetResNames = offsetResMap + readUint16BE(ifp);
+ infile.seek(offsetResMap + 24, SEEK_SET);
+ uint32 offsetResTypes = offsetResMap + infile.readUint16BE();
+ uint32 offsetResNames = offsetResMap + infile.readUint16BE();
// Handle the resource types
- if (fseek(ifp, offsetResTypes, SEEK_SET)) {
- fclose(ifp);
- error("Seek error");
- }
- uint16 numResTypes = readUint16BE(ifp) + 1;
+ infile.seek(offsetResTypes, SEEK_SET);
+
+ uint16 numResTypes = infile.readUint16BE() + 1;
char resType[5];
resType[4] = 0;
for (uint16 i = 0; i < numResTypes; i++) {
- if (fseek(ifp, offsetResTypes + 2 + 8 * i, SEEK_SET)) {
- fclose(ifp);
- error("Seek error");
- }
+ infile.seek(offsetResTypes + 2 + 8 * i, SEEK_SET);
// Read the resource type name
- ifp.read(resType, 4, 1);
+ infile.read(resType, 4, 1);
switch (READ_BE_UINT32(resType)) {
case MKID_BE('csnd'):
case MKID_BE('snd '):
@@ -139,19 +122,16 @@
case MKID_BE('INST'):
case MKID_BE('T7GM'):
{
- printf("Extracting \"%s\" resources\n", resType);
- uint16 numRes = readUint16BE(ifp);
- uint32 offsetRefList = offsetResTypes + readUint16BE(ifp);
+ print("Extracting \"%s\" resources\n", resType);
+ uint16 numRes = infile.readUint16BE();
+ uint32 offsetRefList = offsetResTypes + infile.readUint16BE();
- handleReferenceList(ifp, offsetRefList, numRes, offsetResNames);
+ handleReferenceList(infile, offsetRefList, numRes, offsetResNames);
break;
}
default:
- printf("Skipping \"%s\" resources\n", resType);
+ print("Skipping \"%s\" resources\n", resType);
break;
}
}
-
- fclose(ifp);
- return 0;
}
Modified: tools/branches/gsoc2009-gui/tools.cpp
===================================================================
--- tools/branches/gsoc2009-gui/tools.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/tools.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -40,6 +40,7 @@
#include "compress_tucker.h"
#include "encode_dxa.h"
#include "extract_agos.h"
+#include "extract_cine.h"
#include "extract_gob_stk.h"
#include "extract_kyra.h"
#include "extract_loom_tg16.h"
@@ -48,6 +49,7 @@
#include "extract_mm_nes.h"
#include "extract_parallaction.h"
#include "extract_scumm_mac.h"
+#include "extract_t7g_mac.h"
#include "extract_zak_c64.h"
Tools::Tools() {
@@ -70,6 +72,7 @@
_tools.push_back(new EncodeDXA());
_tools.push_back(new ExtractAgos());
+ _tools.push_back(new ExtractCine());
_tools.push_back(new ExtractGobStk());
_tools.push_back(new ExtractKyra());
_tools.push_back(new ExtractLoomTG16());
@@ -78,6 +81,7 @@
_tools.push_back(new ExtractMMNes());
_tools.push_back(new ExtractParallaction());
_tools.push_back(new ExtractScummMac());
+ _tools.push_back(new ExtractT7GMac());
_tools.push_back(new ExtractZakC64());
}
Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/util.cpp 2009-08-02 22:48:06 UTC (rev 43015)
@@ -382,7 +382,7 @@
return ret;
}
-size_t File::read(void *data, size_t elementSize, size_t elementCount) {
+void File::read(void *data, size_t elementSize, size_t elementCount) {
if (!_file)
throw FileException("File is not open");
if ((_mode & FILEMODE_READ) == 0)
@@ -391,8 +391,15 @@
size_t data_read = fread(data, elementSize, elementCount, _file);
if (data_read != elementCount)
throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
+}
- return data_read;
+size_t File::readN(void *data, size_t elementSize, size_t elementCount) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_READ) == 0)
+ throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+ return fread(data, elementSize, elementCount, _file);
}
std::string File::readString() {
@@ -414,13 +421,21 @@
return s;
}
-size_t File::readN(void *data, size_t elementSize, size_t elementCount) {
+std::string File::readString(size_t len) {
if (!_file)
throw FileException("File is not open");
if ((_mode & FILEMODE_READ) == 0)
throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
- return fread(data, elementSize, elementCount, _file);
+ std::string s('\0', len);
+ std::string::iterator is = s.begin();
+
+ char c;
+ while ((c = readByte())) {
+ *is = c;
+ }
+
+ return s;
}
void File::writeChar(int i) {
Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h 2009-08-02 21:44:44 UTC (rev 43014)
+++ tools/branches/gsoc2009-gui/util.h 2009-08-02 22:48:06 UTC (rev 43015)
@@ -414,7 +414,7 @@
* @param elementSize the size of one element (in bytes)
* @param elementCount the number of elements to read
*/
- size_t read(void *data, size_t elementSize, size_t elementCount);
+ void read(void *data, size_t elementSize, size_t elementCount);
/**
* Works the same way as fread, does NOT throw if it could not read all elements
@@ -423,6 +423,7 @@
* @param data Where to put the read data
* @param elementSize the size of one element (in bytes)
* @param elementCount the number of elements to read
+ * @return number of bytes read
*/
size_t readN(void *data, size_t elementSize, size_t elementCount);
@@ -431,7 +432,19 @@
* Throws FileException if file is not open / if read failed.
*/
std::string readString();
+
+ /**
+ * Reads the queried amount of bytes and returns it as a string
+ * Throws FileException if file is not open / if read failed.
+ *
+ * @param len How many bytes to read
+ * @return the data read
+ */
+ std::string readString(size_t len);
+
+
+
/**
* Writes a single character (equivalent of fputc)
*/
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