X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8478eff5b4ad2b9d910a542b6858137f866ffb22..77c8efc8c37da6d6a5e2e8022d21d1cd7d76371d:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 21598eae9c..2e04e80098 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -64,17 +64,19 @@ #include "wx/msw/mslu.h" // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path() + // and for cygwin_conv_path() // // note that it must be included after #ifdef __GNUWIN32__ #ifdef __CYGWIN__ #include + #include #endif #endif // __GNUWIN32__ // io.h is needed for _get_osfhandle() // Already included by filefn.h for many Windows compilers - #if defined __MWERKS__ || defined __CYGWIN__ + #if defined __CYGWIN__ #include #endif #endif // __WINDOWS__ @@ -96,10 +98,6 @@ #define _MAXPATHLEN 1024 #endif -#ifndef INVALID_FILE_ATTRIBUTES - #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) -#endif - // ---------------------------------------------------------------------------- // private globals // ---------------------------------------------------------------------------- @@ -369,7 +367,7 @@ template static CharType *wxDoRealPath (CharType *path) { static const CharType SEP = wxFILE_SEP_PATH; -#ifdef __WXMSW__ +#ifdef __WINDOWS__ wxUnix2DosFilename(path); #endif if (path[0] && path[1]) { @@ -400,7 +398,7 @@ static CharType *wxDoRealPath (CharType *path) path[0] = SEP; path[1] = wxT('\0'); } -#if defined(__WXMSW__) || defined(__OS2__) +#if defined(__WINDOWS__) || defined(__OS2__) /* Check that path[2] is NULL! */ else if (path[1] == wxT(':') && !path[2]) { @@ -449,7 +447,7 @@ wxChar *wxCopyAbsolutePath(const wxString& filename) { wxString buf = ::wxGetCwd(); wxChar ch = buf.Last(); -#ifdef __WXMSW__ +#ifdef __WINDOWS__ if (ch != wxT('\\') && ch != wxT('/')) buf << wxT("\\"); #else @@ -503,7 +501,7 @@ static CharType *wxDoExpandPath(CharType *buf, const wxString& name) trimchars[3] = 0; static const CharType SEP = wxFILE_SEP_PATH; -#ifdef __WXMSW__ +#ifdef __WINDOWS__ //wxUnix2DosFilename(path); #endif @@ -523,7 +521,7 @@ static CharType *wxDoExpandPath(CharType *buf, const wxString& name) s = nm; d = lnm; -#ifdef __WXMSW__ +#ifdef __WINDOWS__ q = FALSE; #else q = nm[0] == wxT('\\') && nm[1] == wxT('~'); @@ -548,7 +546,7 @@ static CharType *wxDoExpandPath(CharType *buf, const wxString& name) else #else while ((*d++ = *s) != 0) { -# ifndef __WXMSW__ +# ifndef __WINDOWS__ if (*s == wxT('\\')) { if ((*(d - 1) = *++s)!=0) { s++; @@ -560,7 +558,7 @@ static CharType *wxDoExpandPath(CharType *buf, const wxString& name) #endif // No env variables on WinCE #ifndef __WXWINCE__ -#ifdef __WXMSW__ +#ifdef __WINDOWS__ if (*s++ == wxT('$') && (*s == wxT('{') || *s == wxT(')'))) #else if (*s++ == wxT('$')) @@ -679,7 +677,7 @@ wxContractPath (const wxString& filename, return NULL; wxStrcpy (dest, filename); -#ifdef __WXMSW__ +#ifdef __WINDOWS__ wxUnix2DosFilename(dest); #endif @@ -733,16 +731,7 @@ wxChar *wxFileNameFromPath (wxChar *path) wxString wxFileNameFromPath (const wxString& path) { - wxString name, ext; - wxFileName::SplitPath(path, NULL, &name, &ext); - - wxString fullname = name; - if ( !ext.empty() ) - { - fullname << wxFILE_SEP_EXT << ext; - } - - return fullname; + return wxFileName(path).GetFullName(); } // Return just the directory, or NULL if no directory @@ -778,7 +767,7 @@ wxPathOnly (wxChar *path) i --; } -#if defined(__WXMSW__) || defined(__OS2__) +#if defined(__WINDOWS__) || defined(__OS2__) // Try Drive specifier if (wxIsalpha (buf[0]) && buf[1] == wxT(':')) { @@ -827,7 +816,7 @@ wxString wxPathOnly (const wxString& path) i --; } -#if defined(__WXMSW__) || defined(__OS2__) +#if defined(__WINDOWS__) || defined(__OS2__) // Try Drive specifier if (wxIsalpha (buf[0]) && buf[1] == wxT(':')) { @@ -853,6 +842,9 @@ wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathCompon { CFURLRef fullURLRef; fullURLRef = CFURLCreateFromFSRef(NULL, fsRef); + if ( fullURLRef == NULL) + return wxEmptyString; + if ( additionalPathComponent ) { CFURLRef parentURLRef = fullURLRef ; @@ -860,12 +852,10 @@ wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathCompon additionalPathComponent,false); CFRelease( parentURLRef ) ; } - CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, kDefaultPathStyle); + wxCFStringRef cfString( CFURLCopyFileSystemPath(fullURLRef, kDefaultPathStyle )); CFRelease( fullURLRef ) ; - CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString); - CFRelease( cfString ); - CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); - return wxCFStringRef(cfMutableString).AsString(); + + return wxCFStringRef::AsStringWithNormalizationFormC(cfString); } OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) @@ -890,13 +880,10 @@ OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) { - CFStringRef cfname = CFStringCreateWithCharacters( kCFAllocatorDefault, + wxCFStringRef cfname( CFStringCreateWithCharacters( kCFAllocatorDefault, uniname->unicode, - uniname->length ); - CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfname); - CFRelease( cfname ); - CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); - return wxCFStringRef(cfMutableString).AsString() ; + uniname->length ) ); + return wxCFStringRef::AsStringWithNormalizationFormC(cfname); } #ifndef __LP64__ @@ -934,7 +921,7 @@ static void wxDoDos2UnixFilename(T *s) { if (*s == wxT('\\')) *s = wxT('/'); -#ifdef __WXMSW__ +#ifdef __WINDOWS__ else *s = wxTolower(*s); // Case INDEPENDENT #endif @@ -947,14 +934,14 @@ void wxDos2UnixFilename(wchar_t *s) { wxDoDos2UnixFilename(s); } template static void -#if defined(__WXMSW__) || defined(__OS2__) +#if defined(__WINDOWS__) || defined(__OS2__) wxDoUnix2DosFilename(T *s) #else wxDoUnix2DosFilename(T *WXUNUSED(s) ) #endif { // Yes, I really mean this to happen under DOS only! JACS -#if defined(__WXMSW__) || defined(__OS2__) +#if defined(__WINDOWS__) || defined(__OS2__) if (s) while (*s) { @@ -1009,8 +996,7 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil } // helper of generic implementation of wxCopyFile() -#if !(defined(__WIN32__) || defined(__OS2__) || defined(__PALMOS__)) && \ - wxUSE_FILE +#if !(defined(__WIN32__) || defined(__OS2__)) && wxUSE_FILE static bool wxDoCopyFile(wxFile& fileIn, @@ -1062,7 +1048,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) // instead of our code if available // // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite - if ( !::CopyFile(file1.fn_str(), file2.fn_str(), !overwrite) ) + if ( !::CopyFile(file1.t_str(), file2.t_str(), !overwrite) ) { wxLogSysError(_("Failed to copy the file '%s' to '%s'"), file1.c_str(), file2.c_str()); @@ -1072,9 +1058,6 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) #elif defined(__OS2__) if ( ::DosCopy(file1.c_str(), file2.c_str(), overwrite ? DCPY_EXISTING : 0) != 0 ) return false; -#elif defined(__PALMOS__) - // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/ - return false; #elif wxUSE_FILE // !Win32 wxStructStat fbuf; @@ -1165,7 +1148,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) wxUnusedVar(overwrite); return false; -#endif // __WXMSW__ && __WIN32__ +#endif // __WINDOWS__ && __WIN32__ return true; } @@ -1184,7 +1167,7 @@ wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite) return false; } -#if !defined(__WXWINCE__) && !defined(__WXPALMOS__) +#if !defined(__WXWINCE__) // Normal system call if ( wxRename (file1, file2) == 0 ) return true; @@ -1196,6 +1179,7 @@ wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite) return true; } // Give up + wxLogSysError(_("File '%s' couldn't be renamed '%s'"), file1, file2); return false; } @@ -1205,32 +1189,28 @@ bool wxRemoveFile(const wxString& file) || defined(__BORLANDC__) \ || defined(__WATCOMC__) \ || defined(__DMC__) \ - || defined(__GNUWIN32__) \ - || (defined(__MWERKS__) && defined(__MSL__)) + || defined(__GNUWIN32__) int res = wxRemove(file); #elif defined(__WXMAC__) int res = unlink(file.fn_str()); -#elif defined(__WXPALMOS__) - int res = 1; - // TODO with VFSFileDelete() #else int res = unlink(file.fn_str()); #endif - + if ( res ) + { + wxLogSysError(_("File '%s' couldn't be removed"), file); + } return res == 0; } bool wxMkdir(const wxString& dir, int perm) { -#if defined(__WXPALMOS__) - return false; -#else #if defined(__WXMAC__) && !defined(__UNIX__) if ( mkdir(dir.fn_str(), 0) != 0 ) // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too // for the GNU compiler -#elif (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || \ +#elif (!(defined(__WINDOWS__) || defined(__OS2__) || defined(__DOS__))) || \ (defined(__GNUWIN32__) && !defined(__MINGW32__)) || \ defined(__WINE__) || defined(__WXMICROWIN__) const wxChar *dirname = dir.c_str(); @@ -1267,16 +1247,12 @@ bool wxMkdir(const wxString& dir, int perm) } return true; -#endif // PALMOS/!PALMOS } bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) { #if defined(__VMS__) return false; //to be changed since rmdir exists in VMS7.x -#elif defined(__WXPALMOS__) - // TODO with VFSFileRename() - return false; #else #if defined(__OS2__) if ( ::DosDeleteDir(dir.c_str()) != 0 ) @@ -1291,7 +1267,7 @@ bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) } return true; -#endif // PALMOS/!PALMOS +#endif } // does the path exists? (may have or not '/' or '\\' at the end) @@ -1310,12 +1286,7 @@ wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) return NULL; if ( buf ) -#ifdef _PACC_VER - // work around the PalmOS pacc compiler bug - wxStrcpy(buf, filename.data()); -#else wxStrcpy(buf, filename); -#endif else buf = MYcopystring(filename); @@ -1356,7 +1327,7 @@ wxString wxFindFirstFile(const wxString& spec, int flags) if ( !gs_dir->IsOpened() ) { - wxLogSysError(_("Can not enumerate files '%s'"), spec); + wxLogSysError(_("Cannot enumerate files '%s'"), spec); return wxEmptyString; } @@ -1405,11 +1376,7 @@ wxString wxFindNextFile() wxChar *wxDoGetCwd(wxChar *buf, int sz) { -#if defined(__WXPALMOS__) - // TODO - if(buf && sz>0) buf[0] = wxT('\0'); - return buf; -#elif defined(__WXWINCE__) +#if defined(__WXWINCE__) // TODO if(buf && sz>0) buf[0] = wxT('\0'); return buf; @@ -1505,11 +1472,19 @@ wxChar *wxDoGetCwd(wxChar *buf, int sz) // another example of DOS/Unix mix (Cygwin) wxString pathUnix = buf; #if wxUSE_UNICODE + #if CYGWIN_VERSION_DLL_MAJOR >= 1007 + cygwin_conv_path(CCP_POSIX_TO_WIN_W, pathUnix.mb_str(wxConvFile), buf, sz); + #else char bufA[_MAXPATHLEN]; cygwin_conv_to_full_win32_path(pathUnix.mb_str(wxConvFile), bufA); wxConvFile.MB2WC(buf, bufA, sz); + #endif #else + #if CYGWIN_VERSION_DLL_MAJOR >= 1007 + cygwin_conv_path(CCP_POSIX_TO_WIN_A, pathUnix, buf, sz); + #else cygwin_conv_to_full_win32_path(pathUnix, buf); + #endif #endif // wxUSE_UNICODE #endif // __CYGWIN__ } @@ -1540,6 +1515,7 @@ wxString wxGetCwd() bool wxSetWorkingDirectory(const wxString& d) { + bool success = false; #if defined(__OS2__) if (d[1] == ':') { @@ -1549,18 +1525,17 @@ bool wxSetWorkingDirectory(const wxString& d) if (d.length() == 2) return true; } - return (::DosSetCurrentDir(d.c_str()) == 0); + success = (::DosSetCurrentDir(d.c_str()) == 0); #elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__) - return (chdir(wxFNSTRINGCAST d.fn_str()) == 0); + success = (chdir(wxFNSTRINGCAST d.fn_str()) == 0); #elif defined(__WINDOWS__) #ifdef __WIN32__ #ifdef __WXWINCE__ // No equivalent in WinCE wxUnusedVar(d); - return false; #else - return (bool)(SetCurrentDirectory(d.fn_str()) != 0); + success = (SetCurrentDirectory(d.t_str()) != 0); #endif #else // Must change drive, too. @@ -1581,12 +1556,15 @@ bool wxSetWorkingDirectory(const wxString& d) _dos_setdrive(driveNo, &noDrives); } } - bool success = (chdir(WXSTRINGCAST d) == 0); - - return success; + success = (chdir(WXSTRINGCAST d) == 0); #endif #endif + if ( !success ) + { + wxLogSysError(_("Could not set current working directory")); + } + return success; } // Get the OS directory if appropriate (such as the Windows directory). @@ -1596,8 +1574,12 @@ wxString wxGetOSDirectory() #ifdef __WXWINCE__ return wxString(wxT("\\Windows")); #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) - wxChar buf[256]; - GetWindowsDirectory(buf, 256); + wxChar buf[MAX_PATH]; + if ( !GetWindowsDirectory(buf, MAX_PATH) ) + { + wxLogLastError(wxS("GetWindowsDirectory")); + } + return wxString(buf); #elif defined(__WXMAC__) && wxOSX_USE_CARBON return wxMacFindFolderNoSeparator(kOnSystemDisk, 'macs', false); @@ -1785,7 +1767,7 @@ static bool wxCheckWin32Permission(const wxString& path, DWORD access) // quoting the MSDN: "To obtain a handle to a directory, call the // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this // doesn't work under Win9x/ME but then it's not needed there anyhow - const DWORD dwAttr = ::GetFileAttributes(path.fn_str()); + const DWORD dwAttr = ::GetFileAttributes(path.t_str()); if ( dwAttr == INVALID_FILE_ATTRIBUTES ) { // file probably doesn't exist at all @@ -1882,7 +1864,7 @@ bool wxIsExecutable(const wxString &path) // wxFileKind wxGetFileKind(int fd) { -#if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle +#if defined __WINDOWS__ && !defined __WXWINCE__ && defined wxGetOSFHandle switch (::GetFileType(wxGetOSFHandle(fd)) & ~FILE_TYPE_REMOTE) { case FILE_TYPE_CHAR: