[Scummvm-cvs-logs] SF.net SVN: scummvm:[46360] tools/branches/gsoc2009-gui
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Sun Dec 13 21:09:17 CET 2009
Revision: 46360
http://scummvm.svn.sourceforge.net/scummvm/?rev=46360&view=rev
Author: fingolfin
Date: 2009-12-13 20:09:16 +0000 (Sun, 13 Dec 2009)
Log Message:
-----------
TOOLS: Fix building, move around some files, cleanup
* Fix the build system by adding gui/ to the list of module directories,
so that dependencies for source files in it are tracked correctly
* Fixed compilation of the GUI code
* Move some files from utils/ to common/ to get more in sync with the
main ScummVM code base
Modified Paths:
--------------
tools/branches/gsoc2009-gui/Makefile
tools/branches/gsoc2009-gui/compress.h
tools/branches/gsoc2009-gui/compress_saga.cpp
tools/branches/gsoc2009-gui/degob.cpp
tools/branches/gsoc2009-gui/dekyra.cpp
tools/branches/gsoc2009-gui/desword2.cpp
tools/branches/gsoc2009-gui/extract_mm_nes.cpp
tools/branches/gsoc2009-gui/gui/configuration.h
tools/branches/gsoc2009-gui/gui/gui_tools.cpp
tools/branches/gsoc2009-gui/kyra_pak.h
tools/branches/gsoc2009-gui/tool.cpp
tools/branches/gsoc2009-gui/tool.h
tools/branches/gsoc2009-gui/tools.h
tools/branches/gsoc2009-gui/util.h
tools/branches/gsoc2009-gui/utils/adpcm.h
tools/branches/gsoc2009-gui/utils/voc.h
Added Paths:
-----------
tools/branches/gsoc2009-gui/common/
tools/branches/gsoc2009-gui/common/file.cpp
tools/branches/gsoc2009-gui/common/file.h
tools/branches/gsoc2009-gui/common/md5.cpp
tools/branches/gsoc2009-gui/common/md5.h
tools/branches/gsoc2009-gui/common/pack-end.h
tools/branches/gsoc2009-gui/common/pack-start.h
Removed Paths:
-------------
tools/branches/gsoc2009-gui/utils/file.cpp
tools/branches/gsoc2009-gui/utils/file.h
tools/branches/gsoc2009-gui/utils/md5.cpp
tools/branches/gsoc2009-gui/utils/md5.h
tools/branches/gsoc2009-gui/utils/pack-end.h
tools/branches/gsoc2009-gui/utils/pack-start.h
Modified: tools/branches/gsoc2009-gui/Makefile
===================================================================
--- tools/branches/gsoc2009-gui/Makefile 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/Makefile 2009-12-13 20:09:16 UTC (rev 46360)
@@ -62,7 +62,7 @@
# HACK: Until we get proper module support, add these "module dirs" to
# get the dependency tracking code working.
-MODULE_DIRS := ./ utils/
+MODULE_DIRS := ./ utils/ common/ gui/
#######################################################################
@@ -76,10 +76,10 @@
tools_gui$(EXEEXT)
UTILS := \
+ common/file.o \
+ common/md5.o \
utils/adpcm.o \
utils/audiostream.o \
- utils/file.o \
- utils/md5.o \
utils/voc.o \
utils/wave.o
@@ -234,7 +234,7 @@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) `pkg-config --cflags gtk+-2.0` -c sword2_clue.cpp
clean:
- rm -f *.o utils/*.o $(TARGETS)
+ rm -f $(addsuffix *.o,$(MODULE_DIRS)) $(TARGETS)
######################################################################
# The build rules follow - normally you should have no need to
Copied: tools/branches/gsoc2009-gui/common/file.cpp (from rev 46357, tools/branches/gsoc2009-gui/utils/file.cpp)
===================================================================
--- tools/branches/gsoc2009-gui/common/file.cpp (rev 0)
+++ tools/branches/gsoc2009-gui/common/file.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -0,0 +1,516 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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 "file.h"
+#include <stdarg.h>
+
+// 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;
+ _xormode = 0;
+
+ open(filepath, mode);
+}
+
+File::File(const Filename &filepath, const char *mode) {
+ _file = NULL;
+ _mode = FILEMODE_READ;
+ _xormode = 0;
+
+ 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;
+ _xormode = 0;
+
+ 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;
+}
+
+int16 File::readSint16BE() {
+ int16 ret = 0;
+ ret |= int16(readByte() << 8ul);
+ ret |= int16(readByte());
+ return ret;
+}
+
+int16 File::readSint16LE() {
+ int16 ret = 0;
+ ret |= int16(readByte());
+ ret |= int16(readByte() << 8ul);
+ return ret;
+}
+
+int32 File::readSint32BE() {
+ int32 ret = 0;
+ ret |= int32(readByte() << 24);
+ ret |= int32(readByte() << 16);
+ ret |= int32(readByte() << 8);
+ ret |= int32(readByte());
+ return ret;
+}
+
+int32 File::readSint32LE() {
+ int32 ret = 0;
+ ret |= int32(readByte());
+ ret |= int32(readByte() << 8);
+ ret |= int32(readByte() << 16);
+ ret |= int32(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);
+}
+
+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
+ }
+
+ 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::scanString(char *result) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_READ) == 0)
+ throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
+
+ fscanf(_file, "%s", result);
+}
+
+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;
+}
+
Copied: tools/branches/gsoc2009-gui/common/file.h (from rev 46357, tools/branches/gsoc2009-gui/utils/file.h)
===================================================================
--- tools/branches/gsoc2009-gui/common/file.h (rev 0)
+++ tools/branches/gsoc2009-gui/common/file.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -0,0 +1,398 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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_FILE_H
+#define COMMON_FILE_H
+
+#include "util.h"
+
+#include <stdio.h>
+#include <string>
+
+/**
+ * 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) {}
+};
+
+/**
+ * A file path, can be queried for different parts
+ * and the parts can be modified seperately
+ */
+class Filename {
+public:
+ 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; }
+
+ /**
+ * 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);
+
+ /**
+ * Reads a string, using until NULL or EOF or CR/LF
+ * Throws FileException if file is not open / if read failed.
+ */
+ void scanString(char *result);
+
+ /**
+ * 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;
+
+ // 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;
+};
+
+#endif
Copied: tools/branches/gsoc2009-gui/common/md5.cpp (from rev 46357, tools/branches/gsoc2009-gui/utils/md5.cpp)
===================================================================
--- tools/branches/gsoc2009-gui/common/md5.cpp (rev 0)
+++ tools/branches/gsoc2009-gui/common/md5.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -0,0 +1,265 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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 "md5.h"
+
+namespace Common {
+
+#define GET_UINT32(n, b, i) (n) = READ_LE_UINT32(b + i)
+#define PUT_UINT32(n, b, i) WRITE_LE_UINT32(b + i, n)
+
+void md5_starts(md5_context *ctx) {
+ ctx->total[0] = 0;
+ ctx->total[1] = 0;
+
+ ctx->state[0] = 0x67452301;
+ ctx->state[1] = 0xEFCDAB89;
+ ctx->state[2] = 0x98BADCFE;
+ ctx->state[3] = 0x10325476;
+}
+
+static void md5_process(md5_context *ctx, const uint8 data[64]) {
+ uint32 X[16], A, B, C, D;
+
+ GET_UINT32(X[0], data, 0);
+ GET_UINT32(X[1], data, 4);
+ GET_UINT32(X[2], data, 8);
+ GET_UINT32(X[3], data, 12);
+ GET_UINT32(X[4], data, 16);
+ GET_UINT32(X[5], data, 20);
+ GET_UINT32(X[6], data, 24);
+ GET_UINT32(X[7], data, 28);
+ GET_UINT32(X[8], data, 32);
+ GET_UINT32(X[9], data, 36);
+ GET_UINT32(X[10], data, 40);
+ GET_UINT32(X[11], data, 44);
+ GET_UINT32(X[12], data, 48);
+ GET_UINT32(X[13], data, 52);
+ GET_UINT32(X[14], data, 56);
+ GET_UINT32(X[15], data, 60);
+
+#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
+
+#define P(a, b, c, d, k, s, t) \
+{ \
+ a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
+}
+
+ A = ctx->state[0];
+ B = ctx->state[1];
+ C = ctx->state[2];
+ D = ctx->state[3];
+
+#define F(x, y, z) (z ^ (x & (y ^ z)))
+
+ P(A, B, C, D, 0, 7, 0xD76AA478);
+ P(D, A, B, C, 1, 12, 0xE8C7B756);
+ P(C, D, A, B, 2, 17, 0x242070DB);
+ P(B, C, D, A, 3, 22, 0xC1BDCEEE);
+ P(A, B, C, D, 4, 7, 0xF57C0FAF);
+ P(D, A, B, C, 5, 12, 0x4787C62A);
+ P(C, D, A, B, 6, 17, 0xA8304613);
+ P(B, C, D, A, 7, 22, 0xFD469501);
+ P(A, B, C, D, 8, 7, 0x698098D8);
+ P(D, A, B, C, 9, 12, 0x8B44F7AF);
+ P(C, D, A, B, 10, 17, 0xFFFF5BB1);
+ P(B, C, D, A, 11, 22, 0x895CD7BE);
+ P(A, B, C, D, 12, 7, 0x6B901122);
+ P(D, A, B, C, 13, 12, 0xFD987193);
+ P(C, D, A, B, 14, 17, 0xA679438E);
+ P(B, C, D, A, 15, 22, 0x49B40821);
+
+#undef F
+
+#define F(x, y, z) (y ^ (z & (x ^ y)))
+
+ P(A, B, C, D, 1, 5, 0xF61E2562);
+ P(D, A, B, C, 6, 9, 0xC040B340);
+ P(C, D, A, B, 11, 14, 0x265E5A51);
+ P(B, C, D, A, 0, 20, 0xE9B6C7AA);
+ P(A, B, C, D, 5, 5, 0xD62F105D);
+ P(D, A, B, C, 10, 9, 0x02441453);
+ P(C, D, A, B, 15, 14, 0xD8A1E681);
+ P(B, C, D, A, 4, 20, 0xE7D3FBC8);
+ P(A, B, C, D, 9, 5, 0x21E1CDE6);
+ P(D, A, B, C, 14, 9, 0xC33707D6);
+ P(C, D, A, B, 3, 14, 0xF4D50D87);
+ P(B, C, D, A, 8, 20, 0x455A14ED);
+ P(A, B, C, D, 13, 5, 0xA9E3E905);
+ P(D, A, B, C, 2, 9, 0xFCEFA3F8);
+ P(C, D, A, B, 7, 14, 0x676F02D9);
+ P(B, C, D, A, 12, 20, 0x8D2A4C8A);
+
+#undef F
+
+#define F(x, y, z) (x ^ y ^ z)
+
+ P(A, B, C, D, 5, 4, 0xFFFA3942);
+ P(D, A, B, C, 8, 11, 0x8771F681);
+ P(C, D, A, B, 11, 16, 0x6D9D6122);
+ P(B, C, D, A, 14, 23, 0xFDE5380C);
+ P(A, B, C, D, 1, 4, 0xA4BEEA44);
+ P(D, A, B, C, 4, 11, 0x4BDECFA9);
+ P(C, D, A, B, 7, 16, 0xF6BB4B60);
+ P(B, C, D, A, 10, 23, 0xBEBFBC70);
+ P(A, B, C, D, 13, 4, 0x289B7EC6);
+ P(D, A, B, C, 0, 11, 0xEAA127FA);
+ P(C, D, A, B, 3, 16, 0xD4EF3085);
+ P(B, C, D, A, 6, 23, 0x04881D05);
+ P(A, B, C, D, 9, 4, 0xD9D4D039);
+ P(D, A, B, C, 12, 11, 0xE6DB99E5);
+ P(C, D, A, B, 15, 16, 0x1FA27CF8);
+ P(B, C, D, A, 2, 23, 0xC4AC5665);
+
+#undef F
+
+#define F(x, y, z) (y ^ (x | ~z))
+
+ P(A, B, C, D, 0, 6, 0xF4292244);
+ P(D, A, B, C, 7, 10, 0x432AFF97);
+ P(C, D, A, B, 14, 15, 0xAB9423A7);
+ P(B, C, D, A, 5, 21, 0xFC93A039);
+ P(A, B, C, D, 12, 6, 0x655B59C3);
+ P(D, A, B, C, 3, 10, 0x8F0CCC92);
+ P(C, D, A, B, 10, 15, 0xFFEFF47D);
+ P(B, C, D, A, 1, 21, 0x85845DD1);
+ P(A, B, C, D, 8, 6, 0x6FA87E4F);
+ P(D, A, B, C, 15, 10, 0xFE2CE6E0);
+ P(C, D, A, B, 6, 15, 0xA3014314);
+ P(B, C, D, A, 13, 21, 0x4E0811A1);
+ P(A, B, C, D, 4, 6, 0xF7537E82);
+ P(D, A, B, C, 11, 10, 0xBD3AF235);
+ P(C, D, A, B, 2, 15, 0x2AD7D2BB);
+ P(B, C, D, A, 9, 21, 0xEB86D391);
+
+#undef F
+
+ ctx->state[0] += A;
+ ctx->state[1] += B;
+ ctx->state[2] += C;
+ ctx->state[3] += D;
+}
+
+void md5_update(md5_context *ctx, const uint8 *input, uint32 length) {
+ uint32 left, fill;
+
+ if (!length)
+ return;
+
+ left = ctx->total[0] & 0x3F;
+ fill = 64 - left;
+
+ ctx->total[0] += length;
+ ctx->total[0] &= 0xFFFFFFFF;
+
+ if (ctx->total[0] < length)
+ ctx->total[1]++;
+
+ if (left && length >= fill) {
+ memcpy((void *)(ctx->buffer + left), (const void *)input, fill);
+ md5_process(ctx, ctx->buffer);
+ length -= fill;
+ input += fill;
+ left = 0;
+ }
+
+ while (length >= 64) {
+ md5_process(ctx, input);
+ length -= 64;
+ input += 64;
+ }
+
+ if (length) {
+ memcpy((void *)(ctx->buffer + left), (const void *)input, length);
+ }
+}
+
+static const uint8 md5_padding[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+void md5_finish(md5_context *ctx, uint8 digest[16]) {
+ uint32 last, padn;
+ uint32 high, low;
+ uint8 msglen[8];
+
+ high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
+ low = (ctx->total[0] << 3);
+
+ PUT_UINT32(low, msglen, 0);
+ PUT_UINT32(high, msglen, 4);
+
+ last = ctx->total[0] & 0x3F;
+ padn = (last < 56) ? (56 - last) : (120 - last);
+
+ md5_update(ctx, md5_padding, padn);
+ md5_update(ctx, msglen, 8);
+
+ PUT_UINT32(ctx->state[0], digest, 0);
+ PUT_UINT32(ctx->state[1], digest, 4);
+ PUT_UINT32(ctx->state[2], digest, 8);
+ PUT_UINT32(ctx->state[3], digest, 12);
+}
+
+bool md5_file(const char *name, uint8 digest[16], uint32 length) {
+ FILE *f;
+
+ f = fopen(name, "rb");
+ if (f == NULL) {
+ printf("md5_file couldn't open '%s'", name);
+ return false;
+ }
+
+ md5_context ctx;
+ uint32 i;
+ unsigned char buf[1000];
+ bool restricted = (length != 0);
+ int readlen;
+
+ if (!restricted || sizeof(buf) <= length)
+ readlen = sizeof(buf);
+ else
+ readlen = length;
+
+ md5_starts(&ctx);
+
+
+ while ((i = (uint32)fread(buf, 1, readlen, f)) > 0) {
+ md5_update(&ctx, buf, i);
+
+ length -= i;
+ if (restricted && length == 0)
+ break;
+
+ if (restricted && sizeof(buf) > length)
+ readlen = length;
+ }
+
+ md5_finish(&ctx, digest);
+ fclose(f);
+ return true;
+}
+
+}
Copied: tools/branches/gsoc2009-gui/common/md5.h (from rev 46357, tools/branches/gsoc2009-gui/utils/md5.h)
===================================================================
--- tools/branches/gsoc2009-gui/common/md5.h (rev 0)
+++ tools/branches/gsoc2009-gui/common/md5.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -0,0 +1,44 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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_MD5_H
+#define COMMON_MD5_H
+
+#include "../util.h"
+
+namespace Common {
+
+typedef struct {
+ uint32 total[2];
+ uint32 state[4];
+ uint8 buffer[64];
+} md5_context;
+
+void md5_starts(md5_context *ctx);
+void md5_update(md5_context *ctx, const uint8 *input, uint32 length);
+void md5_finish(md5_context *ctx, uint8 digest[16]);
+
+bool md5_file(const char *name, uint8 digest[16], uint32 length = 0);
+
+} // End of namespace Common
+
+#endif
Copied: tools/branches/gsoc2009-gui/common/pack-end.h (from rev 46357, tools/branches/gsoc2009-gui/utils/pack-end.h)
===================================================================
--- tools/branches/gsoc2009-gui/common/pack-end.h (rev 0)
+++ tools/branches/gsoc2009-gui/common/pack-end.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -0,0 +1,25 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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$
+ *
+ */
+
+#if defined(SCUMMVM_USE_PRAGMA_PACK)
+ #pragma pack()
+#endif
Copied: tools/branches/gsoc2009-gui/common/pack-start.h (from rev 46357, tools/branches/gsoc2009-gui/utils/pack-start.h)
===================================================================
--- tools/branches/gsoc2009-gui/common/pack-start.h (rev 0)
+++ tools/branches/gsoc2009-gui/common/pack-start.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -0,0 +1,25 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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$
+ *
+ */
+
+#if defined(SCUMMVM_USE_PRAGMA_PACK)
+ #pragma pack(1)
+#endif
Modified: tools/branches/gsoc2009-gui/compress.h
===================================================================
--- tools/branches/gsoc2009-gui/compress.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/compress.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -94,7 +94,10 @@
void parseAudioArguments();
-protected:
+public:
+ // FIXME: These vars should not be public, but the ToolGUI currently
+ // accesses them directly. We should fix this.
+
/** Formats supported by this tool. */
AudioFormat _supportedFormats;
Modified: tools/branches/gsoc2009-gui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_saga.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/compress_saga.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -24,10 +24,10 @@
#include "compress.h"
#include "compress_saga.h"
-#include "utils/md5.h"
+#include "common/md5.h"
+#include "common/file.h"
#include "utils/util.h"
#include "utils/audiostream.h"
-#include "utils/file.h"
#include "utils/voc.h"
#include "utils/wave.h"
#include "utils/adpcm.h"
Modified: tools/branches/gsoc2009-gui/degob.cpp
===================================================================
--- tools/branches/gsoc2009-gui/degob.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/degob.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -21,7 +21,7 @@
*/
#include "degob_script.h"
-#include "utils/file.h"
+#include "common/file.h"
static void printHelp(const char *bin);
static int getVersion(const char *verStr);
Modified: tools/branches/gsoc2009-gui/dekyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/dekyra.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/dekyra.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -22,7 +22,7 @@
*/
#include "dekyra.h"
-#include "utils/file.h"
+#include "common/file.h"
#include <stdio.h>
Modified: tools/branches/gsoc2009-gui/desword2.cpp
===================================================================
--- tools/branches/gsoc2009-gui/desword2.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/desword2.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -21,7 +21,7 @@
*/
#include "util.h"
-#include "utils/file.h"
+#include "common/file.h"
enum {
GAME_OBJECT = 3,
Modified: tools/branches/gsoc2009-gui/extract_mm_nes.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_nes.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/extract_mm_nes.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1064,7 +1064,7 @@
{ -1, NULL }
};
-#include "utils/pack-start.h" /* START STRUCT PACKING */
+#include "common/pack-start.h" /* START STRUCT PACKING */
struct t_lflindex {
uint8 room_lfl[55];
@@ -1077,7 +1077,7 @@
uint16 sound_addr[100];
} GCC_PACK mm_lfl_index;
-#include "utils/pack-end.h" /* END STRUCT PACKING */
+#include "common/pack-end.h" /* END STRUCT PACKING */
#else /* !MAKE_LFLS */
void ExtractMMNES::dump_resource (File &input, const char *fn_template, int num, const struct t_resource *res, res_type type) {
Modified: tools/branches/gsoc2009-gui/gui/configuration.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/configuration.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/gui/configuration.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -27,6 +27,7 @@
#include <wx/filename.h>
#include "../util.h"
+#include "../compress.h" // for AudioFormat
class ToolGUI;
Modified: tools/branches/gsoc2009-gui/gui/gui_tools.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/gui_tools.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/gui/gui_tools.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -122,7 +122,9 @@
}
bool ToolGUI::supportsAudioFormat(AudioFormat format) const {
- return (_backend->_supportedFormats & format) == format;
+ // FIXME: This is a HACK!
+ CompressionTool *compression = dynamic_cast<CompressionTool *>(_backend);
+ return (compression->_supportedFormats & format) == format;
}
bool ToolGUI::supportsProgressBar() const {
Modified: tools/branches/gsoc2009-gui/kyra_pak.h
===================================================================
--- tools/branches/gsoc2009-gui/kyra_pak.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/kyra_pak.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,5 +1,5 @@
-/* Scumm Tools
- * Copyright (C) 2007 The ScummVM project
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Modified: tools/branches/gsoc2009-gui/tool.cpp
===================================================================
--- tools/branches/gsoc2009-gui/tool.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/tool.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -25,7 +25,7 @@
#include <sstream>
#include "util.h"
-#include "utils/file.h"
+#include "common/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-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/tool.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -28,7 +28,7 @@
#include <string>
#include "util.h"
-#include "utils/file.h"
+#include "common/file.h"
/**
* Different types of tools, used to differentiate them when
Modified: tools/branches/gsoc2009-gui/tools.h
===================================================================
--- tools/branches/gsoc2009-gui/tools.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/tools.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,4 +1,4 @@
-/* tools - Interface for accessing all the tools in a conveinient fashion
+/* tools - Interface for accessing all the tools in a convenient fashion
* Copyright (C) 2009 The ScummVM project
*
* This program is free software; you can redistribute it and/or
Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/util.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,5 +1,5 @@
-/* Scumm Tools
- * Copyright (C) 2002-2006 The ScummVM project
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Modified: tools/branches/gsoc2009-gui/utils/adpcm.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/adpcm.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/adpcm.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -24,7 +24,7 @@
#define SOUND_ADPCM_H
#include "audiostream.h"
-#include "file.h"
+#include "common/file.h"
namespace Audio {
Deleted: tools/branches/gsoc2009-gui/utils/file.cpp
===================================================================
--- tools/branches/gsoc2009-gui/utils/file.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/file.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,516 +0,0 @@
-/* Scumm Tools
- * 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
- * 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 "file.h"
-#include <stdarg.h>
-
-// 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;
- _xormode = 0;
-
- open(filepath, mode);
-}
-
-File::File(const Filename &filepath, const char *mode) {
- _file = NULL;
- _mode = FILEMODE_READ;
- _xormode = 0;
-
- 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;
- _xormode = 0;
-
- 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;
-}
-
-int16 File::readSint16BE() {
- int16 ret = 0;
- ret |= int16(readByte() << 8ul);
- ret |= int16(readByte());
- return ret;
-}
-
-int16 File::readSint16LE() {
- int16 ret = 0;
- ret |= int16(readByte());
- ret |= int16(readByte() << 8ul);
- return ret;
-}
-
-int32 File::readSint32BE() {
- int32 ret = 0;
- ret |= int32(readByte() << 24);
- ret |= int32(readByte() << 16);
- ret |= int32(readByte() << 8);
- ret |= int32(readByte());
- return ret;
-}
-
-int32 File::readSint32LE() {
- int32 ret = 0;
- ret |= int32(readByte());
- ret |= int32(readByte() << 8);
- ret |= int32(readByte() << 16);
- ret |= int32(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);
-}
-
-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
- }
-
- 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::scanString(char *result) {
- if (!_file)
- throw FileException("File is not open");
- if ((_mode & FILEMODE_READ) == 0)
- throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
-
- fscanf(_file, "%s", result);
-}
-
-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;
-}
-
Deleted: tools/branches/gsoc2009-gui/utils/file.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/file.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/file.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,398 +0,0 @@
-/* Scumm Tools
- * 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 COMMON_FILE_H
-#define COMMON_FILE_H
-
-#include "util.h"
-
-#include <stdio.h>
-#include <string>
-
-/**
- * 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) {}
-};
-
-/**
- * A file path, can be queried for different parts
- * and the parts can be modified seperately
- */
-class Filename {
-public:
- 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; }
-
- /**
- * 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);
-
- /**
- * Reads a string, using until NULL or EOF or CR/LF
- * Throws FileException if file is not open / if read failed.
- */
- void scanString(char *result);
-
- /**
- * 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;
-
- // 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;
-};
-
-#endif
Deleted: tools/branches/gsoc2009-gui/utils/md5.cpp
===================================================================
--- tools/branches/gsoc2009-gui/utils/md5.cpp 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/md5.cpp 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,265 +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$
- *
- */
-
-#include "md5.h"
-
-namespace Common {
-
-#define GET_UINT32(n, b, i) (n) = READ_LE_UINT32(b + i)
-#define PUT_UINT32(n, b, i) WRITE_LE_UINT32(b + i, n)
-
-void md5_starts(md5_context *ctx) {
- ctx->total[0] = 0;
- ctx->total[1] = 0;
-
- ctx->state[0] = 0x67452301;
- ctx->state[1] = 0xEFCDAB89;
- ctx->state[2] = 0x98BADCFE;
- ctx->state[3] = 0x10325476;
-}
-
-static void md5_process(md5_context *ctx, const uint8 data[64]) {
- uint32 X[16], A, B, C, D;
-
- GET_UINT32(X[0], data, 0);
- GET_UINT32(X[1], data, 4);
- GET_UINT32(X[2], data, 8);
- GET_UINT32(X[3], data, 12);
- GET_UINT32(X[4], data, 16);
- GET_UINT32(X[5], data, 20);
- GET_UINT32(X[6], data, 24);
- GET_UINT32(X[7], data, 28);
- GET_UINT32(X[8], data, 32);
- GET_UINT32(X[9], data, 36);
- GET_UINT32(X[10], data, 40);
- GET_UINT32(X[11], data, 44);
- GET_UINT32(X[12], data, 48);
- GET_UINT32(X[13], data, 52);
- GET_UINT32(X[14], data, 56);
- GET_UINT32(X[15], data, 60);
-
-#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
-
-#define P(a, b, c, d, k, s, t) \
-{ \
- a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
-}
-
- A = ctx->state[0];
- B = ctx->state[1];
- C = ctx->state[2];
- D = ctx->state[3];
-
-#define F(x, y, z) (z ^ (x & (y ^ z)))
-
- P(A, B, C, D, 0, 7, 0xD76AA478);
- P(D, A, B, C, 1, 12, 0xE8C7B756);
- P(C, D, A, B, 2, 17, 0x242070DB);
- P(B, C, D, A, 3, 22, 0xC1BDCEEE);
- P(A, B, C, D, 4, 7, 0xF57C0FAF);
- P(D, A, B, C, 5, 12, 0x4787C62A);
- P(C, D, A, B, 6, 17, 0xA8304613);
- P(B, C, D, A, 7, 22, 0xFD469501);
- P(A, B, C, D, 8, 7, 0x698098D8);
- P(D, A, B, C, 9, 12, 0x8B44F7AF);
- P(C, D, A, B, 10, 17, 0xFFFF5BB1);
- P(B, C, D, A, 11, 22, 0x895CD7BE);
- P(A, B, C, D, 12, 7, 0x6B901122);
- P(D, A, B, C, 13, 12, 0xFD987193);
- P(C, D, A, B, 14, 17, 0xA679438E);
- P(B, C, D, A, 15, 22, 0x49B40821);
-
-#undef F
-
-#define F(x, y, z) (y ^ (z & (x ^ y)))
-
- P(A, B, C, D, 1, 5, 0xF61E2562);
- P(D, A, B, C, 6, 9, 0xC040B340);
- P(C, D, A, B, 11, 14, 0x265E5A51);
- P(B, C, D, A, 0, 20, 0xE9B6C7AA);
- P(A, B, C, D, 5, 5, 0xD62F105D);
- P(D, A, B, C, 10, 9, 0x02441453);
- P(C, D, A, B, 15, 14, 0xD8A1E681);
- P(B, C, D, A, 4, 20, 0xE7D3FBC8);
- P(A, B, C, D, 9, 5, 0x21E1CDE6);
- P(D, A, B, C, 14, 9, 0xC33707D6);
- P(C, D, A, B, 3, 14, 0xF4D50D87);
- P(B, C, D, A, 8, 20, 0x455A14ED);
- P(A, B, C, D, 13, 5, 0xA9E3E905);
- P(D, A, B, C, 2, 9, 0xFCEFA3F8);
- P(C, D, A, B, 7, 14, 0x676F02D9);
- P(B, C, D, A, 12, 20, 0x8D2A4C8A);
-
-#undef F
-
-#define F(x, y, z) (x ^ y ^ z)
-
- P(A, B, C, D, 5, 4, 0xFFFA3942);
- P(D, A, B, C, 8, 11, 0x8771F681);
- P(C, D, A, B, 11, 16, 0x6D9D6122);
- P(B, C, D, A, 14, 23, 0xFDE5380C);
- P(A, B, C, D, 1, 4, 0xA4BEEA44);
- P(D, A, B, C, 4, 11, 0x4BDECFA9);
- P(C, D, A, B, 7, 16, 0xF6BB4B60);
- P(B, C, D, A, 10, 23, 0xBEBFBC70);
- P(A, B, C, D, 13, 4, 0x289B7EC6);
- P(D, A, B, C, 0, 11, 0xEAA127FA);
- P(C, D, A, B, 3, 16, 0xD4EF3085);
- P(B, C, D, A, 6, 23, 0x04881D05);
- P(A, B, C, D, 9, 4, 0xD9D4D039);
- P(D, A, B, C, 12, 11, 0xE6DB99E5);
- P(C, D, A, B, 15, 16, 0x1FA27CF8);
- P(B, C, D, A, 2, 23, 0xC4AC5665);
-
-#undef F
-
-#define F(x, y, z) (y ^ (x | ~z))
-
- P(A, B, C, D, 0, 6, 0xF4292244);
- P(D, A, B, C, 7, 10, 0x432AFF97);
- P(C, D, A, B, 14, 15, 0xAB9423A7);
- P(B, C, D, A, 5, 21, 0xFC93A039);
- P(A, B, C, D, 12, 6, 0x655B59C3);
- P(D, A, B, C, 3, 10, 0x8F0CCC92);
- P(C, D, A, B, 10, 15, 0xFFEFF47D);
- P(B, C, D, A, 1, 21, 0x85845DD1);
- P(A, B, C, D, 8, 6, 0x6FA87E4F);
- P(D, A, B, C, 15, 10, 0xFE2CE6E0);
- P(C, D, A, B, 6, 15, 0xA3014314);
- P(B, C, D, A, 13, 21, 0x4E0811A1);
- P(A, B, C, D, 4, 6, 0xF7537E82);
- P(D, A, B, C, 11, 10, 0xBD3AF235);
- P(C, D, A, B, 2, 15, 0x2AD7D2BB);
- P(B, C, D, A, 9, 21, 0xEB86D391);
-
-#undef F
-
- ctx->state[0] += A;
- ctx->state[1] += B;
- ctx->state[2] += C;
- ctx->state[3] += D;
-}
-
-void md5_update(md5_context *ctx, const uint8 *input, uint32 length) {
- uint32 left, fill;
-
- if (!length)
- return;
-
- left = ctx->total[0] & 0x3F;
- fill = 64 - left;
-
- ctx->total[0] += length;
- ctx->total[0] &= 0xFFFFFFFF;
-
- if (ctx->total[0] < length)
- ctx->total[1]++;
-
- if (left && length >= fill) {
- memcpy((void *)(ctx->buffer + left), (const void *)input, fill);
- md5_process(ctx, ctx->buffer);
- length -= fill;
- input += fill;
- left = 0;
- }
-
- while (length >= 64) {
- md5_process(ctx, input);
- length -= 64;
- input += 64;
- }
-
- if (length) {
- memcpy((void *)(ctx->buffer + left), (const void *)input, length);
- }
-}
-
-static const uint8 md5_padding[64] = {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-void md5_finish(md5_context *ctx, uint8 digest[16]) {
- uint32 last, padn;
- uint32 high, low;
- uint8 msglen[8];
-
- high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
- low = (ctx->total[0] << 3);
-
- PUT_UINT32(low, msglen, 0);
- PUT_UINT32(high, msglen, 4);
-
- last = ctx->total[0] & 0x3F;
- padn = (last < 56) ? (56 - last) : (120 - last);
-
- md5_update(ctx, md5_padding, padn);
- md5_update(ctx, msglen, 8);
-
- PUT_UINT32(ctx->state[0], digest, 0);
- PUT_UINT32(ctx->state[1], digest, 4);
- PUT_UINT32(ctx->state[2], digest, 8);
- PUT_UINT32(ctx->state[3], digest, 12);
-}
-
-bool md5_file(const char *name, uint8 digest[16], uint32 length) {
- FILE *f;
-
- f = fopen(name, "rb");
- if (f == NULL) {
- printf("md5_file couldn't open '%s'", name);
- return false;
- }
-
- md5_context ctx;
- uint32 i;
- unsigned char buf[1000];
- bool restricted = (length != 0);
- int readlen;
-
- if (!restricted || sizeof(buf) <= length)
- readlen = sizeof(buf);
- else
- readlen = length;
-
- md5_starts(&ctx);
-
-
- while ((i = (uint32)fread(buf, 1, readlen, f)) > 0) {
- md5_update(&ctx, buf, i);
-
- length -= i;
- if (restricted && length == 0)
- break;
-
- if (restricted && sizeof(buf) > length)
- readlen = length;
- }
-
- md5_finish(&ctx, digest);
- fclose(f);
- return true;
-}
-
-}
Deleted: tools/branches/gsoc2009-gui/utils/md5.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/md5.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/md5.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,44 +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_MD5_H
-#define COMMON_MD5_H
-
-#include "../util.h"
-
-namespace Common {
-
-typedef struct {
- uint32 total[2];
- uint32 state[4];
- uint8 buffer[64];
-} md5_context;
-
-void md5_starts(md5_context *ctx);
-void md5_update(md5_context *ctx, const uint8 *input, uint32 length);
-void md5_finish(md5_context *ctx, uint8 digest[16]);
-
-bool md5_file(const char *name, uint8 digest[16], uint32 length = 0);
-
-} // End of namespace Common
-
-#endif
Deleted: tools/branches/gsoc2009-gui/utils/pack-end.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/pack-end.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/pack-end.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,27 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- */
-
-#if defined(SCUMMVM_USE_PRAGMA_PACK)
- #pragma pack()
-#endif
Deleted: tools/branches/gsoc2009-gui/utils/pack-start.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/pack-start.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/pack-start.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -1,27 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- */
-
-#if defined(SCUMMVM_USE_PRAGMA_PACK)
- #pragma pack(1)
-#endif
Modified: tools/branches/gsoc2009-gui/utils/voc.h
===================================================================
--- tools/branches/gsoc2009-gui/utils/voc.h 2009-12-13 19:49:49 UTC (rev 46359)
+++ tools/branches/gsoc2009-gui/utils/voc.h 2009-12-13 20:09:16 UTC (rev 46360)
@@ -24,13 +24,13 @@
#define SOUND_VOC_H
#include "../util.h"
-#include "file.h"
+#include "common/file.h"
namespace Audio {
class AudioStream;
-#include "pack-start.h" /* START STRUCT PACKING */
+#include "common/pack-start.h" /* START STRUCT PACKING */
struct VocFileHeader {
uint8 desc[20];
@@ -46,7 +46,7 @@
uint8 pack;
} GCC_PACK;
-#include "pack-end.h" /* END STRUCT PACKING */
+#include "common/pack-end.h" /* END STRUCT PACKING */
/**
* Take a sample rate parameter as it occurs in a VOC sound header, and
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