X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd362275b853cc0308bbde6a60bb2525d659f709..76015a6bb79156d8af1b5e8b4b8e46b4e192d18f:/src/common/filefn.cpp?ds=sidebyside diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 2da2831468..cb035c4407 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -61,6 +61,7 @@ #ifdef __WINDOWS__ #include "wx/msw/private.h" + #include "wx/msw/missing.h" #include "wx/msw/mslu.h" // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path() @@ -76,7 +77,7 @@ // 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__ @@ -367,7 +368,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]) { @@ -398,7 +399,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]) { @@ -447,7 +448,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 @@ -501,7 +502,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 @@ -521,7 +522,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('~'); @@ -546,7 +547,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++; @@ -558,7 +559,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('$')) @@ -677,7 +678,7 @@ wxContractPath (const wxString& filename, return NULL; wxStrcpy (dest, filename); -#ifdef __WXMSW__ +#ifdef __WINDOWS__ wxUnix2DosFilename(dest); #endif @@ -767,7 +768,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(':')) { @@ -816,7 +817,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(':')) { @@ -842,6 +843,9 @@ wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathCompon { CFURLRef fullURLRef; fullURLRef = CFURLCreateFromFSRef(NULL, fsRef); + if ( fullURLRef == NULL) + return wxEmptyString; + if ( additionalPathComponent ) { CFURLRef parentURLRef = fullURLRef ; @@ -849,12 +853,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 ) @@ -879,13 +881,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__ @@ -923,7 +922,7 @@ static void wxDoDos2UnixFilename(T *s) { if (*s == wxT('\\')) *s = wxT('/'); -#ifdef __WXMSW__ +#ifdef __WINDOWS__ else *s = wxTolower(*s); // Case INDEPENDENT #endif @@ -936,14 +935,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) { @@ -1150,7 +1149,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) wxUnusedVar(overwrite); return false; -#endif // __WXMSW__ && __WIN32__ +#endif // __WINDOWS__ && __WIN32__ return true; } @@ -1191,8 +1190,7 @@ 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()); @@ -1213,7 +1211,7 @@ bool wxMkdir(const wxString& dir, int perm) // 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(); @@ -1358,9 +1356,7 @@ wxString wxFindNextFile() wxCHECK_MSG( gs_dir, "", "You must call wxFindFirstFile before!" ); wxString result; - gs_dir->GetNext(&result); - - if ( result.empty() ) + if ( !gs_dir->GetNext(&result) || result.empty() ) { wxDELETE(gs_dir); return result; @@ -1538,7 +1534,7 @@ bool wxSetWorkingDirectory(const wxString& d) // No equivalent in WinCE wxUnusedVar(d); #else - success = (SetCurrentDirectory(d.fn_str()) != 0); + success = (SetCurrentDirectory(d.t_str()) != 0); #endif #else // Must change drive, too. @@ -1577,8 +1573,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); @@ -1766,7 +1766,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 @@ -1863,7 +1863,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: