From Eric Wing, fix to be able to handle "spacial" characters under OSX.

This commit is contained in:
Robert Osfield
2005-07-26 20:31:43 +00:00
parent 83da1b0894
commit 07af23e280
2 changed files with 116 additions and 156 deletions

View File

@@ -586,62 +586,35 @@ std::string osgDB::findFileInDirectory(const std::string& fileName,const std::st
const int MAX_OSX_PATH_SIZE = 1024;
const std::string OSG_PLUGIN_PATH("/OpenSceneGraph/PlugIns");
char buffer[MAX_OSX_PATH_SIZE];
char bundlePathBuffer[MAX_OSX_PATH_SIZE];
CFURLRef url;
CFStringRef pathString;
CFBundleRef myBundle;
CFStringRef bundlePathString;
FSRef f;
OSErr errCode;
// Start with the the Bundle PlugIns directory.
// Unlike the Cocoa API, it seems that the PlugIn path is relative
// and not absolute. So I will need to fetch both the bundle path
// (which is absolute) and the PlugIn path (which is relative),
// and combine the two to form a full path.
// Get the bundle first
myBundle = CFBundleGetMainBundle();
if(myBundle != NULL)
{
// Get the URL to the bundle
url = CFBundleCopyBundleURL( myBundle );
// Convert the URL to a CFString that looks like a Unix file path
bundlePathString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
// Convert the CFString to a C string
CFStringGetCString( bundlePathString, bundlePathBuffer, MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8 );
// Get the URL to the plugins directory in the bundle
url = CFBundleCopyBuiltInPlugInsURL(myBundle);
// Converting the CFString into a UTF8 C string is not quite correct because
// for files that contain special characters, the BSD C file APIs actually
// expect strings encoded in a special encoding. So Apple provides a
// FileRepresentation function for this purpose.
if( (url != NULL) && (CFURLGetFileSystemRepresentation(url, true, buffer, MAX_OSX_PATH_SIZE)) )
{
filepath.push_back(
std::string(buffer)
);
}
else
{
osg::notify( osg::DEBUG_INFO ) << "Couldn't find the PlugIns folder in the Application Bundle" << std::endl;
}
CFRelease( url );
// Now find the PlugIns directory
// Get the URL to the bundle
url = CFBundleCopyBuiltInPlugInsURL( myBundle );
//pathString = CFURLCopyPath( url );
// Convert the URL to a CFString that looks like a Unix file path
pathString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
// Convert the CFString to a C string
CFStringGetCString( pathString, buffer, MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8 );
// Combine the string and copy it into the FilePath list
filepath.push_back(
std::string(bundlePathBuffer)
+ std::string("/")
+ std::string(buffer)
);
CFRelease( pathString );
CFRelease( bundlePathString );
CFRelease( url );
// I was getting random crashes which I believe were caused by
// releasing the bundle. The documentation says I'm responsible
// for retaining and releasing which didn't immediately register
// in my head. I never retain the bundle, so I don't release it.
// CFRelease( myBundle );
pathString = NULL;
bundlePathString = NULL;
url = NULL;
// myBundle = NULL;
}
@@ -656,19 +629,23 @@ std::string osgDB::findFileInDirectory(const std::string& fileName,const std::st
{
// Get the URL
url = CFURLCreateFromFSRef( 0, &f );
// Convert the URL to a CFString that looks like a Unix file path
pathString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
// Convert the CFString to a C string
CFStringGetCString( pathString, buffer, MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8 );
// Add the directory to the FilePathList
filepath.push_back(
std::string(buffer)
+ OSG_PLUGIN_PATH
);
// Converting the CFString into a UTF8 C string is not quite correct because
// for files that contain special characters, the BSD C file APIs actually
// expect strings encoded in a special encoding. So Apple provides a
// FileRepresentation function for this purpose.
if( (url != NULL) && (CFURLGetFileSystemRepresentation(url, true, buffer, MAX_OSX_PATH_SIZE)) )
{
filepath.push_back(
std::string(buffer)
+ OSG_PLUGIN_PATH
);
}
else
{
osg::notify( osg::DEBUG_INFO ) << "Couldn't find the User's Application Support Path" << std::endl;
}
CFRelease( url );
CFRelease( pathString );
url = NULL;
}
else
{
@@ -681,19 +658,23 @@ std::string osgDB::findFileInDirectory(const std::string& fileName,const std::st
{
// Get the URL
url = CFURLCreateFromFSRef( 0, &f );
// Convert the URL to a CFString that looks like a Unix file path
pathString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
// Convert the CFString to a C string
CFStringGetCString( pathString, buffer, MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8 );
// Add the directory to the FilePathList
filepath.push_back(
std::string(buffer)
+ OSG_PLUGIN_PATH
);
// Converting the CFString into a UTF8 C string is not quite correct because
// for files that contain special characters, the BSD C file APIs actually
// expect strings encoded in a special encoding. So Apple provides a
// FileRepresentation function for this purpose.
if( (url != NULL) && (CFURLGetFileSystemRepresentation(url, true, buffer, MAX_OSX_PATH_SIZE)) )
{
filepath.push_back(
std::string(buffer)
+ OSG_PLUGIN_PATH
);
}
else
{
osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Local System's Application Support Path" << std::endl;
}
CFRelease( url );
CFRelease( pathString );
url = NULL;
}
else
{
@@ -708,19 +689,23 @@ std::string osgDB::findFileInDirectory(const std::string& fileName,const std::st
{
// Get the URL
url = CFURLCreateFromFSRef( 0, &f );
// Convert the URL to a CFString that looks like a Unix file path
pathString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
// Convert the CFString to a C string
CFStringGetCString( pathString, buffer, MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8 );
// Add the directory to the FilePathList
filepath.push_back(
std::string(buffer)
+ OSG_PLUGIN_PATH
);
// Converting the CFString into a UTF8 C string is not quite correct because
// for files that contain special characters, the BSD C file APIs actually
// expect strings encoded in a special encoding. So Apple provides a
// FileRepresentation function for this purpose.
if( (url != NULL) && (CFURLGetFileSystemRepresentation(url, true, buffer, MAX_OSX_PATH_SIZE)) )
{
filepath.push_back(
std::string(buffer)
+ OSG_PLUGIN_PATH
);
}
else
{
osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Network Application Support Path" << std::endl;
}
CFRelease( url );
CFRelease( pathString );
url = NULL;
}
else
{

View File

@@ -255,85 +255,60 @@ static osg::ApplicationUsageProxy Registry_e0(osg::ApplicationUsage::ENVIRONMENT
void Registry::initDataFilePathList()
{
FilePathList filepath;
//
// set up data file paths
//
char *ptr;
if( (ptr = getenv( "OSG_FILE_PATH" )) )
{
//notify(DEBUG_INFO) << "OSG_FILE_PATH("<<ptr<<")"<<std::endl;
convertStringPathIntoFilePathList(ptr, filepath);
}
else if( (ptr = getenv( "OSGFILEPATH" )) )
{
//notify(DEBUG_INFO) << "OSGFILEPATH("<<ptr<<")"<<std::endl;
convertStringPathIntoFilePathList(ptr, filepath);
}
FilePathList filepath;
const int MAX_OSX_PATH_SIZE = 1024;
char buffer[MAX_OSX_PATH_SIZE];
CFURLRef url;
CFBundleRef myBundle;
char* buffer = NULL;
char* bundlePathBuffer = NULL;
CFURLRef url;
CFStringRef pathString;
CFBundleRef myBundle;
CFStringRef bundlePathString;
CFIndex strLen;
CFIndex maxBufferSize;
//
// set up data file paths
//
char *ptr;
myBundle = CFBundleGetMainBundle();
if (myBundle != NULL) {
// Get the URL to the bundle
url = CFBundleCopyBundleURL( myBundle );
// Convert the URL to a CFString that looks like a Unix file path
bundlePathString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
// Convert the CFString to a C string
strLen = CFStringGetLength( bundlePathString );
maxBufferSize = CFStringGetMaximumSizeForEncoding( strLen, kCFStringEncodingUTF8 );
bundlePathBuffer = (char*) malloc(maxBufferSize);
CFStringGetCString( bundlePathString, bundlePathBuffer, maxBufferSize, kCFStringEncodingUTF8 );
CFRelease( url );
if( (ptr = getenv( "OSG_FILE_PATH" )) )
{
//notify(DEBUG_INFO) << "OSG_FILE_PATH("<<ptr<<")"<<std::endl;
convertStringPathIntoFilePathList(ptr, filepath);
}
else if( (ptr = getenv( "OSGFILEPATH" )) )
{
//notify(DEBUG_INFO) << "OSGFILEPATH("<<ptr<<")"<<std::endl;
convertStringPathIntoFilePathList(ptr, filepath);
}
// Now find the resources folder
url = CFBundleCopyResourcesDirectoryURL( myBundle );
//pathString = CFURLCopyPath( url );
// Convert the URL to a CFString that looks like a Unix file path
pathString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
// Convert the CFString to a C string
strLen = CFStringGetLength( pathString );
maxBufferSize = CFStringGetMaximumSizeForEncoding( strLen, kCFStringEncodingUTF8 );
buffer = (char*) malloc(maxBufferSize);
CFStringGetCString( pathString, buffer, maxBufferSize, kCFStringEncodingUTF8 );
// Combine the string and copy it into the FilePath list
filepath.push_back( std::string(bundlePathBuffer)
+ std::string("/")
+ std::string(buffer)
);
CFRelease( pathString );
CFRelease( bundlePathString );
CFRelease( url );
if (bundlePathBuffer != NULL) free(bundlePathBuffer);
if (buffer != NULL) free(buffer);
pathString = NULL;
bundlePathString = NULL;
url = NULL;
}
else
{
osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Application Bundle" << std::endl;
}
setDataFilePathList(filepath);
// Get the bundle first
myBundle = CFBundleGetMainBundle();
if(myBundle != NULL)
{
// Get the URL to the resource directory in the bundle
url = CFBundleCopyResourcesDirectoryURL(myBundle);
// Converting the CFString into a UTF8 C string is not quite correct because
// for files that contain special characters, the BSD C file APIs actually
// expect strings encoded in a special encoding. So Apple provides a
// FileRepresentation function for this purpose.
if( (url != NULL) && (CFURLGetFileSystemRepresentation(url, true, buffer, MAX_OSX_PATH_SIZE)) )
{
filepath.push_back(
std::string(buffer)
);
}
else
{
osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Resource folder in the Application Bundle" << std::endl;
}
CFRelease( url );
url = NULL;
// myBundle = NULL;
}
else
{
osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Application Bundle" << std::endl;
}
setDataFilePathList(filepath);
//osg::notify(INFO)<<"Data FilePathList"<<std::endl;
//PrintFilePathList(osg::notify(INFO),getDataFilePathList());
@@ -569,9 +544,9 @@ std::string Registry::createLibraryNameForExtension(const std::string& ext)
if (itr!=_extAliasMap.end()) return createLibraryNameForExtension(itr->second);
#ifdef OSG_JAVA_BUILD
static std::string prepend = "java";
static std::string prepend = "java";
#else
static std::string prepend = "";
static std::string prepend = "";
#endif
#if defined(WIN32)