X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df5168c427b51f1ab2b3200a5c8f7626b3d24aae..05e1201cb5943fb9c75f5612e9fb9323358edab5:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 40af10e79a..8c6e4a7204 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "filefn.h" #endif @@ -54,9 +54,16 @@ #include "wx/mac/private.h" // includes mac headers #endif +#ifdef __WXWINCE__ +#include "wx/msw/wince/time.h" +#include "wx/msw/private.h" +#else #include +#endif -#ifndef __MWERKS__ +#ifdef __WXWINCE__ +// Nothing +#elif !defined(__MWERKS__) #include #include #else @@ -84,7 +91,7 @@ #include "wx/os2/private.h" #endif #if defined(__WINDOWS__) && !defined(__WXMICROWIN__) -#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) +#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__) #include #include #include @@ -121,7 +128,7 @@ #endif #ifdef __WINDOWS__ - #include + #include "wx/msw/wrapwin.h" #include "wx/msw/mslu.h" // for _getcwd @@ -189,25 +196,6 @@ const off_t wxInvalidOffset = (off_t)-1; // implementation // ============================================================================ -#if defined(__WXMAC__) && !defined(__DARWIN__) - -WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ) -{ - return stat( wxMacStringToCString( file_name ), buf ); -} - -WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode ) -{ - return access( wxMacStringToCString( pathname ), mode ); -} - -WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode ) -{ - return open( wxMacStringToCString( pathname ), flags, mode ); -} - -#endif - #ifdef wxNEED_WX_UNISTD_H WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ) @@ -248,12 +236,14 @@ static inline wxChar* MYcopystring(const wxChar* s) void wxPathList::Add (const wxString& path) { - wxStringList::Append (WXSTRINGCAST path); + wxStringList::Add (WXSTRINGCAST path); } // Add paths e.g. from the PATH environment variable void wxPathList::AddEnvList (const wxString& envVariable) { + // No environment variables on WinCE +#ifndef __WXWINCE__ static const wxChar PATH_TOKS[] = #ifdef __WINDOWS__ /* @@ -292,6 +282,7 @@ void wxPathList::AddEnvList (const wxString& envVariable) delete [] s; } +#endif } // Given a full filename (with path), ensure that that file can @@ -632,6 +623,8 @@ wxChar *wxExpandPath(wxChar *buf, const wxChar *name) } else # endif #endif + // No env variables on WinCE +#ifndef __WXWINCE__ #ifdef __WXMSW__ if (*s++ == wxT('$') && (*s == wxT('{') || *s == wxT(')'))) #else @@ -659,6 +652,8 @@ wxChar *wxExpandPath(wxChar *buf, const wxChar *name) s++; } } +#endif + // __WXWINCE__ } /* Expand ~ and ~user */ @@ -738,6 +733,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin // Handle environment const wxChar *val = (const wxChar *) NULL; +#ifndef __WXWINCE__ wxChar *tcp = (wxChar *) NULL; if (envname != WXSTRINGCAST NULL && (val = wxGetenv (WXSTRINGCAST envname)) != NULL && (tcp = wxStrstr (dest, val)) != NULL) @@ -749,6 +745,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin wxStrcat (tcp, wxT("}")); wxStrcat (tcp, wxFileFunctionsBuffer); } +#endif // Handle User's home (ignore root homes!) size_t len = 0; @@ -961,7 +958,7 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) } // create path string for return value - wxString result( thePath ) ; + wxString result( thePath , wxConvLocal) ; #else Handle myPath ; short length ; @@ -975,7 +972,7 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) (*myPath)[length-1] = 0 ; // create path string for return value - wxString result = wxMacMakeStringFromCString( *myPath ) ; + wxString result( *myPath , wxConvLocal) ; // free allocated handle ::HUnlock( myPath ) ; @@ -1021,7 +1018,7 @@ void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) #if wxUSE_UNICODE WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec ) { - return wxMacFilename2FSSpec( wxMacStringToCString( wxString( path ) ) , spec ) ; + return wxMacFilename2FSSpec( wxConvFile.cWC2MB(path) , spec ) ; } #endif @@ -1283,9 +1280,11 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) bool wxRenameFile (const wxString& file1, const wxString& file2) { - // Normal system call +#ifndef __WXWINCE__ + // Normal system call if ( wxRename (file1, file2) == 0 ) return TRUE; +#endif // Try to copy if (wxCopyFile(file1, file2)) { @@ -1340,7 +1339,11 @@ bool wxMkdir(const wxString& dir, int perm) #endif #else // !MSW, !DOS and !OS/2 VAC++ (void)perm; +#ifdef __WXWINCE__ + if ( !CreateDirectory(dirname, NULL) ) +#else if ( wxMkDir(wxFNSTRINGCAST wxFNCONV(dirname)) != 0 ) +#endif #endif // !MSW/MSW { wxLogSysError(_("Directory '%s' couldn't be created"), dirname); @@ -1355,15 +1358,15 @@ bool wxMkdir(const wxString& dir, int perm) bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) { #ifdef __VMS__ - return FALSE; //to be changed since rmdir exists in VMS7.x + return FALSE; //to be changed since rmdir exists in VMS7.x #elif defined(__WXPM__) - return (::DosDeleteDir((PSZ)dir.c_str()) == 0); + return (::DosDeleteDir((PSZ)dir.c_str()) == 0); #else -#ifdef __SALFORDC__ - return FALSE; // What to do? +#ifdef __WXWINCE__ + return (CreateDirectory(dir, NULL) != 0); #else - return (wxRmDir(OS_FILENAME(dir)) == 0); + return (wxRmDir(OS_FILENAME(dir)) == 0); #endif #endif @@ -1492,6 +1495,9 @@ wxString wxFindNextFile() // copies into buf. wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) { +#ifdef __WXWINCE__ + return NULL; +#else if ( !buf ) { buf = new wxChar[sz + 1]; @@ -1607,6 +1613,9 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) #if !wxUSE_UNICODE #undef cbuf #endif + +#endif + // __WXWINCE__ } wxString wxGetCwd() @@ -1622,37 +1631,42 @@ wxString wxGetCwd() bool wxSetWorkingDirectory(const wxString& d) { #if defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__) - return (chdir(wxFNSTRINGCAST d.fn_str()) == 0); + return (chdir(wxFNSTRINGCAST d.fn_str()) == 0); #elif defined(__WXPM__) - return (::DosSetCurrentDir((PSZ)d.c_str()) == 0); + return (::DosSetCurrentDir((PSZ)d.c_str()) == 0); #elif defined(__WINDOWS__) - + #ifdef __WIN32__ - return (bool)(SetCurrentDirectory(d) != 0); +#ifdef __WXWINCE__ + // No equivalent in WinCE + return FALSE; #else - // Must change drive, too. - bool isDriveSpec = ((strlen(d) > 1) && (d[1] == ':')); - if (isDriveSpec) - { - wxChar firstChar = d[0]; - - // To upper case - if (firstChar > 90) - firstChar = firstChar - 32; - - // To a drive number - unsigned int driveNo = firstChar - 64; - if (driveNo > 0) + return (bool)(SetCurrentDirectory(d) != 0); +#endif +#else + // Must change drive, too. + bool isDriveSpec = ((strlen(d) > 1) && (d[1] == ':')); + if (isDriveSpec) { - unsigned int noDrives; - _dos_setdrive(driveNo, &noDrives); + wxChar firstChar = d[0]; + + // To upper case + if (firstChar > 90) + firstChar = firstChar - 32; + + // To a drive number + unsigned int driveNo = firstChar - 64; + if (driveNo > 0) + { + unsigned int noDrives; + _dos_setdrive(driveNo, &noDrives); + } } - } - bool success = (chdir(WXSTRINGCAST d) == 0); - - return success; + bool success = (chdir(WXSTRINGCAST d) == 0); + + return success; #endif - + #endif } @@ -1660,7 +1674,9 @@ bool wxSetWorkingDirectory(const wxString& d) // On non-Windows platform, probably just return the empty string. wxString wxGetOSDirectory() { -#if defined(__WINDOWS__) && !defined(__WXMICROWIN__) +#ifdef __WXWINCE__ + return wxString(wxT("\\Windows")); +#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) wxChar buf[256]; GetWindowsDirectory(buf, 256); return wxString(buf); @@ -1733,10 +1749,44 @@ void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName, time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename) { +#ifdef __WXWINCE__ + FILETIME creationTime, lastAccessTime, lastWriteTime; + HANDLE fileHandle = ::CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, + 0, FILE_ATTRIBUTE_NORMAL, 0); + if (fileHandle == INVALID_HANDLE_VALUE) + return 0; + else + { + if (GetFileTime(fileHandle, & creationTime, & lastAccessTime, & lastWriteTime)) + { + CloseHandle(fileHandle); + + wxDateTime dateTime; + FILETIME ftLocal; + if ( !::FileTimeToLocalFileTime(&lastWriteTime, &ftLocal) ) + { + wxLogLastError(_T("FileTimeToLocalFileTime")); + } + + SYSTEMTIME st; + if ( !::FileTimeToSystemTime(&ftLocal, &st) ) + { + wxLogLastError(_T("FileTimeToSystemTime")); + } + + dateTime.Set(st.wDay, wxDateTime::Month(st.wMonth - 1), st.wYear, + st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); + return dateTime.GetTicks(); + } + else + return 0; + } +#else wxStructStat buf; wxStat( filename, &buf); return buf.st_mtime; +#endif }