aboutsummaryrefslogtreecommitdiff
path: root/common
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 /common
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 'common')
-rw-r--r--common/file.cpp75
-rw-r--r--common/file.h8
2 files changed, 51 insertions, 32 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;
diff --git a/common/file.h b/common/file.h
index b037b6cdc2..e6a7b1505d 100644
--- a/common/file.h
+++ b/common/file.h
@@ -26,10 +26,6 @@
#include "stdafx.h"
#include "scummsys.h"
-// fopen_nocase is like fopen only that it will try various variations
-// of the given filename (with different cases) if the initial one isn't found.
-FILE *fopen_nocase(const char *path, const char *mode);
-
class File {
private:
@@ -37,6 +33,8 @@ private:
bool _ioFailed;
byte _encbyte;
+FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
+
public:
enum {
kFileReadMode = 1,
@@ -45,7 +43,7 @@ public:
File();
~File();
- bool open(const char *filename, int mode = kFileReadMode, byte encbyte = 0);
+ bool open(const char *filename, const char *directory, int mode = kFileReadMode, byte encbyte = 0);
void close();
bool isOpen();
bool ioFailed();