[Scummvm-cvs-logs] SF.net SVN: scummvm:[42302] tools/branches/gsoc2009-gui
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Thu Jul 9 18:08:13 CEST 2009
Revision: 42302
http://scummvm.svn.sourceforge.net/scummvm/?rev=42302&view=rev
Author: fingolfin
Date: 2009-07-09 16:08:13 +0000 (Thu, 09 Jul 2009)
Log Message:
-----------
Added File::isOpen() method, and changed some more code to not rely on the implicit convesion from File to FILE*
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_queen.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_gob_stk.cpp
tools/branches/gsoc2009-gui/util.h
Modified: tools/branches/gsoc2009-gui/compress_agos.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_agos.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_agos.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -71,7 +71,7 @@
if (!memcmp(buf, "Creative", 8) || !memcmp(buf, "RIFF", 4)) {
return i;
}
- fseek(_input, -8, SEEK_CUR);
+ _input.seek(-8, SEEK_CUR);
offsets[i] = _input.readUint32LE();
}
@@ -97,16 +97,16 @@
char fbuf[2048];
char buf[8];
- fseek(_input, offset, SEEK_SET);
+ _input.seek(offset, SEEK_SET);
_input.read(buf, 1, 8);
if (!memcmp(buf, "Creative", 8)) {
print("VOC found (pos = %d) :\n", offset);
- fseek(_input, 18, SEEK_CUR);
- extractAndEncodeVOC(TEMP_RAW, _input, _format);
+ _input.seek(18, SEEK_CUR);
+ extractAndEncodeVOC(TEMP_RAW, _input.getFileHandle(), _format);
} else if (!memcmp(buf, "RIFF", 4)) {
print("WAV found (pos = %d) :\n", offset);
- extractAndEncodeWAV(TEMP_WAV, _input, _format);
+ extractAndEncodeWAV(TEMP_WAV, _input.getFileHandle(), _format);
} else {
error("Unexpected data at offset: %d", offset);
}
Modified: tools/branches/gsoc2009-gui/compress_gob.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_gob.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_gob.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -179,7 +179,7 @@
*/
void CompressGob::writeEmptyHeader(File &stk, uint16 chunkCount) {
for (uint32 count = 0; count < 2 + (uint32) (chunkCount * 22); count++)
- fputc(0, stk);
+ stk.writeByte(0);
return;
}
@@ -309,7 +309,7 @@
uint32 tmpSize = 0;
do {
- count = fread(buffer, 1, 4096, src);
+ count = src.read(buffer, 1, 4096);
stk.write(buffer, 1, count);
tmpSize += count;
} while (count == 4096);
@@ -334,7 +334,7 @@
uint16 resultcheckpos;
byte resultchecklength;
- size = fileSize(src);
+ size = src.size();
byte *unpacked = new byte [size + 1];
for (int i = 0; i < 4096 - 18; i++)
@@ -406,7 +406,7 @@
// when the 8 operation bits are set.
if ((cpt == 7) | (counter == 0)) {
writeBuffer[0] = cmd;
- fwrite(writeBuffer, 1, buffIndex, stk);
+ stk.write(writeBuffer, 1, buffIndex);
size += buffIndex;
buffIndex = 1;
cmd = 0;
@@ -438,8 +438,8 @@
src2.open(compChunk->name, "rb");
do {
- readCount = fread(buf1, 1, 4096, src1);
- fread(buf2, 1, 4096, src2);
+ readCount = src1.read(buf1, 1, 4096);
+ src2.read(buf2, 1, 4096);
for (int i = 0; checkFl & (i < readCount); i++)
if (buf1[i] != buf2[i])
checkFl = false;
Modified: tools/branches/gsoc2009-gui/compress_kyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_kyra.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_kyra.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -75,7 +75,7 @@
File tempFile(TEMPFILE, "rb");
tempFile.seek(26, SEEK_CUR);
- extractAndEncodeVOC(TEMP_RAW, tempFile, _format);
+ extractAndEncodeVOC(TEMP_RAW, tempFile.getFileHandle(), _format);
tempFile.close();
outputName.setExtension(audio_extensions(_format));
@@ -322,7 +322,7 @@
red[i].resOffset = resOffset;
uint32 pos = (uint32)input.pos();
- fseek(input, resOffset + 4, SEEK_SET);
+ input.seek(resOffset + 4, SEEK_SET);
compressAUDFile(input, outname);
@@ -330,7 +330,7 @@
unlink(outname);
- fseek(input, pos, SEEK_SET);
+ input.seek(pos, SEEK_SET);
}
}
@@ -356,9 +356,9 @@
File f(*infile, "rb");
- uint16 entries = readUint16LE(f);
+ uint16 entries = f.readUint16LE();
uint32 entryTableSize = (entries * 8);
- const uint32 filesize = fileSize(f);
+ const uint32 filesize = f.size();
if (entryTableSize + 2 > filesize) {
error("Unknown filetype of file: '%s'", infile->getFullPath().c_str());
Modified: tools/branches/gsoc2009-gui/compress_queen.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_queen.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_queen.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -135,7 +135,7 @@
File outFinal(*outPath, "wb");
dataStartOffset = inTbl.size() + EXTRA_TBL_HEADER;
- dataSize = fileSize(inData);
+ dataSize = inData.size();
inTbl.seek(7, SEEK_SET); /* Skip past header */
@@ -224,7 +224,7 @@
_entry.size = inputTbl.readUint32BE();
print("Processing entry: %s\n", _entry.filename);
- fseek(inputData, _entry.offset, SEEK_SET);
+ inputData.seek(_entry.offset, SEEK_SET);
if (_versionExtra.compression && strstr(_entry.filename, ".SB")) { /* Do we want to compress? */
uint16 sbVersion;
@@ -261,7 +261,7 @@
/* Append MP3/OGG to data file */
compFile.open(tempEncoded, "rb");
- _entry.size = fileSize(compFile);
+ _entry.size = compFile.size();
fromFileToFile(compFile, outputData, _entry.size);
compFile.close();
@@ -281,7 +281,7 @@
/* XXX patched data files are supposed to be in cwd */
File fpPatch(pf->filename, "rb");
- if (fpPatch) {
+ if (fpPatch.isOpen()) {
_entry.size = fpPatch.size();
print("Patching entry, new size = %d bytes\n", _entry.size);
fromFileToFile(fpPatch, outputData, _entry.size);
Modified: tools/branches/gsoc2009-gui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_saga.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_saga.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -166,7 +166,7 @@
char fbuf[2048];
File tempf(fromFileName, "rb");
- if (tempf == NULL)
+ if (!tempf.isOpen())
error("Unable to open %s", fromFileName);
while ((size = (uint32)tempf.read(fbuf, 1, sizeof(fbuf))) > 0) {
@@ -181,7 +181,7 @@
char fbuf[2048];
File tempf(toFileName, "wb");
- if (tempf == NULL)
+ if (!tempf.isOpen())
error("Unable to open %s", toFileName);
while (inputSize > 0) {
size = (uint32)inputFile.read(fbuf, 1, inputSize > sizeof(fbuf) ? sizeof(fbuf) : inputSize);
@@ -195,17 +195,17 @@
void CompressSaga::writeBufferToFile(uint8 *data, uint32 inputSize, const char *toFileName) {
File tempf(toFileName, "wb");
- if (tempf == NULL)
+ if (!tempf.isOpen())
error("Unable to open %s", toFileName);
tempf.write(data, 1, inputSize);
}
void CompressSaga::writeHeader(File &outputFile) {
- writeByte(outputFile, compression_format(_format));
- writeUint16LE(outputFile, _sampleRate);
- writeUint32LE(outputFile, _sampleSize);
- writeByte(outputFile, _sampleBits);
- writeByte(outputFile, _sampleStereo);
+ outputFile.writeByte(compression_format(_format));
+ outputFile.writeUint16LE(_sampleRate);
+ outputFile.writeUint32LE(_sampleSize);
+ outputFile.writeByte(_sampleBits);
+ outputFile.writeByte(_sampleStereo);
}
uint32 CompressSaga::encodeEntry(File &inputFile, uint32 inputSize, File &outputFile) {
@@ -339,7 +339,7 @@
}
// Go to beginning of the table
- fseek(inputFile, resTableOffset, SEEK_SET);
+ inputFile.seek(resTableOffset, SEEK_SET);
inputTable = (Record*)malloc(resTableCount * sizeof(Record));
Modified: tools/branches/gsoc2009-gui/compress_tinsel.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tinsel.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_tinsel.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -78,9 +78,9 @@
// Append compressed data to output_smp
curFileHandle.open(TEMP_ENC, "rb");
- fseek(curFileHandle, 0, SEEK_END);
+ curFileHandle.seek(0, SEEK_END);
copyLeft = curFileHandle.pos();
- fseek(curFileHandle, 0, SEEK_SET);
+ curFileHandle.seek(0, SEEK_SET);
// Write size of compressed data
_output_smp.writeUint32LE(copyLeft);
// Write actual data
Modified: tools/branches/gsoc2009-gui/compress_touche.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_touche.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_touche.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -51,8 +51,8 @@
/* write 0 offsets/sizes table */
for (i = 0; i < len; ++i) {
- offs_table[i] = readUint32LE(input);
- size_table[i] = readUint32LE(input);
+ offs_table[i] = input.readUint32LE();
+ size_table[i] = input.readUint32LE();
output.writeUint32LE(0);
output.writeUint32LE(0);
current_offset += 8;
@@ -70,7 +70,7 @@
print("VOC found (pos = %d) :\n", offs_table[i]);
input.seek(18, SEEK_CUR);
- extractAndEncodeVOC(TEMP_RAW, input, _format);
+ extractAndEncodeVOC(TEMP_RAW, input.getFileHandle(), _format);
/* append converted data to output file */
File temp(tempEncoded, "rb");
@@ -105,8 +105,8 @@
File output(*outpath, "wb");
- writeUint16LE(output, 1); /* current version */
- writeUint16LE(output, 0); /* flags */
+ output.writeUint16LE(1); /* current version */
+ output.writeUint16LE(0); /* flags */
current_offset = HEADER_SIZE;
@@ -134,7 +134,7 @@
inpath->setFullName(d);
input.open(*inpath, "rb");
- if (input) {
+ if (input.isOpen()) {
offsets_table[i] = current_offset;
current_offset = compress_sound_data_file(current_offset, output, input, input_Vxx_offs, input_Vxx_size, Vxx_HDR_LEN);
input.close();
Modified: tools/branches/gsoc2009-gui/compress_tucker.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tucker.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/compress_tucker.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -62,7 +62,7 @@
char buf[8];
if (input.read(buf, 1, 8) == 8 && memcmp(buf, "RIFF", 4) == 0) {
- extractAndEncodeWAV(TEMP_WAV, input, _format);
+ extractAndEncodeWAV(TEMP_WAV, input.getFileHandle(), _format);
return append_compress_file(output);
}
return 0;
@@ -140,13 +140,13 @@
}
/* fix offsets/sizes table */
- fseek(output, pos, SEEK_SET);
+ output.seek(pos, SEEK_SET);
for (i = 0; i < dir->count; ++i) {
- writeUint32LE(output, temp_table[i].offset);
- writeUint32LE(output, temp_table[i].size);
+ output.writeUint32LE(temp_table[i].offset);
+ output.writeUint32LE(temp_table[i].size);
}
- fseek(output, 0, SEEK_END);
+ output.seek(0, SEEK_END);
return current_offset + dir->count * 8;
}
@@ -305,8 +305,8 @@
/* write 0 offsets/sizes table */
for (i = 0; i < count; ++i) {
- writeUint32LE(output, 0);
- writeUint32LE(output, 0);
+ output.writeUint32LE(0);
+ output.writeUint32LE(0);
}
current_offset = 0;
@@ -314,7 +314,7 @@
temp_table[i].offset = current_offset;
sprintf(filepath, "%s/audio/%s", inpath->getPath().c_str(), audio_files_list[i]);
File input(filepath, "rb");
- if (!input) {
+ if (!input.isOpen()) {
warning("Can't open file '%s'", filepath);
temp_table[i].size = 0;
} else {
@@ -335,13 +335,13 @@
}
/* fix offsets/sizes table */
- fseek(output, pos, SEEK_SET);
+ output.seek(pos, SEEK_SET);
for (i = 0; i < count; ++i) {
- writeUint32LE(output, temp_table[i].offset);
- writeUint32LE(output, temp_table[i].size);
+ output.writeUint32LE(temp_table[i].offset);
+ output.writeUint32LE(temp_table[i].size);
}
- fseek(output, 0, SEEK_END);
+ output.seek(0, SEEK_END);
return current_offset + count * 8;
}
@@ -379,7 +379,7 @@
}
/* fix sound types offsets/counts */
- fseek(output, HEADER_SIZE, SEEK_SET);
+ output.seek(HEADER_SIZE, SEEK_SET);
current_offset = 0;
for (i = 0; i < SOUND_TYPES_COUNT; ++i) {
output.writeUint32LE(current_offset);
Modified: tools/branches/gsoc2009-gui/extract_gob_stk.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_gob_stk.cpp 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/extract_gob_stk.cpp 2009-07-09 16:08:13 UTC (rev 42302)
@@ -90,7 +90,7 @@
}
void ExtractGobStk::readChunkList(File &stk, File &gobConf) {
- uint16 numDataChunks = readUint16LE(stk);
+ uint16 numDataChunks = stk.readUint16LE();
// If we are run multiple times, free previous chunk list
if (_chunks)
@@ -102,9 +102,9 @@
while (numDataChunks-- > 0) {
stk.read(curChunk->name, 1, 13);
- curChunk->size = readUint32LE(stk);
- curChunk->offset = readUint32LE(stk);
- curChunk->packed = readByte(stk) != 0;
+ curChunk->size = stk.readUint32LE();
+ curChunk->offset = stk.readUint32LE();
+ curChunk->packed = stk.readByte() != 0;
curChunk->preGob = false;
// Geisha TOTs are compressed without having the flag set
@@ -160,7 +160,7 @@
buffer[8] = '\0';
strcat(debugStr, buffer);
print("%s\n",debugStr);
- filenamePos = readUint32LE(stk);
+ filenamePos = stk.readUint32LE();
// Filenames - Header
// ==================
@@ -170,8 +170,8 @@
stk.seek(filenamePos, SEEK_SET);
- numDataChunks = readUint32LE(stk);
- miscPos = readUint32LE(stk);
+ numDataChunks = stk.readUint32LE();
+ miscPos = stk.readUint32LE();
if (numDataChunks == 0)
throw ToolException("Empty ITK/STK !");
@@ -192,20 +192,19 @@
// + 04 bytes : Start position of the File Section
// + 04 bytes : Compression flag (AFAIK : 0= uncompressed, 1= compressed)
- if (fseek(stk, miscPos + (cpt * 61), SEEK_SET) != 0)
- throw ToolException("Unable to locate Misc Section");
- filenamePos = readUint32LE(stk);
+ stk.seek(miscPos + (cpt * 61), SEEK_SET);
+ filenamePos = stk.readUint32LE();
if (stk.read(buffer, 1, 36) < 36)
throw ToolException("Unexpected EOF in Misc Section");
- curChunk->size = readUint32LE(stk);
- decompSize = readUint32LE(stk);
+ curChunk->size = stk.readUint32LE();
+ decompSize = stk.readUint32LE();
if (stk.read(buffer, 1, 5) < 5)
throw ToolException("Unexpected EOF in Misc Section");
- filePos = readUint32LE(stk);
- compressFlag = readUint32LE(stk);
+ filePos = stk.readUint32LE();
+ compressFlag = stk.readUint32LE();
if (compressFlag == 1) {
curChunk->packed = true;
@@ -225,8 +224,7 @@
// Filename are stored one after the other, separated by 0x00.
// Those are now long filenames, at the opposite of previous STK version.
- if (fseek(stk, filenamePos, SEEK_SET) != 0)
- throw ToolException("Unable to locate filename");
+ stk.seek(filenamePos, SEEK_SET);
if (fgets(curChunk->name, 64, stk) == 0)
throw ToolException("Unable to read filename");
Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h 2009-07-09 15:59:20 UTC (rev 42301)
+++ tools/branches/gsoc2009-gui/util.h 2009-07-09 16:08:13 UTC (rev 42302)
@@ -365,6 +365,8 @@
*/
void close();
+ bool isOpen() const { return _file != 0; }
+
/**
* Sets the xor mode of the file, bytes written / read to the file
* will be XORed with this value. This value is *not* reset when
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