aboutsummaryrefslogtreecommitdiff
path: root/scumm/smush
diff options
context:
space:
mode:
authorPaweł Kołodziejski2002-09-15 19:28:34 +0000
committerPaweł Kołodziejski2002-09-15 19:28:34 +0000
commitf7ff5c67fada77c23dd870f4da4ef7dae3b47e94 (patch)
tree2d2311161f22a9f9694ca1ac2a0cef6739a9d19f /scumm/smush
parent37d7a52c47e59f7c348154c88d5a2410c0e84aab (diff)
downloadscummvm-rg350-f7ff5c67fada77c23dd870f4da4ef7dae3b47e94.tar.gz
scummvm-rg350-f7ff5c67fada77c23dd870f4da4ef7dae3b47e94.tar.bz2
scummvm-rg350-f7ff5c67fada77c23dd870f4da4ef7dae3b47e94.zip
improved open function in File class
svn-id: r4945
Diffstat (limited to 'scumm/smush')
-rw-r--r--scumm/smush/chunk.cpp18
-rw-r--r--scumm/smush/chunk.h2
-rw-r--r--scumm/smush/player.cpp76
-rw-r--r--scumm/smush/player.h4
4 files changed, 28 insertions, 72 deletions
diff --git a/scumm/smush/chunk.cpp b/scumm/smush/chunk.cpp
index 1c70919c01..efc3d61953 100644
--- a/scumm/smush/chunk.cpp
+++ b/scumm/smush/chunk.cpp
@@ -34,33 +34,33 @@
*/
class FilePtr {
char * _filename;
- FILE * _ifs;
+ File _ifs;
int32 _refcount;
int32 _curPos;
public:
- FilePtr(const char * fname) : _refcount(1), _curPos(0) {
+ FilePtr(const char * fname, const char * directory) : _refcount(1), _curPos(0) {
debug(9, "FilePtr created for %s", fname);
_filename = strdup(fname);
- _ifs = fopen_nocase(fname, "rb");
- if(_ifs == NULL) error("FilePtr unable to read file \"%s\"", fname);
+ _ifs.open(fname, directory);
+ if(_ifs.isOpen() == false) error("FilePtr unable to read file %s", fname);
}
~FilePtr() {
debug(9, "FilePtr destroyed for %s", _filename);
free(_filename);
- fclose(_ifs);
+ _ifs.close();
}
int32 tell() {
return _curPos;
}
bool seek(int32 pos) {
if(pos != _curPos) {
- fseek(_ifs, pos, SEEK_SET);
+ _ifs.seek(pos, SEEK_SET);
_curPos = pos;
}
return true;
}
bool read(void * ptr, int32 size) {
- fread(ptr, size, 1, _ifs);
+ _ifs.read(ptr, size);
_curPos += size;
return true;
}
@@ -90,8 +90,8 @@ FileChunk::~FileChunk() {
if(_data) _data->decRef();
}
-FileChunk::FileChunk(const char * fname) {
- _data = new FilePtr(fname);
+FileChunk::FileChunk(const char * fname, const char * directory) {
+ _data = new FilePtr(fname, directory);
_data->read(&_type, 4);
_type = TO_BE_32(_type);
_data->read(&_size, 4);
diff --git a/scumm/smush/chunk.h b/scumm/smush/chunk.h
index 893ede35f8..b13da2d05d 100644
--- a/scumm/smush/chunk.h
+++ b/scumm/smush/chunk.h
@@ -76,7 +76,7 @@ private:
protected:
FileChunk();
public:
- FileChunk(const char * fname);
+ FileChunk(const char * fname, const char * directory);
virtual ~FileChunk();
type getType() const;
uint32 getSize() const;
diff --git a/scumm/smush/player.cpp b/scumm/smush/player.cpp
index 6e3091f5bf..b61a746e40 100644
--- a/scumm/smush/player.cpp
+++ b/scumm/smush/player.cpp
@@ -616,10 +616,10 @@ void SmushPlayer::handleAnimHeader(Chunk & b) {
}
#define NEW_FILE 1
-static StringResource * getStrings(const char * file, bool is_encoded) {
+static StringResource * getStrings(const char * file, const char * directory, bool is_encoded) {
debug(7, "trying to read text ressources from %s", file);
File theFile;
- theFile.open(file);
+ theFile.open(file, directory);
if (!theFile.isOpen())
return 0;
int32 length = theFile.size();
@@ -633,7 +633,7 @@ static StringResource * getStrings(const char * file, bool is_encoded) {
Chunk::type type = READ_BE_UINT32(filebuffer);
if(type != TYPE_ETRS) {
delete [] filebuffer;
- return getStrings(file, false);
+ return getStrings(file, directory, false);
}
char * old = filebuffer;
filebuffer = new char[length - ETRS_HEADER_LENGTH];
@@ -649,102 +649,58 @@ static StringResource * getStrings(const char * file, bool is_encoded) {
return sr;
}
-bool SmushPlayer::readString(const char * file, bool & ft) {
+bool SmushPlayer::readString(const char * file, const char * directory, bool & ft) {
const char * i = strrchr(file, '.');
if(i == NULL) error("invalid filename : %s", file);
char fname[260];
memcpy(fname, file, i - file);
strcpy(fname + (i - file), ".trs");
- if((_strings = getStrings(fname, false)) != 0) {
+ if((_strings = getStrings(fname, directory, false)) != 0) {
ft = true;
return true;
}
- i = strrchr(file, '\\');
- if(i == NULL) i = strrchr(file, '/');
- else {
- char * j = strrchr(file, '/');
- if(j > i) i = j;
- }
- if(i == NULL) error("invalid filename : %s", file);
- memcpy(fname, file, i - file + 1);
- strcpy(fname + (i - file + 1), "digtxt.trs");
- if((_strings = getStrings(fname, true)) != 0) {
+ if((_strings = getStrings("digtxt.trs", directory, true)) != 0) {
ft = false;
return true;
}
return false;
}
-static FontRenderer * loadFont(const char * file, bool original = false) {
+static FontRenderer * loadFont(const char * file, const char * directory, bool original = false) {
#ifdef DEBUG
debug(5, "loading font from \"%s\"", file);
#endif
FontRenderer * fr = new FontRenderer(original);
SmushPlayer p(fr, false, false);
- p.play(file);
+ p.play(file, directory);
return fr;
}
-bool SmushPlayer::play(const char * file) {
+bool SmushPlayer::play(const char * file, const char * directory) {
#ifdef DEBUG
debug(5, "start of animation : %s", file);
#endif
- char * i = strrchr(file, '\\');
- if(i == NULL)
- {
- i = strrchr(file, '/');
- } else {
- char * j = strrchr(i, '/');
- if(j != NULL)
- i = j;
- }
- char directory[260];
- if(i != NULL) {
- strcpy(directory, file);
- directory[i-file] = 0;
- //! @todo remove this...
- _fname = strdup(i);
- } else {
- directory[0] = 0;
- _fname = strdup(file);
- }
clean();
if(_wait) {
bool isFullthrottle;
- if(!readString(file, isFullthrottle))
+ if(!readString(file, directory, isFullthrottle))
warning("unable to read text information for \"%s\"", file);
if(_strings) {
if(isFullthrottle) {
- if(strcmp(directory, "") == 0) {
- strcpy(directory, "../data/");
- } else {
- char * i = strrchr(directory, '\\');
- char * j = strrchr(directory, '/');
- if(j > i) i = j;
- if(i == NULL) {
- strcpy(directory, "data/");
- } else {
- *i = 0;
- strcat(directory, "/data/");
- }
- }
- char file[260];
- strcpy(file, directory); strcat(file, "scummfnt.nut");
- _fr[0] = loadFont(file, true);
- strcpy(file, directory); strcat(file, "titlfnt.nut");
- _fr[2] = loadFont(file, true);
+ _fr[0] = loadFont("scummfnt.nut", directory, true);
+ _fr[2] = loadFont("titlfnt.nut", directory, true);
} else {
for(int32 i = 0; i < 4; i++) {
- char file[260];
- sprintf(file, "%s/font%d.nut",directory, i);
- _fr[i] = loadFont(file, i != 0);
+ char file_font[20];
+ sprintf((char*)&file_font, "font%d.nut", i);
+ _fr[i] = loadFont(file_font, directory, i != 0);
}
}
}
}
- FileChunk base = FileChunk(file);
+ FileChunk base = FileChunk(file, directory);
checkBlock(base, TYPE_ANIM);
diff --git a/scumm/smush/player.h b/scumm/smush/player.h
index f9decce7f0..4563261f59 100644
--- a/scumm/smush/player.h
+++ b/scumm/smush/player.h
@@ -73,12 +73,12 @@ private:
public:
SmushPlayer(Renderer *, bool wait = true, bool output_sound = true);
virtual ~SmushPlayer();
- bool play(const char *);
+ bool play(const char *, const char * directory);
void updatePalette(void);
void show(const char *);
void hide(const char *);
protected:
- bool readString(const char * file, bool &);
+ bool readString(const char * file, const char * directory, bool &);
void clean();
void checkBlock(const Chunk &, Chunk::type, uint32 = 0);
void handleAnimHeader(Chunk &);