aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/file.cpp29
-rw-r--r--common/file.h5
-rw-r--r--common/stream.h14
3 files changed, 15 insertions, 33 deletions
diff --git a/common/file.cpp b/common/file.cpp
index 4bb6e94fad..24c8907002 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -132,7 +132,6 @@ void File::setDefaultDirectory(const Common::String &directory) {
File::File() {
_handle = NULL;
_ioFailed = false;
- _encbyte = 0;
_name = 0;
}
@@ -141,7 +140,7 @@ File::~File() {
delete [] _name;
}
-bool File::open(const char *filename, const char *directory, AccessMode mode, byte encbyte) {
+bool File::open(const char *filename, const char *directory, AccessMode mode) {
if (_handle) {
debug(2, "File %s already opened", filename);
return false;
@@ -174,8 +173,6 @@ bool File::open(const char *filename, const char *directory, AccessMode mode, by
return false;
}
- _encbyte = encbyte;
-
int len = strlen(filename);
if (_name != 0)
delete [] _name;
@@ -263,19 +260,10 @@ uint32 File::read(void *ptr, uint32 len) {
_ioFailed = true;
}
- if (_encbyte != 0) {
- uint32 t_size = real_len;
- while (t_size--) {
- *ptr2++ ^= _encbyte;
- }
- }
-
return real_len;
}
uint32 File::write(const void *ptr, uint32 len) {
- byte *tmp = 0;
-
if (_handle == NULL) {
error("File is not open!");
return 0;
@@ -284,25 +272,10 @@ uint32 File::write(const void *ptr, uint32 len) {
if (len == 0)
return 0;
- if (_encbyte != 0) {
- // Maybe FIXME: while it's efficient to do the encoding here,
- // it not really nice for a write function to modify its input.
- // Maybe we should work on a copy here...
- tmp = (byte *)malloc(len);
- for (uint32 i = 0; i < len; i ++) {
- tmp[i] = ((const byte *)ptr)[i] ^ _encbyte;
- }
- ptr = tmp;
- }
-
if ((uint32)fwrite(ptr, 1, len, _handle) != len) {
clearerr(_handle);
_ioFailed = true;
}
- if (_encbyte != 0) {
- free(tmp);
- }
-
return len;
}
diff --git a/common/file.h b/common/file.h
index 42d521495f..ba8eb469e4 100644
--- a/common/file.h
+++ b/common/file.h
@@ -32,7 +32,6 @@ private:
FILE * _handle;
bool _ioFailed;
- byte _encbyte;
char *_name; // For debugging
static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
@@ -50,7 +49,7 @@ public:
File();
virtual ~File();
bool open(const char *filename, const Common::String &directory) { return open(filename, directory.c_str()); }
- bool open(const char *filename, const char *directory = NULL, AccessMode mode = kFileReadMode, byte encbyte = 0);
+ bool open(const char *filename, const char *directory = NULL, AccessMode mode = kFileReadMode);
void close();
bool isOpen() const;
bool ioFailed() const;
@@ -62,8 +61,6 @@ public:
void seek(int32 offs, int whence = SEEK_SET);
uint32 read(void *ptr, uint32 size);
uint32 write(const void *ptr, uint32 size);
-
- void setEnc(byte value) { _encbyte = value; }
};
#endif
diff --git a/common/stream.h b/common/stream.h
index bd20bdbc20..e5fdd96b09 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -80,16 +80,21 @@ public:
* XORReadStream is a wrapper around an arbitrary other ReadStream,
* which 'decrypts' the data being read by XORing all data bytes with the given
* encryption 'key'.
+ *
+ * Currently, this is not used anywhere, it's just a demo of how one can chain
+ * streams if necessary.
*/
class XORReadStream : public ReadStream {
private:
byte _encbyte;
ReadStream *_realStream;
public:
- XORReadStream(ReadStream *in, byte enc = 0) : _realStream(in), _encbyte(enc) {}
+ XORReadStream(ReadStream *in = 0, byte enc = 0) : _realStream(in), _encbyte(enc) {}
+ void setStream(ReadStream *in) { _realStream = in; }
void setEnc(byte value) { _encbyte = value; }
uint32 read(void *ptr, uint32 size) {
+ assert(_realStream);
uint32 len = _realStream->read(ptr, size);
if (_encbyte) {
byte *p = (byte *)ptr;
@@ -101,6 +106,13 @@ public:
}
};
+/**
+ * Simple memory based 'stream', which implements the ReadStream interface for
+ * a plain memory block.
+ *
+ * Currently not used anywhere, just a proof of concept, and meant to give an
+ * idea of what streams can be used for.
+ */
class MemoryReadStream : public ReadStream {
private:
const byte *_ptr;