aboutsummaryrefslogtreecommitdiff
path: root/scumm
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
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')
-rw-r--r--scumm/bundle.cpp8
-rw-r--r--scumm/bundle.h4
-rw-r--r--scumm/resource.cpp33
-rw-r--r--scumm/script_v2.cpp3
-rw-r--r--scumm/scummvm.cpp4
-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
-rw-r--r--scumm/sound.cpp27
10 files changed, 54 insertions, 125 deletions
diff --git a/scumm/bundle.cpp b/scumm/bundle.cpp
index 5edd66e98a..80ca8eb487 100644
--- a/scumm/bundle.cpp
+++ b/scumm/bundle.cpp
@@ -31,13 +31,13 @@ Bundle::Bundle() {
Bundle::~Bundle() {
}
-bool Bundle::openVoiceFile(char *filename) {
+bool Bundle::openVoiceFile(const char *filename, const char *directory) {
int32 tag, offset;
if (_voiceFile.isOpen() == true)
return true;
- if (_voiceFile.open(filename) == false) {
+ if (_voiceFile.open(filename, directory) == false) {
warning("Bundle: Can't open voice bundle file: %s", filename);
return false;
}
@@ -71,13 +71,13 @@ bool Bundle::openVoiceFile(char *filename) {
return true;
}
-bool Bundle::openMusicFile(char *filename) {
+bool Bundle::openMusicFile(const char *filename, const char *directory) {
int32 tag, offset;
if (_musicFile.isOpen() == true)
return true;
- if (_musicFile.open(filename) == false) {
+ if (_musicFile.open(filename, directory) == false) {
warning("Bundle: Can't open music bundle file: %s", filename);
return false;
}
diff --git a/scumm/bundle.h b/scumm/bundle.h
index ac1656678d..7d2e1744e2 100644
--- a/scumm/bundle.h
+++ b/scumm/bundle.h
@@ -56,8 +56,8 @@ public:
Bundle();
~Bundle();
- bool openVoiceFile(char *filename);
- bool openMusicFile(char *filename);
+ bool openVoiceFile(const char *filename, const char *directory);
+ bool openMusicFile(const char *filename, const char *directory);
int32 decompressVoiceSampleByName(char *name, byte *comp_final);
int32 decompressVoiceSampleByIndex(int32 index, byte *comp_final);
int32 decompressMusicSampleByName(char *name, int32 number, byte *comp_final);
diff --git a/scumm/resource.cpp b/scumm/resource.cpp
index 1792e90121..cfbf4e7283 100644
--- a/scumm/resource.cpp
+++ b/scumm/resource.cpp
@@ -73,16 +73,16 @@ void Scumm::openRoom(int room)
if (!(_features & GF_SMALL_HEADER)) {
if (_features & GF_AFTER_V7)
- sprintf(buf, "%s%s.la%d", _gameDataPath, _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
+ sprintf(buf, "%s.la%d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
else if (_features & GF_HUMONGOUS)
- sprintf(buf, "%s%s.he%.1d", _gameDataPath, _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
+ sprintf(buf, "%s.he%.1d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
else
- sprintf(buf, "%s%s.%.3d", _gameDataPath, _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
+ sprintf(buf, "%s.%.3d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
_encbyte = (_features & GF_USE_KEY) ? 0x69 : 0;
} else if (!(_features & GF_SMALL_NAMES)) {
if (room == 0 || room >= 900) {
- sprintf(buf, "%s%.3d.lfl", _gameDataPath, room);
+ sprintf(buf, "%.3d.lfl", room);
_encbyte = 0;
if (openResourceFile(buf)) {
return;
@@ -90,11 +90,11 @@ void Scumm::openRoom(int room)
askForDisk(buf);
} else {
- sprintf(buf, "%sdisk%.2d.lec", _gameDataPath, res.roomno[rtRoom][room]);
+ sprintf(buf, "disk%.2d.lec", res.roomno[rtRoom][room]);
_encbyte = 0x69;
}
} else {
- sprintf(buf, "%s%.2d.lfl", _gameDataPath, room);
+ sprintf(buf, "%.2d.lfl", room);
if (_features & GF_OLD_BUNDLE)
_encbyte = 0xFF;
else
@@ -186,26 +186,7 @@ bool Scumm::openResourceFile(const char *filename)
}
strcpy(buf, filename);
- _fileHandle.open(buf, 1, _encbyte);
- if (_fileHandle.isOpen() == false) {
- char *e = strrchr(buf, '/');
- if (!e)
- e = buf;
- do
- *e = tolower(*e);
- while (*e++);
- _fileHandle.open(buf, 1, _encbyte);
- }
-
- if (_fileHandle.isOpen() == false) {
- char *e = strrchr(buf, '/');
- if (!e)
- e = buf;
- do
- *e = toupper(*e);
- while (*e++);
- _fileHandle.open(buf, 1, _encbyte);
- }
+ _fileHandle.open(buf, getGameDataPath(), 1, _encbyte);
return _fileHandle.isOpen();
}
diff --git a/scumm/script_v2.cpp b/scumm/script_v2.cpp
index 19315bce23..fc138ee274 100644
--- a/scumm/script_v2.cpp
+++ b/scumm/script_v2.cpp
@@ -2719,9 +2719,8 @@ void Scumm::o6_miscOps()
SmushPlayer sp(&sr);
char filename[512];
strcpy(filename, _gameDataPath);
- strcat(filename, "video/");
strcat(filename, (char*)getStringAddressVar(VAR_VIDEONAME));
- sp.play(filename);
+ sp.play(filename, getGameDataPath());
}
break;
case 7:
diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp
index d32a76c9cb..df7e268e56 100644
--- a/scumm/scummvm.cpp
+++ b/scumm/scummvm.cpp
@@ -871,9 +871,9 @@ void Scumm::dumpResource(char *tag, int idx, byte *ptr)
sprintf(buf, "dumps/%s%d.dmp", tag, idx);
#endif
- out.open(buf, 1);
+ out.open(buf, "", 1);
if (out.isOpen() == false) {
- out.open(buf, 2);
+ out.open(buf, "", 2);
if (out.isOpen() == false)
return;
out.write(ptr, size);
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 &);
diff --git a/scumm/sound.cpp b/scumm/sound.cpp
index 12032485ed..d9ff62ec12 100644
--- a/scumm/sound.cpp
+++ b/scumm/sound.cpp
@@ -751,10 +751,9 @@ File * Sound::openSfxFile() {
#ifdef COMPRESSED_SOUND_FILE
offset_table = NULL;
- sprintf(buf, "%s%s.so3", _scumm->getGameDataPath(), _scumm->_exe_name);
- if (!file->open(buf)) {
- sprintf(buf, "%smonster.so3", _scumm->getGameDataPath());
- file->open(buf);
+ sprintf(buf, "%s.so3", _scumm->_exe_name);
+ if (!file->open(buf, _scumm->getGameDataPath())) {
+ file->open("monster.so3", _scumm->getGameDataPath());
}
if (file->isOpen() == true) {
/* Now load the 'offset' index in memory to be able to find the MP3 data
@@ -791,10 +790,9 @@ File * Sound::openSfxFile() {
return file;
}
#endif
- sprintf(buf, "%s%s.sou", _scumm->getGameDataPath(), _scumm->_exe_name);
- if (!file->open(buf)) {
- sprintf(buf, "%smonster.sou", _scumm->getGameDataPath());
- file->open(buf);
+ sprintf(buf, "%s.sou", _scumm->_exe_name);
+ if (!file->open(buf, _scumm->getGameDataPath())) {
+ file->open("monster.sou", _scumm->getGameDataPath());
}
return file;
}
@@ -837,11 +835,8 @@ static void music_handler (Scumm * scumm) {
#define OUTPUT_SIZE 66150 // ((22050 * 2 * 2) / 4) * 3
void Sound::playBundleMusic(int32 song) {
- char buf[256];
-
if (_numberBundleMusic == -1) {
- sprintf(buf, "%s%smusic.bun", _scumm->getGameDataPath(), _scumm->_exe_name);
- if (_scumm->_bundle->openMusicFile((char*)&buf) == false) {
+ if (_scumm->_bundle->openMusicFile("digmusic.bun", _scumm->getGameDataPath()) == false) {
return;
}
@@ -958,11 +953,9 @@ void Sound::bundleMusicHandler(Scumm * scumm) {
}
void Sound::playBundleSound(char *sound) {
- char buf[256];
byte * ptr;
- sprintf(buf, "%s%svoice.bun", _scumm->getGameDataPath(), _scumm->_exe_name);
- if (_scumm->_bundle->openVoiceFile((char*)&buf) == false) {
+ if (_scumm->_bundle->openVoiceFile("digvoice.bun", _scumm->getGameDataPath()) == false) {
return;
}
@@ -1093,8 +1086,8 @@ int Sound::getCachedTrack(int track) {
_current_cache %= CACHE_TRACKS;
// Not found, see if it exists
- sprintf(track_name, "%strack%d.mp3", _scumm->getGameDataPath(), track);
- file->open(track_name);
+ sprintf(track_name, "track%d.mp3", track);
+ file->open(track_name, _scumm->getGameDataPath());
_cached_tracks[current_index] = track;
/* First, close the previous file */