X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c70014d966bbfa08d201ca24c825f2d88cc3975..768a499594fd9c9fd0155d0513c7f5b785ce4439:/src/common/filefn.cpp?ds=sidebyside diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index b780caad9a..37df0c74db 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -62,7 +62,7 @@ #endif #ifdef __WINDOWS__ - #include "wx/msw/wrapwin.h" + #include "wx/msw/private.h" #include "wx/msw/mslu.h" // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path() @@ -73,9 +73,15 @@ #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__ + #include + #endif #endif // __WINDOWS__ -#if defined __VMS__ +#if defined(__VMS__) #include #endif @@ -208,7 +214,9 @@ void wxPathList::AddEnvList (const wxString& envVariable) delete [] s; } -#endif +#else // __WXWINCE__ + wxUnusedVar(envVariable); +#endif // !__WXWINCE__/__WXWINCE__ } // Given a full filename (with path), ensure that that file can @@ -230,7 +238,7 @@ bool wxPathList::Member (const wxString& path) { wxString path2( node->GetData() ); if ( -#if defined(__WINDOWS__) || defined(__OS2__) || defined(__VMS__) || defined (__WXMAC__) +#if defined(__WINDOWS__) || defined(__OS2__) || defined(__VMS__) || defined(__WXMAC__) // Case INDEPENDENT path.CompareTo (path2, wxString::ignoreCase) == 0 #else @@ -294,9 +302,11 @@ wxString wxPathList::FindAbsoluteValidPath (const wxString& file) bool wxFileExists (const wxString& filename) { +#if defined(__WXPALMOS__) + return false; +#elif defined(__WIN32__) && !defined(__WXMICROWIN__) // we must use GetFileAttributes() instead of the ANSI C functions because // it can cope with network (UNC) paths unlike them -#if defined(__WIN32__) && !defined(__WXMICROWIN__) DWORD ret = ::GetFileAttributes(filename); return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY); @@ -663,7 +673,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin const wxChar *val; #ifndef __WXWINCE__ wxChar *tcp; - if (envname != WXSTRINGCAST NULL && (val = wxGetenv (WXSTRINGCAST envname)) != NULL && + if (!envname.empty() && (val = wxGetenv (WXSTRINGCAST envname)) != NULL && (tcp = wxStrstr (dest, val)) != NULL) { wxStrcpy (wxFileFunctionsBuffer, tcp + wxStrlen (val)); @@ -673,6 +683,8 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin wxStrcat (tcp, wxT("}")); wxStrcat (tcp, wxFileFunctionsBuffer); } +#else + wxUnusedVar(envname); #endif // Handle User's home (ignore root homes!) @@ -1001,6 +1013,9 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) #elif defined(__OS2__) if ( ::DosCopy(file2, file2, 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; #else // !Win32 wxStructStat fbuf; @@ -1080,7 +1095,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) bool wxRenameFile (const wxString& file1, const wxString& file2) { -#ifndef __WXWINCE__ +#if !defined(__WXWINCE__) && !defined(__WXPALMOS__) // Normal system call if ( wxRename (file1, file2) == 0 ) return true; @@ -1103,20 +1118,25 @@ bool wxRemoveFile(const wxString& file) || defined(__DMC__) \ || defined(__GNUWIN32__) \ || (defined(__MWERKS__) && defined(__MSL__)) - int res = wxRemove(file); + int res = wxRemove(file); #elif defined(__WXMAC__) - int res = unlink(wxFNCONV(file)); + int res = unlink(wxFNCONV(file)); +#elif defined(__WXPALMOS__) + int res = 1; + // TODO with VFSFileDelete() #else - int res = unlink(OS_FILENAME(file)); + int res = unlink(OS_FILENAME(file)); #endif - return res == 0; + return res == 0; } bool wxMkdir(const wxString& dir, int perm) { -#if defined(__WXMAC__) && !defined(__UNIX__) - return (mkdir( wxFNCONV(dir) , 0 ) == 0); +#if defined(__WXPALMOS__) + return false; +#elif defined(__WXMAC__) && !defined(__UNIX__) + return (mkdir( wxFNCONV(dir) , 0 ) == 0); #else // !Mac const wxChar *dirname = dir.c_str(); @@ -1160,23 +1180,22 @@ bool wxMkdir(const wxString& dir, int perm) bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) { -#ifdef __VMS__ +#if defined(__VMS__) return false; //to be changed since rmdir exists in VMS7.x #elif defined(__OS2__) return (::DosDeleteDir((PSZ)dir.c_str()) == 0); -#else - -#ifdef __WXWINCE__ +#elif defined(__WXWINCE__) return (CreateDirectory(dir, NULL) != 0); +#elif defined(__WXPALMOS__) + // TODO with VFSFileRename() + return false; #else return (wxRmDir(OS_FILENAME(dir)) == 0); #endif - -#endif } // does the path exists? (may have or not '/' or '\\' at the end) -bool wxPathExists(const wxChar *pszPathName) +bool wxDirExists(const wxChar *pszPathName) { wxString strPath(pszPathName); @@ -1200,11 +1219,15 @@ bool wxPathExists(const wxChar *pszPathName) strPath << _T('.'); #endif -#if defined(__WIN32__) && !defined(__WXMICROWIN__) +#if defined(__WXPALMOS__) + return false; +#elif defined(__WIN32__) && !defined(__WXMICROWIN__) // stat() can't cope with network paths DWORD ret = ::GetFileAttributes(strPath); return (ret != (DWORD)-1) && (ret & FILE_ATTRIBUTE_DIRECTORY); +#elif defined(__OS2__) + return (::DosSetCurrentDir(WXSTRINGCAST strPath)); #else // !__WIN32__ wxStructStat st; @@ -1221,6 +1244,7 @@ bool wxPathExists(const wxChar *pszPathName) // Get a temporary filename, opening and closing the file. wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) { +#if wxUSE_FILE wxString filename = wxFileName::CreateTempFileName(prefix); if ( filename.empty() ) return NULL; @@ -1231,11 +1255,15 @@ wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) buf = MYcopystring(filename); return buf; +#else + // wxFileName::CreateTempFileName needs wxFile class enabled + return NULL; +#endif } bool wxGetTempFileName(const wxString& prefix, wxString& buf) { - buf = wxFileName::CreateTempFileName(prefix); + buf = wxGetTempFileName(prefix); return !buf.empty(); } @@ -1304,7 +1332,13 @@ wxString wxFindNextFile() // copies into buf. wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) { -#ifdef __WXWINCE__ +#if defined(__WXPALMOS__) + // TODO ? + return NULL; +#elif defined(__WXWINCE__) + // TODO + wxUnusedVar(buf); + wxUnusedVar(sz); return NULL; #else if ( !buf ) @@ -1446,6 +1480,7 @@ bool wxSetWorkingDirectory(const wxString& d) #ifdef __WIN32__ #ifdef __WXWINCE__ // No equivalent in WinCE + wxUnusedVar(d); return false; #else return (bool)(SetCurrentDirectory(d) != 0); @@ -1556,7 +1591,9 @@ void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName, time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename) { -#ifdef __WXWINCE__ +#if defined(__WXPALMOS__) + return 0; +#elif defined(__WXWINCE__) FILETIME creationTime, lastAccessTime, lastWriteTime; HANDLE fileHandle = ::CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, 0, FILE_ATTRIBUTE_NORMAL, 0); @@ -1697,7 +1734,7 @@ int WXDLLEXPORT wxParseCommonDialogsFilter(const wxString& filterStr, wxArrayStr // autocompletion for( size_t j = 0 ; j < descriptions.GetCount() ; j++ ) { - if ( descriptions[j] == wxEmptyString && filters[j] != wxEmptyString ) + if ( descriptions[j].empty() && !filters[j].empty() ) { descriptions[j].Printf(_("Files (%s)"), filters[j].c_str()); } @@ -1858,43 +1895,73 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) // Return the type of an open file // -wxFileTypeEnum wxGetFileType(int fd) +// Some file types on some platforms seem seekable but in fact are not. +// The main use of this function is to allow such cases to be detected +// (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK). +// +// This is important for the archive streams, which benefit greatly from +// being able to seek on a stream, but which will produce corrupt archives +// if they unknowingly seek on a non-seekable stream. +// +// wxFILE_KIND_DISK is a good catch all return value, since other values +// disable features of the archive streams. Some other value must be returned +// for a file type that appears seekable but isn't. +// +// Known examples: +// * Pipes on Windows +// * Files on VMS with a record format other than StreamLF +// +wxFileKind wxGetFileKind(int fd) { - if (isatty(fd)) - return wxFILE_TYPE_TERMINAL; - -#if defined __WXMSW__ +#if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle switch (::GetFileType(wxGetOSFHandle(fd)) & ~FILE_TYPE_REMOTE) { + case FILE_TYPE_CHAR: + return wxFILE_KIND_TERMINAL; case FILE_TYPE_DISK: - return wxFILE_TYPE_DISK; + return wxFILE_KIND_DISK; case FILE_TYPE_PIPE: - return wxFILE_TYPE_PIPE; + return wxFILE_KIND_PIPE; } - return wxFILE_TYPE_UNKNOWN; + return wxFILE_KIND_UNKNOWN; + +#elif defined(__UNIX__) + if (isatty(fd)) + return wxFILE_KIND_TERMINAL; -#elif defined __UNIX__ struct stat st; fstat(fd, &st); if (S_ISFIFO(st.st_mode)) - return wxFILE_TYPE_PIPE; + return wxFILE_KIND_PIPE; if (!S_ISREG(st.st_mode)) - return wxFILE_TYPE_UNKNOWN; + return wxFILE_KIND_UNKNOWN; - #if defined __VMS__ + #if defined(__VMS__) if (st.st_fab_rfm != FAB$C_STMLF) - return wxFILE_TYPE_UNKNOWN; + return wxFILE_KIND_UNKNOWN; #endif - return wxFILE_TYPE_DISK; + return wxFILE_KIND_DISK; #else - if (lseek(fd, 0, SEEK_CUR) != -1) - return wxFILE_TYPE_DISK; - else - return wxFILE_TYPE_UNKNOWN; + #define wxFILEKIND_STUB + (void)fd; + return wxFILE_KIND_DISK; +#endif +} + +wxFileKind wxGetFileKind(FILE *fp) +{ + // Note: The watcom rtl dll doesn't have fileno (the static lib does). + // Should be fixed in version 1.4. +#if defined(wxFILEKIND_STUB) || \ + (defined(__WATCOMC__) && __WATCOMC__ <= 1230 && defined(__SW_BR)) + (void)fp; + return wxFILE_KIND_DISK; +#else + return wxGetFileKind(fileno(fp)); #endif }