wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
{
#ifdef __DARWIN__
- FSRef theRef;
- char thePath[FILENAME_MAX];
-
- // convert the FSSpec to an FSRef
- (void) FSpMakeFSRef( spec, &theRef );
- // get the POSIX path associated with the FSRef
- (void) FSRefMakePath( &theRef, (UInt8 *)thePath, sizeof(thePath) );
-
+ int i;
+ int j;
+ OSErr theErr;
+ OSStatus theStatus;
+ Boolean isDirectory = false;
+ Str255 theParentPath = "\p";
+ FSSpec theParentSpec;
+ FSRef theParentRef;
+ char theFileName[FILENAME_MAX];
+ char thePath[FILENAME_MAX];
+
+ strcpy(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
wxString result( thePath ) ;
#else
// instead of our code if available
//
// NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
- return ::CopyFile(file1, file2, !overwrite) != 0;
+ if ( !::CopyFile(file1, file2, !overwrite) )
+ {
+ wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
+ file1.c_str(), file2.c_str());
+
+ return FALSE;
+ }
#elif defined(__WXPM__)
- if (::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) == 0)
- return TRUE;
- else
+ if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 )
return FALSE;
#else // !Win32
wxStructStat fbuf;
return FALSE;
}
#endif // OS/2 || Mac
+#endif // __WXMSW__ && __WIN32__
return TRUE;
-#endif // __WXMSW__ && __WIN32__
}
bool
wxString wxFindFirstFile(const wxChar *spec, int flags)
{
- gs_dirPath = wxPathOnly(spec);
+ wxSplitPath(spec, &gs_dirPath, NULL, NULL);
if ( gs_dirPath.IsEmpty() )
gs_dirPath = wxT(".");
if ( gs_dirPath.Last() != wxFILE_SEP_PATH )
// for the compilers which have Unicode version of _getcwd(), call it
// directly, for the others call the ANSI version and do the translation
#if !wxUSE_UNICODE
- #define cbuf buf
+ #define cbuf buf
#else // wxUSE_UNICODE
- bool needsANSI = TRUE;
+ bool needsANSI = TRUE;
- #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
+ #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
wxCharBuffer c_buffer(sz);
- char *cbuf = (char*)(const char*)c_buffer;
- #endif
+ char *cbuf = (char*)(const char*)c_buffer;
+ #endif
#ifdef HAVE_WGETCWD
- #if wxUSE_UNICODE_MSLU
- if ( wxGetOsVersion() != wxWIN95 )
- #endif
- {
- ok = _wgetcwd(buf, sz) != NULL;
- needsANSI = FALSE;
- }
+ #if wxUSE_UNICODE_MSLU
+ if ( wxGetOsVersion() != wxWIN95 )
+ #else
+ char *cbuf = NULL; // never really used because needsANSI will always be FALSE
+ #endif
+ {
+ ok = _wgetcwd(buf, sz) != NULL;
+ needsANSI = FALSE;
+ }
#endif
- if ( needsANSI )
+ if ( needsANSI )
#endif // wxUSE_UNICODE
- {
+ {
#ifdef _MSC_VER
ok = _getcwd(cbuf, sz) != NULL;
#elif defined(__WXMAC__) && !defined(__DARWIN__)
#else // !Win32/VC++ !Mac !OS2
ok = getcwd(cbuf, sz) != NULL;
#endif // platform
- }
+
+ #if wxUSE_UNICODE
+ // finally convert the result to Unicode if needed
+ wxConvFile.MB2WC(buf, cbuf, sz);
+ #endif // wxUSE_UNICODE
+ }
if ( !ok )
{
wxString pathUnix = buf;
cygwin_conv_to_full_win32_path(pathUnix, buf);
#endif // __CYGWIN__
-
- // finally convert the result to Unicode if needed
-#if wxUSE_UNICODE
- wxConvFile.MB2WC(buf, cbuf, sz);
-#endif // wxUSE_UNICODE
}
return buf;
#if !wxUSE_UNICODE
- #undef cbuf
+ #undef cbuf
#endif
}