diff options
author | Paweł Kołodziejski | 2002-09-15 19:28:34 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2002-09-15 19:28:34 +0000 |
commit | f7ff5c67fada77c23dd870f4da4ef7dae3b47e94 (patch) | |
tree | 2d2311161f22a9f9694ca1ac2a0cef6739a9d19f /common/file.cpp | |
parent | 37d7a52c47e59f7c348154c88d5a2410c0e84aab (diff) | |
download | scummvm-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 'common/file.cpp')
-rw-r--r-- | common/file.cpp | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/common/file.cpp b/common/file.cpp index f7dfa2ae8f..bce682a9be 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -22,38 +22,59 @@ #include "file.h" #include "engine.h" // For debug/warning/error -FILE *fopen_nocase(const char *path, const char *mode) -{ +FILE *File::fopenNoCase(const char *filename, const char * directory, const char *mode) { FILE *file; + char buf[256]; + char *ptr; - file = fopen(path, mode); + strcpy(buf, directory); + if (directory[0] != 0) { + strcpy(buf, directory); + strcat(buf, "/"); + } + strcat(buf, filename); + + file = fopen(buf, mode); if (file) return file; - char buf[256], *ptr; - int32 i = 0, pos = 0; - - strcpy(buf, path); - while (buf[i] != 0) { - if ((buf[i] == '/') || (buf[i] == '\\')) { - pos = i + 1; + char dirs[7][10]; + dirs[0][0] = 0; + strcpy(dirs[1], "video/"); + strcpy(dirs[2], "VIDEO/"); + strcpy(dirs[3], "data/"); + strcpy(dirs[4], "DATA/"); + strcpy(dirs[5], "resource/"); + strcpy(dirs[6], "RESOURCE/"); + + for (uint8 l = 0; l < 7; l++) { + strcpy(buf, directory); + if (directory[0] != 0) { + strcpy(buf, directory); + strcat(buf, "/"); } - i++; + strcat(buf, dirs[l]); + int8 len = strlen(buf); + strcat(buf, filename); + + ptr = buf + len; + do + *ptr++ = toupper(*ptr); + while (*ptr); + file = fopen(buf, mode); + if (file) + return file; + + ptr = buf + len; + do + *ptr++ = tolower(*ptr); + while (*ptr); + file = fopen(buf, mode); + if (file) + return file; } - - ptr = buf + pos; - do - *ptr++ = toupper(*ptr); - while (*ptr); - file = fopen(buf, mode); - if (file) - return file; - ptr = buf + pos; - do - *ptr++ = tolower(*ptr); - while (*ptr); - return fopen(buf, mode); + return NULL; } File::File() { @@ -66,7 +87,7 @@ File::~File() { close(); } -bool File::open(const char *filename, int mode, byte encbyte) { +bool File::open(const char *filename, const char *directory, int mode, byte encbyte) { if (_handle) { debug(2, "File %s already opened", filename); @@ -76,14 +97,14 @@ bool File::open(const char *filename, int mode, byte encbyte) { clearIOFailed(); if (mode == kFileReadMode) { - _handle = fopen_nocase(filename, "rb"); + _handle = fopenNoCase(filename, directory, "rb"); if (_handle == NULL) { debug(2, "File %s not found", filename); return false; } } else if (mode == kFileWriteMode) { - _handle = fopen_nocase(filename, "wb"); + _handle = fopenNoCase(filename, directory, "wb"); if (_handle == NULL) { debug(2, "File %s not opened", filename); return false; |