[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.58,1.59 file.h,1.22,1.23 stream.h,1.1,1.2
Max Horn
fingolfin at users.sourceforge.net
Sat Apr 17 09:30:07 CEST 2004
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.57,1.58
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm resource.cpp,1.200,1.201 script_v5.cpp,1.236,1.237 scumm.h,1.395,1.396 sound.cpp,1.331,1.332
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31340/common
Modified Files:
file.cpp file.h stream.h
Log Message:
Removed XOR encoding stuff from File class; instead the new Scumm::XORFile class provides this functionality now
Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- file.cpp 17 Apr 2004 12:42:40 -0000 1.58
+++ file.cpp 17 Apr 2004 16:29:02 -0000 1.59
@@ -132,7 +132,6 @@
File::File() {
_handle = NULL;
_ioFailed = false;
- _encbyte = 0;
_name = 0;
}
@@ -141,7 +140,7 @@
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 @@
return false;
}
- _encbyte = encbyte;
-
int len = strlen(filename);
if (_name != 0)
delete [] _name;
@@ -263,19 +260,10 @@
_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 @@
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;
}
Index: file.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- file.h 17 Apr 2004 09:57:15 -0000 1.22
+++ file.h 17 Apr 2004 16:29:02 -0000 1.23
@@ -32,7 +32,6 @@
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 @@
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 @@
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
Index: stream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/stream.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- stream.h 17 Apr 2004 09:57:15 -0000 1.1
+++ stream.h 17 Apr 2004 16:29:02 -0000 1.2
@@ -80,16 +80,21 @@
* 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 @@
}
};
+/**
+ * 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;
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.57,1.58
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm resource.cpp,1.200,1.201 script_v5.cpp,1.236,1.237 scumm.h,1.395,1.396 sound.cpp,1.331,1.332
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list