From dabfcbf10c6bd6048f677017402ec335bb3c60e9 Mon Sep 17 00:00:00 2001 From: Oystein Eftevaag Date: Wed, 15 Mar 2006 09:41:22 +0000 Subject: Moving the MacOS bundle file checking to another function, it was getting called redundantly. svn-id: r21309 --- common/file.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'common/file.cpp') diff --git a/common/file.cpp b/common/file.cpp index 900edf966c..8d0658818b 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -102,24 +102,6 @@ static FILE *fopenNoCase(const char *filename, const char *directory, const char } #endif -// If all else fails, try looking inside the application bundle on MacOS for the lowercase file. -#ifdef MACOSX - if (!file) { - ptr = buf + offsetToFileName; - while (*ptr) { - *ptr = tolower(*ptr); - ptr++; - } - - CFStringRef fileName = CFStringCreateWithBytes(NULL, (const UInt8 *)buf, strlen(buf), kCFStringEncodingASCII, false); - CFURLRef fileUrl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), fileName, NULL, NULL); - if (fileUrl) { - if (CFURLGetFileSystemRepresentation(fileUrl, true, (UInt8 *)buf, sizeof(buf))) - file = fopen(buf, mode); - } - } -#endif - return file; } @@ -185,6 +167,21 @@ bool File::open(const char *filename, AccessMode mode, const char *directory) { // Last resort: try the current directory if (_handle == NULL) _handle = fopenNoCase(filename, "", modeStr); + + // Last last (really) resort: try looking inside the application bundle on MacOS for the lowercase file. +#ifdef MACOSX + if (!_handle) { + CFStringRef cfFileName = CFStringCreateWithBytes(NULL, (const UInt8 *)filename, strlen(filename), kCFStringEncodingASCII, false); + CFURLRef fileUrl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfFileName, NULL, NULL); + if (fileUrl) { + UInt8 buf[256]; + if (CFURLGetFileSystemRepresentation(fileUrl, false, (UInt8 *)buf, 256)) { + _handle = fopen((char *)buf, modeStr); + } + } + } +#endif + } if (_handle == NULL) { -- cgit v1.2.3