X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6ad68ad8c829a59953913ae034e63ed689562c82..b53aea81d2e102224b452ef5bf7aee1132f37c6f:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index b9053ba8ac..322f7c16c6 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -96,12 +96,17 @@ #define _MAXPATHLEN 1024 #endif +#ifndef INVALID_FILE_ATTRIBUTES + #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +#endif + // ---------------------------------------------------------------------------- // private globals // ---------------------------------------------------------------------------- -// MT-FIXME: get rid of this horror and all code using it +#if WXWIN_COMPATIBILITY_2_8 static wxChar wxFileFunctionsBuffer[4*_MAXPATHLEN]; +#endif #if defined(__VISAGECPP__) && __IBMCPP__ >= 400 // @@ -289,9 +294,10 @@ wxString wxPathList::FindAbsoluteValidPath (const wxString& file) const } // ---------------------------------------------------------------------------- -// miscellaneous global functions (TOFIX!) +// miscellaneous global functions // ---------------------------------------------------------------------------- +#if WXWIN_COMPATIBILITY_2_8 static inline wxChar* MYcopystring(const wxString& s) { wxChar* copy = new wxChar[s.length() + 1]; @@ -304,6 +310,7 @@ static inline CharType* MYcopystring(const CharType* s) CharType* copy = new CharType[wxStrlen(s) + 1]; return wxStrcpy(copy, s); } +#endif bool @@ -316,7 +323,7 @@ wxFileExists (const wxString& filename) // it can cope with network (UNC) paths unlike them DWORD ret = ::GetFileAttributes(filename.fn_str()); - return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY); + return (ret != INVALID_FILE_ATTRIBUTES) && !(ret & FILE_ATTRIBUTE_DIRECTORY); #else // !__WIN32__ #ifndef S_ISREG #define S_ISREG(mode) ((mode) & S_IFREG) @@ -356,6 +363,7 @@ wxIsAbsolutePath (const wxString& filename) return false ; } +#if WXWIN_COMPATIBILITY_2_8 /* * Strip off any extension (dot something) from end of file, * IF one exists. Inserts zero into buffer. @@ -474,7 +482,7 @@ wxString wxRealPath(const wxString& path) wxChar *wxCopyAbsolutePath(const wxString& filename) { if (filename.empty()) - return (wxChar *) NULL; + return NULL; if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer, filename))) { @@ -707,7 +715,7 @@ wxContractPath (const wxString& filename, static wxChar dest[_MAXPATHLEN]; if (filename.empty()) - return (wxChar *) NULL; + return NULL; wxStrcpy (dest, filename); #ifdef __WXMSW__ @@ -751,6 +759,8 @@ wxContractPath (const wxString& filename, return dest; } +#endif // #if WXWIN_COMPATIBILITY_2_8 + // Return just the filename, not the path (basename) wxChar *wxFileNameFromPath (wxChar *path) { @@ -818,7 +828,7 @@ wxPathOnly (wxChar *path) } #endif } - return (wxChar *) NULL; + return NULL; } // Return just the directory, or NULL if no directory @@ -945,13 +955,16 @@ void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) OSStatus err = noErr; FSRef fsRef; wxMacPathToFSRef( path , &fsRef ); - err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, spec, NULL); + err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, spec, NULL); verify_noerr( err ); } #endif #endif // __WXMAC__ + +#if WXWIN_COMPATIBILITY_2_8 + template static void wxDoDos2UnixFilename(T *s) { @@ -994,6 +1007,8 @@ wxDoUnix2DosFilename(T *WXUNUSED(s) ) void wxUnix2DosFilename(char *s) { wxDoUnix2DosFilename(s); } void wxUnix2DosFilename(wchar_t *s) { wxDoUnix2DosFilename(s); } +#endif // #if WXWIN_COMPATIBILITY_2_8 + // Concatenate two files to form third bool wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& file3) @@ -1339,7 +1354,7 @@ bool wxDirExists(const wxString& pathName) // stat() can't cope with network paths DWORD ret = ::GetFileAttributes(strPath.fn_str()); - return (ret != (DWORD)-1) && (ret & FILE_ATTRIBUTE_DIRECTORY); + return (ret != INVALID_FILE_ATTRIBUTES) && (ret & FILE_ATTRIBUTE_DIRECTORY); #elif defined(__OS2__) FILESTATUS3 Info = {{0}}; APIRET rc = ::DosQueryPathInfo((PSZ)(WXSTRINGCAST strPath), FIL_STANDARD, @@ -1361,6 +1376,8 @@ bool wxDirExists(const wxString& pathName) #endif // __WIN32__/!__WIN32__ } +#if WXWIN_COMPATIBILITY_2_8 + // Get a temporary filename, opening and closing the file. wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) { @@ -1395,6 +1412,8 @@ bool wxGetTempFileName(const wxString& prefix, wxString& buf) #endif // wxUSE_FILE/!wxUSE_FILE } +#endif // #if WXWIN_COMPATIBILITY_2_8 + // Get first file name matching given wild card. static wxDir *gs_dir = NULL; @@ -1402,14 +1421,13 @@ static wxString gs_dirPath; wxString wxFindFirstFile(const wxString& spec, int flags) { - wxSplitPath(spec, &gs_dirPath, NULL, NULL); + wxFileName::SplitPath(spec, &gs_dirPath, NULL, NULL); if ( gs_dirPath.empty() ) gs_dirPath = wxT("."); if ( !wxEndsWithPathSeparator(gs_dirPath ) ) gs_dirPath << wxFILE_SEP_PATH; - if (gs_dir) - delete gs_dir; + delete gs_dir; // can be NULL, this is ok gs_dir = new wxDir(gs_dirPath); if ( !gs_dir->IsOpened() ) @@ -1439,7 +1457,7 @@ wxString wxFindFirstFile(const wxString& spec, int flags) wxString wxFindNextFile() { - wxASSERT_MSG( gs_dir, wxT("You must call wxFindFirstFile before!") ); + wxCHECK_MSG( gs_dir, "", "You must call wxFindFirstFile before!" ); wxString result; gs_dir->GetNext(&result); @@ -1517,7 +1535,7 @@ wxChar *wxDoGetCwd(wxChar *buf, int sz) { sz -= 3; rc = ::DosQueryCurrentDir( 0 // current drive - ,cbuf + 3 + ,(PBYTE)cbuf + 3 ,(PULONG)&sz ); cbuf[0] = char('A' + (ulDriveNum - 1)); @@ -1657,7 +1675,7 @@ wxString wxGetOSDirectory() wxChar buf[256]; GetWindowsDirectory(buf, 256); return wxString(buf); -#elif defined(__WXMAC__) && !defined(__WXOSX_IPHONE__) +#elif defined(__WXMAC__) && wxOSX_USE_CARBON return wxMacFindFolder(kOnSystemDisk, 'macs', false); #else return wxEmptyString; @@ -1702,6 +1720,7 @@ bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& sz return false; } +#if WXWIN_COMPATIBILITY_2_8 void WXDLLIMPEXP_BASE wxSplitPath(const wxString& fileName, wxString *pstrPath, wxString *pstrName, @@ -1709,6 +1728,7 @@ void WXDLLIMPEXP_BASE wxSplitPath(const wxString& fileName, { wxFileName::SplitPath(fileName, pstrPath, pstrName, pstrExt); } +#endif // #if WXWIN_COMPATIBILITY_2_8 #if wxUSE_DATETIME @@ -1841,12 +1861,20 @@ 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 - bool isdir = wxDirExists(path); - if ( isdir && wxGetOsVersion() == wxOS_WINDOWS_9X ) + const DWORD dwAttr = ::GetFileAttributes(path.fn_str()); + if ( dwAttr == INVALID_FILE_ATTRIBUTES ) + { + // file probably doesn't exist at all + return false; + } + + if ( wxGetOsVersion() == wxOS_WINDOWS_9X ) { // FAT directories always allow all access, even if they have the - // readonly flag set - return true; + // readonly flag set, and FAT files can only be read-only + return (dwAttr & FILE_ATTRIBUTE_DIRECTORY) || + (access != GENERIC_WRITE || + !(dwAttr & FILE_ATTRIBUTE_READONLY)); } HANDLE h = ::CreateFile @@ -1856,7 +1884,9 @@ static bool wxCheckWin32Permission(const wxString& path, DWORD access) FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, - isdir ? FILE_FLAG_BACKUP_SEMANTICS : 0, + dwAttr & FILE_ATTRIBUTE_DIRECTORY + ? FILE_FLAG_BACKUP_SEMANTICS + : 0, NULL ); if ( h != INVALID_HANDLE_VALUE )