mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 08:25:35 +00:00
- Implemented case insensitive file reading. Left old system as a fallback
in case some engine writer decide to do something unwise - Removed used of ConfMan.getKey("path") in file-related cases, because now File class handles that - Fixed bug in ScummEngine_v80he::o80_getFileSize() where path delimiters weren't translated svn-id: r21443
This commit is contained in:
parent
3331de7105
commit
22042bc637
@ -276,6 +276,10 @@ static bool launcherDialog(GameDetector &detector, OSystem &system) {
|
||||
}
|
||||
|
||||
static int runGame(GameDetector &detector, OSystem &system, const Common::String &edebuglevels) {
|
||||
// We add it here, so MD5-based detection will be able to
|
||||
// read mixed case files
|
||||
Common::File::addDefaultDirectory(ConfMan.get("path"));
|
||||
|
||||
// Create the game engine
|
||||
Engine *engine = detector.createEngine(&system);
|
||||
if (!engine) {
|
||||
@ -301,12 +305,17 @@ static int runGame(GameDetector &detector, OSystem &system, const Common::String
|
||||
system.setWindowCaption(caption.c_str());
|
||||
}
|
||||
|
||||
Common::File::addDefaultDirectoryRecursive(ConfMan.get("path"));
|
||||
|
||||
// Add extrapath (if any) to the directory search list
|
||||
if (ConfMan.hasKey("extrapath"))
|
||||
Common::File::addDefaultDirectory(ConfMan.get("extrapath"));
|
||||
Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
|
||||
|
||||
if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain))
|
||||
Common::File::addDefaultDirectory(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
|
||||
Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
|
||||
|
||||
// As a last resort add current directory and lock further additions
|
||||
Common::File::addDefaultDirectory(".", true);
|
||||
|
||||
int result;
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "common/file.h"
|
||||
#include "common/util.h"
|
||||
#include "backends/fs/fs.h"
|
||||
|
||||
#ifdef MACOSX
|
||||
#include "CoreFoundation/CoreFoundation.h"
|
||||
@ -30,6 +31,8 @@
|
||||
namespace Common {
|
||||
|
||||
StringList File::_defaultDirectories;
|
||||
File::FilesMap File::_filesMap;
|
||||
bool File::_lockedDirectories;
|
||||
|
||||
|
||||
static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode) {
|
||||
@ -105,16 +108,80 @@ static FILE *fopenNoCase(const char *filename, const char *directory, const char
|
||||
return file;
|
||||
}
|
||||
|
||||
void File::addDefaultDirectory(const String &directory) {
|
||||
void File::addDefaultDirectory(const String &directory, bool lockDirectories) {
|
||||
String lfn;
|
||||
|
||||
if (_lockedDirectories)
|
||||
error("addDefaultDirectory is called too late. Move all calls to engine constructor");
|
||||
|
||||
_lockedDirectories = lockDirectories;
|
||||
|
||||
FilesystemNode dir(directory.c_str());
|
||||
|
||||
if (!dir.isDirectory())
|
||||
return;
|
||||
|
||||
_defaultDirectories.push_back(directory);
|
||||
|
||||
FSList fslist(dir.listDir(FilesystemNode::kListFilesOnly));
|
||||
|
||||
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
|
||||
lfn = file->displayName();
|
||||
lfn.toLowercase();
|
||||
if (!_filesMap.contains(lfn))
|
||||
_filesMap[lfn] = file->path();
|
||||
}
|
||||
}
|
||||
|
||||
void File::addDefaultDirectoryRecursive(const String &directory, int level, int baseLen) {
|
||||
if (level > 4)
|
||||
return;
|
||||
|
||||
String lfn;
|
||||
|
||||
if (_lockedDirectories)
|
||||
error("addDefaultDirectoryRecursive is called too late. Move all calls to engine constructor");
|
||||
|
||||
FilesystemNode dir(directory.c_str());
|
||||
|
||||
if (!dir.isDirectory())
|
||||
return;
|
||||
|
||||
_defaultDirectories.push_back(directory);
|
||||
|
||||
if (baseLen == 0) {
|
||||
baseLen = directory.size();
|
||||
if (directory.lastChar() != '/'
|
||||
#if defined(__MORPHOS__) || defined(__amigaos4__)
|
||||
&& directory.lastChar() != ':'
|
||||
#endif
|
||||
&& directory.lastChar() != '\\')
|
||||
baseLen++;
|
||||
}
|
||||
|
||||
FSList fslist(dir.listDir(FilesystemNode::kListAll));
|
||||
|
||||
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
|
||||
if (file->isDirectory()) {
|
||||
addDefaultDirectoryRecursive(file->path(), level + 1, baseLen);
|
||||
} else {
|
||||
lfn = String(file->path().c_str() + baseLen);
|
||||
lfn.toLowercase();
|
||||
if (!_filesMap.contains(lfn))
|
||||
_filesMap[lfn] = file->path();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void File::resetDefaultDirectories() {
|
||||
_defaultDirectories.clear();
|
||||
_filesMap.clear();
|
||||
_lockedDirectories = false;
|
||||
}
|
||||
|
||||
File::File()
|
||||
: _handle(0), _ioFailed(false), _refcount(1) {
|
||||
: _handle(0), _ioFailed(false), _refcount(1) {
|
||||
_lockedDirectories = false;
|
||||
}
|
||||
|
||||
//#define DEBUG_FILE_REFCOUNT
|
||||
@ -155,10 +222,18 @@ bool File::open(const char *filename, AccessMode mode, const char *directory) {
|
||||
|
||||
clearIOFailed();
|
||||
|
||||
String fname(filename);
|
||||
|
||||
fname.toLowercase();
|
||||
|
||||
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
|
||||
if (mode == kFileWriteMode || directory) {
|
||||
_handle = fopenNoCase(filename, directory ? directory : "", modeStr);
|
||||
} else if (_filesMap.contains(fname)) {
|
||||
debug(3, "Opening hashed: %s", _filesMap[fname].c_str());
|
||||
_handle = fopen(_filesMap[fname].c_str(), modeStr);
|
||||
} else {
|
||||
|
||||
StringList::const_iterator x;
|
||||
// Try all default directories
|
||||
for (x = _defaultDirectories.begin(); _handle == NULL && x != _defaultDirectories.end(); ++x) {
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "common/scummsys.h"
|
||||
#include "common/str.h"
|
||||
#include "common/stream.h"
|
||||
#include "common/assocarray.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
@ -44,8 +45,11 @@ protected:
|
||||
/** The name of this file, for debugging. */
|
||||
String _name;
|
||||
|
||||
typedef AssocArray<String, String> FilesMap;
|
||||
|
||||
static StringList _defaultDirectories;
|
||||
static FilesMap _filesMap;
|
||||
static bool _lockedDirectories;
|
||||
|
||||
public:
|
||||
enum AccessMode {
|
||||
@ -53,7 +57,8 @@ public:
|
||||
kFileWriteMode = 2
|
||||
};
|
||||
|
||||
static void addDefaultDirectory(const String &directory);
|
||||
static void addDefaultDirectory(const String &directory, bool lockDirectories = false);
|
||||
static void addDefaultDirectoryRecursive(const String &directory, int level = 0, int baseLen = 0);
|
||||
static void resetDefaultDirectories();
|
||||
|
||||
File();
|
||||
|
@ -343,7 +343,7 @@ Engine *Engine_GOB_create(GameDetector * detector, OSystem *syst) {
|
||||
uint8 md5sum[16];
|
||||
char md5str[32 + 1];
|
||||
|
||||
if (Common::md5_file("intro.stk", md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
|
||||
if (Common::md5_file("intro.stk", md5sum, NULL, kMD5FileSizeLimit)) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ KyraEngine::KyraEngine(GameDetector *detector, OSystem *system)
|
||||
if (!Common::File::exists(g->checkFile))
|
||||
continue;
|
||||
|
||||
if (Common::md5_file(g->checkFile, md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
|
||||
if (Common::md5_file(g->checkFile, md5sum, NULL, kMD5FileSizeLimit)) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ void LureEngine::detectGame() {
|
||||
if (!Common::File::exists(g->checkFile))
|
||||
continue;
|
||||
|
||||
if (Common::md5_file(g->checkFile, md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
|
||||
if (Common::md5_file(g->checkFile, md5sum, NULL, kMD5FileSizeLimit)) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
sprintf(md5str + j * 2, "%02x", (int)md5sum[j]);
|
||||
}
|
||||
|
@ -560,7 +560,7 @@ int ScummEngine_v72he::convertFilePath(byte *dst, bool setFilePath) {
|
||||
|
||||
if (setFilePath) {
|
||||
char filePath[256];
|
||||
sprintf(filePath, "%s%s", _gameDataPath.c_str(), dst + r);
|
||||
sprintf(filePath, "%s", dst + r);
|
||||
if (!Common::File::exists(filePath)) {
|
||||
sprintf(filePath, "%s%s", _saveFileMan->getSavePath(), dst + r);
|
||||
}
|
||||
|
@ -399,9 +399,15 @@ void ScummEngine_v80he::o80_createSound() {
|
||||
|
||||
void ScummEngine_v80he::o80_getFileSize() {
|
||||
byte filename[256];
|
||||
uint i;
|
||||
|
||||
copyScriptString(filename, sizeof(filename));
|
||||
|
||||
for (i = 0; i < strlen((const char *)filename); i++) {
|
||||
if (filename[i] == '\\')
|
||||
filename[i] = '/';
|
||||
}
|
||||
|
||||
Common::File f;
|
||||
if (!f.open((char *)filename)) {
|
||||
push(-1);
|
||||
|
@ -1595,7 +1595,7 @@ Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst) {
|
||||
// Instead, use the fs.h code to get a list of all files in that
|
||||
// directory and simply check whether that filename is contained
|
||||
// in it.
|
||||
if (Common::File::exists(detectName, ConfMan.get("path").c_str())) {
|
||||
if (Common::File::exists(detectName)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -1630,7 +1630,7 @@ Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst) {
|
||||
} else {
|
||||
// Compute the MD5 of the file, and (if we succeeded) store a hex version
|
||||
// of it in gameMD5 (useful to print it to the user in messages).
|
||||
if (Common::md5_file(detectName, md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
|
||||
if (Common::md5_file(detectName, md5sum, NULL, kMD5FileSizeLimit)) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
sprintf(gameMD5 + j*2, "%02x", (int)md5sum[j]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user