corrected FSSpec to POSIX file name conversions for Mac OS X (Apple DevTools)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14919 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
11632c43fa
commit
8372d79dc2
@ -873,14 +873,56 @@ wxString wxPathOnly (const wxString& path)
|
|||||||
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
|
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
|
||||||
{
|
{
|
||||||
#ifdef __DARWIN__
|
#ifdef __DARWIN__
|
||||||
FSRef theRef;
|
int i;
|
||||||
char thePath[FILENAME_MAX];
|
int j;
|
||||||
|
OSErr theErr;
|
||||||
|
OSStatus theStatus;
|
||||||
|
Boolean isDirectory = false;
|
||||||
|
Str255 theParentPath = "\p";
|
||||||
|
FSSpec theParentSpec;
|
||||||
|
FSRef theParentRef;
|
||||||
|
char theFileName[FILENAME_MAX];
|
||||||
|
char thePath[FILENAME_MAX];
|
||||||
|
|
||||||
// convert the FSSpec to an FSRef
|
strcpy(thePath, "");
|
||||||
(void) FSpMakeFSRef( spec, &theRef );
|
|
||||||
// get the POSIX path associated with the FSRef
|
|
||||||
(void) FSRefMakePath( &theRef, (UInt8 *)thePath, sizeof(thePath) );
|
|
||||||
|
|
||||||
|
// GD: Separate file name from path and make a FSRef to the parent
|
||||||
|
// directory. This is necessary since FSRefs cannot reference files
|
||||||
|
// that have not yet been created.
|
||||||
|
// Based on example code from Apple Technical Note TN2022
|
||||||
|
// http://developer.apple.com/technotes/tn/tn2022.html
|
||||||
|
|
||||||
|
// check whether we are converting a directory
|
||||||
|
isDirectory = ((spec->name)[spec->name[0]] == ':');
|
||||||
|
// count length of file name
|
||||||
|
for (i = spec->name[0] - (isDirectory ? 1 : 0); ((spec->name[i] != ':') && (i > 0)); i--);
|
||||||
|
// copy file name
|
||||||
|
// prepend path separator since it will later be appended to the path
|
||||||
|
theFileName[0] = wxFILE_SEP_PATH;
|
||||||
|
for (j = i + 1; j <= spec->name[0] - (isDirectory ? 1 : 0); j++) {
|
||||||
|
theFileName[j - i] = spec->name[j];
|
||||||
|
}
|
||||||
|
theFileName[j - i] = '\0';
|
||||||
|
// copy path if any
|
||||||
|
for (j = 1; j <= i; j++) {
|
||||||
|
theParentPath[++theParentPath[0]] = spec->name[j];
|
||||||
|
}
|
||||||
|
theErr = FSMakeFSSpec(spec->vRefNum, spec->parID, theParentPath, &theParentSpec);
|
||||||
|
if (theErr == noErr) {
|
||||||
|
// convert the FSSpec to an FSRef
|
||||||
|
theErr = FSpMakeFSRef(&theParentSpec, &theParentRef);
|
||||||
|
}
|
||||||
|
if (theErr == noErr) {
|
||||||
|
// get the POSIX path associated with the FSRef
|
||||||
|
theStatus = FSRefMakePath(&theParentRef,
|
||||||
|
(UInt8 *)thePath, sizeof(thePath));
|
||||||
|
}
|
||||||
|
if (theStatus == noErr) {
|
||||||
|
// append file name to path
|
||||||
|
// includes previously prepended path separator
|
||||||
|
strcat(thePath, theFileName);
|
||||||
|
}
|
||||||
|
|
||||||
// create path string for return value
|
// create path string for return value
|
||||||
wxString result( thePath ) ;
|
wxString result( thePath ) ;
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user