[Scummvm-cvs-logs] SF.net SVN: scummvm:[42496] tools/branches/gsoc2009-gui

Remere at users.sourceforge.net Remere at users.sourceforge.net
Wed Jul 15 02:41:40 CEST 2009


Revision: 42496
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42496&view=rev
Author:   Remere
Date:     2009-07-15 00:41:39 +0000 (Wed, 15 Jul 2009)

Log Message:
-----------
*Moved compression related functions into the CompressionTool class.
*Updated the compression functions to use the new interface.
*Fixed obvious error with compress_queen (accepting anything but one input file, rather than exactly one).

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/compress.cpp
    tools/branches/gsoc2009-gui/compress.h
    tools/branches/gsoc2009-gui/compress_agos.cpp
    tools/branches/gsoc2009-gui/compress_kyra.cpp
    tools/branches/gsoc2009-gui/compress_queen.cpp
    tools/branches/gsoc2009-gui/compress_scumm_sou.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/extract_scumm_mac.cpp
    tools/branches/gsoc2009-gui/util.cpp
    tools/branches/gsoc2009-gui/util.h

Modified: tools/branches/gsoc2009-gui/compress.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -58,7 +58,7 @@
 
 const char *tempEncoded = TEMP_MP3;
 
-void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample) {
+void CompressionTool::setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample) {
 	rawAudioType.isLittleEndian = isLittleEndian;
 	rawAudioType.isStereo = isStereo;
 	rawAudioType.bitsPerSample = bitsPerSample;
@@ -98,7 +98,7 @@
     return 48000;
 }
 
-void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, AudioFormat compmode) {
+void CompressionTool::encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, AudioFormat compmode) {
 	bool err = false;
 	char fbuf[2048];
 	char *tmp = fbuf;
@@ -147,9 +147,9 @@
 		err = system(fbuf) != 0;
 
 		if (err) {
-			printf("Got error from encoder. (check your parameters)\n");
-			printf("Encoder Commandline: %s\n", fbuf );
-			exit(-1);
+			char buf[2048];
+			sprintf(buf, "Error in MP3 encoder.(check parameters) \nMP3 Encoder Commandline:%s\n", fbuf);
+			throw ToolException(buf, err);
 		} else {
 			return;
 		}
@@ -190,9 +190,9 @@
 			err = system(fbuf) != 0;
 
 			if (err) {
-				printf("Got error from encoder. (check your parameters)\n");
-				printf("Encoder Commandline: %s\n", fbuf );
-				exit(-1);
+				char buf[2048];35xk'x25uk
+				sprintf(buf, "Error in Vorbis encoder. (check parameters)\nVorbis Encoder Commandline:%s\n", fbuf);
+				throw ToolException(buf, err);
 			} else {
 				return;
 			}
@@ -230,49 +230,46 @@
 			err = system(fbuf) != 0;
 
 			if (err) {
-				printf("Got error from encoder. (check your parameters)\n");
-				printf("Encoder Commandline: %s\n", fbuf );
-				exit(-1);
+				char buf[2048];
+				sprintf(buf, "Error in FLAC encoder. (check parameters)\nFLAC Encoder Commandline:%s\n", fbuf);
+				throw ToolException(buf, err);
 			} else {
 				return;
 			}
 		}
 #endif
 		if (rawInput) {
-			FILE *inputRaw;
 			long length;
 			char *rawData;
 
-			inputRaw = fopen(inname, "rb");
+			File inputRaw(inname, "rb");
 			length = fileSize(inputRaw);
 			rawData = (char *)malloc(length);
-			fread(rawData, 1, length, inputRaw);
+			inputRaw.read(rawData, 1, length);
 
-			printf(" - length = %ld\n", length);
-			printf(" - channels = %d\n", (rawAudioType.isStereo ? 2 : 1));
-			printf(" - sample rate = %d\n", rawSamplerate);
-			printf(" - compression = %dbits\n", rawAudioType.bitsPerSample);
+			print(" - length = %ld\n", length);
+			print(" - channels = %d\n", (rawAudioType.isStereo ? 2 : 1));
+			print(" - sample rate = %d\n", rawSamplerate);
+			print(" - compression = %dbits\n", rawAudioType.bitsPerSample);
 
 			encodeRaw(rawData, length, rawSamplerate, outname, compmode);
 
-			fclose(inputRaw);
 			free(rawData);
 		} else {
-			FILE *inputWav;
 			int fmtHeaderSize, length, numChannels, sampleRate, bitsPerSample;
 			char *wavData;
 
-			inputWav = fopen(inname, "rb");
+			File inputWav(inname, "rb");
 
 			/* Standard PCM fmt header is 16 bits, but at least Simon 1 and 2 use 18 bits */
-			fseek(inputWav, 16, SEEK_SET);
-			fmtHeaderSize = readUint32LE(inputWav);
+			inputWav.seek(16, SEEK_SET);
+			fmtHeaderSize = inputWav.readUint32LE();
 
-			fseek(inputWav, 22, SEEK_SET);
-			numChannels = readUint16LE(inputWav);
-			sampleRate = readUint32LE(inputWav);
+			inputWav.seek(22, SEEK_SET);
+			numChannels = inputWav.readUint16LE();
+			sampleRate = inputWav.readUint32LE();
 
-			fseek(inputWav, 34, SEEK_SET);
+			inputWav.seek(34, SEEK_SET);
 			bitsPerSample = readUint16LE(inputWav);
 
 			/* The size of the raw audio is after the RIFF chunk (12 bytes), fmt chunk (8 + fmtHeaderSize bytes), and data chunk id (4 bytes) */
@@ -280,25 +277,23 @@
 			length = readUint32LE(inputWav);
 
 			wavData = (char *)malloc(length);
-			fread(wavData, 1, length, inputWav);
+			inputWav.read(wavData, 1, length);
 
-			printf(" - length = %d\n", length);
-			printf(" - channels = %d\n", numChannels);
-			printf(" - sample rate = %d\n", sampleRate);
-			printf(" - compression = %dbits\n", bitsPerSample);
+			print(" - length = %d\n", length);
+			print(" - channels = %d\n", numChannels);
+			print(" - sample rate = %d\n", sampleRate);
+			print(" - compression = %dbits\n", bitsPerSample);
 
 			setRawAudioType(true, numChannels == 2, (uint8)bitsPerSample);
 			encodeRaw(wavData, length, sampleRate, outname, compmode);
 
-			fclose(inputWav);
 			free (wavData);
 		}
 }
 
-void encodeRaw(char *rawData, int length, int samplerate, const char *outname, AudioFormat compmode) {
+void CompressionTool::encodeRaw(char *rawData, int length, int samplerate, const char *outname, AudioFormat compmode) {
 #ifndef DISABLE_BUILTIN_VORBIS
 	if (compmode == AUDIO_VORBIS) {
-		FILE *outputOgg;
 		char outputString[256] = "";
 		int numChannels = (rawAudioType.isStereo ? 2 : 1);
 		int totalSamples = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
@@ -319,7 +314,7 @@
 		ogg_packet header_comm;
 		ogg_packet header_code;
 
-		outputOgg = fopen(outname,"wb");
+		File outputOgg(outname, "wb");
 
 		vorbis_info_init(&vi);
 
@@ -494,12 +489,10 @@
 		vorbis_dsp_clear(&vd);
 		vorbis_info_clear(&vi);
 
-		fclose(outputOgg);
-
 		if (!oggparms.silent) {
-			printf("\nDone encoding file \"%s\"\n", outname);
-			printf("\n\tFile length:  %dm %ds\n", (int)(totalSamples / samplerate / 60), (totalSamples / samplerate % 60));
-			printf("\tAverage bitrate: %.1f kb/s\n\n", (8.0 * (double)totalBytes / 1000.0) / ((double)totalSamples / (double)samplerate));
+			print("\nDone encoding file \"%s\"\n", outname);
+			print("\n\tFile length:  %dm %ds\n", (int)(totalSamples / samplerate / 60), (totalSamples / samplerate % 60));
+			print("\tAverage bitrate: %.1f kb/s\n\n", (8.0 * (double)totalBytes / 1000.0) / ((double)totalSamples / (double)samplerate));
 		}
 	}
 #endif
@@ -531,7 +524,7 @@
 		}
 
 		if (!flacparms.silent) {
-			printf("Encoding to\n         \"%s\"\nat compression level %d using blocksize %d\n\n", outname, flacparms.compressionLevel, flacparms.blocksize);
+			print("Encoding to\n         \"%s\"\nat compression level %d using blocksize %d\n\n", outname, flacparms.compressionLevel, flacparms.blocksize);
 		}
 
 		encoder = FLAC__stream_encoder_new();
@@ -548,9 +541,9 @@
 		initStatus = FLAC__stream_encoder_init_file(encoder, outname, NULL, NULL);
 
 		if (initStatus != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
-			printf("Got error from encoder. (check your paramters)\n");
-			printf("FLAC error: %s\n\n", FLAC__StreamEncoderInitStatusString[initStatus]);
-			exit(-1);
+			char buf[2048];
+			sprintf(buf, "Error in FLAC encoder. (check the parameters)\nExact error was:%s\n", FLAC__StreamEncoderInitStatusString[initStatus]);
+			throw ToolException(buf);
 		} else {
 			FLAC__stream_encoder_process_interleaved(encoder, flacData, samplesPerChannel);
 		}
@@ -561,41 +554,39 @@
 		free(flacData);
 
 		if (!flacparms.silent) {
-			printf("\nDone encoding file \"%s\"\n", outname);
-			printf("\n\tFile length:  %dm %ds\n\n", (int)(samplesPerChannel / samplerate / 60), (samplesPerChannel / samplerate % 60));
+			print("\nDone encoding file \"%s\"\n", outname);
+			print("\n\tFile length:  %dm %ds\n\n", (int)(samplesPerChannel / samplerate / 60), (samplesPerChannel / samplerate % 60));
 		}
 	}
 #endif
 }
 
-void extractAndEncodeWAV(const char *outName, FILE *input, AudioFormat compMode) {
+void CompressionTool::extractAndEncodeWAV(const char *outName, File &input, AudioFormat compMode) {
 	unsigned int length;
-	FILE *f;
 	char fbuf[2048];
 	size_t size;
 
-	fseek(input, -4, SEEK_CUR);
-	length = readUint32LE(input);
+	input.seek(-4, SEEK_CUR);
+	length = input.readUint32LE();
 	length += 8;
-	fseek(input, -8, SEEK_CUR);
+	input.seek(-8, SEEK_CUR);
 
 	/* Copy the WAV data to a temporary file */
-	f = fopen(outName, "wb");
+	File f(outName, "wb");
 	while (length > 0) {
-		size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length, input);
+		size = input.readN(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length);
 		if (size <= 0)
 			break;
 		length -= (int)size;
-		fwrite(fbuf, 1, size, f);
+		f.write(fbuf, 1, size);
 	}
-	fclose(f);
+	f.close();
 
 	/* Convert the WAV temp file to OGG/MP3 */
 	encodeAudio(outName, false, -1, tempEncoded, compMode);
 }
 
-void extractAndEncodeVOC(const char *outName, FILE *input, AudioFormat compMode) {
-	FILE *f;
+void CompressionTool::extractAndEncodeVOC(const char *outName, File &input, AudioFormat compMode) {
 	int bits;
 	int blocktype;
 	int channels;
@@ -606,9 +597,9 @@
 	size_t size;
 	int real_samplerate = -1;
 
-	f = fopen(outName, "wb");
+	File f(outName, "wb");
 
-	while ((blocktype = fgetc(input))) {
+	while ((blocktype = input.readByte())) {
 		if (blocktype != 1 && blocktype != 9) {
 			/*
 			   We only generate a warning, instead of erroring out, because
@@ -622,21 +613,21 @@
 		}
 
 		/* Sound Data */
-		printf(" Sound Data\n");
-		length = fgetc(input);
-		length |= fgetc(input) << 8;
-		length |= fgetc(input) << 16;
+		print(" Sound Data\n");
+		length = input.readChar();
+		length |= input.readChar() << 8;
+		length |= input.readChar() << 16;
 
 		if (blocktype == 1) {
 			length -= 2;
-			sample_rate = fgetc(input);
-			comp = fgetc(input);
+			sample_rate = input.readByte();
+			comp = input.readByte();
 			real_samplerate = getSampleRateFromVOCRate(sample_rate);
 		} else { /* (blocktype == 9) */
 			length -= 12;
 			real_samplerate = sample_rate = readUint32LE(input);
-			bits = fgetc(input);
-			channels = fgetc(input);
+			bits = input.readChar();;
+			channels = input.readChar();;
 			if (bits != 8 || channels != 1) {
 				error("Unsupported VOC file format (%d bits per sample, %d channels)", bits, channels);
 			}
@@ -644,9 +635,9 @@
 			readUint32LE(input);
 		}
 
-		printf(" - length = %d\n", length);
-		printf(" - sample rate = %d (%02x)\n", real_samplerate, sample_rate);
-		printf(" - compression = %s (%02x)\n",
+		print(" - length = %d\n", length);
+		print(" - sample rate = %d (%02x)\n", real_samplerate, sample_rate);
+		print(" - compression = %s (%02x)\n",
 			   (comp ==	   0 ? "8bits"   :
 				(comp ==   1 ? "4bits"   :
 				 (comp ==  2 ? "2.6bits" :
@@ -670,7 +661,7 @@
 		}
 	}
 
-	fclose(f);
+	f.close();
 
 	assert(real_samplerate != -1);
 
@@ -680,7 +671,7 @@
 	encodeAudio(outName, true, real_samplerate, tempEncoded, compMode);
 }
 
-int process_mp3_parms(int argc, char *argv[], int* i) {
+int CompressionTool::processMp3Parms(int argc, char *argv[], int* i) {
 	for (; *i < argc; (*i)++) {
 		if (strcmp(argv[*i], "--vbr") == 0) {
 			encparms.abr = 0;
@@ -758,7 +749,7 @@
 	return 1;
 }
 
-int process_ogg_parms(int argc, char *argv[], int* i) {
+int CompressionTool::processOggParms(int argc, char *argv[], int* i) {
 	for (; *i < argc; (*i)++) {
 		if (strcmp(argv[*i], "-b") == 0) {
 			oggparms.nominalBitr = atoi(argv[*i + 1]);
@@ -829,7 +820,7 @@
 	return 1;
 }
 
-int process_flac_parms(int argc, char *argv[], int *i){
+int CompressionTool::processFlacParms(int argc, char *argv[], int *i){
 	for (; *i < argc; (*i)++) {
 		if (strcmp(argv[*i], "-b") == 0) {
 			flacparms.blocksize = atoi(argv[*i + 1]);
@@ -876,44 +867,6 @@
 	return 1;
 }
 
-AudioFormat process_audio_params(int argc, char *argv[], int* i) {
-	/* Compression mode */
-	AudioFormat compMode = AUDIO_MP3;
-
-	for (; *i < argc - 2; ++*i) {
-		if (strcmp(argv[*i], "--mp3") == 0)
-			compMode = AUDIO_MP3;
-		else if (strcmp(argv[*i], "--vorbis") == 0)
-			compMode = AUDIO_VORBIS;
-		else if (strcmp(argv[*i], "--flac") == 0)
-			compMode = AUDIO_FLAC;
-		else
-			break;
-	}
-
-	switch (compMode) {
-	case AUDIO_MP3:
-		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc - 2, argv, i))
-			return AUDIO_NONE;
-		break;
-	case AUDIO_VORBIS:
-		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc - 2, argv, i))
-			return AUDIO_NONE;
-		break;
-	case AUDIO_FLAC:
-		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc - 2, argv, i))
-			return AUDIO_NONE;
-		break;
-	default:	// cannot occur but we check anyway to avoid compiler warnings
-		break;
-	}
-
-	return compMode;
-}
-
 // Compression tool interface
 // Duplicates code above in the new way
 // The old code can be removed once all tools have been converted
@@ -943,17 +896,17 @@
 	switch (_format) {
 	case AUDIO_MP3:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(_arguments.size() - 2, _argv, &arg))
+		if (!processMp3Parms(_arguments.size() - 2, _argv, &arg))
 			throw ToolException("Could not parse command line arguments, use --help for options");
 		break;
 	case AUDIO_VORBIS:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(_arguments.size() - 2, _argv, &arg))
+		if (!processOggParms(_arguments.size() - 2, _argv, &arg))
 			throw ToolException("Could not parse command line arguments, use --help for options");
 		break;
 	case AUDIO_FLAC:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(_arguments.size() - 2, _argv, &arg))
+		if (!processFlacParms(_arguments.size() - 2, _argv, &arg))
 			throw ToolException("Could not parse arguments: Use --help for options");
 		break;
 	default: // cannot occur but we check anyway to avoid compiler warnings

Modified: tools/branches/gsoc2009-gui/compress.h
===================================================================
--- tools/branches/gsoc2009-gui/compress.h	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress.h	2009-07-15 00:41:39 UTC (rev 42496)
@@ -92,6 +92,18 @@
 	std::string _oggMinBitrate;
 	std::string _oggAvgBitrate;
 	std::string _oggMaxBitrate;
+	
+public:
+	int processMp3Parms(int argc, char *argv[], int* i);
+	int processOggParms(int argc, char *argv[], int* i);
+	int processFlacParms(int argc, char *argv[], int* i);
+
+	void extractAndEncodeVOC(const char *outName, File &input, AudioFormat compMode);
+	void extractAndEncodeWAV(const char *outName, File &input, AudioFormat compMode);
+
+	void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, AudioFormat compmode);
+	void encodeRaw(char *rawData, int length, int samplerate, const char *outname, AudioFormat compmode);
+	void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample);
 };
 
 /*
@@ -99,19 +111,7 @@
  */
 const extern char *tempEncoded;
 
-extern AudioFormat process_audio_params(int argc, char *argv[], int* i);
-extern int process_mp3_parms(int argc, char *argv[], int* i);
-extern int process_ogg_parms(int argc, char *argv[], int* i);
-extern int process_flac_parms(int argc, char *argv[], int* i);
 
-extern void extractAndEncodeVOC(const char *outName, FILE *input, AudioFormat compMode);
-extern void extractAndEncodeWAV(const char *outName, FILE *input, AudioFormat compMode);
-
-extern void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, AudioFormat compmode);
-extern void encodeRaw(char *rawData, int length, int samplerate, const char *outname, AudioFormat compmode);
-extern void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample);
-
-
 /* Integer definitions for the constants above */
 #define maxBitrDef atoi(maxBitrDef_str)
 #define algqualDef atoi(algqualDef_str)

Modified: tools/branches/gsoc2009-gui/compress_agos.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_agos.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress_agos.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -103,10 +103,10 @@
 	if (!memcmp(buf, "Creative", 8)) {
 		print("VOC found (pos = %d) :\n", offset);
 		_input.seek(18, SEEK_CUR);
-		extractAndEncodeVOC(TEMP_RAW, _input.getFileHandle(), _format);
+		extractAndEncodeVOC(TEMP_RAW, _input, _format);
 	} else if (!memcmp(buf, "RIFF", 4)) {
 		print("WAV found (pos = %d) :\n", offset);
-		extractAndEncodeWAV(TEMP_WAV, _input.getFileHandle(), _format);
+		extractAndEncodeWAV(TEMP_WAV, _input, _format);
 	} else {
 		error("Unexpected data at offset: %d", offset);
 	}

Modified: tools/branches/gsoc2009-gui/compress_kyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_kyra.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress_kyra.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -75,7 +75,7 @@
 
 		File tempFile(TEMPFILE, "rb");
 		tempFile.seek(26, SEEK_CUR);
-		extractAndEncodeVOC(TEMP_RAW, tempFile.getFileHandle(), _format);
+		extractAndEncodeVOC(TEMP_RAW, tempFile, _format);
 		tempFile.close();
 
 		outputName.setExtension(audio_extensions(_format));

Modified: tools/branches/gsoc2009-gui/compress_queen.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_queen.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress_queen.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -90,7 +90,8 @@
 };
 
 CompressQueen::CompressQueen(const std::string &name) : CompressionTool(name) {
-	
+	_outputToDirectory = false;
+
 	_helptext = "\nUsage: %s [mode] [mode params] [-o outputfile] <inputfile (queen.1)>\n" kCompressionAudioHelp;
 }
 
@@ -115,7 +116,7 @@
 	uint32 numRead;
 
 	while (amount > 0) {
-		numRead = in.read(fBuf, 1, amount > 2048 ? 2048 : amount);
+		numRead = in.readN(fBuf, 1, amount > 2048 ? 2048 : amount);
 		if (numRead <= 0) {
 			break;
 		}
@@ -169,7 +170,7 @@
 	uint32 prevOffset;
 
 	// Check input
-	if (_inputPaths.size() == 1)
+	if (_inputPaths.size() != 1)
 		error("One input file expected!");
 	Filename inpath(_inputPaths[0]);
 	Filename &outpath = _outputPath;
@@ -254,6 +255,7 @@
 			_entry.size -= headerSize;
 
 			fromFileToFile(inputData, tmpFile, _entry.size);
+			tmpFile.close();
 
 			/* Invoke encoder */
 			setRawAudioType(false, false, 8);

Modified: tools/branches/gsoc2009-gui/compress_scumm_sou.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_scumm_sou.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress_scumm_sou.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -103,7 +103,7 @@
 	_output_idx.writeUint32BE((uint32)_output_snd.pos());
 	_output_idx.writeUint32BE(tags);
 	while (tags > 0) {
-		fputc(fgetc(_input), _output_snd);
+		_output_snd.writeChar(_input.readChar());
 		tags--;
 	}
 

Modified: tools/branches/gsoc2009-gui/compress_tinsel.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tinsel.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress_tinsel.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -58,7 +58,7 @@
 	char buffer[2048];
 	File curFileHandle;
 
-	printf("Assuming DW1 sample being 8-bit raw...\n");
+	print("Assuming DW1 sample being 8-bit raw...\n");
 
 	unlink(TEMP_RAW); unlink(TEMP_ENC);
 	curFileHandle.open(TEMP_RAW, "wb");
@@ -131,12 +131,12 @@
 	char buffer[2048];
 	File curFileHandle;
 
-	printf("Assuming DW2 sample using ADPCM 6-bit, decoding to 16-bit raw...\n");
+	print("Assuming DW2 sample using ADPCM 6-bit, decoding to 16-bit raw...\n");
 
 	// Allocate buffer for the ADPCM-compressed sample
 	inBuffer = (byte *)malloc(sampleSize);
 	if (!inBuffer) {
-		printf("malloc failed!\n");
+		print("malloc failed!\n");
 		return;
 	}
 
@@ -144,7 +144,7 @@
 	uncompressedSize = (sampleSize/3)*4*2+16;
 	outBuffer = (int16 *)malloc(uncompressedSize);
 	if (!outBuffer) {
-		printf("malloc failed!\n");
+		print("malloc failed!\n");
 		return;
 	}
 
@@ -287,7 +287,7 @@
 				error("The sourcefiles are already compressed, aborting...\n");
 			}
 			// Got sample(s), so convert...
-			printf("Converting sample %d of %d\n", indexNo, indexCount);
+			print("Converting sample %d of %d\n", indexNo, indexCount);
 
 			// Seek to Sample in input-file and read SampleSize
 			_input_smp.seek(indexOffset, SEEK_SET);

Modified: tools/branches/gsoc2009-gui/compress_touche.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_touche.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress_touche.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -70,7 +70,7 @@
 
 			print("VOC found (pos = %d) :\n", offs_table[i]);
 			input.seek(18, SEEK_CUR);
-			extractAndEncodeVOC(TEMP_RAW, input.getFileHandle(), _format);
+			extractAndEncodeVOC(TEMP_RAW, input, _format);
 
 			/* append converted data to output file */
 			File temp(tempEncoded, "rb");

Modified: tools/branches/gsoc2009-gui/compress_tucker.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tucker.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/compress_tucker.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -62,7 +62,7 @@
 	char buf[8];
 
 	if (input.read(buf, 1, 8) == 8 && memcmp(buf, "RIFF", 4) == 0) {
-		extractAndEncodeWAV(TEMP_WAV, input.getFileHandle(), _format);
+		extractAndEncodeWAV(TEMP_WAV, input, _format);
 		return append_compress_file(output);
 	}
 	return 0;
@@ -368,14 +368,14 @@
 
 	/* compress the .wav files in each directory */
 	for (i = 0; i < SOUND_TYPES_COUNT; ++i) {
-		printf("Processing directory '%s'...\n", sound_directory_table[i].name);
+		print("Processing directory '%s'...\n", sound_directory_table[i].name);
 		sound_directory_size[i] = compress_sounds_directory(inpath, outpath, output, &sound_directory_table[i]);
-		printf("Done (%d bytes)\n", sound_directory_size[i]);
+		print("Done (%d bytes)\n", sound_directory_size[i]);
 	}
 	if (flags & HEADER_FLAG_AUDIO_INTRO) {
-		printf("Processing directory 'audio'...\n");
+		print("Processing directory 'audio'...\n");
 		audio_directory_size = compress_audio_directory(inpath, outpath, output);
-		printf("Done (%d bytes)\n", audio_directory_size);
+		print("Done (%d bytes)\n", audio_directory_size);
 	}
 
 	/* fix sound types offsets/counts */
@@ -397,7 +397,7 @@
 	unlink(TEMP_RAW);
 	unlink(tempEncoded);
 
-	printf("Done.\n");
+	print("Done.\n");
 }
 
 

Modified: tools/branches/gsoc2009-gui/extract_gob_stk.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_gob_stk.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/extract_gob_stk.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -290,8 +290,6 @@
 			delete[] data;
 		}
 
-		fflush(chunkFile);
-
 		curChunk = curChunk->next;
 	}
 }

Modified: tools/branches/gsoc2009-gui/extract_scumm_mac.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_scumm_mac.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/extract_scumm_mac.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -82,7 +82,7 @@
 		if (!file_name[0])
 			error("\'%s\'. file has no name.", inpath.getFullPath().c_str());
 		
-		printf("extracting \'%s\'", file_name);
+		print("extracting \'%s\'", file_name);
 
 		/* For convenience compatibility with scummvm (and case sensitive
 		 * file systems) change the file name to lowercase.
@@ -107,7 +107,7 @@
 			print("data file \'%s\' may be not a file extract_scumm_mac can extract.\n", inpath.getFullPath().c_str());
 		}
 
-		printf(", saving as \'%s\'\n", file_name);
+		print(", saving as \'%s\'\n", file_name);
 
 		/* Consistency check. make sure the file data is in the file */
 		if (file_off + file_len > data_file_len) {

Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/util.cpp	2009-07-15 00:41:39 UTC (rev 42496)
@@ -359,16 +359,21 @@
 	_xormode = xormode;
 }
 
-uint8 File::readByte() {
+int File::readChar() {
 	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() + ")");
 
 	int u8 = fgetc(_file);
-	u8 ^= _xormode;
 	if (u8 == EOF)
 		throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
+	u8 ^= _xormode;
+	return u8;
+}
+
+uint8 File::readByte() {
+	int u8 = readChar();
 	return (uint8)u8;
 }
 
@@ -417,18 +422,31 @@
 	return data_read;
 }
 
-void File::writeByte(uint8 b) {
+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);
+}
+
+void File::writeChar(int i) {
+	if (!_file) 
 		throw FileException("File  is not open");
 	if ((_mode & FILEMODE_WRITE) == 0)
 		throw FileException("Tried to write to a file opened in read mode (" + _name.getFullPath() + ")");
 
-	b ^= _xormode;
+	i ^= _xormode;
 
-	if (fwrite(&b, 1, 1, _file) != 1)
+	if (fwrite(&i, 1, 1, _file) != 1)
 		throw FileException("Could not write to file (" + _name.getFullPath() + ")");
 }
 
+void File::writeByte(uint8 b) {
+	writeChar(b);
+}
+
 void File::writeUint16BE(uint16 value) {
 	writeByte((uint8)(value >> 8));
 	writeByte((uint8)(value));

Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h	2009-07-14 23:03:40 UTC (rev 42495)
+++ tools/branches/gsoc2009-gui/util.h	2009-07-15 00:41:39 UTC (rev 42496)
@@ -387,6 +387,10 @@
 	void setXorMode(uint8 xormode);
 	
 	/**
+	 * Reads a single character (equivalent of fgetc
+	 */
+	int readChar();
+	/**
 	 * Read a single unsigned byte.
 	 * Throws FileException if file is not open / if read failed.
 	 */
@@ -421,13 +425,22 @@
 	 * @param elementCount the number of elements to read
 	 */
 	size_t read(void *data, size_t elementSize, size_t elementCount);
-	// Just an alias, for now... 
-	// (if we change the other version to throw it will be 
-	// easier if the concerned places already use the no-throw version)
-	size_t readN(void *data, size_t elementSize, size_t elementCount) {return read(data, elementSize, elementCount);}
+	/**
+	 * Works the same way as fread, does NOT throw if it could not read all elements
+	 * still throws if file is not open.
+	 *
+	 * @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
+	 */
+	size_t readN(void *data, size_t elementSize, size_t elementCount);
 
 	
 	/**
+	 * Writes a single character (equivalent of fputc)
+	 */
+	void writeChar(int c);
+	/**
 	 * Writes a single byte to the file.
 	 * Throws FileException if file is not open / if write failed.
 	 */
@@ -489,10 +502,6 @@
 	 * @todo get rid of this ASAP
 	 */
 	operator FILE *() { return _file; }
-	/**
-	 * Explicit conversion to a FILE *, all code should use this in the future
-	 */
-	FILE *handle() {return _file;}
 
 	// FIXME: Remove this method ASAP
 	FILE *getFileHandle() { return _file; }


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