Changed File::open to take a Common::String as file name parameter

svn-id: r21867
This commit is contained in:
Max Horn 2006-04-14 01:48:51 +00:00
parent 5072816109
commit 1470dadb1d
12 changed files with 33 additions and 35 deletions

View file

@ -68,7 +68,7 @@ void ConfigFile::clear() {
bool ConfigFile::loadFromFile(const String &filename) {
File file;
if (file.open(filename.c_str(), File::kFileReadMode))
if (file.open(filename, File::kFileReadMode))
return loadFromStream(file);
else
return false;
@ -170,7 +170,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
bool ConfigFile::saveToFile(const String &filename) {
File file;
if (file.open(filename.c_str(), File::kFileWriteMode))
if (file.open(filename, File::kFileWriteMode))
return saveToStream(file);
else
return false;

View file

@ -137,7 +137,7 @@ void ConfigManager::loadConfigFile(const String &filename) {
void ConfigManager::loadFile(const String &filename) {
File cfg_file;
if (!cfg_file.open(filename.c_str())) {
if (!cfg_file.open(filename)) {
printf("Creating configuration file: %s\n", filename.c_str());
} else {
char buf[MAXLINELEN];

View file

@ -67,7 +67,6 @@ static FILE *fopenNoCase(const String &filename, const String &directory, const
// Try again, with file name converted to upper case
//
if (!file) {
for (i = offsetToFileName; i < buf.size(); ++i) {
buf[i] = toupper(buf[i]);
}
@ -185,20 +184,19 @@ void File::decRef() {
}
bool File::open(const char *f, AccessMode mode, const char *directory) {
bool File::open(const String &filename, AccessMode mode, const char *directory) {
assert(mode == kFileReadMode || mode == kFileWriteMode);
if (f == NULL || *f == 0) {
if (filename.empty()) {
error("File::open: No filename was specified!");
}
if (_handle) {
error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), f);
error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
}
clearIOFailed();
String filename(f);
String fname(filename);
fname.toLowercase();
@ -265,7 +263,7 @@ bool File::open(const char *f, AccessMode mode, const char *directory) {
return true;
}
bool File::exists(const char *filename, const char *directory) {
bool File::exists(const String &filename, const char *directory) {
// FIXME: Ugly ugly hack!
File tmp;
return tmp.open(filename, kFileReadMode, directory);

View file

@ -60,8 +60,8 @@ public:
void incRef();
void decRef();
virtual bool open(const char *filename, AccessMode mode = kFileReadMode, const char *directory = NULL);
static bool exists(const char *filename, const char *directory = NULL);
virtual bool open(const String &filename, AccessMode mode = kFileReadMode, const char *directory = NULL);
static bool exists(const String &filename, const char *directory = NULL);
virtual void close();
bool isOpen() const;

View file

@ -239,7 +239,7 @@ PAKFile::PAKFile(const Common::String& file, bool isAmiga) {
uint8 *buffer = 0;
_open = false;
if (!pakfile.open(file.c_str())) {
if (!pakfile.open(file)) {
debug(3, "couldn't open pakfile '%s'\n", file.c_str());
return;
}

View file

@ -101,7 +101,7 @@ DetectedGameList Engine_QUEEN_detectGames(const FSList &fslist) {
if (0 == scumm_stricmp("queen.1", gameName) || 0 == scumm_stricmp("queen.1c", gameName)) {
Common::File dataFile;
dataFile.open(file->path().c_str());
dataFile.open(file->path());
assert(dataFile.isOpen());
if (0 == scumm_stricmp("queen.1", gameName)) { //an unmodified file

View file

@ -1556,7 +1556,7 @@ static int detectGame(const FSList *fslist, Common::Language language, Common::P
tstr.toLowercase();
if(!filesMD5.contains(tstr)) {
if (testFile.open(file->_key.c_str())) {
if (testFile.open(file->_key)) {
testFile.close();
if (Common::md5_file(file->_key.c_str(), md5sum, NULL, FILE_MD5_BYTES)) {

View file

@ -56,7 +56,7 @@ void ScummFile::resetSubfile() {
seek(0, SEEK_SET);
}
bool ScummFile::open(const char *filename, AccessMode mode) {
bool ScummFile::open(const Common::String &filename, AccessMode mode) {
if (File::open(filename, mode)) {
resetSubfile();
return true;
@ -65,7 +65,7 @@ bool ScummFile::open(const char *filename, AccessMode mode) {
}
}
bool ScummFile::openSubFile(const char *filename) {
bool ScummFile::openSubFile(const Common::String &filename) {
assert(isOpen());
// Disable the XOR encryption and reset any current subfile range
@ -112,7 +112,7 @@ bool ScummFile::openSubFile(const char *filename) {
return false;
}
if (scumm_stricmp(file_name, filename) == 0) {
if (scumm_stricmp(file_name, filename.c_str()) == 0) {
// We got a match!
setSubfileRange(file_off, file_len);
return true;
@ -1380,11 +1380,11 @@ bool ScummNESFile::generateIndex() {
return true;
}
bool ScummNESFile::open(const char *filename, AccessMode mode) {
bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
uint8 md5sum[16];
if (_ROMset == kROMsetNum) {
if (Common::md5_file(filename, md5sum)) {
if (Common::md5_file(filename.c_str(), md5sum)) {
char md5str[32+1];
for (int j = 0; j < 16; j++) {
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
@ -1439,10 +1439,10 @@ void ScummNESFile::close() {
File::close();
}
bool ScummNESFile::openSubFile(const char *filename) {
bool ScummNESFile::openSubFile(const Common::String &filename) {
assert(isOpen());
const char *ext = strrchr(filename, '.');
const char *ext = strrchr(filename.c_str(), '.');
char resNum[3];
int res;
@ -1556,7 +1556,7 @@ bool ScummC64File::openDisk(char num) {
return true;
}
bool ScummC64File::open(const char *filename, AccessMode mode) {
bool ScummC64File::open(const Common::String &filename, AccessMode mode) {
uint16 signature;
// check signature
@ -1708,10 +1708,10 @@ void ScummC64File::close() {
File::close();
}
bool ScummC64File::openSubFile(const char *filename) {
bool ScummC64File::openSubFile(const Common::String &filename) {
assert(isOpen());
const char *ext = strrchr(filename, '.');
const char *ext = strrchr(filename.c_str(), '.');
char resNum[3];
int res;

View file

@ -31,8 +31,8 @@ class BaseScummFile : public Common::File {
public:
virtual void setEnc(byte value) = 0;
virtual bool open(const char *filename, AccessMode mode = kFileReadMode) = 0;
virtual bool openSubFile(const char *filename) = 0;
virtual bool open(const Common::String &filename, AccessMode mode = kFileReadMode) = 0;
virtual bool openSubFile(const Common::String &filename) = 0;
virtual bool eof() = 0;
virtual uint32 pos() = 0;
@ -54,8 +54,8 @@ public:
void setSubfileRange(uint32 start, uint32 len);
void resetSubfile();
bool open(const char *filename, AccessMode mode = kFileReadMode);
bool openSubFile(const char *filename);
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
bool openSubFile(const Common::String &filename);
bool eof();
uint32 pos();
@ -96,8 +96,8 @@ public:
ScummNESFile();
void setEnc(byte value);
bool open(const char *filename, AccessMode mode = kFileReadMode);
bool openSubFile(const char *filename);
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
bool openSubFile(const Common::String &filename);
void close();
bool eof() { return _stream->eos(); }
@ -142,8 +142,8 @@ public:
ScummC64File(const char *disk1, const char *disk2, bool maniac);
void setEnc(byte value);
bool open(const char *filename, AccessMode mode = kFileReadMode);
bool openSubFile(const char *filename);
bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
bool openSubFile(const Common::String &filename);
void close();
bool eof() { return _stream->eos(); }

View file

@ -250,7 +250,7 @@ bool ScummEngine::openFile(BaseScummFile &file, const char *filename, bool resou
char name[128];
file.close();
file.open(_containerFile.c_str());
file.open(_containerFile);
assert(file.isOpen());
strncpy(name, filename, 128);

View file

@ -1305,7 +1305,7 @@ static int detectGame(const FSList *fslist, Common::Language language, Common::P
tstr.toLowercase();
if(!filesMD5.contains(tstr)) {
if (testFile.open(file->_key.c_str())) {
if (testFile.open(file->_key)) {
testFile.close();
if (Common::md5_file(file->_key.c_str(), md5sum, NULL, FILE_MD5_BYTES)) {

View file

@ -140,7 +140,7 @@ Surface *ImageDecoder::loadFile(const Common::String &name) {
Surface *newSurf = 0;
Common::File imageFile;
if (imageFile.open(name.c_str())) {
if (imageFile.open(name)) {
newSurf = loadFile(imageFile);
}