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

remere at users.sourceforge.net remere at users.sourceforge.net
Thu Aug 6 04:05:53 CEST 2009


Revision: 43079
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43079&view=rev
Author:   remere
Date:     2009-08-06 02:05:53 +0000 (Thu, 06 Aug 2009)

Log Message:
-----------
*Cleaned up code, removed the duplicated File class, removed old, unused functions and added doxygen.

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/Makefile
    tools/branches/gsoc2009-gui/compress_gob.cpp
    tools/branches/gsoc2009-gui/compress_saga.cpp
    tools/branches/gsoc2009-gui/compress_scumm_san.cpp
    tools/branches/gsoc2009-gui/desword2.cpp
    tools/branches/gsoc2009-gui/gui/pages.cpp
    tools/branches/gsoc2009-gui/kyra_pak.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/adpcm.cpp
    tools/branches/gsoc2009-gui/utils/adpcm.h
    tools/branches/gsoc2009-gui/utils/file.cpp
    tools/branches/gsoc2009-gui/utils/file.h
    tools/branches/gsoc2009-gui/utils/util.h
    tools/branches/gsoc2009-gui/utils/voc.cpp
    tools/branches/gsoc2009-gui/utils/voc.h
    tools/branches/gsoc2009-gui/utils/wave.cpp
    tools/branches/gsoc2009-gui/utils/wave.h

Removed Paths:
-------------
    tools/branches/gsoc2009-gui/utils/stream.h

Modified: tools/branches/gsoc2009-gui/Makefile
===================================================================
--- tools/branches/gsoc2009-gui/Makefile	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/Makefile	2009-08-06 02:05:53 UTC (rev 43079)
@@ -138,13 +138,15 @@
 dekyra$(EXEEXT): dekyra.o dekyra_v1.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+
 
-descumm$(EXEEXT): descumm-tool.o descumm.o descumm6.o descumm-common.o util.o tool.o
+descumm$(EXEEXT): descumm-tool.o descumm.o descumm6.o descumm-common.o util.o tool.o $(UTILS)
 	$(CXX) $(LDFLAGS) -o $@ $+
 
-desword2$(EXEEXT): desword2.o util.o tool.o
+desword2$(EXEEXT): desword2.o util.o tool.o $(UTILS)
 	$(CXX) $(LDFLAGS) -o $@ $+
 
-degob$(EXEEXT): degob.o degob_script.o degob_script_v1.o degob_script_v2.o degob_script_v3.o degob_script_v4.o degob_script_v5.o degob_script_v6.o degob_script_bargon.o util.o tool.o
+degob$(EXEEXT): degob.o degob_script.o degob_script_v1.o degob_script_v2.o degob_script_v3.o \
+	degob_script_v4.o degob_script_v5.o degob_script_v6.o degob_script_bargon.o \
+	util.o tool.o $(UTILS)
 	$(CXX) $(LDFLAGS) -o $@ $+
 
 #encode_dxa$(EXEEXT): encode_dxa.o compress.o util.o tool.o

Modified: tools/branches/gsoc2009-gui/compress_gob.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_gob.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/compress_gob.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -125,7 +125,7 @@
 
 // All the other reads concern file + compression flag
 	std::string fname = gobConf.readString();
-	while (!gobConf.reachedEOF()) {
+	while (!gobConf.eos()) {
 		strcpy(curChunk->name, fname.c_str());
 		fname = gobConf.readString();
 		if ((fname == "1") || (_execMode & MODE_FORCE))
@@ -157,7 +157,7 @@
 		src1.close();
 		
 		std::string tmp = gobConf.readString();
-		if (!gobConf.reachedEOF()) {
+		if (!gobConf.eos()) {
 			curChunk->next = new Chunk;
 			curChunk = curChunk->next;
 			chunkCount++;

Modified: tools/branches/gsoc2009-gui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_saga.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/compress_saga.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -228,12 +228,11 @@
 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) {
-		inputData = Audio::loadVOCFromStream(inputFileStream, size, rate);
+		inputData = Audio::loadVOCFromStream(inputFile, size, rate);
 
 		_sampleSize = size;
 		_sampleRate = rate;
@@ -262,7 +261,7 @@
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
 	if (_currentFileDescription->resourceType == kSoundWAV) {
-		if (!Audio::loadWAVFromStream(inputFileStream, size, rate, flags))
+		if (!Audio::loadWAVFromStream(inputFile, size, rate, flags))
 			error("Unable to read WAV");
 
 		_sampleSize = size;
@@ -284,7 +283,7 @@
 		_sampleStereo = _currentFileDescription->stereo;
 		writeHeader(outputFile);
 
-		Audio::AudioStream *voxStream = Audio::makeADPCMStream(&inputFileStream, inputSize, Audio::kADPCMOki);
+		Audio::AudioStream *voxStream = Audio::makeADPCMStream(&inputFile, inputSize, Audio::kADPCMOki);
 		buffer = (byte *)malloc(_sampleSize);
 		uint32 voxSize = voxStream->readBuffer((int16*)buffer, inputSize * 2);
 		if (voxSize != inputSize * 2)

Modified: tools/branches/gsoc2009-gui/compress_scumm_san.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_scumm_san.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/compress_scumm_san.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -667,7 +667,7 @@
 		output.writeUint32BE(frameSize);
 		for (;;) {
 			tag = input.readUint32BE(); // chunk tag
-			if (input.reachedEOF())
+			if (input.eos())
 				break;
 			if (tag == 'FRME') {
 				input.seek(-4, SEEK_CUR);

Modified: tools/branches/gsoc2009-gui/desword2.cpp
===================================================================
--- tools/branches/gsoc2009-gui/desword2.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/desword2.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -21,6 +21,7 @@
  */
 
 #include "util.h"
+#include "utils/file.h"
 
 enum {
 	GAME_OBJECT = 3,

Modified: tools/branches/gsoc2009-gui/gui/pages.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/gui/pages.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -378,7 +378,10 @@
 			_configuration.compressing? TOOLTYPE_COMPRESSION : TOOLTYPE_EXTRACTION);
 		if(ls.size() == 1) {
 			_configuration.selectedTool = g_tools.get(ls[0]);
-			switchPage(new ChooseOutPage(_topframe));
+			if (_configuration.selectedTool->getInputList().size() == 1)
+				switchPage(new ChooseOutPage(_topframe));
+			else
+				switchPage(new ChooseExtraInPage(_topframe));
 		} else {
 			switchPage(new ChooseToolPage(_topframe, ls));
 		}

Modified: tools/branches/gsoc2009-gui/kyra_pak.cpp
===================================================================
--- tools/branches/gsoc2009-gui/kyra_pak.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/kyra_pak.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -37,7 +37,7 @@
 	}
 
 	char lastFilenameByte = 0;
-	while (!f.reachedEOF()) {
+	while (!f.eos()) {
 		// The start offset of a file should never be in the filelist
 		if (offset < f.pos() || offset > filesize) {
 			return false;
@@ -46,10 +46,10 @@
 		byte c = 0;
 
 		lastFilenameByte = 0;
-		while (!f.reachedEOF() && (c = f.readByte()) != 0)
+		while (!f.eos() && (c = f.readByte()) != 0)
 			lastFilenameByte = c;
 
-		if (f.reachedEOF()) {
+		if (f.eos()) {
 			return false;
 		}
 

Modified: tools/branches/gsoc2009-gui/tool.cpp
===================================================================
--- tools/branches/gsoc2009-gui/tool.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/tool.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -26,6 +26,7 @@
 #include <sstream>
 
 #include "util.h"
+#include "utils/file.h"
 #include "tool.h"
 
 Tool::Tool(const std::string &name, ToolType type) {

Modified: tools/branches/gsoc2009-gui/tool.h
===================================================================
--- tools/branches/gsoc2009-gui/tool.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/tool.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -27,6 +27,7 @@
 #include <string>
 
 #include "util.h"
+#include "utils/file.h"
 
 /** 
  * Different types of tools, used to differentiate them when 
@@ -111,10 +112,12 @@
 	 * Fatal error in the tool, throws a ToolException,
 	 * you shouldn't really catch this exception.
 	 */
+
 	void error(const char *format, ...);
 	/**
 	 * A warning, the same as print but WARNING: is prepended to the message.
 	 */
+
 	void warning(const char *format, ...);
 	/**
 	 * Prints a message, to either stdout or the GUI, always use this instead of printf

Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/util.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -111,489 +111,3 @@
 	return sz;
 }
 
-// Filenname implementation
-Filename::Filename(const char *path) {
-	_path = path;
-}
-Filename::Filename(std::string path) {
-	_path = path;
-}
-
-Filename::Filename(const Filename& filename) {
-	_path = filename._path;
-}
-
-Filename& Filename::operator=(const Filename& filename) {
-	_path = filename._path;
-	return *this;
-}
-
-void Filename::setFullPath(const std::string &path) {
-	_path = path;
-}
-
-void Filename::setFullName(const std::string &newname) {
-	_path = getPath() + newname;
-}
-
-void Filename::addExtension(const std::string &ext) {
-	_path += ext;
-}
-
-void Filename::setExtension(const std::string &ext) {
-	size_t dot = _path.rfind('.');
-	if (dot == std::string::npos) {
-		_path += ext;
-	} else {
-		_path.resize(dot);
-		_path += ext;
-	}
-}
-
-bool Filename::equals(const Filename &other) const {
-#ifdef _WIN32
-	// On Windows paths are case-insensitive
-	return scumm_stricmp(_path.c_str(), other._path.c_str()) == 0;
-#else
-	return _path == other._path;
-#endif
-}
-
-bool Filename::empty() const {
-	return _path.empty();
-}
-
-bool Filename::directory() const {
-	return getFullName().size() == 0;
-}
-
-bool Filename::exists() const { 
-	// This fails if we don't have permission to read the file
-	// but in most cases, that's the same thing for us.
-	FILE *f = fopen(_path.c_str(), "r");
-	if (f) {
-		fclose(f);
-		return true;
-	}
-	return false;
-}
-
-bool Filename::hasExtension(std::string ext) const {
-	size_t dot = _path.rfind('.');
-	if (dot == std::string::npos)
-		return false;
-
-	// Check that dot position is less than /, since some
-	// directories contain ., like /home/.data/file
-	size_t slash = _path.rfind('/');
-	if (slash != std::string::npos)
-		if (slash > dot)
-			return false;
-
-	slash = _path.rfind('\\');
-	if (slash != std::string::npos)
-		if (slash > dot)
-			return false;
-
-	// We compare extensions, skip any dots
-	if (_path[dot] == '.')
-		dot++;
-	if (ext[0] == '.')
-		ext = ext.substr(1);
-
-	std::string tmp = _path.substr(dot);
-#ifdef _WIN32
-	// On Windows paths are case-insensitive
-	return scumm_stricmp(tmp.c_str(), ext.c_str()) == 0;
-#else
-	return tmp == ext;
-#endif
-}
-
-std::string Filename::getFullPath() const {
-	return _path;
-}
-
-std::string Filename::getFullName() const {
-	size_t slash = _path.rfind('/');
-	if (slash == std::string::npos)
-		slash = _path.rfind('\\');
-
-	if (slash == std::string::npos)
-		return _path;
-
-	return _path.substr(slash + 1);
-}
-
-std::string Filename::getName() const {
-	size_t slash = _path.rfind('/');
-	size_t dot = _path.rfind('.');
-	if (slash == std::string::npos)
-		slash = _path.rfind('\\');
-
-	if (dot == std::string::npos)
-		dot = _path.size();
-
-	if (slash == std::string::npos)
-		return _path.substr(0, dot);
-
-	if (dot < slash)
-		dot = _path.size();
-
-	return _path.substr(slash + 1, dot - slash - 1);
-}
-
-std::string Filename::getExtension() const {
-	size_t slash = _path.rfind('/');
-	size_t dot = _path.rfind('.');
-	if (slash == std::string::npos)
-		slash = _path.rfind('\\');
-
-	if (slash == std::string::npos)
-		slash = 0;
-
-	if (dot == std::string::npos)
-		return "";
-
-	if (dot < slash)
-		return "";
-
-	return _path.substr(dot + 1);
-}
-
-std::string Filename::getPath() const {
-	size_t slash = _path.rfind('/');
-	if (slash == std::string::npos)
-		slash = _path.rfind('\\');
-
-	if (slash == std::string::npos)
-		return "";
-
-	return _path.substr(0, slash + 1);
-}
-
-// File interface
-// While this does massive duplication of the code above, it's required to make sure that
-// unconverted tools are backwards-compatible
-
-File::File() {
-	_file = NULL;
-	_mode = FILEMODE_READ;
-	_xormode = 0;
-}
-
-File::File(const Filename &filepath, FileMode mode) {
-	_file = NULL;
-	_mode = FILEMODE_READ;
-
-	open(filepath, mode);
-}
-
-File::File(const Filename &filepath, const char *mode) {
-	_file = NULL;
-	_mode = FILEMODE_READ;
-
-	open(filepath, mode);
-}
-
-File::~File() {
-	close();
-}
-
-void File::open(const Filename &filepath, const char *mode) {
-	FileMode m = FILEMODE_WRITE;
-	do {
-		switch(*mode) {
-		case 'w': m = FILEMODE_WRITE; break;
-		case 'r': m = FILEMODE_READ; break;
-		case 'b': m = FileMode(m | FILEMODE_BINARY); break;
-		case '+': m = FileMode(m | FILEMODE_APPEND); break;
-		default: throw FileException(std::string("Unsupported FileMode ") + mode);
-		}
-	} while(*++mode);
-	
-	open(filepath, m);
-}
-
-void File::open(const Filename &filepath, FileMode mode) {
-	// Clean up previously opened file
-	close();
-
-	std::string strmode;
-	if (mode & FILEMODE_READ)
-		strmode += 'r';
-	if (mode & FILEMODE_WRITE)
-		strmode += 'w';
-	if (mode & FILEMODE_BINARY)
-		strmode += 'b';
-	if (mode & FILEMODE_APPEND)
-		strmode += '+';
-
-	_file = fopen(filepath.getFullPath().c_str(), strmode.c_str());
-	_mode = mode;
-	_name = filepath;
-
-	if (!_file)
-		throw FileException("Could not open file " + filepath.getFullPath());
-}
-
-void File::close() {
-	if (_file)
-		fclose(_file);
-	_file = NULL;
-}
-
-void File::setXorMode(uint8 xormode) {
-	_xormode = xormode;
-}
-
-int File::readChar() {
-	if (!_file) 
-		throw FileException("File is not open");
-	if ((_mode & FILEMODE_READ) == 0)
-		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
-
-	int u8 = fgetc(_file);
-	if (u8 == EOF)
-		throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
-	u8 ^= _xormode;
-	return u8;
-}
-
-uint8 File::readByte() {
-	int u8 = readChar();
-	return (uint8)u8;
-}
-
-uint16 File::readUint16BE() {
-	uint16 ret = 0;
-	ret |= uint16(readByte() << 8ul);
-	ret |= uint16(readByte());
-	return ret;
-}
-
-uint16 File::readUint16LE() {
-	uint16 ret = 0;
-	ret |= uint16(readByte());
-	ret |= uint16(readByte() << 8ul);
-	return ret;
-}
-
-uint32 File::readUint32BE() {
-	uint32 ret = 0;
-	ret |= uint32(readByte() << 24);
-	ret |= uint32(readByte() << 16);
-	ret |= uint32(readByte() << 8);
-	ret |= uint32(readByte());
-	return ret;
-}
-
-uint32 File::readUint32LE() {
-	uint32 ret = 0;
-	ret |= uint32(readByte());
-	ret |= uint32(readByte() << 8);
-	ret |= uint32(readByte() << 16);
-	ret |= uint32(readByte() << 24);
-	return ret;
-}
-
-void File::read(void *data, size_t elementSize, size_t elementCount) {
-	if (!_file) 
-		throw FileException("File is not open");
-	if ((_mode & FILEMODE_READ) == 0)
-		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
-
-	size_t data_read = fread(data, elementSize, elementCount, _file);
-	if (data_read != elementCount)
-		throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
-}
-
-size_t File::readN(void *data, size_t elementSize, size_t elementCount) {
-	if (!_file) 
-		throw FileException("File is not open");
-	if ((_mode & FILEMODE_READ) == 0)
-		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
-
-	return fread(data, elementSize, elementCount, _file);
-}
-
-std::string File::readString() {
-	if (!_file) 
-		throw FileException("File is not open");
-	if ((_mode & FILEMODE_READ) == 0)
-		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
-
-	std::string s;
-	try {
-		char c;
-		while ((c = readByte())) {
-			s += c;
-		}
-	} catch (FileException &) {
-		// pass, we reached EOF
-	}
-
-	return s;
-}
-
-std::string File::readString(size_t len) {
-	if (!_file) 
-		throw FileException("File is not open");
-	if ((_mode & FILEMODE_READ) == 0)
-		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
-
-	std::string s('\0', len);
-	std::string::iterator is = s.begin();
-
-	char c;
-	while ((c = readByte())) {
-		*is = c;
-	}
-
-	return s;
-}
-
-void File::writeChar(int i) {
-	if (!_file) 
-		throw FileException("File  is not open");
-	if ((_mode & FILEMODE_WRITE) == 0)
-		throw FileException("Tried to write to a file opened in read mode (" + _name.getFullPath() + ")");
-
-	i ^= _xormode;
-
-	if (fwrite(&i, 1, 1, _file) != 1)
-		throw FileException("Could not write to file (" + _name.getFullPath() + ")");
-}
-
-void File::writeByte(uint8 b) {
-	writeChar(b);
-}
-
-void File::writeUint16BE(uint16 value) {
-	writeByte((uint8)(value >> 8));
-	writeByte((uint8)(value));
-}
-
-void File::writeUint16LE(uint16 value) {
-	writeByte((uint8)(value));
-	writeByte((uint8)(value >> 8));
-}
-
-void File::writeUint32BE(uint32 value) {
-	writeByte((uint8)(value >> 24));
-	writeByte((uint8)(value >> 16));
-	writeByte((uint8)(value >> 8));
-	writeByte((uint8)(value));
-}
-
-void File::writeUint32LE(uint32 value) {
-	writeByte((uint8)(value));
-	writeByte((uint8)(value >> 8));
-	writeByte((uint8)(value >> 16));
-	writeByte((uint8)(value >> 24));
-}
-
-size_t File::write(const void *data, size_t elementSize, size_t elementCount) {
-	if (!_file) 
-		throw FileException("File is not open");
-	if ((_mode & FILEMODE_WRITE) == 0)
-		throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
-
-	size_t data_read = fwrite(data, elementSize, elementCount, _file);
-	if (data_read != elementCount)
-		throw FileException("Could not write to file (" + _name.getFullPath() + ")");
-
-	return data_read;
-}
-
-void File::printf(const char *format, ...) {
-	if (!_file) 
-		throw FileException("File is not open");
-	if ((_mode & FILEMODE_WRITE) == 0)
-		throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
-
-
-	va_list va;
-
-	va_start(va, format);
-	vfprintf(_file, format, va);
-	va_end(va);
-}
-
-void File::seek(long offset, int origin) {
-	if (!_file) 
-		throw FileException("File is not open");
-
-	if (fseek(_file, offset, origin) != 0)
-		throw FileException("Could not seek in file (" + _name.getFullPath() + ")");
-}
-
-void File::rewind() {
-	return ::rewind(_file);
-}
-
-int File::pos() const {
-	return ftell(_file);
-}
-
-bool File::reachedEOF() const {
-	return feof(_file) != 0;
-}
-
-uint32 File::size() const {
-	uint32 sz;
-	uint32 p = ftell(_file);
-	fseek(_file, 0, SEEK_END);
-	sz = ftell(_file);
-	fseek(_file, p, SEEK_SET);
-	return sz;
-}
-
-
-// Functions to parse the command line
-
-void displayHelp(const char *msg, const char *exename) {
-	if (!msg) {
-		printf("\nUsage: %s [-o <output dir> = out/] <file 1> ... <file n>\n", exename);
-	}
-	else {
-		printf(msg, exename);
-	}
-	exit(2);
-}
-
-void parseHelpArguments(const char * const argv[], int argc, const char *msg) {
-	if (argc < 2 || strcmp(argv[1], "--help") == 0 || scumm_stricmp(argv[1], "-h") == 0) {
-		displayHelp(msg, argv[0]);
-	}
-}
-
-bool parseOutputArguments(Filename *outputname, bool output_directory, const char * const argv[], int argc, int start_arg) {
-	if (start_arg >= 0 && (strcmp(argv[start_arg], "-o") == 0 || strcmp(argv[start_arg], "--output") == 0)) {
-		/* It's a -o argument, can we check next arg? */
-
-		if (start_arg + 1 < argc) {
-			outputname->setFullPath(argv[start_arg + 1]);
-
-			if (output_directory) {
-				/* Ensure last character is a /, this way we force directory output */
-				char lastchr = outputname->getFullPath()[outputname->getFullPath().size() - 1];
-				if (lastchr != '/' && lastchr != '\\') {
-					outputname->_path += '/';
-				}
-			}
-			return true;
-		} else {
-			error("Expected directory path after '-o' or '--output'.");
-		}
-	}
-	return false;
-}
-
-bool parseOutputFileArguments(Filename *outputname, const char * const argv[], int argc, int start_arg) {
-	return parseOutputArguments(outputname, false, argv, argc, start_arg);
-}
-
-bool parseOutputDirectoryArguments(Filename *outputname, const char * const argv[], int argc, int start_arg) {
-	return parseOutputArguments(outputname, true, argv, argc, start_arg);
-}

Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/util.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -39,68 +39,12 @@
 #include <process.h>
 #endif
 
-#include <exception>
+#include "utils/util.h"
 #include <string>
 #include <stdexcept>
 
-/*
- * Some useful types
- */
 
-typedef unsigned char byte;
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef signed char int8;
-typedef signed short int16;
-#ifdef __amigaos4__
-#include <exec/types.h>
-#include <stdlib.h>
-#else
-typedef unsigned int uint32;
-typedef signed int int32;
-#endif
-
-
 /*
- * Various utility macros
- */
-
-#if defined(_MSC_VER)
-
-	#define scumm_stricmp stricmp
-	#define scumm_strnicmp _strnicmp
-	#define snprintf _snprintf
-
-	#define SCUMM_LITTLE_ENDIAN
-	#pragma once
-	#pragma warning( disable : 4068 ) /* turn off "unknown pragma" warning */
-	#pragma warning( disable : 4996 ) /* turn off warnings about unsafe functions */
-
-#elif defined(__MINGW32__)
-
-	#define scumm_stricmp stricmp
-	#define scumm_strnicmp strnicmp
-
-	#define SCUMM_LITTLE_ENDIAN
-
-#elif defined(UNIX)
-
-	#define scumm_stricmp strcasecmp
-	#define scumm_strnicmp strncasecmp
-
-	#if defined(__DECCXX) /* Assume alpha architecture */
-	#define INVERSE_MKID
-	#define SCUMM_NEED_ALIGNMENT
-	#endif
-
-#else
-
-	#error No system type defined
-
-#endif
-
-
-/*
  * GCC specific stuff
  */
 #if defined(__GNUC__)
@@ -233,371 +177,4 @@
 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
-
-/**
- * Throw an exception of this type (or subtype of it), if the tool fails fatally.
- * This type is intended for general errors
- */
-class ToolException : public std::runtime_error {
-public:
-	/**
-	 * Construct an exception, with an appropriate error message
-	 * A return value for the tool should be supplied if none is appropriate
-	 * @todo If the tools are even more C++ized, the tool should decide retcode itself, not by exception
-	 *
-	 * @param error The error message
-	 * @param retcode The return value of the process
-	 */
-	ToolException(std::string error, int retcode = -1) : std::runtime_error(error), _retcode(retcode) {}
-
-	int _retcode;
-};
-
-/**
- * Something unexpected happened while reading / writing to a file
- * Usually premature end, or that it could not be opened (write / read protected)
- */
-class FileException : public ToolException {
-public: 
-	FileException(std::string error, int retcode = -1) : ToolException(error, retcode) {}
-};
-
-/**
- * Something unexpected happened while reading / writing to a file
- * Usually premature end, or that it could not be opened (write / read protected)
- */
-class AbortException : public ToolException {
-public: 
-	AbortException() : ToolException("Operation was aborted", -2) {}
-};
-
-/**
- * A file path, can be queried for different parts
- * and the parts can be modified seperately
- */
-struct Filename {
-	std::string _path;
-
-	Filename(std::string path = "");
-	Filename(const char *path);
-	Filename(const Filename &path);
-	Filename& operator=(const Filename &fn);
-
-	inline bool operator==(const Filename &fn){
-		return equals(fn);
-	}
-	
-	/**
-	 * Change the entire path including directory, volume and actual filname.
-	 *
-	 * @param path The new path.
-	 */
-	void setFullPath(const std::string &path);
-
-	/**
-	 * Sets the name of the file referred to, does not change the directory referred to.
-	 *
-	 * @param name New filename.
-	 */
-	void setFullName(const std::string &name);
-
-	/**
-	 * Adds an extension to the filename (does not replace any current extension).
-	 *
-	 * @param ext Extension to add.
-	 */
-	void addExtension(const std::string &ext);
-
-	/**
-	 * Sets the extension of the filename, replacing any current one, or adding one if there isn't any.
-	 *
-	 * @param ext The new extension of the filename.
-	 */
-	void setExtension(const std::string &ext);
-
-	/**
-	 * Returns true if the file has that extension.
-	 *
-	 * @param ext Extension to check for, only last extension is checked.
-	 * @return True if the filename has that extension.
-	 */
-	bool hasExtension(std::string ext) const;
-
-	/**
-	 * Has the filename been set to anything.
-	 */
-	bool empty() const;
-
-	/**
-	 * Returns true if the file exists, does NOT work for directories
-	 */
-	bool exists() const;
-
-	/**
-	 * Returns true if the file is a directory, which is if the path ends with '/'.
-	 *
-	 * @return true if the path looks like a directory.
-	 */
-	bool directory() const;
-
-	/**
-	 * True if the filenames are different (relative and absolute paths will NOT compare equally).
-	 *
-	 * @param other The filename to compare to.
-	 * @return True if they are equal.
-	 */
-	bool equals(const Filename &other) const;
-	
-
-	/**
-	 * Returns the entire path.
-	 */
-	std::string getFullPath() const;
-
-	/**
-	 * Returns the filename (ie. strips all directories from the path)
-	 */
-	std::string getFullName() const;
-
-	/**
-	 * Returns the name of the file, excluding extension and directories.
-	 * Note that in the case of multiple extensions, only the last extension is stripped.
-	 */
-	std::string getName() const;
-
-	/**
-	 * Get the extension of the filename, only the last extension in case of many.
-	 */
-	std::string getExtension() const;
-
-	/**
-	 * Returns the path of the filename, the name and extension of the file is stripped.
-	 */
-	std::string getPath() const;
-};
-
-/**
- * Possible modes for opening files
- */
-enum FileMode {
-	FILEMODE_READ = 1,
-	FILEMODE_WRITE = 2,
-	FILEMODE_BINARY = 4,
-	FILEMODE_APPEND = 8,
-};
-
-/**
- * A basic wrapper around the FILE class.
- * Offers functionality to write words easily, and deallocates the FILE
- * automatically on destruction.
- */
-class File {
-public:
-	/**
-	 * Opens the given file path as an in/out stream, depending on the
-	 * second argument.
-	 * File is always opened in binary mode
-	 *
-	 * @param filename The file to open
-	 * @param mode The mode to open the file in, can be either OR mask or in text
-	 */
-	File(const Filename &filename, FileMode mode);
-	File(const Filename &filename, const char *mode);
-	/**
-	 * Create an empty file, used for two-step construction.
-	 */
-	File();
-	~File();
-
-	/**
-	 * Opens the given file path as an in/out stream, depending on the
-	 * second argument.
-	 *
-	 * @param filename The file to open
-	 * @param mode The mode to open the file in
-	 */
-	void open(const Filename &filename, const char *mode);
-	void open(const Filename &filename, FileMode mode);
-
-	/**
-	 * Closes the file, if it's open
-	 */
-	void close();
-
-	/**
-	 * If the file is opened for reading / writing
-	 */
-	bool isOpen() const { return _file != 0; }
-
-	/**
-	 * True if there is nothing more to read from this file
-	 */
-	bool reachedEOF() const;
-
-	/**
-	 * Sets the xor mode of the file, bytes written / read to the file
-	 * will be XORed with this value. This value is *not* reset when
-	 * opening a new file.
-	 * Only works for write* and read* operation, not for the array
-	 * "read" and "write" methods
-	 */
-	void setXorMode(uint8 xormode);
-	
-	/**
-	 * Reads a single character (equivalent of fgetc
-	 */
-	int readChar();
-	/**
-	 * Read a single unsigned byte.
-	 * Throws FileException if file is not open / if read failed.
-	 */
-	uint8 readByte();
-	/**
-	 * Read a single 16-bit word, big endian.
-	 * Throws FileException if file is not open / if read failed.
-	 */
-	uint16 readUint16BE();
-	/**
-	 * Read a single 16-bit word, little endian.
-	 * Throws FileException if file is not open / if read failed.
-	 */
-	uint16 readUint16LE();
-	/**
-	 * Read a single 32-bit word, big endian.
-	 * Throws FileException if file is not open / if read failed.
-	 */
-	uint32 readUint32BE();
-	/**
-	 * Read a single 32-bit word, little endian.
-	 * Throws FileException if file is not open / if read failed.
-	 */
-	uint32 readUint32LE();
-
-	/**
-	 * Works the same way as fread, but throws on error or if it could
-	 * not read all elements.
-	 *
-	 * @param data Where to put the read data
-	 * @param elementSize the size of one element (in bytes)
-	 * @param elementCount the number of elements to read
-	 */
-	void read(void *data, size_t elementSize, size_t elementCount);
-
-	/**
-	 * Works the same way as fread, does NOT throw if it could not read all elements
-	 * still throws if file is not open.
-	 *
-	 * @param data Where to put the read data
-	 * @param elementSize the size of one element (in bytes)
-	 * @param elementCount the number of elements to read
-	 * @return number of bytes read
-	 */
-	size_t readN(void *data, size_t elementSize, size_t elementCount);
-
-	/**
-	 * Reads a full string, until NULL or EOF
-	 * Throws FileException if file is not open / if read failed.
-	 */
-	std::string readString();
-
-	/**
-	 * Reads the queried amount of bytes and returns it as a string
-	 * Throws FileException if file is not open / if read failed.
-	 *
-	 * @param len How many bytes to read
-	 * @return the data read
-	 */
-	std::string readString(size_t len);
-	
-
-
-
-	/**
-	 * Writes a single character (equivalent of fputc)
-	 */
-	void writeChar(int c);
-	/**
-	 * Writes a single byte to the file.
-	 * Throws FileException if file is not open / if write failed.
-	 */
-	void writeByte(uint8 b);
-	/**
-	 * Writes a single 16-bit word to the file, big endian.
-	 * Throws FileException if file is not open / if write failed.
-	 */
-	void writeUint16BE(uint16 value);
-	/**
-	 * Writes a single 16-bit word to the file, little endian.
-	 * Throws FileException if file is not open / if write failed.
-	 */
-	void writeUint16LE(uint16 value);
-	/**
-	 * Writes a single 32-bit word to the file, big endian.
-	 * Throws FileException if file is not open / if write failed.
-	 */
-	void writeUint32BE(uint32 value);
-	/**
-	 * Writes a single 32-bit word to the file, little endian.
-	 * Throws FileException if file is not open / if write failed.
-	 */
-	void writeUint32LE(uint32 value);
-
-	/**
-	 * Works the same way as fwrite, but throws on error or if
-	 * it could not write all data.
-	 *
-	 * @param data Where to read data from
-	 * @param elementSize the size of one element (in bytes)
-	 * @param elementCount the number of elements to read
-	 */
-	size_t write(const void *data, size_t elementSize, size_t elementCount);
-
-	/**
-	 * Works the same as fprintf
-	 */
-	void printf(const char *format, ...);
-
-	/**
-	 * Seek to the specified position in the stream.
-	 *
-	 * @param offset how many bytes to jump
-	 * @param origin SEEK_SET, SEEK_CUR or SEEK_END
-	 */
-	void seek(long offset, int origin);
-
-	// TODO: document
-	void rewind();
-
-	/**
-	 * Returns current position of the file cursor
-	 */
-	int pos() const;
-
-	/**
-	 * Returns the length of the file, in bytes, does not move the cursor.
-	 */
-	uint32 size() const;
-
-	// FIXME: Remove this method ASAP
-	FILE *getFileHandle() { return _file; }
-
-protected:
-	/** The mode the file was opened in. */
-	FileMode _mode;
-	/** Internal reference to the file. */
-	FILE *_file;
-	/** The name of the file, used for better error messages. */
-	Filename _name;
-	/** xor with this value while reading/writing (default 0), does not work for "read"/"write", only for byte operations. */
-	uint8 _xormode;
-};
-
-void displayHelp(const char *msg = NULL, const char *exename = NULL);
-void parseHelpArguments(const char * const argv[], int argc, const char *msg = NULL);
-bool parseOutputFileArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
-bool parseOutputDirectoryArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
-
-
 #endif

Modified: tools/branches/gsoc2009-gui/utils/adpcm.cpp
===================================================================
--- tools/branches/gsoc2009-gui/utils/adpcm.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/adpcm.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -30,7 +30,7 @@
 // flexibility of this code.
 class ADPCMInputStream : public AudioStream {
 private:
-	Common::SeekableReadStream *_stream;
+	File *_stream;
 	uint32 _endpos;
 	int _channels;
 	typesADPCM _type;
@@ -63,7 +63,7 @@
 	int16 decodeMS(ADPCMChannelStatus *c, byte);
 
 public:
-	ADPCMInputStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels = 2, uint32 blockAlign = 0);
+	ADPCMInputStream(File *stream, uint32 size, typesADPCM type, int rate, int channels = 2, uint32 blockAlign = 0);
 	~ADPCMInputStream() {};
 
 	int readBuffer(int16 *buffer, const int numSamples);
@@ -72,7 +72,7 @@
 	int readBufferMSIMA2(int16 *buffer, const int numSamples);
 	int readBufferMS(int channels, int16 *buffer, const int numSamples);
 
-	bool endOfData() const { return (_stream->eos() || _stream->pos() >= _endpos); }
+	bool endOfData() const { return (_stream->eos() || _stream->pos() >= (int)_endpos); }
 	bool isStereo() const	{ return false; }
 	int getRate() const	{ return _rate; }
 };
@@ -84,7 +84,7 @@
 // In addition, also MS IMA ADPCM is supported. See
 //   <http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM>.
 
-ADPCMInputStream::ADPCMInputStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign)
+ADPCMInputStream::ADPCMInputStream(File *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign)
 	: _stream(stream), _channels(channels), _type(type), _blockAlign(blockAlign), _rate(rate) {
 
 	_status.last = 0;
@@ -126,7 +126,7 @@
 
 	assert(numSamples % 2 == 0);
 
-	for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
+	for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < (int)_endpos; samples += 2) {
 		data = _stream->readByte();
 		WRITE_LE_UINT16(buffer + samples,     decodeOKI((data >> 4) & 0x0f));
 		WRITE_LE_UINT16(buffer + samples + 1, decodeOKI(data & 0x0f));
@@ -143,7 +143,7 @@
 
 	samples = 0;
 
-	while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) {
+	while (samples < numSamples && !_stream->eos() && _stream->pos() < (int)_endpos) {
 		if (_blockPos == _blockAlign) {
 			// read block header
 			_status.last = _stream->readSint16LE();
@@ -151,7 +151,7 @@
 			_blockPos = 4;
 		}
 
-		for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
+		for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < (int)_endpos; samples += 2) {
 			data = _stream->readByte();
 			_blockPos++;
 			WRITE_LE_UINT16(buffer + samples,     decodeMSIMA(data & 0x0f));
@@ -169,7 +169,7 @@
 	uint32 data;
 	int nibble;
 
-	for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos;) {
+	for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < (int)_endpos;) {
 		for (int channel = 0; channel < 2; channel++) {
 			data = _stream->readUint32LE();
 
@@ -199,7 +199,7 @@
 
 	samples = 0;
 
-	while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) {
+	while (samples < numSamples && !_stream->eos() && _stream->pos() < (int)_endpos) {
 		if (_blockPos == _blockAlign) {
 			// read block header
 			_status.ch[0].predictor = Common::CLIP(_stream->readByte(), (byte)0, (byte)6);
@@ -227,7 +227,7 @@
 		}
 
 
-		for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
+		for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < (int)_endpos; samples += 2) {
 			data = _stream->readByte();
 			_blockPos++;
 			WRITE_LE_UINT16(buffer + samples,     decodeMS(&_status.ch[0], (data >> 4) & 0x0f));
@@ -347,7 +347,7 @@
 	return (int16)predictor;
 }
 
-AudioStream *makeADPCMStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign) {
+AudioStream *makeADPCMStream(File *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign) {
 	return new ADPCMInputStream(stream, size, type, rate, channels, blockAlign);
 }
 

Modified: tools/branches/gsoc2009-gui/utils/adpcm.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/adpcm.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/adpcm.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -24,7 +24,7 @@
 #define SOUND_ADPCM_H
 
 #include "audiostream.h"
-#include "stream.h"
+#include "file.h"
 
 namespace Audio {
 
@@ -36,7 +36,7 @@
 	kADPCMMS
 };
 
-AudioStream *makeADPCMStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate = 22050, int channels = 2, uint32 blockAlign = 0);
+AudioStream *makeADPCMStream(File *stream, uint32 size, typesADPCM type, int rate = 22050, int channels = 2, uint32 blockAlign = 0);
 
 } // End of namespace Audio
 

Modified: tools/branches/gsoc2009-gui/utils/file.cpp
===================================================================
--- tools/branches/gsoc2009-gui/utils/file.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/file.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -1,5 +1,5 @@
 /* Scumm Tools
- * Copyright (C) 2004-2006  The ScummVM Team
+ * Copyright (C) 2004-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,99 +22,485 @@
 
 #include "file.h"
 
+#include <stdarg.h>
 
-namespace Common {
 
+// Filenname implementation
+Filename::Filename(const char *path) {
+	_path = path;
+}
+Filename::Filename(std::string path) {
+	_path = path;
+}
 
-File::File(FILE *file)
-	: _handle(file), _ioFailed(false), _owned(true) {
+Filename::Filename(const Filename& filename) {
+	_path = filename._path;
 }
 
-File::File(::File &file)
-	: _handle(file.getFileHandle()), _ioFailed(false), _owned(false) {
+Filename& Filename::operator=(const Filename& filename) {
+	_path = filename._path;
+	return *this;
 }
 
+void Filename::setFullPath(const std::string &path) {
+	_path = path;
+}
+
+void Filename::setFullName(const std::string &newname) {
+	_path = getPath() + newname;
+}
+
+void Filename::addExtension(const std::string &ext) {
+	_path += ext;
+}
+
+void Filename::setExtension(const std::string &ext) {
+	size_t dot = _path.rfind('.');
+	if (dot == std::string::npos) {
+		_path += ext;
+	} else {
+		_path.resize(dot);
+		_path += ext;
+	}
+}
+
+bool Filename::equals(const Filename &other) const {
+#ifdef _WIN32
+	// On Windows paths are case-insensitive
+	return scumm_stricmp(_path.c_str(), other._path.c_str()) == 0;
+#else
+	return _path == other._path;
+#endif
+}
+
+bool Filename::empty() const {
+	return _path.empty();
+}
+
+bool Filename::directory() const {
+	return getFullName().size() == 0;
+}
+
+bool Filename::exists() const { 
+	// This fails if we don't have permission to read the file
+	// but in most cases, that's the same thing for us.
+	FILE *f = fopen(_path.c_str(), "r");
+	if (f) {
+		fclose(f);
+		return true;
+	}
+	return false;
+}
+
+bool Filename::hasExtension(std::string ext) const {
+	size_t dot = _path.rfind('.');
+	if (dot == std::string::npos)
+		return false;
+
+	// Check that dot position is less than /, since some
+	// directories contain ., like /home/.data/file
+	size_t slash = _path.rfind('/');
+	if (slash != std::string::npos)
+		if (slash > dot)
+			return false;
+
+	slash = _path.rfind('\\');
+	if (slash != std::string::npos)
+		if (slash > dot)
+			return false;
+
+	// We compare extensions, skip any dots
+	if (_path[dot] == '.')
+		dot++;
+	if (ext[0] == '.')
+		ext = ext.substr(1);
+
+	std::string tmp = _path.substr(dot);
+#ifdef _WIN32
+	// On Windows paths are case-insensitive
+	return scumm_stricmp(tmp.c_str(), ext.c_str()) == 0;
+#else
+	return tmp == ext;
+#endif
+}
+
+std::string Filename::getFullPath() const {
+	return _path;
+}
+
+std::string Filename::getFullName() const {
+	size_t slash = _path.rfind('/');
+	if (slash == std::string::npos)
+		slash = _path.rfind('\\');
+
+	if (slash == std::string::npos)
+		return _path;
+
+	return _path.substr(slash + 1);
+}
+
+std::string Filename::getName() const {
+	size_t slash = _path.rfind('/');
+	size_t dot = _path.rfind('.');
+	if (slash == std::string::npos)
+		slash = _path.rfind('\\');
+
+	if (dot == std::string::npos)
+		dot = _path.size();
+
+	if (slash == std::string::npos)
+		return _path.substr(0, dot);
+
+	if (dot < slash)
+		dot = _path.size();
+
+	return _path.substr(slash + 1, dot - slash - 1);
+}
+
+std::string Filename::getExtension() const {
+	size_t slash = _path.rfind('/');
+	size_t dot = _path.rfind('.');
+	if (slash == std::string::npos)
+		slash = _path.rfind('\\');
+
+	if (slash == std::string::npos)
+		slash = 0;
+
+	if (dot == std::string::npos)
+		return "";
+
+	if (dot < slash)
+		return "";
+
+	return _path.substr(dot + 1);
+}
+
+std::string Filename::getPath() const {
+	size_t slash = _path.rfind('/');
+	if (slash == std::string::npos)
+		slash = _path.rfind('\\');
+
+	if (slash == std::string::npos)
+		return "";
+
+	return _path.substr(0, slash + 1);
+}
+
+// File interface
+// While this does massive duplication of the code above, it's required to make sure that
+// unconverted tools are backwards-compatible
+
+File::File() {
+	_file = NULL;
+	_mode = FILEMODE_READ;
+	_xormode = 0;
+}
+
+File::File(const Filename &filepath, FileMode mode) {
+	_file = NULL;
+	_mode = FILEMODE_READ;
+
+	open(filepath, mode);
+}
+
+File::File(const Filename &filepath, const char *mode) {
+	_file = NULL;
+	_mode = FILEMODE_READ;
+
+	open(filepath, mode);
+}
+
 File::~File() {
-	if (_owned)
-		close();
+	close();
 }
 
+void File::open(const Filename &filepath, const char *mode) {
+	FileMode m = FILEMODE_WRITE;
+	do {
+		switch(*mode) {
+		case 'w': m = FILEMODE_WRITE; break;
+		case 'r': m = FILEMODE_READ; break;
+		case 'b': m = FileMode(m | FILEMODE_BINARY); break;
+		case '+': m = FileMode(m | FILEMODE_APPEND); break;
+		default: throw FileException(std::string("Unsupported FileMode ") + mode);
+		}
+	} while(*++mode);
+	
+	open(filepath, m);
+}
+
+void File::open(const Filename &filepath, FileMode mode) {
+	// Clean up previously opened file
+	close();
+
+	std::string strmode;
+	if (mode & FILEMODE_READ)
+		strmode += 'r';
+	if (mode & FILEMODE_WRITE)
+		strmode += 'w';
+	if (mode & FILEMODE_BINARY)
+		strmode += 'b';
+	if (mode & FILEMODE_APPEND)
+		strmode += '+';
+
+	_file = fopen(filepath.getFullPath().c_str(), strmode.c_str());
+	_mode = mode;
+	_name = filepath;
+
+	if (!_file)
+		throw FileException("Could not open file " + filepath.getFullPath());
+}
+
 void File::close() {
-	_handle = NULL;
+	if (_file)
+		fclose(_file);
+	_file = NULL;
 }
 
-bool File::isOpen() const {
-	return _handle != NULL;
+void File::setXorMode(uint8 xormode) {
+	_xormode = xormode;
 }
 
-bool File::ioFailed() const {
-	return _ioFailed != 0;
+int File::readChar() {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_READ) == 0)
+		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+	int u8 = fgetc(_file);
+	if (u8 == EOF)
+		throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
+	u8 ^= _xormode;
+	return u8;
 }
 
-void File::clearIOFailed() {
-	_ioFailed = false;
+uint8 File::readByte() {
+	int u8 = readChar();
+	return (uint8)u8;
 }
 
-bool File::eof() const {
-	if (_handle == NULL) {
-		error("File::eof: File is not open!");
-		return false;
-	}
+uint16 File::readUint16BE() {
+	uint16 ret = 0;
+	ret |= uint16(readByte() << 8ul);
+	ret |= uint16(readByte());
+	return ret;
+}
 
-	return feof(_handle) != 0;
+uint16 File::readUint16LE() {
+	uint16 ret = 0;
+	ret |= uint16(readByte());
+	ret |= uint16(readByte() << 8ul);
+	return ret;
 }
 
-uint32 File::pos() const {
-	if (_handle == NULL) {
-		error("File::pos: File is not open!");
-		return 0;
-	}
+uint32 File::readUint32BE() {
+	uint32 ret = 0;
+	ret |= uint32(readByte() << 24);
+	ret |= uint32(readByte() << 16);
+	ret |= uint32(readByte() << 8);
+	ret |= uint32(readByte());
+	return ret;
+}
 
-	return ftell(_handle);
+uint32 File::readUint32LE() {
+	uint32 ret = 0;
+	ret |= uint32(readByte());
+	ret |= uint32(readByte() << 8);
+	ret |= uint32(readByte() << 16);
+	ret |= uint32(readByte() << 24);
+	return ret;
 }
 
-uint32 File::size() const {
-	if (_handle == NULL) {
-		error("File::size: File is not open!");
-		return 0;
-	}
+int16 File::readSint16BE() {
+	int16 ret = 0;
+	ret |= int16(readByte() << 8ul);
+	ret |= int16(readByte());
+	return ret;
+}
 
-	uint32 oldPos = ftell(_handle);
-	fseek(_handle, 0, SEEK_END);
-	uint32 length = ftell(_handle);
-	fseek(_handle, oldPos, SEEK_SET);
+int16 File::readSint16LE() {
+	int16 ret = 0;
+	ret |= int16(readByte());
+	ret |= int16(readByte() << 8ul);
+	return ret;
+}
 
-	return length;
+int32 File::readSint32BE() {
+	int32 ret = 0;
+	ret |= int32(readByte() << 24);
+	ret |= int32(readByte() << 16);
+	ret |= int32(readByte() << 8);
+	ret |= int32(readByte());
+	return ret;
 }
 
-void File::seek(int32 offs, int whence) {
-	if (_handle == NULL) {
-		error("File::seek: File is not open!");
-		return;
-	}
+int32 File::readSint32LE() {
+	int32 ret = 0;
+	ret |= int32(readByte());
+	ret |= int32(readByte() << 8);
+	ret |= int32(readByte() << 16);
+	ret |= int32(readByte() << 24);
+	return ret;
+}
 
-	if (fseek(_handle, offs, whence) != 0)
-		clearerr(_handle);
+void File::read(void *data, size_t elementSize, size_t elementCount) {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_READ) == 0)
+		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+	size_t data_read = fread(data, elementSize, elementCount, _file);
+	if (data_read != elementCount)
+		throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
 }
 
-uint32 File::read(void *ptr, uint32 len) {
-	byte *ptr2 = (byte *)ptr;
-	size_t real_len;
+size_t File::readN(void *data, size_t elementSize, size_t elementCount) {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_READ) == 0)
+		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
 
-	if (_handle == NULL) {
-		error("File::read: File is not open!");
-		return 0;
+	return fread(data, elementSize, elementCount, _file);
+}
+
+size_t File::read(void *data, size_t bytes) {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_READ) == 0)
+		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+	return fread(data, 1, bytes, _file);
+}
+
+std::string File::readString() {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_READ) == 0)
+		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+	std::string s;
+	try {
+		char c;
+		while ((c = readByte())) {
+			s += c;
+		}
+	} catch (FileException &) {
+		// pass, we reached EOF
 	}
 
-	if (len == 0)
-		return 0;
+	return s;
+}
 
-	real_len = fread(ptr2, 1, len, _handle);
-	if (real_len < len) {
-		_ioFailed = true;
+std::string File::readString(size_t len) {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_READ) == 0)
+		throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+	std::string s('\0', len);
+	std::string::iterator is = s.begin();
+
+	char c;
+	while ((c = readByte())) {
+		*is = c;
 	}
 
-	return (uint32)real_len;
+	return s;
 }
 
-}	// End of namespace Common
+void File::writeChar(int i) {
+	if (!_file) 
+		throw FileException("File  is not open");
+	if ((_mode & FILEMODE_WRITE) == 0)
+		throw FileException("Tried to write to a file opened in read mode (" + _name.getFullPath() + ")");
+
+	i ^= _xormode;
+
+	if (fwrite(&i, 1, 1, _file) != 1)
+		throw FileException("Could not write to file (" + _name.getFullPath() + ")");
+}
+
+void File::writeByte(uint8 b) {
+	writeChar(b);
+}
+
+void File::writeUint16BE(uint16 value) {
+	writeByte((uint8)(value >> 8));
+	writeByte((uint8)(value));
+}
+
+void File::writeUint16LE(uint16 value) {
+	writeByte((uint8)(value));
+	writeByte((uint8)(value >> 8));
+}
+
+void File::writeUint32BE(uint32 value) {
+	writeByte((uint8)(value >> 24));
+	writeByte((uint8)(value >> 16));
+	writeByte((uint8)(value >> 8));
+	writeByte((uint8)(value));
+}
+
+void File::writeUint32LE(uint32 value) {
+	writeByte((uint8)(value));
+	writeByte((uint8)(value >> 8));
+	writeByte((uint8)(value >> 16));
+	writeByte((uint8)(value >> 24));
+}
+
+size_t File::write(const void *data, size_t elementSize, size_t elementCount) {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_WRITE) == 0)
+		throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
+
+	size_t data_read = fwrite(data, elementSize, elementCount, _file);
+	if (data_read != elementCount)
+		throw FileException("Could not write to file (" + _name.getFullPath() + ")");
+
+	return data_read;
+}
+
+void File::printf(const char *format, ...) {
+	if (!_file) 
+		throw FileException("File is not open");
+	if ((_mode & FILEMODE_WRITE) == 0)
+		throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
+
+
+	va_list va;
+
+	va_start(va, format);
+	vfprintf(_file, format, va);
+	va_end(va);
+}
+
+void File::seek(long offset, int origin) {
+	if (!_file) 
+		throw FileException("File is not open");
+
+	if (fseek(_file, offset, origin) != 0)
+		throw FileException("Could not seek in file (" + _name.getFullPath() + ")");
+}
+
+void File::rewind() {
+	return ::rewind(_file);
+}
+
+int File::pos() const {
+	return ftell(_file);
+}
+
+bool File::eos() const {
+	return feof(_file) != 0;
+}
+
+uint32 File::size() const {
+	uint32 sz;
+	uint32 p = ftell(_file);
+	fseek(_file, 0, SEEK_END);
+	sz = ftell(_file);
+	fseek(_file, p, SEEK_SET);
+	return sz;
+}
+

Modified: tools/branches/gsoc2009-gui/utils/file.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/file.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/file.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -1,5 +1,5 @@
 /* Scumm Tools
- * Copyright (C) 2004-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
@@ -23,50 +23,372 @@
 #ifndef COMMON_FILE_H
 #define COMMON_FILE_H
 
-#include "stream.h"
+#include "util.h"
 
-namespace Common {
+#include <stdio.h>
+#include <string>
 
-class File : public SeekableReadStream {
-protected:
-	/** POSIX file handle to the actual file; 0 if no file is open. */
-	FILE *_handle;
+/**
+ * Something unexpected happened while reading / writing to a file
+ * Usually premature end, or that it could not be opened (write / read protected)
+ */
+class FileException : public ToolException {
+public: 
+	FileException(std::string error, int retcode = -1) : ToolException(error, retcode) {}
+};
 
-	/** If we own the internal handle or not (we don't if we're constructed from a ::File object */
-	bool _owned;
+/**
+ * A file path, can be queried for different parts
+ * and the parts can be modified seperately
+ */
+class Filename {
+public:
+	std::string _path;
 
-	/** Status flag which tells about recent I/O failures. */
-	bool _ioFailed;
+	Filename(std::string path = "");
+	Filename(const char *path);
+	Filename(const Filename &path);
+	Filename& operator=(const Filename &fn);
 
-private:
-	// Disallow copying File objects. There is not strict reason for this,
-	// except that so far we never had real need for such a feature, and
-	// code that accidentally copied File objects tended to break in strange
-	// ways.
-	File(const File &f);
-	File &operator  =(const File &f);
+	inline bool operator==(const Filename &fn){
+		return equals(fn);
+	}
+	
+	/**
+	 * Change the entire path including directory, volume and actual filname.
+	 *
+	 * @param path The new path.
+	 */
+	void setFullPath(const std::string &path);
 
+	/**
+	 * Sets the name of the file referred to, does not change the directory referred to.
+	 *
+	 * @param name New filename.
+	 */
+	void setFullName(const std::string &name);
+
+	/**
+	 * Adds an extension to the filename (does not replace any current extension).
+	 *
+	 * @param ext Extension to add.
+	 */
+	void addExtension(const std::string &ext);
+
+	/**
+	 * Sets the extension of the filename, replacing any current one, or adding one if there isn't any.
+	 *
+	 * @param ext The new extension of the filename.
+	 */
+	void setExtension(const std::string &ext);
+
+	/**
+	 * Returns true if the file has that extension.
+	 *
+	 * @param ext Extension to check for, only last extension is checked.
+	 * @return True if the filename has that extension.
+	 */
+	bool hasExtension(std::string ext) const;
+
+	/**
+	 * Has the filename been set to anything.
+	 */
+	bool empty() const;
+
+	/**
+	 * Returns true if the file exists, does NOT work for directories
+	 */
+	bool exists() const;
+
+	/**
+	 * Returns true if the file is a directory, which is if the path ends with '/'.
+	 *
+	 * @return true if the path looks like a directory.
+	 */
+	bool directory() const;
+
+	/**
+	 * True if the filenames are different (relative and absolute paths will NOT compare equally).
+	 *
+	 * @param other The filename to compare to.
+	 * @return True if they are equal.
+	 */
+	bool equals(const Filename &other) const;
+	
+
+	/**
+	 * Returns the entire path.
+	 */
+	std::string getFullPath() const;
+
+	/**
+	 * Returns the filename (ie. strips all directories from the path)
+	 */
+	std::string getFullName() const;
+
+	/**
+	 * Returns the name of the file, excluding extension and directories.
+	 * Note that in the case of multiple extensions, only the last extension is stripped.
+	 */
+	std::string getName() const;
+
+	/**
+	 * Get the extension of the filename, only the last extension in case of many.
+	 */
+	std::string getExtension() const;
+
+	/**
+	 * Returns the path of the filename, the name and extension of the file is stripped.
+	 */
+	std::string getPath() const;
+};
+
+/**
+ * Possible modes for opening files
+ */
+enum FileMode {
+	FILEMODE_READ = 1,
+	FILEMODE_WRITE = 2,
+	FILEMODE_BINARY = 4,
+	FILEMODE_APPEND = 8,
+};
+
+/**
+ * A basic wrapper around the FILE class.
+ * Offers functionality to write words easily, and deallocates the FILE
+ * automatically on destruction.
+ */
+class File {
 public:
+	/**
+	 * Opens the given file path as an in/out stream, depending on the
+	 * second argument.
+	 * File is always opened in binary mode
+	 *
+	 * @param filename The file to open
+	 * @param mode The mode to open the file in, can be either OR mask or in text
+	 */
+	File(const Filename &filename, FileMode mode);
+	File(const Filename &filename, const char *mode);
+	/**
+	 * Create an empty file, used for two-step construction.
+	 */
+	File();
+	~File();
 
-	File(FILE *file);
-	// Allow construction from a ::File object, note that we *do not* own the file pointer
-	// in this scenario, we just act as a different wrapper for the file
-	// FIXME: Actually -- why do we have *two* wrappers anyway???
-	File(::File &file);
-	virtual ~File();
+	/**
+	 * Opens the given file path as an in/out stream, depending on the
+	 * second argument.
+	 *
+	 * @param filename The file to open
+	 * @param mode The mode to open the file in
+	 */
+	void open(const Filename &filename, const char *mode);
+	void open(const Filename &filename, FileMode mode);
 
-	virtual void close();
-	bool isOpen() const;
-	bool ioFailed() const;
-	void clearIOFailed();
-	bool eos() const { return eof(); }
-	bool eof() const;
-	uint32 pos() const;
+	/**
+	 * Closes the file, if it's open
+	 */
+	void close();
+
+	/**
+	 * If the file is opened for reading / writing
+	 */
+	bool isOpen() const { return _file != 0; }
+
+	/**
+	 * Sets the xor mode of the file, bytes written / read to the file
+	 * will be XORed with this value. This value is *not* reset when
+	 * opening a new file.
+	 * Only works for write* and read* operation, not for the array
+	 * "read" and "write" methods
+	 */
+	void setXorMode(uint8 xormode);
+	
+	/**
+	 * Reads a single character (equivalent of fgetc
+	 */
+	int readChar();
+	/**
+	 * Read a single unsigned byte.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	uint8 readByte();
+	/**
+	 * Read a single 16-bit word, big endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	uint16 readUint16BE();
+	/**
+	 * Read a single 16-bit word, little endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	uint16 readUint16LE();
+	/**
+	 * Read a single 32-bit word, big endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	uint32 readUint32BE();
+	/**
+	 * Read a single 32-bit word, little endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	uint32 readUint32LE();
+	
+	/**
+	 * Read a single 16-bit word, big endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	int16 readSint16BE();
+	/**
+	 * Read a single 16-bit word, little endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	int16 readSint16LE();
+	/**
+	 * Read a single 32-bit word, big endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	int32 readSint32BE();
+	/**
+	 * Read a single 32-bit word, little endian.
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	int32 readSint32LE();
+
+
+	/**
+	 * Works the same way as fread, but throws on error or if it could
+	 * not read all elements.
+	 *
+	 * @param data Where to put the read data
+	 * @param elementSize the size of one element (in bytes)
+	 * @param elementCount the number of elements to read
+	 */
+	void read(void *data, size_t elementSize, size_t elementCount);
+
+	/**
+	 * Works the same way as fread, does NOT throw if it could not read all elements
+	 * still throws if file is not open.
+	 *
+	 * @param data Where to put the read data
+	 * @param elementSize the size of one element (in bytes)
+	 * @param elementCount the number of elements to read
+	 * @return number of bytes read
+	 */
+	size_t readN(void *data, size_t elementSize, size_t elementCount);
+
+	/**
+	 * Read on a shorter form, does not throw (like readN)
+	 *
+	 * @param data Where to put the data in memory.
+	 * @param bytes How many bytes of data to read.
+	 * @return Returns the amount of bytes actually read
+	 */
+	size_t read(void *data, size_t bytes);
+
+	/**
+	 * Reads a full string, until NULL or EOF
+	 * Throws FileException if file is not open / if read failed.
+	 */
+	std::string readString();
+
+	/**
+	 * Reads the queried amount of bytes and returns it as a string
+	 * Throws FileException if file is not open / if read failed.
+	 *
+	 * @param len How many bytes to read
+	 * @return the data read
+	 */
+	std::string readString(size_t len);
+	
+
+
+	/**
+	 * Writes a single character (equivalent of fputc)
+	 */
+	void writeChar(int c);
+	/**
+	 * Writes a single byte to the file.
+	 * Throws FileException if file is not open / if write failed.
+	 */
+	void writeByte(uint8 b);
+	/**
+	 * Writes a single 16-bit word to the file, big endian.
+	 * Throws FileException if file is not open / if write failed.
+	 */
+	void writeUint16BE(uint16 value);
+	/**
+	 * Writes a single 16-bit word to the file, little endian.
+	 * Throws FileException if file is not open / if write failed.
+	 */
+	void writeUint16LE(uint16 value);
+	/**
+	 * Writes a single 32-bit word to the file, big endian.
+	 * Throws FileException if file is not open / if write failed.
+	 */
+	void writeUint32BE(uint32 value);
+	/**
+	 * Writes a single 32-bit word to the file, little endian.
+	 * Throws FileException if file is not open / if write failed.
+	 */
+	void writeUint32LE(uint32 value);
+
+	/**
+	 * Works the same way as fwrite, but throws on error or if
+	 * it could not write all data.
+	 *
+	 * @param data Where to read data from
+	 * @param elementSize the size of one element (in bytes)
+	 * @param elementCount the number of elements to read
+	 */
+	size_t write(const void *data, size_t elementSize, size_t elementCount);
+
+	/**
+	 * Works the same as fprintf
+	 */
+	void printf(const char *format, ...);
+
+	/**
+	 * Seek to the specified position in the stream.
+	 *
+	 * @param offset how many bytes to jump
+	 * @param origin SEEK_SET, SEEK_CUR or SEEK_END
+	 */
+	void seek(long offset, int origin);
+
+	/**
+	 * Resets the file pointer to the start of the file, in essence the same as re-opening it.
+	 */
+	void rewind();
+
+	/**
+	 * Returns current position of the file cursor
+	 */
+	int pos() const;
+
+	/**
+	 * True if there is nothing more to read from this file
+	 */
+	bool eos() const;
+
+	/**
+	 * Returns the length of the file, in bytes, does not move the cursor.
+	 */
 	uint32 size() const;
-	void seek(int32 offs, int whence = SEEK_SET);
-	uint32 read(void *dataPtr, uint32 dataSize);
+
+	// FIXME: Remove this method ASAP
+	FILE *getFileHandle() { return _file; }
+
+protected:
+	/** The mode the file was opened in. */
+	FileMode _mode;
+	/** Internal reference to the file. */
+	FILE *_file;
+	/** The name of the file, used for better error messages. */
+	Filename _name;
+	/** xor with this value while reading/writing (default 0), does not work for "read"/"write", only for byte operations. */
+	uint8 _xormode;
 };
 
-} // End of namespace Common
-
 #endif

Deleted: tools/branches/gsoc2009-gui/utils/stream.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/stream.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/stream.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -1,152 +0,0 @@
-/* Scumm Tools
- * 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 COMMON_STREAM_H
-#define COMMON_STREAM_H
-
-#include "../util.h"
-
-namespace Common {
-
-/**
- * Virtual base class for both ReadStream and WriteStream.
- */
-class Stream {
-public:
-	virtual ~Stream() {}
-
-	/**
-	 * Returns true if any I/O failure occured.
-	 * This flag is never cleared automatically. In order to clear it,
-	 * client code has to call clearIOFailed() explicitly.
-	 *
-	 * @todo Instead of returning a plain bool, maybe we should define
-	 *       a list of error codes which can be returned here.
-	 */
-	virtual bool ioFailed() const { return false; }
-
-	/**
-	 * Reset the I/O error status.
-	 */
-	virtual void clearIOFailed() {}
-};
-
-
-/**
- * Generic interface for a readable data stream.
- */
-class ReadStream : virtual public Stream {
-public:
-	/**
-	 * Returns true if the end of the stream has been reached.
-	 */
-	virtual bool eos() const = 0;
-
-	/**
-	 * Read data from the stream. Subclasses must implement this
-	 * method; all other read methods are implemented using it.
-	 *
-	 * @param dataPtr	pointer to a buffer into which the data is read
-	 * @param dataSize	number of bytes to be read
-	 * @return the number of bytes which were actually read.
-	 */
-	virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
-
-
-	// The remaining methods all have default implementations; subclasses
-	// need not (and should not) overload them.
-
-	byte readByte() {
-		byte b = 0;
-		read(&b, 1);
-		return b;
-	}
-
-	int8 readSByte() {
-		int8 b = 0;
-		read(&b, 1);
-		return b;
-	}
-
-	uint16 readUint16LE() {
-		uint16 a = readByte();
-		uint16 b = readByte();
-		return a | (b << 8);
-	}
-
-	uint32 readUint32LE() {
-		uint32 a = readUint16LE();
-		uint32 b = readUint16LE();
-		return (b << 16) | a;
-	}
-
-	uint16 readUint16BE() {
-		uint16 b = readByte();
-		uint16 a = readByte();
-		return a | (b << 8);
-	}
-
-	uint32 readUint32BE() {
-		uint32 b = readUint16BE();
-		uint32 a = readUint16BE();
-		return (b << 16) | a;
-	}
-
-	int16 readSint16LE() {
-		return (int16)readUint16LE();
-	}
-
-	int32 readSint32LE() {
-		return (int32)readUint32LE();
-	}
-
-	int16 readSint16BE() {
-		return (int16)readUint16BE();
-	}
-
-	int32 readSint32BE() {
-		return (int32)readUint32BE();
-	}
-};
-
-
-/**
- * Interface for a seekable & readable data stream.
- *
- * @todo We really need better error handling here!
- *       Like seek should somehow indicate whether it failed.
- */
-class SeekableReadStream : public ReadStream {
-public:
-
-	virtual uint32 pos() const = 0;
-	virtual uint32 size() const = 0;
-
-	virtual void seek(int32 offset, int whence = SEEK_SET) = 0;
-
-	void skip(uint32 offset) { seek(offset, SEEK_CUR); }
-};
-
-
-}	// End of namespace Common
-
-#endif

Modified: tools/branches/gsoc2009-gui/utils/util.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/util.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/util.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -23,6 +23,10 @@
 #ifndef COMMON_UTIL_H
 #define COMMON_UTIL_H
 
+#include <exception>
+#include <stdexcept>
+#include <string>
+
 namespace Common {
 
 
@@ -90,6 +94,91 @@
 
 	kPlatformUnknown = -1
 };
-}
 
+} // End of Common namespace
+
+/*
+ * Some useful types
+ */
+
+typedef unsigned char byte;
+typedef unsigned char uint8;
+typedef unsigned short uint16;
+typedef signed char int8;
+typedef signed short int16;
+#ifdef __amigaos4__
+#include <exec/types.h>
+#include <stdlib.h>
+#else
+typedef unsigned int uint32;
+typedef signed int int32;
 #endif
+
+/*
+ * Various utility macros
+ */
+
+#if defined(_MSC_VER)
+
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp _strnicmp
+	#define snprintf _snprintf
+
+	#define SCUMM_LITTLE_ENDIAN
+	#pragma once
+	#pragma warning( disable : 4068 ) /* turn off "unknown pragma" warning */
+	#pragma warning( disable : 4996 ) /* turn off warnings about unsafe functions */
+
+#elif defined(__MINGW32__)
+
+	#define scumm_stricmp strcasecmp
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp strnicmp
+
+	#define SCUMM_LITTLE_ENDIAN
+
+#elif defined(UNIX)
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
+
+	#if defined(__DECCXX) /* Assume alpha architecture */
+	#define INVERSE_MKID
+	#define SCUMM_NEED_ALIGNMENT
+	#endif
+
+#else
+
+	#error No system type defined
+
+#endif
+
+
+/**
+ * Throw an exception of this type (or subtype of it), if the tool fails fatally.
+ * This type is intended for general errors
+ */
+class ToolException : public std::runtime_error {
+public:
+	/**
+	 * Construct an exception, with an appropriate error message
+	 * A return value for the tool should be supplied if none is appropriate
+	 * @todo If the tools are even more C++ized, the tool should decide retcode itself, not by exception
+	 *
+	 * @param error The error message
+	 * @param retcode The return value of the process
+	 */
+	ToolException(std::string error, int retcode = -1) : std::runtime_error(error), _retcode(retcode) {}
+
+	int _retcode;
+};
+
+/**
+ * Something unexpected happened while reading / writing to a file
+ * Usually premature end, or that it could not be opened (write / read protected)
+ */
+class AbortException : public ToolException {
+public: 
+	AbortException() : ToolException("Operation was aborted", -2) {}
+};
+
+#endif

Modified: tools/branches/gsoc2009-gui/utils/voc.cpp
===================================================================
--- tools/branches/gsoc2009-gui/utils/voc.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/voc.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -21,7 +21,6 @@
  */
 
 #include "voc.h"
-#include "stream.h"
 #include "audiostream.h"
 
 
@@ -41,7 +40,7 @@
 	}
 }
 
-byte *loadVOCFromStream(Common::ReadStream &stream, int &size, int &rate, int &loops, int &begin_loop, int &end_loop) {
+byte *loadVOCFromStream(File &stream, int &size, int &rate, int &loops, int &begin_loop, int &end_loop) {
 	VocFileHeader fileHeader;
 
 	if (stream.read(&fileHeader, 8) != 8)
@@ -121,12 +120,12 @@
 	return ret_sound;
 }
 
-byte *loadVOCFromStream(Common::ReadStream &stream, int &size, int &rate) {
+byte *loadVOCFromStream(File &stream, int &size, int &rate) {
 	int loops, begin_loop, end_loop;
 	return loadVOCFromStream(stream, size, rate, loops, begin_loop, end_loop);
 }
 
-AudioStream *makeVOCStream(Common::ReadStream &stream) {
+AudioStream *makeVOCStream(File &stream) {
 	int size, rate;
 	byte *data = loadVOCFromStream(stream, size, rate);
 

Modified: tools/branches/gsoc2009-gui/utils/voc.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/voc.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/voc.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -24,9 +24,8 @@
 #define SOUND_VOC_H
 
 #include "../util.h"
+#include "file.h"
 
-namespace Common { class ReadStream; }
-
 namespace Audio {
 
 class AudioStream;
@@ -67,7 +66,7 @@
  * responsibility to dellocate that data again later on! Currently this
  * function only supports uncompressed raw PCM data.
  */
-extern byte *loadVOCFromStream(Common::ReadStream &stream, int &size, int &rate);
+extern byte *loadVOCFromStream(File &stream, int &size, int &rate);
 
 /**
  * Try to load a VOC from the given seekable stream and create an AudioStream
@@ -76,7 +75,7 @@
  *
  * This function uses loadVOCFromStream() internally.
  */
-AudioStream *makeVOCStream(Common::ReadStream &stream);
+AudioStream *makeVOCStream(File &stream);
 
 } // End of namespace Audio
 

Modified: tools/branches/gsoc2009-gui/utils/wave.cpp
===================================================================
--- tools/branches/gsoc2009-gui/utils/wave.cpp	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/wave.cpp	2009-08-06 02:05:53 UTC (rev 43079)
@@ -20,35 +20,12 @@
  *
  */
 
-/* Scumm Tools
- * 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$
- *
- */
-
-#include "stream.h"
 #include "audiostream.h"
 #include "adpcm.h"
 
 namespace Audio {
 
-bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate, byte &flags, uint16 *wavType, int *blockAlign_) {
+bool loadWAVFromStream(File &stream, int &size, int &rate, byte &flags, uint16 *wavType, int *blockAlign_) {
 	const uint32 initialPos = stream.pos();
 	byte buf[4+1];
 
@@ -159,7 +136,7 @@
 
 	do {
 		stream.seek(offset, SEEK_CUR);
-		if (stream.pos() >= initialPos + wavLength + 8) {
+		if (stream.pos() >= int(initialPos + wavLength + 8)) {
 			warning("getWavInfo: Cannot find 'data' chunk");
 			return false;
 		}
@@ -177,7 +154,7 @@
 	return true;
 }
 
-AudioStream *makeWAVStream(Common::SeekableReadStream &stream) {
+AudioStream *makeWAVStream(File &stream) {
 	int size, rate;
 	byte flags;
 	uint16 type;

Modified: tools/branches/gsoc2009-gui/utils/wave.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/wave.h	2009-08-05 21:32:42 UTC (rev 43078)
+++ tools/branches/gsoc2009-gui/utils/wave.h	2009-08-06 02:05:53 UTC (rev 43079)
@@ -23,9 +23,8 @@
 #ifndef SOUND_WAVE_H
 #define SOUND_WAVE_H
 
+class File;
 
-namespace Common { class SeekableReadStream; }
-
 namespace Audio {
 
 class AudioStream;
@@ -37,7 +36,7 @@
  * necessary for playback. Currently this function only supports uncompressed
  * raw PCM data as well as IMA ADPCM.
  */
-extern bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate, byte &flags, uint16 *wavType = 0, int *blockAlign = 0);
+extern bool loadWAVFromStream(File &stream, int &size, int &rate, byte &flags, uint16 *wavType = 0, int *blockAlign = 0);
 
 /**
  * Try to load a WAVE from the given seekable stream and create an AudioStream
@@ -46,7 +45,7 @@
  *
  * This function uses loadWAVFromStream() internally.
  */
-AudioStream *makeWAVStream(Common::SeekableReadStream &stream);
+AudioStream *makeWAVStream(File &stream);
 
 } // End of namespace Audio
 


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