]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filename.cpp
Another blind attempt to fix AltGr issues in wxSTC, and a context menu
[wxWidgets.git] / src / common / filename.cpp
index 34fafde83d8a2df7c3ba64b1e4a43bc85e02dee2..46f2d0c03de56d57596b75d296ac36bd4b80c927 100644 (file)
 #ifdef __UNIX_LIKE__
     #include <sys/types.h>
     #include <utime.h>
+    #include <sys/stat.h>
+    #include <unistd.h>
+#endif
+
+#ifdef __MWERKS__
+    #include <stat.h>
+    #include <unistd.h>
+    #include <unix.h>
 #endif
 
 // ----------------------------------------------------------------------------
@@ -61,7 +69,7 @@
 
 // small helper class which opens and closes the file - we use it just to get
 // a file handle for the given file name to pass it to some Win32 API function
-#ifdef __WIN32__
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
 
 class wxFileHandle
 {
@@ -113,19 +121,37 @@ private:
 // private functions
 // ----------------------------------------------------------------------------
 
-#ifdef __WIN32__
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
 
 // convert between wxDateTime and FILETIME which is a 64-bit value representing
 // the number of 100-nanosecond intervals since January 1, 1601.
 
-static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt)
+// the number of milliseconds between the Unix Epoch (January 1, 1970) and the
+// FILETIME reference point (January 1, 1601)
+static const wxLongLong FILETIME_EPOCH_OFFSET = wxLongLong(0xa97, 0x30b66800);
+
+static void ConvertFileTimeToWx(wxDateTime *dt, const FILETIME &ft)
 {
-    // TODO
+    wxLongLong ll(ft.dwHighDateTime, ft.dwLowDateTime);
+
+    // convert 100ns to ms
+    ll /= 10000;
+
+    // move it to our Epoch
+    ll -= FILETIME_EPOCH_OFFSET;
+
+    *dt = wxDateTime(ll);
 }
 
-static void ConvertFileTimeToWx(wxDateTime *dt, const FILETIME &ft)
+static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt)
 {
-    // TODO
+    // do the reverse of ConvertFileTimeToWx()
+    wxLongLong ll = dt.GetValue();
+    ll *= 10000;
+    ll += FILETIME_EPOCH_OFFSET;
+
+    ft->dwHighDateTime = ll.GetHi();
+    ft->dwLowDateTime = ll.GetLo();
 }
 
 #endif // __WIN32__
@@ -477,8 +503,8 @@ bool wxFileName::SameAs( const wxFileName &filepath, wxPathFormat format)
 /* static */
 bool wxFileName::IsCaseSensitive( wxPathFormat format )
 {
-    // only DOS filenames are case-sensitive
-    return GetFormat(format) != wxPATH_DOS;
+    // only DOS and OpenVMS filenames are case-sensitive
+    return GetFormat(format) != wxPATH_DOS && GetFormat(format) != wxPATH_VMS;
 }
 
 bool wxFileName::IsRelative( wxPathFormat format )
@@ -524,6 +550,10 @@ wxString wxFileName::GetPathSeparators(wxPathFormat format)
         case wxPATH_MAC:
             seps = wxFILE_SEP_PATH_MAC;
             break;
+       
+        case wxPATH_VMS:
+            seps = wxFILE_SEP_PATH_VMS;
+            break;
     }
 
     return seps;
@@ -626,6 +656,17 @@ wxString wxFileName::GetFullPath( wxPathFormat format ) const
         }
     }
     else
+    if (format == wxPATH_VMS)
+    {
+       ret += '[';
+        for (size_t i = 0; i < m_dirs.GetCount(); i++)
+        {
+            ret += '.';
+            ret += m_dirs[i];
+        }
+       ret += ']';
+    }
+    else
     {
         for (size_t i = 0; i < m_dirs.GetCount(); i++)
         {
@@ -791,8 +832,10 @@ wxPathFormat wxFileName::GetFormat( wxPathFormat format )
     {
 #if defined(__WXMSW__) || defined(__WXPM__)
         format = wxPATH_DOS;
-#elif defined(__WXMAC__)
+#elif defined(__WXMAC__) && !defined(__DARWIN__)
         format = wxPATH_MAC; 
+#elif defined(__VMS)
+        format = wxPATH_VMS; 
 #else
         format = wxPATH_UNIX;
 #endif
@@ -827,6 +870,18 @@ void wxFileName::SplitPath(const wxString& fullpath,
             posLastDot = wxString::npos;
         }
     }
+    else
+     if ( (posLastDot != wxString::npos) && (format == wxPATH_VMS) )
+    {
+        if ( (posLastDot == 0) ||
+             (fullpath[posLastDot - 1] == ']' ) )
+        {
+            // under OpenVMS, dot may be (and commonly is) the first character of
+            // the filename, don't treat the entire filename as extension in
+            // this case
+            posLastDot = wxString::npos;
+        }
+    }
 
     // if we do have a dot and a slash, check that the dot is in the name part
     if ( (posLastDot != wxString::npos) &&
@@ -899,9 +954,17 @@ bool wxFileName::SetTimes(const wxDateTime *dtCreate,
                           const wxDateTime *dtMod)
 {
 #if defined(__UNIX_LIKE__)
+    if ( !dtAccess && !dtMod )
+    {
+        // can't modify the creation time anyhow, don't try
+        return TRUE;
+    }
+
+    // if dtAccess or dtMod is not specified, use the other one (which must be
+    // non NULL because of the test above) for both times
     utimbuf utm;
-    utm.actime = dtAccess ? dtAccess : dtAccess->GetTicks();
-    utm.modtime = dtMod ? dtMod : dtMod->GetTicks();
+    utm.actime = dtAccess ? dtAccess->GetTicks() : dtMod->GetTicks();
+    utm.modtime = dtMod ? dtMod->GetTicks() : dtAccess->GetTicks();
     if ( utime(GetFullPath(), &utm) == 0 )
     {
         return TRUE;
@@ -959,7 +1022,20 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess,
                           wxDateTime *dtMod,
                           wxDateTime *dtChange) const
 {
-#if defined(__UNIX_LIKE__)
+#if defined(__UNIX_LIKE__) 
+    wxStructStat stBuf;
+    if ( wxStat(GetFullPath(), &stBuf) == 0 )
+    {
+        if ( dtAccess )
+            dtAccess->Set(stBuf.st_atime);
+        if ( dtMod )
+            dtMod->Set(stBuf.st_mtime);
+        if ( dtChange )
+            dtChange->Set(stBuf.st_ctime);
+
+        return TRUE;
+    }
+#elif defined(__WXMAC__)
     wxStructStat stBuf;
     if ( wxStat(GetFullPath(), &stBuf) == 0 )
     {