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

Remere at users.sourceforge.net Remere at users.sourceforge.net
Tue Jul 7 01:42:10 CEST 2009


Revision: 42195
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42195&view=rev
Author:   Remere
Date:     2009-07-06 23:42:10 +0000 (Mon, 06 Jul 2009)

Log Message:
-----------
*Converted compress_gob, compress_kyra, compress_queen, compress_saga, compress_tinsel, compress_touche, compress_tucker to the new, C++ style format, and added them to the UI. Also added some small required features.

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/Makefile
    tools/branches/gsoc2009-gui/compress.cpp
    tools/branches/gsoc2009-gui/compress.h
    tools/branches/gsoc2009-gui/compress_agos.cpp
    tools/branches/gsoc2009-gui/compress_agos.h
    tools/branches/gsoc2009-gui/compress_gob.cpp
    tools/branches/gsoc2009-gui/compress_gob.h
    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/gui/tools.cpp
    tools/branches/gsoc2009-gui/tool.cpp
    tools/branches/gsoc2009-gui/tool.h
    tools/branches/gsoc2009-gui/util.cpp
    tools/branches/gsoc2009-gui/util.h
    tools/branches/gsoc2009-gui/utils/file.cpp
    tools/branches/gsoc2009-gui/utils/file.h

Added Paths:
-----------
    tools/branches/gsoc2009-gui/compress_kyra.h
    tools/branches/gsoc2009-gui/compress_queen.h
    tools/branches/gsoc2009-gui/compress_saga.h
    tools/branches/gsoc2009-gui/compress_tinsel.h
    tools/branches/gsoc2009-gui/compress_touche.h
    tools/branches/gsoc2009-gui/compress_tucker.h

Modified: tools/branches/gsoc2009-gui/Makefile
===================================================================
--- tools/branches/gsoc2009-gui/Makefile	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/Makefile	2009-07-06 23:42:10 UTC (rev 42195)
@@ -187,7 +187,7 @@
 
 tools_gui$(EXEEXT): gui/main.o gui/pages.o gui/tools.o compress_agos.o compress_gob.o compress_kyra.o \
 	compress_queen.o compress_saga.o compress_scumm_bun.o compress_scumm_san.o compress_scumm_sou.o \
-	compress_sword1.o compress_sword2.o compress_touche.o compress_tucker.o encode_dxa.o \
+	compress_sword1.o compress_sword2.o compress_touche.o compress_tucker.o compress_tinsel.o encode_dxa.o \
 	extract_agos.o extract_gob_stk.o extract_kyra.o extract_loom_tg16.o extract_mm_apple.o \
 	extract_mm_c64.o extract_mm_nes.o extract_parallaction.o extract_scumm_mac.o \
 	extract_zak_c64.o kyra_pak.o kyra_ins.o compress.o util.o tool.o $(UTILS)

Modified: tools/branches/gsoc2009-gui/compress.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -22,21 +22,6 @@
 
 #include "compress.h"
 
-// The order should match the AudioFormat enum
-const char *audio_extensions(AudioFormat format) {
-	switch(format) {
-	case AUDIO_MP3:
-		return ".mp3";
-	case AUDIO_VORBIS:
-		return ".ogg";
-	case AUDIO_FLAC:
-		return ".fla";
-	case AUDIO_NONE:
-	default:
-		return ".unk";
-	}
-}
-
 typedef struct  {
 	uint32 minBitr;
 	uint32 maxBitr;
@@ -934,17 +919,18 @@
 // The old code can be removed once all tools have been converted
 
 CompressionTool::CompressionTool(const std::string &name) : Tool(name) {
+	_format = AUDIO_MP3;
 }
 
 void CompressionTool::parseAudioArguments() {
-	AudioFormat format = AUDIO_NONE;
+	_format = AUDIO_NONE;
 
 	if (_arguments[_arguments_parsed] ==  "--mp3")
-		format = AUDIO_MP3;
+		_format = AUDIO_MP3;
 	else if (_arguments[_arguments_parsed] == "--vorbis")
-		format = AUDIO_VORBIS;
+		_format = AUDIO_VORBIS;
 	else if (_arguments[_arguments_parsed] == "--flac")
-		format = AUDIO_FLAC;
+		_format = AUDIO_FLAC;
 	else
 		// No audio arguments then
 		return;
@@ -954,7 +940,7 @@
 	// Need workaround to be sign-correct
 	int arg = (int)_arguments_parsed;
 
-	switch (format) {
+	switch (_format) {
 	case AUDIO_MP3:
 		tempEncoded = TEMP_MP3;
 		if (!process_mp3_parms(_arguments.size() - 2, _argv, &arg))

Modified: tools/branches/gsoc2009-gui/compress.h
===================================================================
--- tools/branches/gsoc2009-gui/compress.h	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -70,6 +70,8 @@
 
 	void parseAudioArguments();
 public:
+	AudioFormat _format;
+
 	// Settings
 	// mp3 settings
 	std::string _mp3CompressionType;

Modified: tools/branches/gsoc2009-gui/compress_agos.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_agos.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_agos.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -26,7 +26,6 @@
 #define TEMP_IDX	"tempfile.idx"
 
 CompressAgos::CompressAgos(const std::string &name) : CompressionTool(name) {
-	_compMode = AUDIO_MP3;
 	_convertMac = false;
 
 	_outputToDirectory = false;
@@ -104,10 +103,10 @@
 	if (!memcmp(buf, "Creative", 8)) {
 		print("VOC found (pos = %d) :\n", offset);
 		fseek(_input, 18, SEEK_CUR);
-		extractAndEncodeVOC(TEMP_RAW, _input, _compMode);
+		extractAndEncodeVOC(TEMP_RAW, _input, _format);
 	} else if (!memcmp(buf, "RIFF", 4)) {
 		print("WAV found (pos = %d) :\n", offset);
-		extractAndEncodeWAV(TEMP_WAV, _input, _compMode);
+		extractAndEncodeWAV(TEMP_WAV, _input, _format);
 	} else {
 		error("Unexpected data at offset: %d", offset);
 	}
@@ -204,6 +203,7 @@
 void CompressAgos::parseExtraArguments() {
 	if (_arguments[_arguments_parsed] == "--mac") {
 		_convertMac = true;
+		++_arguments_parsed;
 	}
 }
 
@@ -215,7 +215,7 @@
 
 	if (_outputPath.empty()) {
 		_outputPath = inpath;
-		_outputPath.setExtension(audio_extensions(_compMode));
+		_outputPath.setExtension(audio_extensions(_format));
 	}
 
 	if (_convertMac) {

Modified: tools/branches/gsoc2009-gui/compress_agos.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_agos.h	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_agos.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -35,7 +35,6 @@
 	void parseExtraArguments();
 
 	File _input, _output_idx, _output_snd;
-	AudioFormat _compMode;
 	bool _convertMac;
 
 	void end();

Modified: tools/branches/gsoc2009-gui/compress_gob.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_gob.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_gob.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -23,7 +23,7 @@
 #include "util.h"
 #include "compress_gob.h"
 
-struct Chunk {
+struct CompressGob::Chunk {
 	char name[64];
 	uint32 size, realSize, offset;
 	uint8 packed;
@@ -34,53 +34,39 @@
 	~Chunk() { delete next; }
 };
 
-Chunk *readChunkConf(FILE *gobconf, const char *stkName, uint16 &chunkCount);
-void writeEmptyHeader(FILE *stk, uint16 chunkCount);
-void writeBody(Filename *inpath, FILE *stk, Chunk *chunks);
-uint32 writeBodyStoreFile(FILE *stk, FILE *src);
-uint32 writeBodyPackFile(FILE *stk, FILE *src);
-void rewriteHeader(FILE *stk, uint16 chunkCount, Chunk *chunks);
-bool filcmp(FILE *src1, Chunk *compChunk);
-bool checkDico(byte *unpacked, uint32 unpackedIndex, int32 counter, byte *dico, uint16 currIndex, uint16 &pos, uint8 &length);
 
-uint8 execMode;
-
-int export_main(compress_gob)(int argc, char *argv[]) {
-	const char *helptext = 
-		"\nUsage: %s [-f] [-o <output> = out.stk] <conf file>\n"
+CompressGob::CompressGob(const std::string &name) : CompressionTool(name) {
+	_helptext = 
+		"\nUsage: " + _name + " [-f] [-o <output> = out.stk] <conf file>\n"
 		"<conf file> is a .gob file generated extract_gob_stk\n"
 		"<-f> ignores the compression flag in the .gob file and force compression for all files\n\n"
 		"The STK/ITK archive will be created in the current directory.\n";
 
-	Chunk *chunks;
-	FILE *stk;
-	FILE *gobConf;
-	uint16 chunkCount;
-	Filename inpath, outpath;
-	int first_arg = 1;
-	int last_arg = argc - 1;
+	_execMode = MODE_NORMAL;
+	_chunks = NULL;
+}
 
-	// Now we try to find the proper output
-	// also make sure we skip those arguments
-	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
-		first_arg += 2;
-	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
-		last_arg -= 2;
-	else
-		// Standard output
-		outpath.setFullPath("out.stk");
+CompressGob::~CompressGob() {
+	delete _chunks;
+}
 
-
-	execMode = MODE_NORMAL;
-	if(strcmp(argv[first_arg],  "-f") == 0) {
-		execMode |= MODE_FORCE;
-		++first_arg;
+void CompressGob::parseExtraArguments() {
+	if (_arguments[_arguments_parsed] == "-f") {
+		_execMode |= MODE_FORCE;
+		++_arguments_parsed;
 	}
+}
 
-	if (last_arg - first_arg != 0)
-		error("Expected only one input file");
+void CompressGob::execute() {
+	File stk;
+	File gobConf;
+	uint16 chunkCount;
 
-	inpath.setFullPath(argv[first_arg]);
+	// We only got one input file
+	if (_inputPaths.size() > 1)
+		error("Only one input file expected!");
+	Filename inpath(_inputPaths[0]);
+	Filename &outpath = _outputPath;
 
 	// We output with .stk extension, if there is no specific out file
 	if (outpath.empty()) {
@@ -89,38 +75,20 @@
 	}
 
 	// Open input (config) file
-	if (!(gobConf = fopen(inpath.getFullPath().c_str(), "r")))
-		error("Couldn't open conf file '%s'", inpath.getFullPath().c_str());
+	gobConf.open(inpath, "r");
 
-	if (!(stk = fopen(outpath.getFullPath().c_str(), "wb")))
-		error("Couldn't create file \"%s\"", outpath.getFullPath().c_str());
+	stk.open(outpath, "wb");
 
 	// Read the input into memory
-	chunks = readChunkConf(gobConf, outpath.getFullName().c_str(), chunkCount);
-	fclose(gobConf);
+	_chunks = readChunkConf(gobConf, outpath, chunkCount);
+	gobConf.close();
 
 	// Output in compressed format
 	writeEmptyHeader (stk, chunkCount);
-	writeBody(&inpath, stk, chunks);
-	rewriteHeader(stk, chunkCount, chunks);
-
-	// Cleanup
-	fflush(stk);
-	delete chunks;
-	fclose(stk);
-	return 0;
+	writeBody(&inpath, stk, _chunks);
+	rewriteHeader(stk, chunkCount, _chunks);
 }
 
-void extractError(FILE *f1, FILE *f2, Chunk *chunks, const char *msg) {
-	if (f1)
-		fclose(f1);
-	if (f2)
-		fclose(f2);
-	delete chunks;
-
-	error(msg);
-}
-
 /*! \brief Config file parser
  * \param gobConf Config file to parse
  * \param stk STK/ITK archive file to be created
@@ -133,17 +101,17 @@
  * In order to have a slightly better compression ration in some cases (Playtoons), it
  * also detects duplicate files.
  */
-Chunk *readChunkConf(FILE *gobConf, const char *stkName, uint16 &chunkCount) {
+CompressGob::Chunk *CompressGob::readChunkConf(File &gobConf, const Filename &stkName, uint16 &chunkCount) {
 	Chunk *chunks = new Chunk;
 	Chunk *curChunk = chunks;
 	Chunk *parseChunk;
-	FILE *src1;
+	File src1;
 	char buffer[1024];
 
 	chunkCount = 1;
 
 // First read: Output filename
-	fscanf(gobConf, "%s", stkName);
+	fscanf(gobConf, "%s", stkName.getFullPath().c_str());
 
 // Second read: signature
 	fscanf(gobConf, "%s", buffer);
@@ -157,15 +125,13 @@
 	while (!feof(gobConf)) {
 		strcpy(curChunk->name, buffer);
 		fscanf(gobConf, "%s", buffer);
-		if ((strcmp(buffer, "1") == 0) || (execMode & MODE_FORCE))
+		if ((strcmp(buffer, "1") == 0) || (_execMode & MODE_FORCE))
 			curChunk->packed = true;
 		else
 			curChunk->packed = false;
 
-		if (! (src1 = fopen(curChunk->name, "rb"))) {
-			error("Unable to read %s", curChunk->name);
-		}
-		fseek(src1, 0, SEEK_END);
+		src1.open(curChunk->name, "rb");
+		src1.seek(0, SEEK_END);
 // if file is too small, force 'Store' method
 		if ((curChunk->realSize = ftell(src1)) < 8) 
 			curChunk->packed = 0;
@@ -179,13 +145,13 @@
 // If files are identical, use the same compressed chunk instead of re-compressing the same thing
 					curChunk->packed = 2;
 					curChunk->replChunk = parseChunk;
-					printf("Identical files : %s %s (%d bytes)\n", curChunk->name, parseChunk->name, curChunk->realSize);
+					print("Identical files : %s %s (%d bytes)\n", curChunk->name, parseChunk->name, curChunk->realSize);
 					break;
 				}
 			}
 			parseChunk = parseChunk->next;
 		}
-		fclose(src1);
+		src1.close();
 		
 		fscanf(gobConf, "%s", buffer);
 		if (!feof(gobConf)) {
@@ -207,7 +173,7 @@
  *
  * This header will be overwritten just before the end of the program execution
  */
-void writeEmptyHeader(FILE *stk, uint16 chunkCount) {
+void CompressGob::writeEmptyHeader(File &stk, uint16 chunkCount) {
 	for (uint32 count = 0; count < 2 + (uint32) (chunkCount * 22); count++)
 		fputc(0, stk);
 
@@ -223,46 +189,42 @@
  * with the size of the chunk in the archive, the compression method (if modified),
  * ...
  */
-void writeBody(Filename *inpath, FILE *stk, Chunk *chunks) {
+void CompressGob::writeBody(Filename *inpath, File &stk, Chunk *chunks) {
 	Chunk *curChunk = chunks;
-	FILE *src;
+	File src;
 	uint32 tmpSize;
 	
 	while(curChunk) {
 		inpath->setFullName(curChunk->name);
-		if (!(src = fopen(inpath->getFullPath().c_str(), "rb")))
-			error("Couldn't open file \"%s\"", inpath->getFullPath().c_str());
+		src.open(*inpath, "rb");
 
 		if (curChunk->packed == 2)
-			printf("Identical file %12s\t(compressed size %d bytes)\n", curChunk->name, curChunk->replChunk->size);
+			print("Identical file %12s\t(compressed size %d bytes)\n", curChunk->name, curChunk->replChunk->size);
 
 		curChunk->offset = ftell(stk);
 		if (curChunk->packed == 1) {
-			printf("Compressing %12s\t", curChunk->name);
+			print("Compressing %12s\t", curChunk->name);
 			curChunk->size = writeBodyPackFile(stk, src);
-			printf("%d -> %d bytes", curChunk->realSize, curChunk->size);
+			print("%d -> %d bytes", curChunk->realSize, curChunk->size);
 			if (curChunk->size >= curChunk->realSize) {
 // If compressed size >= realsize, compression is useless
 // => Store instead
 				curChunk->packed = 0;
-				fseek(stk, curChunk->offset, SEEK_SET);
+				stk.seek(curChunk->offset, SEEK_SET);
 				rewind(src);
-				printf("!!!");
+				print("!!!");
 			}
-			printf("\n");
+			print("\n");
 		} 
 
 		if (curChunk->packed == 0) {
 			tmpSize = 0;
-			printf("Storing %12s\t", curChunk->name);
+			print("Storing %12s\t", curChunk->name);
 			curChunk->size = writeBodyStoreFile(stk, src);
-			printf("%d bytes\n", curChunk->size);
+			print("%d bytes\n", curChunk->size);
 		}
-
-		fclose(src);
 		curChunk = curChunk->next;
 	}
-	return;
 }
 
 /*! \brief Rewrites the header of the archive file
@@ -284,7 +246,7 @@
  * The duplicate files are defined using the same information
  * as the one of the replacement file.
 */
-void rewriteHeader(FILE *stk, uint16 chunkCount, Chunk *chunks) {
+void CompressGob::rewriteHeader(File &stk, uint16 chunkCount, Chunk *chunks) {
 	uint16 i;
 	char buffer[1024];
 	Chunk *curChunk = chunks;
@@ -293,7 +255,7 @@
 
 	buffer[0] = chunkCount & 0xFF;
 	buffer[1] = chunkCount >> 8;
-	fwrite(buffer, 1, 2, stk);
+	stk.write(buffer, 1, 2);
 // TODO : Implement STK21
 	while (curChunk) {
 		for (i = 0; i < 13; i++)
@@ -301,7 +263,7 @@
 				buffer[i] = curChunk->name[i];
 			else
 				buffer[i] = '\0';
-		fwrite(buffer, 1, 13, stk);
+		stk.write(buffer, 1, 13);
 
 		if (curChunk->packed == 2)
 		{
@@ -325,10 +287,9 @@
 			buffer[7] = curChunk->offset >> 24;
 			buffer[8] = curChunk->packed;
 		}
-		fwrite(buffer, 1, 9, stk);
+		stk.write(buffer, 1, 9);
 		curChunk = curChunk->next;
 	}
-	return;
 }
 
 /*! \brief Stores a file in the archive file
@@ -338,14 +299,14 @@
  *
  * This function stores a file in the STK archive
  */
-uint32 writeBodyStoreFile(FILE *stk, FILE *src) {
+uint32 CompressGob::writeBodyStoreFile(File &stk, File &src) {
 	int count;
 	char buffer[4096];
 	uint32 tmpSize = 0;
 
 	do {
 		count = fread(buffer, 1, 4096, src);
-		fwrite(buffer, 1, count, stk);
+		stk.write(buffer, 1, count);
 		tmpSize += count;
 	} while (count == 4096);
 	return tmpSize;
@@ -358,7 +319,7 @@
  *
  * This function compress a file in the STK archive
  */
-uint32 writeBodyPackFile(FILE *stk, FILE *src) {
+uint32 CompressGob::writeBodyPackFile(File &stk, File &src) {
 	byte dico[4114];
 	byte writeBuffer[17];
 	uint32 counter;
@@ -375,13 +336,13 @@
 	for (int i = 0; i < 4096 - 18; i++)
 		dico[i] = 0x20;
 
-	fread(unpacked, 1, size, src);
+	src.read(unpacked, 1, size);
 
 	writeBuffer[0] = size & 0xFF;
 	writeBuffer[1] = size >> 8;
 	writeBuffer[2] = size >> 16;
 	writeBuffer[3] = size >> 24;
-	fwrite(writeBuffer, 1, 4, stk);
+	stk.write(writeBuffer, 1, 4);
 
 // Size is already checked : small files (less than 8 characters) 
 // are not compressed, so copying the first three bytes is safe.
@@ -462,16 +423,15 @@
  * This function compares a file to another defined in a chunk. The file sizes 
  * are already tested outside the function.
  */
-bool filcmp(FILE *src1, Chunk *compChunk) {
+bool CompressGob::filcmp(File &src1, Chunk *compChunk) {
 	uint16 readCount;
 	bool checkFl = true;
 	char buf1[4096]; 
 	char buf2[4096];
-	FILE *src2;
+	File src2;
 
 	rewind(src1);
-	if (!(src2 = fopen(compChunk->name, "rb")))
-		error("Couldn't open file \"%s\"", compChunk->name);
+	src2.open(compChunk->name, "rb");
 	
 	do {
 		readCount = fread(buf1, 1, 4096, src1);
@@ -480,7 +440,6 @@
 			if (buf1[i] != buf2[i])
 				checkFl = false;
 	} while (checkFl & (readCount == 4096));
-	fclose(src2);
 
 	return checkFl;
 }
@@ -500,7 +459,7 @@
  * are found in the dictionary. The match lengths are limited to 18 characters, as the 
  * length (minus 3) is stored on 4 bits.
  */
-bool checkDico(byte *unpacked, uint32 unpackedIndex, int32 counter, byte *dico, uint16 currIndex, uint16 &pos, uint8 &length) {
+bool CompressGob::checkDico(byte *unpacked, uint32 unpackedIndex, int32 counter, byte *dico, uint16 currIndex, uint16 &pos, uint8 &length) {
 	uint16 tmpPos, bestPos;
 	uint8 tmpLength, bestLength, i;
 
@@ -540,6 +499,7 @@
 
 #ifdef STANDALONE_MAIN
 int main(int argc, char *argv[]) {
-	return export_main(compress_gob)(argc, argv);
+	CompressGob gob(argv[0]);
+	return gob.run(argc, argv);
 }
 #endif

Modified: tools/branches/gsoc2009-gui/compress_gob.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_gob.h	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_gob.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -23,6 +23,8 @@
 #ifndef COMPRESS_GOB_H
 #define COMPRESS_GOB_H
 
+#include "compress.h"
+
 #define confSTK21 "STK21"
 #define confSTK10 "STK10"
 
@@ -31,4 +33,31 @@
 #define MODE_FORCE  2
 #define MODE_SET    4
 
+
+class CompressGob : public CompressionTool {
+public:
+	CompressGob(const std::string &name = "compress_gob");
+	~CompressGob();
+
+	virtual void execute();
+
+protected:
+	struct Chunk;
+	
+	uint8 _execMode;
+	Chunk *_chunks;
+
+	void parseExtraArguments();
+
+	Chunk *readChunkConf(File &gobconf, const Filename &stkName, uint16 &chunkCount);
+	void writeEmptyHeader(File &stk, uint16 chunkCount);
+	void writeBody(Filename *inpath, File &stk, Chunk *chunks);
+	uint32 writeBodyStoreFile(File &stk, File &src);
+	uint32 writeBodyPackFile(File &stk, File &src);
+	void rewriteHeader(File &stk, uint16 chunkCount, Chunk *chunks);
+	bool filcmp(File &src1, Chunk *compChunk);
+	bool checkDico(byte *unpacked, uint32 unpackedIndex, int32 counter, byte *dico, uint16 currIndex, uint16 &pos, uint8 &length);
+
+};
+
 #endif

Modified: tools/branches/gsoc2009-gui/compress_kyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_kyra.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_kyra.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -20,48 +20,25 @@
  *
  */
 
+#include "compress_kyra.h"
+
 #include "compress.h"
 #include "kyra_pak.h"
 
-static void process(Filename *infile, Filename *output);
-static void processKyra3(Filename *infile, Filename *output);
-static bool detectKyra3File(Filename *infile);
-
 #define TEMPFILE "TEMP.VOC"
 
-static AudioFormat gCompMode = AUDIO_MP3;
+CompressKyra::CompressKyra(const std::string &name) : CompressionTool(name) {
+	_helptext = "\nUsage: " + _name + " [mode params] [-o outfile] <infile>\n" kCompressionAudioHelp;
+}
 
-int export_main(compress_kyra)(int argc, char *argv[]) {
-	const char *helptext = "\nUsage: %s [mode] [mode params] [-o out = ] <infile>\n" kCompressionAudioHelp;
+void CompressKyra::execute() {
+	// Check input
+	if (_inputPaths.size() == 1)
+		error("One input file expected!");
+	Filename inpath(_inputPaths[0]);
+	Filename &outpath = _outputPath;
 
-	Filename inpath, outpath;
-	int first_arg = 1;
-	int last_arg = argc - 1;
-
-	parseHelpArguments(argv, argc, helptext);
-
-	// Compression mode
-	gCompMode = process_audio_params(argc, argv, &first_arg);
-
-	if (gCompMode == AUDIO_NONE) {
-		// Unknown mode (failed to parse arguments), display help and exit
-		displayHelp(helptext, argv[0]);
-	}
-	
-	// Now we try to find the proper output file
-	// also make sure we skip those arguments
-	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
-		first_arg += 2;
-	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
-		last_arg -= 2;
-	else
-		// Standard output file is 'out'
-		outpath.setFullPath("out");
-	
-	inpath.setFullName(argv[first_arg]);
-	outpath.setFullName(argv[first_arg]);
-
-	if (inpath.equals(&outpath))
+	if (inpath == outpath)
 		error("Infile and outfile cannot be the same file");
 
 	bool isKyra3 = detectKyra3File(&inpath);
@@ -69,11 +46,9 @@
 		process(&inpath, &outpath);
 	else
 		processKyra3(&inpath, &outpath);
-
-	return 0;
 }
 
-static void process(Filename *infile, Filename *outfile) {
+void CompressKyra::process(Filename *infile, Filename *outfile) {
 	PAKFile input, output;
 
 	if (!input.loadFile(infile->getFullPath().c_str(), false))
@@ -98,12 +73,12 @@
 		input.outputFileAs(list->filename, TEMPFILE);
 		outputName._path = list->filename;
 
-		FILE *tempFile = fopen(TEMPFILE, "rb");
-		fseek(tempFile, 26, SEEK_CUR);
-		extractAndEncodeVOC(TEMP_RAW, tempFile, gCompMode);
-		fclose(tempFile);
+		File tempFile(TEMPFILE, "rb");
+		tempFile.seek(26, SEEK_CUR);
+		extractAndEncodeVOC(TEMP_RAW, tempFile, _format);
+		tempFile.close();
 
-		outputName.setExtension(audio_extensions(gCompMode));
+		outputName.setExtension(audio_extensions(_format));
 
 		output.addFile(outputName.getFullPath().c_str(), tempEncoded);
 
@@ -115,12 +90,12 @@
 	if (output.getFileList())
 		output.saveFile(outfile->getFullPath().c_str());
 	else
-		printf("file '%s' doesn't contain any .voc files\n", infile->getFullPath().c_str());
+		print("file '%s' doesn't contain any .voc files\n", infile->getFullPath().c_str());
 }
 
 // Kyra3 specifc code
 
-static uint16 clip8BitSample(int16 sample) {
+uint16 CompressKyra::clip8BitSample(int16 sample) {
 	if (sample > 255)
 		return 255;
 	if (sample < 0)
@@ -128,10 +103,10 @@
 	return sample;
 }
 
-static int decodeChunk(FILE *in, FILE *out) {
-	uint16 size = readUint16LE(in);
-	uint16 outSize = readUint16LE(in);
-	uint32 id = readUint32LE(in);
+int CompressKyra::decodeChunk(File &in, File &out) {
+	uint16 size = in.readU16LE();
+	uint16 outSize = in.readU16LE();
+	uint32 id = in.readU32LE();
 	byte *inputBuffer, *outputBuffer;
 	int bytesRead = 0;
 
@@ -166,8 +141,6 @@
 		}
 		while (size > 0)  {
 			int written = fwrite(outputBuffer, 1, size, out);
-			if (written <= 0)
-				error("[1] Couldn't write data");
 			size -= written;
 		}
 		free(outputBuffer);
@@ -278,37 +251,32 @@
 	byte type;
 } AUDHeader;
 
-static void compressAUDFile(FILE *input, const char *outfile) {
+void CompressKyra::compressAUDFile(File &input, const char *outfile) {
 	AUDHeader header;
 
-	header.freq = readUint16LE(input);
-	header.size = readUint32LE(input);
-	header.flags = readByte(input);
-	header.type = readByte(input);
-	//printf("%d Hz, %d bytes, type %d (%08X)\n", header.freq, header.size, header.type, header.flags);
+	header.freq = input.readU16LE();
+	header.size = input.readU32LE();
+	header.flags = input.readByte();
+	header.type = input.readByte();
+	//print("%d Hz, %d bytes, type %d (%08X)\n", header.freq, header.size, header.type, header.flags);
 
-	FILE *output = fopen(TEMP_RAW, "wb");
+	File output(TEMP_RAW, "wb");
 
-	if (!output)
-		error("Couldn't create temporary file '%s'", TEMP_RAW);
-
 	uint32 remaining = header.size;
 	while (remaining > 0)
 		remaining -= decodeChunk(input, output);
 
-	fclose(output);
+	encodeAudio(TEMP_RAW, true, header.freq, outfile, _format);
 
-	encodeAudio(TEMP_RAW, true, header.freq, outfile, gCompMode);
-
 	unlink(TEMP_RAW);
 }
 
-struct DuplicatedFile {
+struct CompressKyra::DuplicatedFile {
 	uint32 resFilename;
 	uint32 resOffset;
 };
 
-static const DuplicatedFile *findDuplicatedFile(uint32 resOffset, const DuplicatedFile *list, const uint32 maxEntries) {
+const CompressKyra::DuplicatedFile *CompressKyra::findDuplicatedFile(uint32 resOffset, const DuplicatedFile *list, const uint32 maxEntries) {
 	for (uint32 i = 0; i < maxEntries; ++i) {
 		if (list[i].resOffset == resOffset && list[i].resOffset != 0)
 			return &list[i];
@@ -317,42 +285,36 @@
 	return 0;
 }
 
-static void processKyra3(Filename *infile, Filename *outfile) {
+void CompressKyra::processKyra3(Filename *infile, Filename *outfile) {
 	if (infile->hasExtension("AUD")) {
-		outfile->setExtension(audio_extensions(gCompMode));
+		outfile->setExtension(audio_extensions(_format));
 
-		FILE *input = fopen(infile->getFullPath().c_str(), "rb");
-		if (!input)
-			error("Couldn't open file '%s'", infile->getFullPath().c_str());
+		File input(*infile, "rb");
 
 		compressAUDFile(input, outfile->getFullPath().c_str());
-
-		fclose(input);
 	} else if (infile->hasExtension("TLK")) {
 		PAKFile output;
 
-		FILE *input = fopen(infile->getFullPath().c_str(), "rb");
-		if (!input)
-			error("Couldn't open file '%s'", infile->getFullPath().c_str());
+		File input(*infile, "rb");
 
 		if (!output.loadFile(NULL, false))
 			return;
 
-		uint16 files = readUint16LE(input);
+		uint16 files = input.readU16LE();
 		DuplicatedFile *red = new DuplicatedFile[files];
 		memset(red, 0, sizeof(DuplicatedFile)*files);
 
 		for (uint16 i = 0; i < files; ++i) {
-			uint32 resFilename = readUint32LE(input);
-			uint32 resOffset = readUint32LE(input);
+			uint32 resFilename = input.readU32LE();
+			uint32 resOffset = input.readU32LE();
 
 			char outname[16];
-			snprintf(outname, 16, "%.08u.%s", resFilename, audio_extensions(gCompMode));
+			snprintf(outname, 16, "%.08u.%s", resFilename, audio_extensions(_format));
 
 			const DuplicatedFile *file = findDuplicatedFile(resOffset, red, files);
 			if (file) {
 				char linkname[16];
-				snprintf(linkname, 16, "%.08u.%s", file->resFilename, audio_extensions(gCompMode));
+				snprintf(linkname, 16, "%.08u.%s", file->resFilename, audio_extensions(_format));
 
 				output.linkFiles(outname, linkname);
 			} else {
@@ -373,7 +335,6 @@
 		}
 
 		delete[] red;
-		fclose(input);
 
 		if (output.getFileList())
 			output.saveFile(outfile->getFullPath().c_str());
@@ -382,7 +343,7 @@
 	}
 }
 
-bool detectKyra3File(Filename *infile) {
+bool CompressKyra::detectKyra3File(Filename *infile) {
 	if (infile->hasExtension("AUD")) {
 		return true;
 	} else if (infile->hasExtension("VRM") || infile->hasExtension("PAK")) {
@@ -393,23 +354,20 @@
 		if (PAKFile::isPakFile(infile->getFullPath().c_str()))
 			return false;
 
-		FILE *f = fopen(infile->getFullPath().c_str(), "rb");
-		if (!f)
-			error("Couldn't open file '%s'", infile->getFullPath().c_str());
+		File f(*infile, "rb");
 
 		uint16 entries = readUint16LE(f);
 		uint32 entryTableSize = (entries * 8);
 		const uint32 filesize = fileSize(f);
 
 		if (entryTableSize + 2 > filesize) {
-			fclose(f);
 			error("Unknown filetype of file: '%s'", infile->getFullPath().c_str());
 		}
 
 		uint32 offset = 0;
 		for (uint16 i = 0; i < entries; ++i) {
-			readUint32LE(f);
-			offset = readUint32LE(f);
+			f.readU32LE();
+			offset = f.readU32LE();
 
 			if (offset > filesize)
 				error("Unknown filetype of file: '%s'", infile->getFullPath().c_str());
@@ -419,6 +377,9 @@
 	}
 
 	error("Unknown filetype of file: '%s'", infile->getFullPath().c_str());
+
+	// Never reached
+	return false;
 }
 
 #ifdef STANDALONE_MAIN

Added: tools/branches/gsoc2009-gui/compress_kyra.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_kyra.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/compress_kyra.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -0,0 +1,46 @@
+/* compress_kyra_bun - compressor for kyra sound file packages
+ * Copyright (C) 2006  The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMPRESS_KYRA_H
+#define COMPRESS_KYRA_H
+
+#include "compress.h"
+
+class CompressKyra : public CompressionTool {
+public:
+	CompressKyra(const std::string &name = "compress_kyra");
+
+	virtual void execute();
+
+protected:
+	struct DuplicatedFile;
+
+	uint16 clip8BitSample(int16 sample);
+	int decodeChunk(File &in, File &out);
+	void compressAUDFile(File &input, const char *outfile);
+	const DuplicatedFile *findDuplicatedFile(uint32 resOffset, const DuplicatedFile *list, const uint32 maxEntries);
+	void process(Filename *infile, Filename *output);
+	void processKyra3(Filename *infile, Filename *output);
+	bool detectKyra3File(Filename *infile);
+};
+
+#endif


Property changes on: tools/branches/gsoc2009-gui/compress_kyra.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: tools/branches/gsoc2009-gui/compress_queen.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_queen.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_queen.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -1,5 +1,5 @@
 /* compress_queen - Rebuild QUEEN.1 file to contain Resource Table (and optionally compress sound & speech)
- * Copyright (C) 2003-2006  The ScummVM Team
+ * Copyright (C) 2009  The ScummVM Team
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -22,9 +22,10 @@
 
 #include "compress.h"
 
-static const uint32 QTBL = 'QTBL';
-static AudioFormat gCompMode = AUDIO_MP3;
+#include "compress_queen.h"
 
+const uint32 QTBL = 'QTBL';
+
 #define INPUT_TBL	"queen.tbl"
 #define FINAL_OUT	"queen.1c"
 
@@ -38,13 +39,6 @@
 #define SB_HEADER_SIZE_V110 122
 
 enum {
-	COMPRESSION_NONE = 0,
-	COMPRESSION_MP3 = 1,
-	COMPRESSION_OGG = 2,
-	COMPRESSION_FLAC = 3
-};
-
-enum {
 	VER_ENG_FLOPPY     = 0,
 	VER_ENG_TALKIE     = 1,
 	VER_FRE_FLOPPY     = 2,
@@ -65,36 +59,12 @@
 	VER_PC_COUNT       = 13 /* PC versions */
 };
 
-struct GameVersion {
-	char versionString[6];
-	uint8 isFloppy;
-	uint8 isDemo;
-	uint32 tableOffset;
-	uint32 dataFileSize;
-};
-
-struct Entry {
-	char filename[13];
-	uint8 bundle;
-	uint32 offset;
-	uint32 size;
-};
-
-Entry entry;
-
-struct VersionExtra {
-	uint8	compression;
-	uint16	entries;
-};
-
-VersionExtra versionExtra;
-
 struct PatchFile {
 	const char *filename;
 	char lang;
 };
 
-const struct GameVersion gameVersions[] = {
+const struct CompressQueen::GameVersion gameVersions[] = {
 	{ "PEM10", 1, 0, 0x00000008,  22677657 },
 	{ "CEM10", 0, 0, 0x0000584E, 190787021 },
 	{ "PFM10", 1, 0, 0x0002CD93,  22157304 },
@@ -119,9 +89,12 @@
 	{ "BUD1.DOG",   'I' }
 };
 
-const struct GameVersion *version;
+CompressQueen::CompressQueen(const std::string &name) : CompressionTool(name) {
+	
+	_helptext = "\nUsage: %s [mode] [mode params] [-o outputfile] <inputfile (queen.1)>\n" kCompressionAudioHelp;
+}
 
-const struct GameVersion *detectGameVersion(uint32 size) {
+const CompressQueen::GameVersion *CompressQueen::detectGameVersion(uint32 size) {
 	const struct GameVersion *pgv = gameVersions;
 	int i;
 
@@ -137,13 +110,7 @@
 	return NULL;
 }
 
-void checkOpen(FILE *fp, const char *filename) {
-	if (!fp) {
-		error("Cannot open file: %s", filename);
-	}
-}
-
-void fromFileToFile(FILE *in, FILE *out, uint32 amount) {
+void CompressQueen::fromFileToFile(File &in, File &out, uint32 amount) {
 	char fBuf[2048];
 	uint32 numRead;
 
@@ -154,155 +121,121 @@
 		}
 
 		amount -= numRead;
-		fwrite(fBuf, 1, numRead, out);
+		out.write(fBuf, 1, numRead);
 	}
 }
 
-void createFinalFile(Filename *outPath) {
-	FILE *inTbl, *inData, *outFinal;
+void CompressQueen::createFinalFile(Filename *outPath) {
 	int i;
 	uint32 dataStartOffset;
 	uint32 dataSize;
 
-	inTbl = fopen(TEMP_TBL, "rb");
-	checkOpen(inTbl, TEMP_TBL);
-	inData = fopen(TEMP_DAT, "rb");
-	checkOpen(inData, TEMP_DAT);
+	File inTbl(TEMP_TBL, "rb");
+	File inData(TEMP_DAT, "rb");
+	File outFinal(*outPath, "wb");
 
-	outFinal = fopen(outPath->getFullPath().c_str(), "wb");
-	checkOpen(outFinal, outPath->getFullPath().c_str());
-
-	dataStartOffset = fileSize(inTbl) + EXTRA_TBL_HEADER;
+	dataStartOffset = inTbl.size() + EXTRA_TBL_HEADER;
 	dataSize = fileSize(inData);
 
-	fseek(inTbl, 7, SEEK_SET);	/* Skip past header */
+	inTbl.seek(7, SEEK_SET);	/* Skip past header */
 
 	/* Write new header */
-	writeUint32BE(outFinal, QTBL);
-	fwrite(version->versionString, 6, 1, outFinal);
-	writeByte(outFinal, version->isFloppy);
-	writeByte(outFinal, version->isDemo);
-	writeByte(outFinal, versionExtra.compression);
-	writeUint16BE(outFinal, versionExtra.entries);
+	outFinal.writeU32BE(QTBL);
+	outFinal.write(_version->versionString, 6, 1);
+	outFinal.writeByte(_version->isFloppy);
+	outFinal.writeByte(_version->isDemo);
+	outFinal.writeByte(_versionExtra.compression);
+	outFinal.writeU16BE(_versionExtra.entries);
 
-	for (i = 0; i < versionExtra.entries; i++) {
+	for (i = 0; i < _versionExtra.entries; i++) {
 		fromFileToFile(inTbl, outFinal, 12);
-		writeByte(outFinal, readByte(inTbl));
-		writeUint32BE(outFinal, dataStartOffset + readUint32BE(inTbl));
-		writeUint32BE(outFinal, readUint32BE(inTbl));
+		outFinal.writeByte(inTbl.readByte());
+		outFinal.writeU32BE(dataStartOffset + inTbl.readU32BE());
+		outFinal.writeU32BE(inTbl.readU32BE());
 	}
 
 	/* Append contents of temporary datafile to final datafile */
 	fromFileToFile(inData, outFinal, dataSize);
 
-	fclose(inTbl);
-	fclose(inData);
-	fclose(outFinal);
-
 	/* Cleanup */
 	unlink(TEMP_TBL);
 	unlink(TEMP_DAT);
 }
 
-int export_main(compress_queen)(int argc, char *argv[]) {
-	const char *helptext = "\nUsage: %s [mode] [mode params] [-o outputfile] <inputfile (queen.1)>\n" kCompressionAudioHelp;
-
-	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
-	uint8 compressionType = COMPRESSION_NONE;
-	Filename inpath, outpath;;
+void CompressQueen::execute() {
+	File inputData, inputTbl, outputTbl, outputData, compFile;
 	char tmp[5];
 	int size, i = 1;
 	uint32 prevOffset;
-	int first_arg = 1;
-	int last_arg = argc - 1;
 
-	parseHelpArguments(argv, argc, helptext);
+	// Check input
+	if (_inputPaths.size() == 1)
+		error("One input file expected!");
+	Filename inpath(_inputPaths[0]);
+	Filename &outpath = _outputPath;
 
-	gCompMode = process_audio_params(argc, argv, &first_arg);
-
-	if (gCompMode == AUDIO_NONE) {
-		// Unknown mode (failed to parse arguments), display help and exit
-		displayHelp(helptext, argv[0]);
-	}
-	
-	// Now we try to find the proper output file
-	// also make sure we skip those arguments
-	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
-		first_arg += 2;
-	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
-		last_arg -= 2;
-	else 
-		// Just leave it empty, we just change extension of input file
-		;
-
-	inpath.setFullPath(argv[first_arg]);
-
 	if (outpath.empty()) {
 		outpath = inpath;
 		outpath.setFullName(FINAL_OUT);
 	}
 
 	/* Open input file (QUEEN.1) */
-	inputData = fopen(inpath.getFullPath().c_str(), "rb");
-	checkOpen(inputData, inpath.getFullPath().c_str());
+	inputData.open(inpath, "rb");
 
 	/* Open TBL file (QUEEN.TBL) */
 	inpath.setFullName(INPUT_TBL);
-	inputTbl = fopen(inpath.getFullPath().c_str(), "rb");
-	checkOpen(inputTbl, inpath.getFullPath().c_str());
+	inputTbl.open(inpath, "rb");
 
-	size = fileSize(inputData);
-	fread(tmp, 1, 4, inputTbl);
+	size = inputData.size();
+	inputTbl.read(tmp, 1, 4);
 	tmp[4] = '\0';
 
 	if (memcmp(tmp, "QTBL", 4)) {
 		error("Invalid TBL file");
 	}
 
-	if (readUint32BE(inputTbl) != CURRENT_TBL_VERSION) {
+	if (inputTbl.readU32BE() != CURRENT_TBL_VERSION) {
 		error("You are using an incorrect (outdated?) version of the queen.tbl file");
 	}
 
-	version = detectGameVersion(size);
-	fseek(inputTbl, version->tableOffset, SEEK_SET);
+	_version = detectGameVersion(size);
+	inputTbl.seek(_version->tableOffset, SEEK_SET);
 
-	versionExtra.compression = compressionType;
-	versionExtra.entries = readUint16BE(inputTbl);
+	_versionExtra.compression = compression_format(_format);
+	_versionExtra.entries = inputTbl.readU16BE();
 
-	outputTbl = fopen(TEMP_TBL, "wb");
-	checkOpen(outputTbl, TEMP_TBL);
+	outputTbl.open(TEMP_TBL, "wb");
 
-	outputData = fopen(TEMP_DAT, "wb");
-	checkOpen(outputData, TEMP_DAT);
+	outputData.open(TEMP_DAT, "wb");
 
 	/* Write tablefile header */
-	writeUint32BE(outputTbl, QTBL);
-	writeByte(outputTbl, versionExtra.compression);
-	writeUint16BE(outputTbl, versionExtra.entries);
+	outputTbl.writeU32BE(QTBL);
+	outputTbl.writeByte(_versionExtra.compression);
+	outputTbl.writeU16BE(_versionExtra.entries);
 
-	for (i = 0; i < versionExtra.entries; i++) {
+	for (i = 0; i < _versionExtra.entries; i++) {
 		prevOffset = ftell(outputData);
 
 		/* Read entry */
-		fread(entry.filename, 1, 12, inputTbl);
-		entry.filename[12] = '\0';
-		entry.bundle = readByte(inputTbl);
-		entry.offset = readUint32BE(inputTbl);
-		entry.size = readUint32BE(inputTbl);
+		inputTbl.read(_entry.filename, 1, 12);
+		_entry.filename[12] = '\0';
+		_entry.bundle = inputTbl.readByte();
+		_entry.offset = inputTbl.readU32BE();
+		_entry.size = inputTbl.readU32BE();
 
-		printf("Processing entry: %s\n", entry.filename);
-		fseek(inputData, entry.offset, SEEK_SET);
+		print("Processing entry: %s\n", _entry.filename);
+		fseek(inputData, _entry.offset, SEEK_SET);
 
-		if (versionExtra.compression && strstr(entry.filename, ".SB")) { /* Do we want to compress? */
+		if (_versionExtra.compression && strstr(_entry.filename, ".SB")) { /* Do we want to compress? */
 			uint16 sbVersion;
 			int headerSize;
 
 			/* Read in .SB */
-			tmpFile = fopen(TEMP_SB, "wb");
-			fseek(inputData, entry.offset, SEEK_SET);
+			File tmpFile(TEMP_SB, "wb");
+			inputData.seek(_entry.offset, SEEK_SET);
 
-			fseek(inputData, 2, SEEK_CUR);
-			sbVersion = readUint16LE(inputData);
+			inputData.seek(2, SEEK_CUR);
+			sbVersion = inputData.readU16LE();
 
 			switch (sbVersion) {
 			case 104:
@@ -317,21 +250,20 @@
 				break;
 			}
 
-			fseek(inputData, headerSize - 4, SEEK_CUR);
-			entry.size -= headerSize;
+			inputData.seek(headerSize - 4, SEEK_CUR);
+			_entry.size -= headerSize;
 
-			fromFileToFile(inputData, tmpFile, entry.size);
-			fclose(tmpFile);
+			fromFileToFile(inputData, tmpFile, _entry.size);
 
 			/* Invoke encoder */
 			setRawAudioType(false, false, 8);
-			encodeAudio(TEMP_SB, true, 11840, tempEncoded, gCompMode);
+			encodeAudio(TEMP_SB, true, 11840, tempEncoded, _format);
 
 			/* Append MP3/OGG to data file */
-			compFile = fopen(tempEncoded, "rb");
-			entry.size = fileSize(compFile);
-			fromFileToFile(compFile, outputData, entry.size);
-			fclose(compFile);
+			compFile.open(tempEncoded, "rb");
+			_entry.size = fileSize(compFile);
+			fromFileToFile(compFile, outputData, _entry.size);
+			compFile.close();
 
 			/* Delete temporary files */
 			unlink(TEMP_SB);
@@ -345,15 +277,15 @@
 			for (j = 0; j < ARRAYSIZE(patchFiles); ++j) {
 				const struct PatchFile *pf = &patchFiles[j];
 
-				if (version->versionString[1] == pf->lang && strcmp(pf->filename, entry.filename) == 0) {
+				if (_version->versionString[1] == pf->lang && strcmp(pf->filename, _entry.filename) == 0) {
 					/* XXX patched data files are supposed to be in cwd */
-					FILE *fpPatch = fopen(pf->filename, "rb");
+					File fpPatch(pf->filename, "rb");
 
 					if (fpPatch) {
-						entry.size = fileSize(fpPatch);
-						printf("Patching entry, new size = %d bytes\n", entry.size);
-						fromFileToFile(fpPatch, outputData, entry.size);
-						fclose(fpPatch);
+						_entry.size = fpPatch.size();
+						print("Patching entry, new size = %d bytes\n", _entry.size);
+						fromFileToFile(fpPatch, outputData, _entry.size);
+						fpPatch.close();
 						patched = true;
 					}
 
@@ -362,32 +294,25 @@
 			}
 
 			if (!patched) {
-				fromFileToFile(inputData, outputData, entry.size);
+				fromFileToFile(inputData, outputData, _entry.size);
 			}
 		}
 
 		/* Write entry to table */
-		fwrite(entry.filename, 12, 1, outputTbl);
-		writeByte(outputTbl, entry.bundle);
-		writeUint32BE(outputTbl, prevOffset);
-		writeUint32BE(outputTbl, entry.size);
+		outputTbl.write(_entry.filename, 12, 1);
+		outputTbl.writeByte(_entry.bundle);
+		outputTbl.writeU32BE(prevOffset);
+		outputTbl.writeU32BE(_entry.size);
 	}
 
-	/* Close files */
-	fclose(outputTbl);
-	fclose(outputData);
-	fclose(inputTbl);
-	fclose(inputData);
-
 	/* Merge the temporary table and temporary datafile to create final file */
 	createFinalFile(&outpath);
-
-	return 0;
 }
 
-#ifdef STANDALON_MAIN
+#ifdef STANDALONE_MAIN
 int main(int argc, char *argv[]) {
-	return export_main(compress_queen)(argc, argv);
+	CompressQueen queen(argv[0]);
+	return queen.run(argc, argv);
 }
 #endif
 

Added: tools/branches/gsoc2009-gui/compress_queen.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_queen.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/compress_queen.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -0,0 +1,65 @@
+/* compress_queen - Rebuild QUEEN.1 file to contain Resource Table (and optionally compress sound & speech)
+ * Copyright (C) 2009  The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMPRESS_QUEEN_H
+#define COMPRESS_QUEEN_H
+
+#include "compress.h"
+
+class CompressQueen : public CompressionTool {
+public:
+	CompressQueen(const std::string &name = "compress_queen");
+
+	virtual void execute();
+
+	// Keeping structs here avoids name-clashes with other tools
+	struct GameVersion {
+		char versionString[6];
+		uint8 isFloppy;
+		uint8 isDemo;
+		uint32 tableOffset;
+		uint32 dataFileSize;
+	};
+
+	struct Entry {
+		char filename[13];
+		uint8 bundle;
+		uint32 offset;
+		uint32 size;
+	};
+
+	struct VersionExtra {
+		uint8	compression;
+		uint16	entries;
+	};
+
+protected:
+	Entry _entry;
+	VersionExtra _versionExtra;
+	const GameVersion *_version;
+
+	void createFinalFile(Filename *outPath);
+	void fromFileToFile(File &in, File &out, uint32 amount);
+	const GameVersion *detectGameVersion(uint32 size);
+};
+
+#endif


Property changes on: tools/branches/gsoc2009-gui/compress_queen.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: tools/branches/gsoc2009-gui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_saga.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_saga.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -1,4 +1,3 @@
-
 /* compress_saga - Compress SAGA engine digital sound files into
  * MP3 and Ogg Vorbis format
  * Copyright (C) 2004, Marcoen Hirschberg
@@ -24,6 +23,7 @@
  */
 
 #include "compress.h"
+#include "compress_saga.h"
 #include "utils/md5.h"
 #include "utils/util.h"
 #include "utils/audiostream.h"
@@ -37,25 +37,8 @@
 #define RSC_TABLEENTRY_SIZE 8
 #define HEADER_SIZE 9
 
-enum GameSoundTypes {
-	kSoundPCM = 0,
-	kSoundVOX = 1,
-	kSoundVOC = 2,
-	kSoundWAV = 3,
-	kSoundMacPCM = 4
-};
-
-struct GameFileDescription {
-	const char *fileName;
-	bool swapEndian;
-	const char *md5;
-	GameSoundTypes resourceType;
-	long frequency;
-	bool stereo;
-};
-
 // Known ITE files
-static GameFileDescription ITE_GameFiles[] = {
+static CompressSaga::GameFileDescription ITE_GameFiles[] = {
 	//	Filename					swapEndian	md5									resourceType	frequency	stereo
 	{"sounds.rsc",					false,		"e2ccb61c325d6d1ead3be0e731fe29fe", kSoundPCM,		22050,		false},	// PC CD/disk
 	{"sounds.rsc",					true,		"95863b89a0916941f6c5e1789843ba14", kSoundPCM,		22050,		false},	// Mac
@@ -86,7 +69,7 @@
 };
 
 // Known IHNM files
-static GameFileDescription IHNM_GameFiles[] = {
+static CompressSaga::GameFileDescription IHNM_GameFiles[] = {
 	//	Filename					swapEndian	md5									resourceType	frequency	stereo
 	// FIXME: sfx.res is disabled for now, as there are issues when trying to encode it
 	//{"sfx.res",					false,		"1c610d543f32ec8b525e3f652536f269", kSoundWAV,		-1,			false},
@@ -103,18 +86,7 @@
 
 // --------------------------------------------------------------------------------
 
-enum SAGAGameType {
-	GType_ITE = 0,
-	GType_IHNM = 1
-};
-
-struct GameDescription {
-	SAGAGameType gameType;
-	int filesCount;
-	GameFileDescription *filesDescriptions;
-};
-
-static GameDescription gameDescriptions[] = {
+static CompressSaga::GameDescription gameDescriptions[] = {
 	// Inherit the earth
 	{
 		GType_ITE,
@@ -136,30 +108,28 @@
 	uint32 size;
 } Record;
 
-static AudioFormat gCompMode = AUDIO_MP3;
+// Constructor
+CompressSaga::CompressSaga(const std::string &name) : CompressionTool(name) {
+	_currentGameDescription = NULL;
+	_currentFileDescription = NULL;
 
-GameDescription *currentGameDescription = NULL;
-GameFileDescription *currentFileDescription = NULL;
+	_helptext = "\nUsage: %s [mode] [mode params] [-o outputfile = infile.cmp] <inputfile>\n" kCompressionAudioHelp;
+}
 
-uint16 sampleRate;
-uint32 sampleSize;
-uint8 sampleBits;
-uint8 sampleStereo;
-
 // --------------------------------------------------------------------------------
 
-bool detectFile(Filename *infile) {
+bool CompressSaga::detectFile(Filename *infile) {
 	int gamesCount = ARRAYSIZE(gameDescriptions);
 	int i, j;
 	uint8 md5sum[16];
 	char md5str[32+1];
 
 	Common::md5_file(infile->getFullPath().c_str(), md5sum, FILE_MD5_BYTES);
-	printf("Input file name: %s\n", infile->getFullPath());
+	print("Input file name: %s\n", infile->getFullPath());
 	for (j = 0; j < 16; j++) {
 		sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
 	}
-	printf("md5: %s\n", md5str);
+	print("md5: %s\n", md5str);
 
 	for (i = 0; i < gamesCount; i++) {
 		for (j = 0; j < gameDescriptions[i].filesCount; j++) {
@@ -167,10 +137,10 @@
 				// MD5 based detection, needed to distinguish the different file encodings
 				// of the ITE sound files
 				if (strcmp(gameDescriptions[i].filesDescriptions[j].md5, md5str) == 0) {
-					currentGameDescription = &gameDescriptions[i];
-					currentFileDescription = &currentGameDescription->filesDescriptions[j];
+					_currentGameDescription = &gameDescriptions[i];
+					_currentFileDescription = &_currentGameDescription->filesDescriptions[j];
 
-					printf("Matched game: Inherit the Earth: Quest for the Orb\n");
+					print("Matched game: Inherit the Earth: Quest for the Orb\n");
 					return true;
 				}
 			} else {			// IHNM
@@ -178,25 +148,24 @@
 				// same encoding
 
 				if (scumm_stricmp(gameDescriptions[i].filesDescriptions[j].fileName, infile->getFullName().c_str()) == 0) {
-					currentGameDescription = &gameDescriptions[i];
-					currentFileDescription = &currentGameDescription->filesDescriptions[j];
+					_currentGameDescription = &gameDescriptions[i];
+					_currentFileDescription = &_currentGameDescription->filesDescriptions[j];
 
-					printf("Matched game: I have no mouth, and I must scream\n");
+					print("Matched game: I have no mouth, and I must scream\n");
 					return true;
 				}
 			}
 		}
 	}
-	printf("Unsupported file\n");
+	print("Unsupported file\n");
 	return false;
 }
 
-uint32 copyFile(const char *fromFileName, FILE* outputFile) {
+uint32 CompressSaga::copyFile(const char *fromFileName, File &outputFile) {
 	uint32 size;
 	char fbuf[2048];
-	FILE * tempf;
+	File tempf(fromFileName, "rb");
 
-	tempf = fopen(fromFileName, "rb");
 	if (tempf == NULL)
 		error("Unable to open %s", fromFileName);
 
@@ -204,16 +173,14 @@
 		fwrite(fbuf, 1, size, outputFile);
 	}
 	size = ftell(tempf);
-	fclose(tempf);
 	return size;
 }
 
-void copyFile(FILE* inputFile, uint32 inputSize, const char* toFileName) {
+void CompressSaga::copyFile(File &inputFile, uint32 inputSize, const char *toFileName) {
 	uint32 size;
 	char fbuf[2048];
-	FILE * tempf;
+	File tempf(toFileName, "wb");
 
-	tempf = fopen(toFileName, "wb");
 	if (tempf == NULL)
 		error("Unable to open %s", toFileName);
 	while (inputSize > 0) {
@@ -224,124 +191,122 @@
 		fwrite(fbuf, 1, size, tempf);
 		inputSize -= size;
 	}
-	fclose(tempf);
 }
 
-void writeBufferToFile(uint8* data, uint32 inputSize, const char* toFileName) {
-	FILE * tempf;
-
-	tempf = fopen(toFileName, "wb");
+void CompressSaga::writeBufferToFile(uint8 *data, uint32 inputSize, const char *toFileName) {
+	File tempf(toFileName, "wb");
 	if (tempf == NULL)
 		error("Unable to open %s", toFileName);
 	fwrite(data, 1, inputSize, tempf);
-	fclose(tempf);
 }
 
-void writeHeader(FILE* outputFile) {
-	writeByte(outputFile, gCompMode);
-	writeUint16LE(outputFile, sampleRate);
-	writeUint32LE(outputFile, sampleSize);
-	writeByte(outputFile, sampleBits);
-	writeByte(outputFile, sampleStereo);
+void CompressSaga::writeHeader(File &outputFile) {
+	writeByte(outputFile, compression_format(_format));
+	writeUint16LE(outputFile, _sampleRate);
+	writeUint32LE(outputFile, _sampleSize);
+	writeByte(outputFile, _sampleBits);
+	writeByte(outputFile, _sampleStereo);
 }
 
-uint32 encodeEntry(FILE* inputFile, uint32 inputSize, FILE* outputFile) {
+uint32 CompressSaga::encodeEntry(File &inputFile, uint32 inputSize, File &outputFile) {
 	uint8 *inputData = 0;
 	byte *buffer = 0;
 	Common::File inputFileStream(inputFile);
 	int rate, size;
 	byte flags;
 
-	if (currentFileDescription->resourceType == kSoundVOC) {
+	if (_currentFileDescription->resourceType == kSoundVOC) {
 		inputData = Audio::loadVOCFromStream(inputFileStream, size, rate);
 
-		sampleSize = size;
-		sampleRate = rate;
-		sampleBits = 8;
-		sampleStereo = 0;
+		_sampleSize = size;
+		_sampleRate = rate;
+		_sampleBits = 8;
+		_sampleStereo = 0;
 		writeHeader(outputFile);
 
-		writeBufferToFile(inputData, sampleSize, TEMP_RAW);
+		writeBufferToFile(inputData, _sampleSize, TEMP_RAW);
 		free(inputData);
 
 		setRawAudioType( true, false, 8);
-		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
+		encodeAudio(TEMP_RAW, true, _sampleRate, tempEncoded, _format);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
-	if (currentFileDescription->resourceType == kSoundPCM) {
-		sampleSize = inputSize;
-		sampleRate = (uint16)currentFileDescription->frequency;
-		sampleBits = 16;
-		sampleStereo = currentFileDescription->stereo;
+	if (_currentFileDescription->resourceType == kSoundPCM) {
+		_sampleSize = inputSize;
+		_sampleRate = (uint16)_currentFileDescription->frequency;
+		_sampleBits = 16;
+		_sampleStereo = _currentFileDescription->stereo;
 		writeHeader(outputFile);
 
 		copyFile(inputFile, inputSize, TEMP_RAW);
 
-		setRawAudioType( !currentFileDescription->swapEndian, sampleStereo != 0, sampleBits);
-		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
+		setRawAudioType( !_currentFileDescription->swapEndian, _sampleStereo != 0, _sampleBits);
+		encodeAudio(TEMP_RAW, true, _sampleRate, tempEncoded, _format);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
-	if (currentFileDescription->resourceType == kSoundWAV) {
+	if (_currentFileDescription->resourceType == kSoundWAV) {
 		if (!Audio::loadWAVFromStream(inputFileStream, size, rate, flags))
 			error("Unable to read WAV");
 
-		sampleSize = size;
-		sampleRate = rate;
-		sampleBits = ((flags & Audio::Mixer::FLAG_16BITS) != 0) ? 16 : 8;
-		sampleStereo = ((flags & Audio::Mixer::FLAG_STEREO) != 0);
+		_sampleSize = size;
+		_sampleRate = rate;
+		_sampleBits = ((flags & Audio::Mixer::FLAG_16BITS) != 0) ? 16 : 8;
+		_sampleStereo = ((flags & Audio::Mixer::FLAG_STEREO) != 0);
 		writeHeader(outputFile);
 
 		copyFile(inputFile, size, TEMP_RAW);
 
-		setRawAudioType( true, sampleStereo != 0, sampleBits);
-		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
+		setRawAudioType( true, _sampleStereo != 0, _sampleBits);
+		encodeAudio(TEMP_RAW, true, _sampleRate, tempEncoded, _format);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
-	if (currentFileDescription->resourceType == kSoundVOX) {
-		sampleSize = inputSize * 4;
-		sampleRate = (uint16)currentFileDescription->frequency;
-		sampleBits = 16;
-		sampleStereo = currentFileDescription->stereo;
+	if (_currentFileDescription->resourceType == kSoundVOX) {
+		_sampleSize = inputSize * 4;
+		_sampleRate = (uint16)_currentFileDescription->frequency;
+		_sampleBits = 16;
+		_sampleStereo = _currentFileDescription->stereo;
 		writeHeader(outputFile);
 
 		Audio::AudioStream *voxStream = Audio::makeADPCMStream(&inputFileStream, inputSize, Audio::kADPCMOki);
-		buffer = (byte *)malloc(sampleSize);
+		buffer = (byte *)malloc(_sampleSize);
 		uint32 voxSize = voxStream->readBuffer((int16*)buffer, inputSize * 2);
 		if (voxSize != inputSize * 2)
 			error("Wrong VOX output size");
-		writeBufferToFile((uint8 *)buffer, sampleSize, TEMP_RAW);
+		writeBufferToFile((uint8 *)buffer, _sampleSize, TEMP_RAW);
 		free(buffer);
 
-		setRawAudioType( !currentFileDescription->swapEndian, sampleStereo != 0, sampleBits);
-		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
+		setRawAudioType( !_currentFileDescription->swapEndian, _sampleStereo != 0, _sampleBits);
+		encodeAudio(TEMP_RAW, true, _sampleRate, tempEncoded, _format);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
-	if (currentFileDescription->resourceType == kSoundMacPCM) {
+	if (_currentFileDescription->resourceType == kSoundMacPCM) {
 		error("MacBinary files are not supported yet");
 		// TODO
 		// Note: MacBinary files are unsigned. With the pending changes to setRawAudioType, there will need
 		// to be some changes here
 		/*
 		copyFile(inputFile, inputSize, TEMP_RAW);
-		sampleSize = inputSize - 36;
-		sampleRate = (uint16)currentFileDescription->frequency;
+		_sampleSize = inputSize - 36;
+		_sampleRate = (uint16)currentFileDescription->frequency;
 		// The MAC CD Guild version has 8 bit sound, whereas the other versions have 16 bit sound
-		sampleBits = 8;
-		sampleStereo = currentFileDescription->stereo;
+		_sampleBits = 8;
+		_sampleStereo = currentFileDescription->stereo;
 		writeHeader(outputFile);
 
-		setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, sampleBits);
+		setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, _sampleBits);
 		encodeAudio(TEMP_RAW, true, currentFileDescription->frequency, tempEncoded, gCompMode);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 		*/
 	}
 
-	error("Unsupported resourceType %ul\n", currentFileDescription->resourceType);
+	error("Unsupported resourceType %ul\n", _currentFileDescription->resourceType);
+	// Never reached
+	return 0;
 }
 
-void sagaEncode(Filename *inpath, Filename *outpath) {
-	FILE *inputFile;
-	FILE *outputFile;
+void CompressSaga::sagaEncode(Filename *inpath, Filename *outpath) {
+	File inputFile;
+	File outputFile;
 	uint32 inputFileSize;
 	uint32 resTableOffset;
 	uint32 resTableCount;
@@ -350,25 +315,25 @@
 	Record *inputTable;
 	Record *outputTable;
 
-	inputFile = fopen(inpath->getFullPath().c_str(), "rb");
-	inputFileSize = fileSize(inputFile);
-	printf("Filesize: %ul\n", inputFileSize);
+	inputFile.open(*inpath, "rb");
+	inputFileSize = inputFile.size();
+	print("Filesize: %ul\n", inputFileSize);
 	/*
 	 * At the end of the resource file there are 2 values: one points to the
 	 * beginning of the resource table the other gives the number of
 	 * records in the table
 	 */
-	fseek(inputFile, inputFileSize - RSC_TABLEINFO_SIZE, SEEK_SET);
+	inputFile.seek(inputFileSize - RSC_TABLEINFO_SIZE, SEEK_SET);
 
-	if (!currentFileDescription->swapEndian) {
-		resTableOffset = readUint32LE(inputFile);
-		resTableCount = readUint32LE(inputFile);
+	if (!_currentFileDescription->swapEndian) {
+		resTableOffset = inputFile.readU32LE();
+		resTableCount = inputFile.readU32LE();
 	} else {
-		resTableOffset = readUint32BE(inputFile);
-		resTableCount = readUint32BE(inputFile);
+		resTableOffset = inputFile.readU32BE();
+		resTableCount = inputFile.readU32BE();
 	}
 
-	printf("Table offset: %ul\nnumber of records: %ul\n", resTableOffset, resTableCount);
+	print("Table offset: %ul\nnumber of records: %ul\n", resTableOffset, resTableCount);
 	if (resTableOffset != inputFileSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * resTableCount) {
 		error("Something's wrong with your resource file");
 	}
@@ -381,15 +346,15 @@
 	// Put offsets of all the records in a table
 	for (i = 0; i < resTableCount; i++) {
 
-		if (!currentFileDescription->swapEndian) {
-			inputTable[i].offset = readUint32LE(inputFile);
-			inputTable[i].size = readUint32LE(inputFile);
+		if (!_currentFileDescription->swapEndian) {
+			inputTable[i].offset = inputFile.readU32LE();
+			inputTable[i].size = inputFile.readU32LE();
 		} else {
-			inputTable[i].offset = readUint32BE(inputFile);
-			inputTable[i].size = readUint32BE(inputFile);
+			inputTable[i].offset = inputFile.readU32BE();
+			inputTable[i].size = inputFile.readU32BE();
 		}
 
-		printf("Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
+		print("Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
 
 		if ((inputTable[i].offset > inputFileSize) ||
 			(inputTable[i].offset + inputTable[i].size > inputFileSize)) {
@@ -403,10 +368,10 @@
 		*outpath = *inpath;
 		outpath->setExtension(".cmp");
 	}
-	outputFile = fopen(outpath->getFullPath().c_str(), "wb");
+	outputFile.open(*outpath, "wb");
 
 	for (i = 0; i < resTableCount; i++) {
-		fseek(inputFile, inputTable[i].offset, SEEK_SET);
+		inputFile.seek(inputTable[i].offset, SEEK_SET);
 		outputTable[i].offset = ftell(outputFile);
 
 		if (inputTable[i].size >= 8) {
@@ -415,17 +380,17 @@
 			outputTable[i].size = inputTable[i].size;	// Empty sound resource
 		}
 	}
-	fclose(inputFile);
+	inputFile.close();
 
 	resTableOffset = ftell(outputFile);
 	for (i = 0; i < resTableCount; i++) {
-		writeUint32LE(outputFile, outputTable[i].offset);
-		writeUint32LE(outputFile, outputTable[i].size);
+		outputFile.writeU32LE(outputTable[i].offset);
+		outputFile.writeU32LE(outputTable[i].size);
 	}
-	writeUint32LE(outputFile, resTableOffset);
-	writeUint32LE(outputFile, resTableCount);	// Should be the same number of entries
+	outputFile.writeU32LE(resTableOffset);
+	outputFile.writeU32LE(resTableCount);	// Should be the same number of entries
 
-	fclose(outputFile);
+	outputFile.close();
 
 	free(inputTable);
 	free(outputTable);
@@ -434,38 +399,16 @@
 	unlink(TEMP_RAW);
 	unlink(tempEncoded);
 
-	printf("Done!\n");
+	print("Done!\n");
 }
 
-int export_main(compress_saga)(int argc, char *argv[]) {
-	const char *helptext = "\nUsage: %s [mode] [mode params] [-o outputfile = infile.cmp] <inputfile>\n" kCompressionAudioHelp;
+void CompressSaga::execute() {
+	// Check input
+	if (_inputPaths.size() == 1)
+		error("One input file expected!");
+	Filename inpath(_inputPaths[0]);
+	Filename &outpath = _outputPath;
 
-	Filename inpath, outpath;
-	int first_arg = 1;
-	int last_arg = argc - 1;
-
-	parseHelpArguments(argv, argc, helptext);
-
-	// compression mode
-	gCompMode = process_audio_params(argc, argv, &first_arg);
-
-	if (gCompMode == AUDIO_NONE) {
-		// Unknown mode (failed to parse arguments), display help and exit
-		displayHelp(helptext, argv[0]);
-	}
-
-	// Now we try to find the proper output file
-	// also make sure we skip those arguments
-	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
-		first_arg += 2;
-	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
-		last_arg -= 2;
-	else 
-		// Just leave it empty, we just change extension of input file
-		;
-
-	inpath.setFullPath(argv[first_arg]);
-
 	// ITE
 	inpath.setExtension(".rsc");
 	if (detectFile(&inpath)) {
@@ -491,13 +434,12 @@
 			}
 		}
 	}
-
-	return 0;
 }
 
 #ifdef STANDALONE_MAIN
 int main(int argc, char *argv[]) {
-	return export_main(compress_saga)(argc, argv);
+	CompressSaga saga(argv[0]);
+	return saga.run(argc, argv);
 }
 #endif
 

Added: tools/branches/gsoc2009-gui/compress_saga.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_saga.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/compress_saga.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -0,0 +1,88 @@
+/* compress_saga - Compress SAGA engine digital sound files into
+ * MP3 and Ogg Vorbis format
+ * Copyright (C) 2004, Marcoen Hirschberg
+ * Copyright (C) 2004-2006  The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+
+#ifndef COMPRESS_SAGA_H
+#define COMPRESS_SAGA_H
+
+#include "compress.h"
+
+enum SAGAGameSoundTypes {
+	kSoundPCM = 0,
+	kSoundVOX = 1,
+	kSoundVOC = 2,
+	kSoundWAV = 3,
+	kSoundMacPCM = 4
+};
+
+enum SAGAGameType {
+	GType_ITE = 0,
+	GType_IHNM = 1
+};
+
+class CompressSaga : public CompressionTool {
+public:
+	CompressSaga(const std::string &name = "compress_saga");
+
+	virtual void execute();
+
+	// Declarations should be inside the class to prevent linker errors
+
+	struct GameFileDescription {
+		const char *fileName;
+		bool swapEndian;
+		const char *md5;
+		SAGAGameSoundTypes resourceType;
+		long frequency;
+		bool stereo;
+	};
+
+	struct GameDescription {
+		SAGAGameType gameType;
+		int filesCount;
+		GameFileDescription *filesDescriptions;
+	};
+
+protected:
+
+	GameDescription *_currentGameDescription;
+	GameFileDescription *_currentFileDescription;
+
+	uint16 _sampleRate;
+	uint32 _sampleSize;
+	uint8 _sampleBits;
+	uint8 _sampleStereo;
+
+	bool detectFile(Filename *infile);
+	uint32 copyFile(const char *fromFileName, File &outputFile);
+	void copyFile(File &inputFile, uint32 inputSize, const char *toFileName);
+	void writeBufferToFile(uint8 *data, uint32 inputSize, const char *toFileName);
+	void writeHeader(File &outputFile);
+	uint32 encodeEntry(File &inputFile, uint32 inputSize, File &outputFile);
+	void sagaEncode(Filename *inpath, Filename *outpath);
+};
+
+#endif
+
+


Property changes on: tools/branches/gsoc2009-gui/compress_saga.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: tools/branches/gsoc2009-gui/compress_tinsel.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tinsel.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_tinsel.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -25,7 +25,7 @@
 #include "compress.h"
 #include "util.h"
 
-#if 0
+#include "compress_tinsel.h"
 
 // data-format of index-file:
 //  [pointer to data file DWORD] [pointer to data file DWORD] [pointer to data file DWORD]
@@ -47,51 +47,50 @@
 #define TEMP_RAW "tempfile.raw"
 #define TEMP_ENC "tempfile.enc"
 
-static FILE *input_idx, *input_smp, *output_idx, *output_smp;
-static CompressMode gCompMode = kMP3Mode;
-static char INPUT_IDX[256], INPUT_SMP[256];
+CompressTinsel::CompressTinsel(const std::string &name) : CompressionTool(name) {
+	_helptext = "\nUsage: " + _name + " [mode-params] [-o outputname] <infile.smp> [infile.idx]\n" + kCompressionAudioHelp;
+}
 
 /* Converts raw-data sample in input_smp of size SampleSize to requested dataformat and writes to output_smp */
-void convertTinselRawSample (uint32 sampleSize) {
+void CompressTinsel::convertTinselRawSample (uint32 sampleSize) {
 	uint32 copyLeft = 0;
 	uint32 doneRead = 0;
 	char buffer[2048];
-    FILE *curFileHandle;
+	File curFileHandle;
 
 	printf("Assuming DW1 sample being 8-bit raw...\n");
 
 	unlink(TEMP_RAW); unlink(TEMP_ENC);
-	curFileHandle = fopen(TEMP_RAW, "wb");
+	curFileHandle.open(TEMP_RAW, "wb");
 	copyLeft = sampleSize;
 	while (copyLeft > 0) {
-		doneRead = fread(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft, input_smp);
+		doneRead = fread(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft, _input_smp);
 		if (doneRead <= 0)
 			break;
 		copyLeft -= (int)doneRead;
-		fwrite(buffer, 1, doneRead, curFileHandle);
+		curFileHandle.write(buffer, 1, doneRead);
 	}
-	fclose(curFileHandle);
+	curFileHandle.close();
 
 	// Encode this raw data...
 	setRawAudioType(true, false, 8); // LE, mono, 8-bit (??)
-	encodeAudio(TEMP_RAW, true, 22050, TEMP_ENC, gCompMode);
+	encodeAudio(TEMP_RAW, true, 22050, TEMP_ENC, _format);
 
 	// Append compressed data to output_smp
-	curFileHandle = fopen(TEMP_ENC, "rb");
+	curFileHandle.open(TEMP_ENC, "rb");
 	fseek(curFileHandle, 0, SEEK_END);
 	copyLeft = ftell(curFileHandle);
-    fseek(curFileHandle, 0, SEEK_SET);
+	fseek(curFileHandle, 0, SEEK_SET);
 	// Write size of compressed data
-	writeUint32LE(output_smp, copyLeft);
+	_output_smp.writeU32LE(copyLeft);
 	// Write actual data
 	while (copyLeft > 0) {
 		doneRead = fread(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft, curFileHandle);
 		if (doneRead <= 0)
 			break;
 		copyLeft -= (int)doneRead;
-		fwrite(buffer, 1, doneRead, output_smp);
+		_output_smp.write(buffer, 1, doneRead);
 	}
-	fclose(curFileHandle);
 }
 
 static const double TinselFilterTable[4][2] = {
@@ -101,12 +100,18 @@
 	{1.53125, -0.859375}
 };
 
-template<typename T> inline T CLIP (T v, T amin, T amax)
-		{ if (v < amin) return amin; else if (v > amax) return amax; else return v; }
+template<typename T> inline T CLIP (T v, T amin, T amax) {
+	if (v < amin)
+		return amin;
+	else if (v > amax)
+		return amax;
+	else
+		return v;
+}
 
 /* Converts ADPCM-data sample in input_smp of size SampleSize to requested dataformat and writes to output_smp */
 /* Quick hack together from adpcm.cpp */
-void convertTinselADPCMSample (uint32 sampleSize) {
+void CompressTinsel::convertTinselADPCMSample (uint32 sampleSize) {
 	byte *inBuffer, *inPos;
 	int16 *outBuffer, *outPos;
 	double predictor = 0;
@@ -124,7 +129,7 @@
 	uint32 copyLeft = 0;
 	uint32 doneRead = 0;
 	char buffer[2048];
-    FILE *curFileHandle;
+	File curFileHandle;
 
 	printf("Assuming DW2 sample using ADPCM 6-bit, decoding to 16-bit raw...\n");
 
@@ -143,14 +148,14 @@
 		return;
 	}
 
-	fread(inBuffer, 1, sampleSize, input_smp);
+	_input_smp.read(inBuffer, 1, sampleSize);
 
 	// 1 channel, 22050 rate, block align 24,
 	blockAlign = 24; // Fixed for Tinsel 6-bit
 	blockPos = blockAlign; // To make sure first header is read
 
 	inPos = inBuffer; outPos = outBuffer;
-    decodeLeft = sampleSize;
+	decodeLeft = sampleSize;
 	while (decodeLeft > 0) {
 		if (blockPos == blockAlign) {
 			// read Tinsel header
@@ -200,83 +205,42 @@
 		sample += (d0 * k0) + (d1 * k1);
 		d1 = d0;
 		d0 = sample;
-        *outPos = (int16) CLIP<double>(sample, -32768.0, 32767.0); outPos++;
+		*outPos = (int16) CLIP<double>(sample, -32768.0, 32767.0); outPos++;
 		decodedCount++;
 		chunkPos = (chunkPos + 1) % 4;
 	}
 
-	unlink(TEMP_RAW); unlink(TEMP_ENC);
-	curFileHandle = fopen(TEMP_RAW, "wb");
-	fwrite(outBuffer, 1, decodedCount*2, curFileHandle);
-	fclose(curFileHandle);
+	unlink(TEMP_RAW);
+	unlink(TEMP_ENC);
 
-	free(inBuffer); free(outBuffer);
+	curFileHandle.open(TEMP_RAW, "wb");
+	curFileHandle.write(outBuffer, 1, decodedCount*2);
 
+	free(inBuffer);
+	free(outBuffer);
+
 	// Encode this raw data...
 	setRawAudioType(true, false, 16); // LE, mono, 16-bit
-	encodeAudio(TEMP_RAW, true, 22050, TEMP_ENC, gCompMode);
+	encodeAudio(TEMP_RAW, true, 22050, TEMP_ENC, _format);
 
 	// Append compressed data to output_smp
-	curFileHandle = fopen(TEMP_ENC, "rb");
-	fseek(curFileHandle, 0, SEEK_END);
+	curFileHandle.open(TEMP_ENC, "rb");
+	curFileHandle.seek(0, SEEK_END);
 	copyLeft = ftell(curFileHandle);
-    fseek(curFileHandle, 0, SEEK_SET);
+	curFileHandle.seek(0, SEEK_SET);
 	// Write size of compressed data
-	writeUint32LE(output_smp, copyLeft);
+	_output_smp.writeU32LE(copyLeft);
 	// Write actual data
 	while (copyLeft > 0) {
 		doneRead = fread(buffer, 1, copyLeft > sizeof(buffer) ? sizeof(buffer) : copyLeft, curFileHandle);
 		if (doneRead <= 0)
 			break;
 		copyLeft -= (int)doneRead;
-		fwrite(buffer, 1, doneRead, output_smp);
+		_output_smp.write(buffer, 1, doneRead);
 	}
-	fclose(curFileHandle);
 }
 
-void showhelp(char *exename) {
-	printf("\nUsage: %s [params] [file]\n", exename);
-
-	printf("\nParams:\n");
-	printf(" --mp3        encode to MP3 format (default)\n");
-	printf(" --vorbis     encode to Vorbis format\n");
-	printf(" --flac       encode to Flac format\n");
-	printf("(If one of these is specified, it must be the first parameter.)\n");
-
-	printf("\nMP3 mode params:\n");
-	printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
-	printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);
-	printf(" --vbr        LAME uses the VBR mode (default)\n");
-	printf(" --abr        LAME uses the ABR mode\n");
-	printf(" -V <value>   specifies the value (0 - 9) of VBR quality (0=best) (default:%d)\n", vbrqualDef);
-	printf(" -q <value>   specifies the MPEG algorithm quality (0-9; 0=best) (default:%d)\n", algqualDef);
-	printf(" --silent     the output of LAME is hidden (default:disabled)\n");
-
-	printf("\nVorbis mode params:\n");
-	printf(" -b <rate>    <rate> is the nominal bitrate (default:unset)\n");
-	printf(" -m <rate>    <rate> is the minimum bitrate (default:unset)\n");
-	printf(" -M <rate>    <rate> is the maximum bitrate (default:unset)\n");
-	printf(" -q <value>   specifies the value (0 - 10) of VBR quality (10=best) (default:%d)\n", oggqualDef);
-	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
-
-	printf("\nFlac mode params:\n");
- 	printf(" --fast       FLAC uses compression level 0\n");
- 	printf(" --best       FLAC uses compression level 8\n");
- 	printf(" -<value>     specifies the value (0 - 8) of compression (8=best)(default:%d)\n", flacCompressDef);
- 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
-	printf(" --verify     files are encoded and then decoded to check accuracy\n");
- 	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
-
-	printf("\n --help     this help message\n");
-
-	printf("\n\nIf a parameter is not given the default value is used\n");
-	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
-	exit(2);
-}
-
-int main(int argc, char *argv[]) {
-	char inputPath[768];
-	int i;
+void CompressTinsel::execute() {
 	uint32 indexNo = 0;
 	uint32 indexCount = 0;
 	uint32 indexOffset = 0;
@@ -284,99 +248,62 @@
 	uint32 sampleSize = 0;
 	uint32 sampleCount = 0;
 
-	if (argc < 2) {
-		showhelp(argv[0]);
-	}
+	Filename inpath_smp, inpath_idx;
 
-	/* Compression mode */
-	gCompMode = kMP3Mode;
-	i = 1;
+	// Check input
+	if (_inputPaths.size() < 1)
+		error("Atleast one input file expected!");
 
-	if (strcmp(argv[1], "--mp3") == 0) {
-		gCompMode = kMP3Mode;
-		i++;
-	} else if (strcmp(argv[1], "--vorbis") == 0) {
-		gCompMode = kVorbisMode;
-		i++;
-	} else if (strcmp(argv[1], "--flac") == 0) {
-		gCompMode = kFlacMode;
-		i++;
+	if (_inputPaths.size() == 1) {
+		// One input, assume idx and change extension for second input
+		inpath_smp = _inputPaths[0];
+		inpath_idx = inpath_smp;
+		inpath_idx.setExtension(".idx");
+	} else if(_inputPaths.size() == 2) {
+		inpath_smp = _inputPaths[0];
+		inpath_idx = _inputPaths[1];
+	} else {
+		error("At most two input files expected!");
 	}
+	Filename &outpath = _outputPath;
 
-	switch (gCompMode) {
-	case kMP3Mode:
-		if (!process_mp3_parms(argc, argv, i))
-			showhelp(argv[0]);
-		break;
-	case kVorbisMode:
-		if (!process_ogg_parms(argc, argv, i))
-			showhelp(argv[0]);
-		break;
-	case kFlacMode:
-		if (!process_flac_parms(argc, argv, i))
-			showhelp(argv[0]);
-		break;
-	}
+	_input_idx.open(inpath_idx, "rb");
+	_input_smp.open(inpath_smp, "rb");
 
-	getPath(argv[argc - 1], inputPath);
-
-	sprintf(INPUT_IDX, "%s.idx", argv[argc - 1]);
-	sprintf(INPUT_SMP, "%s.smp", argv[argc - 1]);
-
-	input_idx = fopen(INPUT_IDX, "rb");
-	if (!input_idx) {
-		printf("Cannot open file: %s\n", INPUT_IDX);
-		exit(-1);
-	}
-
-	input_smp = fopen(INPUT_SMP, "rb");
-	if (!input_smp) {
-		printf("Cannot open file: %s\n", INPUT_SMP);
-		exit(-1);
-	}
-
 	unlink(TEMP_IDX);
-	output_idx = fopen(TEMP_IDX, "wb");
-	if (!output_idx) {
-		printf("Can't open file " TEMP_IDX " for write!\n" );
-		exit(-1);
-	}
+	_output_idx.open(TEMP_IDX, "wb");
+
 	unlink(TEMP_SMP);
-	output_smp = fopen(TEMP_SMP, "wb");
-	if (!output_smp) {
-		printf("Can't open file " TEMP_SMP " for write!\n");
-		exit(-1);
-	}
+	_output_smp.open(TEMP_SMP, "wb");
 
-	fseek(input_idx, 0, SEEK_END);
-	indexCount = ftell(input_idx) / sizeof(uint32);
-    fseek(input_idx, 0, SEEK_SET);
+	_input_idx.seek(0, SEEK_END);
+	indexCount = ftell(_input_idx) / sizeof(uint32);
+	_input_idx.seek(0, SEEK_SET);
 
 	loopCount = indexCount;
 	while (loopCount>0) {
-		indexOffset = readUint32LE(input_idx);
+		indexOffset = _input_idx.readU32LE();
 		if (indexOffset) {
 			if (indexNo==0) {
-				printf("The sourcefiles are already compressed, aborting...\n");
-				return 1;
+				error("The sourcefiles are already compressed, aborting...\n");
 			}
 			// Got sample(s), so convert...
 			printf("Converting sample %d of %d\n", indexNo, indexCount);
 
 			// Seek to Sample in input-file and read SampleSize
-			fseek(input_smp, indexOffset, SEEK_SET);
-			sampleSize = readUint32LE(input_smp);
+			_input_smp.seek(indexOffset, SEEK_SET);
+			sampleSize = _input_smp.readU32LE();
 
 			// Write offset of new data to new index file
-			writeUint32LE(output_idx, ftell(output_smp));
+			_output_idx.writeU32LE(ftell(_output_smp));
 
 			if (sampleSize & 0x80000000) {
 				// multiple samples in ADPCM format
 				sampleCount = sampleSize & ~0x80000000;
 				// Write sample count to new sample file
-				writeUint32LE(output_smp, sampleSize);
+				_output_smp.writeU32LE(sampleSize);
 				while (sampleCount>0) {
-					sampleSize = readUint32LE(input_smp);
+					sampleSize = _input_smp.readU32LE();
 					convertTinselADPCMSample(sampleSize);
 					sampleCount--;
 				}
@@ -387,28 +314,29 @@
 		} else {
 			if (indexNo==0) {
 				// Write signature as index 0
-				switch (gCompMode) {
-				case kMP3Mode: writeUint32BE(output_idx, MKID_BE('MP3 ')); break;
-				case kVorbisMode: writeUint32BE(output_idx, MKID_BE('OGG ')); break;
-				case kFlacMode: writeUint32BE(output_idx, MKID_BE('FLAC')); break;
+				switch (_format) {
+				case AUDIO_MP3: _output_idx.writeU32BE(MKID_BE('MP3 ')); break;
+				case AUDIO_VORBIS: _output_idx.writeU32BE(MKID_BE('OGG ')); break;
+				case AUDIO_FLAC: _output_idx.writeU32BE(MKID_BE('FLAC')); break;
+				default: throw ToolException("Unknown audio format!");
 				}
 			} else {
-				writeUint32LE(output_idx, 0);
+				_output_idx.writeU32LE(0);
 			}
 		}
-		loopCount--; indexNo++;
+		loopCount--;
+		indexNo++;
 	}
-	fclose(output_smp);
-	fclose(output_idx);
-	fclose(input_smp);
-	fclose(input_idx);
 
 	/* And some clean-up :-) */
 	unlink(TEMP_RAW);
 	unlink(TEMP_ENC);
-
-	return 0;
 }
 
-#endif
 
+#ifdef STANDALONE_MAIN
+int main(int argc, char *argv[]) {
+	CompressTinsel tinsel(argv[0]);
+	return tinsel.run(argc, argv);
+}
+#endif

Added: tools/branches/gsoc2009-gui/compress_tinsel.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_tinsel.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/compress_tinsel.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -0,0 +1,39 @@
+/* compress_tinsel - .smp compressor
+ * Copyright (C) 2009 The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMPRESS_TINSEL_H
+#define COMPRESS_TINSEL_H
+
+class CompressTinsel : public CompressionTool {
+public:
+	CompressTinsel(const std::string &name = "compress_tinsel");
+
+	virtual void execute();
+
+protected:
+	File _input_idx, _input_smp, _output_idx, _output_smp;
+
+	void convertTinselRawSample(uint32 sampleSize);
+	void convertTinselADPCMSample(uint32 sampleSize);
+};
+
+#endif


Property changes on: tools/branches/gsoc2009-gui/compress_tinsel.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: tools/branches/gsoc2009-gui/compress_touche.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_touche.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_touche.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -1,5 +1,3 @@
-
-
 /* compress_touche - Compress Touche Speech Data Files
  * Copyright (C) 2006  The ScummVM Team
  *
@@ -23,6 +21,7 @@
  */
 
 #include "compress.h"
+#include "compress_touche.h"
 
 #define CURRENT_VER     1
 #define HEADER_SIZE     4
@@ -34,15 +33,18 @@
 #define OUTPUT_OGG   "TOUCHE.SOG"
 #define OUTPUT_FLA   "TOUCHE.SOF"
 
-static AudioFormat gCompMode = AUDIO_MP3;
-
 static uint32 input_OBJ_offs[OBJ_HDR_LEN];
 static uint32 input_OBJ_size[OBJ_HDR_LEN];
 static uint32 input_Vxx_offs[Vxx_HDR_LEN];
 static uint32 input_Vxx_size[Vxx_HDR_LEN];
 
-static uint32 compress_sound_data_file(uint32 current_offset, FILE *output, FILE *input, uint32 *offs_table, uint32 *size_table, int len) {
-	FILE *temp;
+CompressTouche::CompressTouche(const std::string &name) : CompressionTool(name) {
+	_inputFromDirectory = true;
+
+	const char *helptext = "\nUsage: %s [params] [-o outputfile TOUCHE.*] <inputdir>\n* differs with compression type.\n" kCompressionAudioHelp;
+}
+
+uint32 CompressTouche::compress_sound_data_file(uint32 current_offset, File &output, File &input, uint32 *offs_table, uint32 *size_table, int len) {
 	int i, size;
 	uint8 buf[2048];
 	uint32 start_offset = current_offset;
@@ -51,30 +53,27 @@
 	for (i = 0; i < len; ++i) {
 		offs_table[i] = readUint32LE(input);
 		size_table[i] = readUint32LE(input);
-		writeUint32LE(output, 0);
-		writeUint32LE(output, 0);
+		output.writeU32LE(0);
+		output.writeU32LE(0);
 		current_offset += 8;
 	}
 	for (i = 0; i < len; ++i) {
 		if (size_table[i] == 0) {
 			offs_table[i] = 0;
 		} else {
-			fseek(input, offs_table[i], SEEK_SET);
-			fread(buf, 1, 8, input);
+			input.seek(offs_table[i], SEEK_SET);
+			input.read(buf, 1, 8);
 
 			if (memcmp(buf, "Creative", 8) != 0) {
 				error("Invalid VOC data found");
 			}
 
-			printf("VOC found (pos = %d) :\n", offs_table[i]);
-			fseek(input, 18, SEEK_CUR);
-			extractAndEncodeVOC(TEMP_RAW, input, gCompMode);
+			print("VOC found (pos = %d) :\n", offs_table[i]);
+			input.seek(18, SEEK_CUR);
+			extractAndEncodeVOC(TEMP_RAW, input, _format);
 
 			/* append converted data to output file */
-			temp = fopen(tempEncoded, "rb");
-			if (!temp) {
-				error("Cannot open file '%s' for reading", tempEncoded);
-			}
+			File temp(tempEncoded, "rb");
 
 			size_table[i] = 0;
 
@@ -83,33 +82,28 @@
 				size_table[i] += size;
 			}
 
-			fclose(temp);
 			offs_table[i] = current_offset;
 			current_offset += size_table[i];
 		}
 	}
 
 	/* fix data offsets table */
-	fseek(output, start_offset, SEEK_SET);
+	output.seek(start_offset, SEEK_SET);
 	for (i = 0; i < len; ++i) {
-		writeUint32LE(output, offs_table[i]);
-		writeUint32LE(output, size_table[i]);
+		output.writeU32LE(offs_table[i]);
+		output.writeU32LE(size_table[i]);
 	}
-	fseek(output, 0, SEEK_END);
+	output.seek(0, SEEK_END);
 
 	return current_offset;
 }
 
-static void compress_sound_data(Filename *inpath, Filename *outpath) {
+void CompressTouche::compress_sound_data(Filename *inpath, Filename *outpath) {
 	int i;
-	FILE *output, *input;
 	uint32 current_offset;
 	uint32 offsets_table[MAX_OFFSETS];
 
-	output = fopen(outpath->getFullPath().c_str(), "wb");
-	if (!output) {
-		error("Cannot open file '%s' for writing", outpath->getFullPath().c_str());
-	}
+	File output(*outpath, "wb");
 
 	writeUint16LE(output, 1); /* current version */
 	writeUint16LE(output, 0); /* flags */
@@ -119,21 +113,18 @@
 	/* write 0 offsets table */
 	for (i = 0; i < MAX_OFFSETS; ++i) {
 		offsets_table[i] = 0;
-		writeUint32LE(output, offsets_table[i]);
+		output.writeU32LE(offsets_table[i]);
 		current_offset += 4;
 	}
 
 	/* process 'OBJ' file */
 	inpath->setFullName("OBJ");
-	input = fopen(inpath->getFullPath().c_str(), "rb");
-	if (!input) {
-		error("Cannot open file 'OBJ' for reading");
-	}
+	File input(*inpath, "rb");
 
 	offsets_table[0] = current_offset;
 	current_offset = compress_sound_data_file(current_offset, output, input, input_OBJ_offs, input_OBJ_size, OBJ_HDR_LEN);
-	fclose(input);
-	printf("Processed '%s'.\n", inpath->getFullPath().c_str());
+	input.close();
+	print("Processed '%s'.\n", inpath->getFullPath().c_str());
 
 	/* process Vxx files */
 	for (i = 1; i < MAX_OFFSETS; ++i) {
@@ -142,56 +133,39 @@
 		sprintf(d, "V%d", i);
 		inpath->setFullName(d);
 
-		input = fopen(inpath->getFullPath().c_str(), "rb");
+		input.open(*inpath, "rb");
 		if (input) {
 			offsets_table[i] = current_offset;
 			current_offset = compress_sound_data_file(current_offset, output, input, input_Vxx_offs, input_Vxx_size, Vxx_HDR_LEN);
-			fclose(input);
-			printf("Processed '%s'.\n", inpath->getFullPath().c_str());
+			input.close();
+			print("Processed '%s'.\n", inpath->getFullPath().c_str());
 		}
 	}
 
 	/* fix global offsets table at the beginning of the file */
-	fseek(output, HEADER_SIZE, SEEK_SET);
+	output.seek(HEADER_SIZE, SEEK_SET);
 	for (i = 0; i < MAX_OFFSETS; ++i) {
-		writeUint32LE(output, offsets_table[i]);
+		output.writeU32LE(offsets_table[i]);
 	}
 
-	fclose(output);
+	output.close();
 
 	/* cleanup */
 	unlink(TEMP_RAW);
 	unlink(tempEncoded);
 
-	printf("Done.\n");
+	print("Done.\n");
 }
 
+void CompressTouche::execute() {
+	// We only got one input file
+	if (_inputPaths.size() > 1)
+		error("Only one input file expected!");
+	Filename inpath(_inputPaths[0]);
+	Filename &outpath = _outputPath;
 
-int export_main(compress_touche)(int argc, char *argv[]) {
-	const char *helptext = "\nUsage: %s [params] [-o outputfile TOUCHE.*] <inputdir>\n* differs with compression type.\n" kCompressionAudioHelp;
-	
-	Filename inpath, outpath;
-	int first_arg = 1;
-	int last_arg = argc - 1;
-
-	parseHelpArguments(argv, argc, helptext);
-
-	// compression mode
-	gCompMode = process_audio_params(argc, argv, &first_arg);
-
-	if (gCompMode == AUDIO_NONE) {
-		// Unknown mode (failed to parse arguments), display help and exit
-		displayHelp(helptext, argv[0]);
-	}
-
-	// Now we try to find the proper output file
-	// also make sure we skip those arguments
-	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
-		first_arg += 2;
-	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
-		last_arg -= 2;
-	else {
-		switch(gCompMode) {
+	if (outpath.empty()) {
+		switch(_format) {
 		case AUDIO_MP3:
 			outpath.setFullName(OUTPUT_MP3);
 			break;
@@ -202,28 +176,18 @@
 			outpath.setFullName(OUTPUT_FLA);
 			break;
 		default:
-			displayHelp(helptext, argv[0]);
+			throw ToolException("Unknown audio format");
 			break;
 		}
 	}
 
-	inpath.setFullPath(argv[first_arg]);
-
-	// Append '/' if it's not already done
-	// TODO: We need a way to detect a directory here!
-	size_t s = inpath._path.size();
-	if (inpath._path[s-1] == '/' || inpath._path[s-1] == '\\') {
-		inpath._path[s] = '/';
-		inpath._path[s+1] = '\0';
-	}
-
 	compress_sound_data(&inpath, &outpath);
-	return 0;
 }
 
 #ifdef STANDALONE_MAIN
 int main(int argc, char *argv[]) {
-	return export_main(compress_touche)(argc, argv);
+	CompressTouche touche(argv[0]);
+	return touche.run(argc, argv);
 }
 #endif
 

Added: tools/branches/gsoc2009-gui/compress_touche.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_touche.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/compress_touche.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -0,0 +1,41 @@
+/* compress_touche - Compress Touche Speech Data Files
+ * Copyright (C) 2009  The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMPRESS_TOUCHE_H
+#define COMPRESS_TOUCHE_H
+
+#include "compress.h"
+
+class CompressTouche : public CompressionTool {
+public:
+	CompressTouche(const std::string &name = "compress_touche");
+
+	virtual void execute();
+
+protected:
+
+	uint32 compress_sound_data_file(uint32 current_offset, File &output, File &input, uint32 *offs_table, uint32 *size_table, int len);
+	void compress_sound_data(Filename *inpath, Filename *outpath);
+};
+
+#endif
+


Property changes on: tools/branches/gsoc2009-gui/compress_touche.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: tools/branches/gsoc2009-gui/compress_tucker.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tucker.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/compress_tucker.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -22,6 +22,8 @@
 
 #include "compress.h"
 
+#include "compress_tucker.h"
+
 #define CURRENT_VER  1
 #define HEADER_SIZE  4
 #define HEADER_FLAG_AUDIO_INTRO (1 << 0)
@@ -30,8 +32,6 @@
 #define OUTPUT_OGG  "TUCKER.SOG"
 #define OUTPUT_FLA  "TUCKER.SOF"
 
-static AudioFormat gCompMode = AUDIO_MP3;
-
 struct CompressedData {
 	int offset;
 	int size;
@@ -39,40 +39,42 @@
 
 static CompressedData temp_table[10000];
 
-static int append_compress_file(FILE *output) {
+CompressTucker::CompressTucker(const std::string &name) : CompressionTool(name) {
+	_inputFromDirectory = true;
+
+	_helptext = "\nUsage: %s [mode params] [-o outputdir] inputdir\n";
+}
+
+int CompressTucker::append_compress_file(File &output) {
 	char buf[2048];
-	FILE *input_temp;
 	int sz, compress_sz = 0;
 
-	input_temp = fopen(tempEncoded, "rb");
-	if (input_temp) {
-		while ((sz = fread(buf, 1, sizeof(buf), input_temp)) > 0) {
-			if ((sz = fwrite(buf, 1, sz, output)) > 0) {
-				compress_sz += sz;
-			}
+	File input_temp(tempEncoded, "rb");
+	while ((sz = fread(buf, 1, sizeof(buf), input_temp)) > 0) {
+		if ((sz = fwrite(buf, 1, sz, output)) > 0) {
+			compress_sz += sz;
 		}
-		fclose(input_temp);
 	}
 	return compress_sz;
 }
 
-static int compress_file_wav(FILE *input, FILE *output) {
+int CompressTucker::compress_file_wav(File &input, File &output) {
 	char buf[8];
 
 	if (fread(buf, 1, 8, input) == 8 && memcmp(buf, "RIFF", 4) == 0) {
-		extractAndEncodeWAV(TEMP_WAV, input, gCompMode);
+		extractAndEncodeWAV(TEMP_WAV, input, _format);
 		return append_compress_file(output);
 	}
 	return 0;
 }
 
-static int compress_file_raw(const char *input, bool is16, FILE *output) {
+int CompressTucker::compress_file_raw(const char *input, bool is16, File &output) {
 	if (is16) {
 		setRawAudioType(true, false, 16);
 	} else {
 		setRawAudioType(false, false, 8);
 	}
-	encodeAudio(input, true, 22050, tempEncoded, gCompMode);
+	encodeAudio(input, true, 22050, tempEncoded, _format);
 	return append_compress_file(output);
 }
 
@@ -94,13 +96,13 @@
 	{ "SPEECH", "sam%04d.wav", MAX_SPEECH_FILES }
 };
 
-static uint32 compress_sounds_directory(const Filename *inpath, const Filename *outpath, FILE *output, const struct SoundDirectory *dir) {
+uint32 CompressTucker::compress_sounds_directory(const Filename *inpath, const Filename *outpath, File &output, const struct SoundDirectory *dir) {
 	char filepath[1024];
 	char *filename;
 	//struct stat s;
 	int i, pos;
 	uint32 current_offset;
-	FILE *input;
+	File input;
 
 	assert(dir->count <= ARRAYSIZE(temp_table));
 
@@ -119,8 +121,8 @@
 
 	/* write 0 offsets/sizes table */
 	for (i = 0; i < dir->count; ++i) {
-		writeUint32LE(output, 0);
-		writeUint32LE(output, 0);
+		output.writeU32LE(0);
+		output.writeU32LE(0);
 	}
 
 	/* compress .wav files in directory */
@@ -128,11 +130,10 @@
 	for (i = 0; i < dir->count; ++i) {
 		temp_table[i].offset = current_offset;
 		sprintf(filename, dir->fmt, i);
-		input = fopen(filepath, "rb");
-		if (input) {
+		try {
+			input.open(filepath, "rb");
 			temp_table[i].size = compress_file_wav(input, output);
-			fclose(input);
-		} else {
+		} catch (...) {
 			temp_table[i].size = 0;
 		}
 		current_offset += temp_table[i].size;
@@ -294,11 +295,10 @@
 	2, 1
 };
 
-static uint32 compress_audio_directory(const Filename *inpath, const Filename *outpath, FILE *output) {
+uint32 CompressTucker::compress_audio_directory(const Filename *inpath, const Filename *outpath, File &output) {
 	char filepath[1024];
 	int i, pos, count;
 	uint32 current_offset;
-	FILE *input;
 
 	count = ARRAYSIZE(audio_files_list);
 	pos = ftell(output);
@@ -313,7 +313,7 @@
 	for (i = 0; i < count; ++i) {
 		temp_table[i].offset = current_offset;
 		sprintf(filepath, "%s/audio/%s", inpath->getPath().c_str(), audio_files_list[i]);
-		input = fopen(filepath, "rb");
+		File input(filepath, "rb");
 		if (!input) {
 			warning("Can't open file '%s'", filepath);
 			temp_table[i].size = 0;
@@ -346,29 +346,25 @@
 	return current_offset + count * 8;
 }
 
-static void compress_sound_files(const Filename *inpath, const Filename *outpath) {
+void CompressTucker::compress_sound_files(const Filename *inpath, const Filename *outpath) {
 	int i;
-	FILE *output;
 	uint32 current_offset;
 	uint32 sound_directory_size[SOUND_TYPES_COUNT];
 	uint32 audio_directory_size;
 	const uint16 flags = 0; // HEADER_FLAG_AUDIO_INTRO;
 
-	output = fopen(outpath->getFullPath().c_str(), "wb");
-	if (!output) {
-		error("Cannot open file '%s' for writing", outpath->getFullPath().c_str());
-	}
+	File output(*outpath, "wb");
 
-	writeUint16LE(output, CURRENT_VER);
-	writeUint16LE(output, flags);
+	output.writeU16LE(CURRENT_VER);
+	output.writeU16LE(flags);
 
 	/* write 0 offsets/count */
 	for (i = 0; i < SOUND_TYPES_COUNT; ++i) {
-		writeUint32LE(output, 0);
-		writeUint32LE(output, 0);
+		output.writeU32LE(0);
+		output.writeU32LE(0);
 	}
 	if (flags & HEADER_FLAG_AUDIO_INTRO) {
-		writeUint32LE(output, 0);
+		output.writeU32LE(0);
 	}
 
 	/* compress the .wav files in each directory */
@@ -387,13 +383,13 @@
 	fseek(output, HEADER_SIZE, SEEK_SET);
 	current_offset = 0;
 	for (i = 0; i < SOUND_TYPES_COUNT; ++i) {
-		writeUint32LE(output, current_offset);
-		writeUint32LE(output, sound_directory_table[i].count);
+		output.writeU32LE(current_offset);
+		output.writeU32LE(sound_directory_table[i].count);
 		current_offset += sound_directory_size[i];
 	}
 	if (flags & HEADER_FLAG_AUDIO_INTRO) {
-		writeUint32LE(output, current_offset);
-		writeUint32LE(output, ARRAYSIZE(audio_files_list));
+		output.writeU32LE(current_offset);
+		output.writeU32LE(ARRAYSIZE(audio_files_list));
 		current_offset += audio_directory_size;
 	}
 
@@ -408,35 +404,20 @@
 }
 
 
-int export_main(compress_tucker)(int argc, char *argv[]) {
-	const char *helptext = "\nUsage: %s [mode] [mode params] [-o outputdir] inputdir\n";
+void CompressTucker::execute() {
+	// We only got one input dir
+	if (_inputPaths.size() > 1)
+		error("Only one input directory expected!");
+	Filename inpath(_inputPaths[0]);
+	Filename &outpath = _outputPath;
 
-	Filename inpath, outpath;
-	int first_arg = 1;
-	int last_arg = argc - 1;
-	
-	parseHelpArguments(argv, argc, helptext);
-
-	// compression mode
-	gCompMode = process_audio_params(argc, argv, &first_arg);
-
-
-	// Now we try to find the proper output file
-	// also make sure we skip those arguments
-	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
-		first_arg += 2;
-	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
-		last_arg -= 2;
-
-	inpath.setFullPath(argv[first_arg]);
-
 	// Default out is same as in directory, file names differ by extension
 	if (outpath.empty()) {
 		outpath = inpath;
 	}
 
 	// Temporary output file
-	switch(gCompMode) {
+	switch(_format) {
 	case AUDIO_MP3:
 		tempEncoded = TEMP_MP3;
 		outpath.setFullName(OUTPUT_MP3);
@@ -450,12 +431,11 @@
 		outpath.setFullName(OUTPUT_FLA);
 		break;
 	default:
-		displayHelp(helptext, argv[0]);
+		throw ToolException("Unknown audio format");
 		break;
 	}
 
 	compress_sound_files(&inpath, &outpath);
-	return 0;
 }
 
 #ifdef STANDALONE_MAIN

Added: tools/branches/gsoc2009-gui/compress_tucker.h
===================================================================
--- tools/branches/gsoc2009-gui/compress_tucker.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/compress_tucker.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -0,0 +1,46 @@
+/* compress_tucker - Compress Bud Tucker Sound Data Files
+ * Copyright (C) 2009  The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMPRESS_TUCKER_H
+#define COMPRESS_TUCKER_H
+
+#include "compress.h"
+
+class CompressTucker : public CompressionTool {
+public:
+	CompressTucker(const std::string &name = "compress_tucker");
+
+	virtual void execute();
+
+protected:
+
+	int append_compress_file(File &output);
+	int compress_file_wav(File &input, File &output);
+	int compress_file_raw(const char *input, bool is16, File &output);
+	uint32 compress_sounds_directory(const Filename *inpath, const Filename *outpath, File &output, const struct SoundDirectory *dir);
+	uint32 compress_audio_directory(const Filename *inpath, const Filename *outpath, File &output);
+	void compress_sound_data(Filename *inpath, Filename *outpath);
+	void compress_sound_files(const Filename *inpath, const Filename *outpath);
+};
+
+#endif
+


Property changes on: tools/branches/gsoc2009-gui/compress_tucker.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: tools/branches/gsoc2009-gui/gui/tools.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/tools.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/gui/tools.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -36,6 +36,13 @@
 
 // Include all tools
 #include "../compress_agos.h"
+#include "../compress_gob.h"
+#include "../compress_kyra.h"
+#include "../compress_queen.h"
+#include "../compress_saga.h"
+#include "../compress_tinsel.h"
+#include "../compress_touche.h"
+#include "../compress_tucker.h"
 #include "../extract_agos.h"
 #include "../extract_gob_stk.h"
 
@@ -51,6 +58,27 @@
 	// Compress agos also has a --mac parameter, need to add an additional page / option for this
 	addTool(new ToolGUI(new CompressAgos()));
 
+	// Compress gob also has a --f parameter, need to add an additional page / option for this
+	addTool(new ToolGUI(new CompressGob()));
+
+	// Compress kyra...
+	addTool(new ToolGUI(new CompressKyra()));
+
+	// Compress queen...
+	addTool(new ToolGUI(new CompressQueen()));
+
+	// Compress saga...
+	addTool(new ToolGUI(new CompressSaga()));
+
+	// Compress tinsel...
+	addTool(new ToolGUI(new CompressTinsel()));
+	
+	// Compress touche...
+	addTool(new ToolGUI(new CompressTouche(), wxT("/")));
+	
+	// Compress tucker...
+	addTool(new ToolGUI(new CompressTucker(), wxT("/")));
+
 	// extract_agos
 	addTool(new ToolGUI(new ExtractAgos()));
 
@@ -254,7 +282,7 @@
 	// Sensible defaults
 	ToolInput input;
 	input._extension = input_extensions;
-	input._file = true;
+	input._file = input_extensions != wxT("/");
 	_inputs.push_back(input);
 
 	_inoutHelpText = wxT("Output files produced by the tool will be put in this directory.");

Modified: tools/branches/gsoc2009-gui/tool.cpp
===================================================================
--- tools/branches/gsoc2009-gui/tool.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/tool.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -32,6 +32,7 @@
 	_arguments_parsed = 0;
 	_argv = NULL;
 
+	_inputFromDirectory = false;
 	_outputToDirectory = true;
 	_supported_formats = AUDIO_NONE;
 
@@ -70,7 +71,17 @@
 
 	// Read input files from CLI
 	while (_arguments_parsed < _arguments.size()) {
-		_inputPaths.push_back(_arguments[_arguments_parsed++]);
+		std::string &in = _arguments[_arguments_parsed++];
+		if(_inputFromDirectory) {
+			// Append '/' to input if it's not already done
+			// TODO: We need a way to detect a proper directory here!
+			size_t s = in.size();
+			if (in[s-1] == '/' || in[s-1] == '\\') {
+				in[s] = '/';
+				in[s+1] = '\0';
+			}
+		}
+		_inputPaths.push_back(in);
 	}
 
 	if (_inputPaths.empty()) {

Modified: tools/branches/gsoc2009-gui/tool.h
===================================================================
--- tools/branches/gsoc2009-gui/tool.h	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/tool.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -81,10 +81,12 @@
 	// We need to keep the raw arguments to invoke some functions
 	char **_argv;
 
-	// What does this tool support?
+	/** If this tools outputs to a directory, not a file */
 	bool _outputToDirectory;
+	/** We don't take a single file, but an entire directory as input */
+	bool _inputFromDirectory;
+	/** */
 	AudioFormat _supported_formats;
-	std::vector<std::string> _games;
 
 	/** Name of the tool */
 	std::string _name;

Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/util.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -27,6 +27,34 @@
 	#define	vsnprintf _vsnprintf
 #endif
 
+const char *audio_extensions(AudioFormat format) {
+	switch(format) {
+	case AUDIO_MP3:
+		return ".mp3";
+	case AUDIO_VORBIS:
+		return ".ogg";
+	case AUDIO_FLAC:
+		return ".fla";
+	case AUDIO_NONE:
+	default:
+		return ".unk";
+	}
+}
+
+CompressionFormat compression_format(AudioFormat format) {
+	switch(format) {
+	case AUDIO_MP3:
+		return COMPRESSION_MP3;
+	case AUDIO_VORBIS:
+		return COMPRESSION_OGG;
+	case AUDIO_FLAC:
+		return COMPRESSION_FLAC;
+	case AUDIO_NONE:
+	default:
+		throw ToolException("Unknown compression format");
+	}
+}
+
 void error(const char *s, ...) {
 	char buf[1024];
 	va_list va;

Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/util.h	2009-07-06 23:42:10 UTC (rev 42195)
@@ -240,7 +240,19 @@
 	AUDIO_ALL = AUDIO_VORBIS | AUDIO_FLAC | AUDIO_MP3
 };
 
+/**
+ * Another enum, which cannot be ORed
+ * These are the values written to the output files
+ */
+enum CompressionFormat {
+	COMPRESSION_NONE = 0,
+	COMPRESSION_MP3 = 1,
+	COMPRESSION_OGG = 2,
+	COMPRESSION_FLAC = 3
+};
+
 const char *audio_extensions(AudioFormat format);
+CompressionFormat compression_format(AudioFormat format);
 
 // Below this line are more C++ ish interface
 // Above is kept for compatibility with non-converted tools

Modified: tools/branches/gsoc2009-gui/utils/file.cpp
===================================================================
--- tools/branches/gsoc2009-gui/utils/file.cpp	2009-07-06 19:50:59 UTC (rev 42194)
+++ tools/branches/gsoc2009-gui/utils/file.cpp	2009-07-06 23:42:10 UTC (rev 42195)
@@ -26,13 +26,17 @@
 namespace Common {
 
 
-File::File(FILE*file)
-	: _handle(file), _ioFailed(false) {
+File::File(FILE *file)
+	: _handle(file), _ioFailed(false), _owned(true) {
 }
 
+File::File(::File &file)
+	: _handle((FILE *)file), _ioFailed(false), _owned(false) {
+}
 
 File::~File() {
-	close();
+	if(_owned)
+		close();
 }
 
 void File::close() {


@@ Diff output truncated at 100000 characters. @@

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