+ return false;
+}
+
+#endif // wxUSE_DATETIME
+
+
+// ----------------------------------------------------------------------------
+// file size functions
+// ----------------------------------------------------------------------------
+
+#if wxUSE_LONGLONG
+
+/* static */
+wxULongLong wxFileName::GetSize(const wxString &filename)
+{
+ if (!wxFileExists(filename))
+ return wxInvalidSize;
+
+#if defined(__WIN32__)
+ wxFileHandle f(filename, wxFileHandle::ReadAttr);
+ if (!f.IsOk())
+ return wxInvalidSize;
+
+ DWORD lpFileSizeHigh;
+ DWORD ret = GetFileSize(f, &lpFileSizeHigh);
+ if ( ret == INVALID_FILE_SIZE && ::GetLastError() != NO_ERROR )
+ return wxInvalidSize;
+
+ return wxULongLong(lpFileSizeHigh, ret);
+#else // ! __WIN32__
+ wxStructStat st;
+ if (wxStat( filename, &st) != 0)
+ return wxInvalidSize;
+ return wxULongLong(st.st_size);
+#endif
+}
+
+/* static */
+wxString wxFileName::GetHumanReadableSize(const wxULongLong &bs,
+ const wxString &nullsize,
+ int precision,
+ wxSizeConvention conv)
+{
+ // deal with trivial case first
+ if ( bs == 0 || bs == wxInvalidSize )
+ return nullsize;
+
+ // depending on the convention used the multiplier may be either 1000 or
+ // 1024 and the binary infix may be empty (for "KB") or "i" (for "KiB")
+ double multiplier = 1024.;
+ wxString biInfix;
+
+ switch ( conv )
+ {
+ case wxSIZE_CONV_TRADITIONAL:
+ // nothing to do, this corresponds to the default values of both
+ // the multiplier and infix string
+ break;
+
+ case wxSIZE_CONV_IEC:
+ biInfix = "i";
+ break;
+
+ case wxSIZE_CONV_SI:
+ multiplier = 1000;
+ break;
+ }
+
+ const double kiloByteSize = multiplier;
+ const double megaByteSize = multiplier * kiloByteSize;
+ const double gigaByteSize = multiplier * megaByteSize;
+ const double teraByteSize = multiplier * gigaByteSize;
+
+ const double bytesize = bs.ToDouble();
+
+ wxString result;
+ if ( bytesize < kiloByteSize )
+ result.Printf("%s B", bs.ToString());
+ else if ( bytesize < megaByteSize )
+ result.Printf("%.*f K%sB", precision, bytesize/kiloByteSize, biInfix);
+ else if (bytesize < gigaByteSize)
+ result.Printf("%.*f M%sB", precision, bytesize/megaByteSize, biInfix);
+ else if (bytesize < teraByteSize)
+ result.Printf("%.*f G%sB", precision, bytesize/gigaByteSize, biInfix);
+ else
+ result.Printf("%.*f T%sB", precision, bytesize/teraByteSize, biInfix);
+
+ return result;
+}
+
+wxULongLong wxFileName::GetSize() const
+{
+ return GetSize(GetFullPath());
+}
+
+wxString wxFileName::GetHumanReadableSize(const wxString& failmsg,
+ int precision,
+ wxSizeConvention conv) const
+{
+ return GetHumanReadableSize(GetSize(), failmsg, precision, conv);
+}
+
+#endif // wxUSE_LONGLONG
+
+// ----------------------------------------------------------------------------
+// Mac-specific functions
+// ----------------------------------------------------------------------------
+
+#if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON
+
+namespace
+{
+
+class MacDefaultExtensionRecord
+{
+public:
+ MacDefaultExtensionRecord()
+ {
+ m_type =
+ m_creator = 0 ;
+ }
+
+ // default copy ctor, assignment operator and dtor are ok
+
+ MacDefaultExtensionRecord(const wxString& ext, OSType type, OSType creator)
+ : m_ext(ext)
+ {
+ m_type = type;
+ m_creator = creator;
+ }
+
+ wxString m_ext;
+ OSType m_type;
+ OSType m_creator;
+};
+
+WX_DECLARE_OBJARRAY(MacDefaultExtensionRecord, MacDefaultExtensionArray);
+
+bool gMacDefaultExtensionsInited = false;
+
+#include "wx/arrimpl.cpp"
+
+WX_DEFINE_EXPORTED_OBJARRAY(MacDefaultExtensionArray);
+
+MacDefaultExtensionArray gMacDefaultExtensions;
+
+// load the default extensions
+const MacDefaultExtensionRecord gDefaults[] =
+{
+ MacDefaultExtensionRecord( "txt", 'TEXT', 'ttxt' ),
+ MacDefaultExtensionRecord( "tif", 'TIFF', '****' ),
+ MacDefaultExtensionRecord( "jpg", 'JPEG', '****' ),
+};
+
+void MacEnsureDefaultExtensionsLoaded()
+{
+ if ( !gMacDefaultExtensionsInited )
+ {
+ // we could load the pc exchange prefs here too
+ for ( size_t i = 0 ; i < WXSIZEOF( gDefaults ) ; ++i )
+ {
+ gMacDefaultExtensions.Add( gDefaults[i] ) ;
+ }
+ gMacDefaultExtensionsInited = true;
+ }
+}
+
+} // anonymous namespace
+
+bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator )
+{
+ FSRef fsRef ;
+ FSCatalogInfo catInfo;
+ FileInfo *finfo ;
+
+ if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr )
+ {
+ if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
+ {
+ finfo = (FileInfo*)&catInfo.finderInfo;
+ finfo->fileType = type ;
+ finfo->fileCreator = creator ;
+ FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ;
+ return true ;
+ }
+ }
+ return false ;
+}
+
+bool wxFileName::MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) const
+{
+ FSRef fsRef ;
+ FSCatalogInfo catInfo;
+ FileInfo *finfo ;
+
+ if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr )
+ {
+ if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
+ {
+ finfo = (FileInfo*)&catInfo.finderInfo;
+ *type = finfo->fileType ;
+ *creator = finfo->fileCreator ;
+ return true ;
+ }
+ }
+ return false ;
+}
+
+bool wxFileName::MacSetDefaultTypeAndCreator()
+{
+ wxUint32 type , creator ;
+ if ( wxFileName::MacFindDefaultTypeAndCreator(GetExt() , &type ,
+ &creator ) )
+ {
+ return MacSetTypeAndCreator( type , creator ) ;
+ }
+ return false;
+}
+
+bool wxFileName::MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator )
+{
+ MacEnsureDefaultExtensionsLoaded() ;
+ wxString extl = ext.Lower() ;
+ for( int i = gMacDefaultExtensions.Count() - 1 ; i >= 0 ; --i )
+ {
+ if ( gMacDefaultExtensions.Item(i).m_ext == extl )
+ {
+ *type = gMacDefaultExtensions.Item(i).m_type ;
+ *creator = gMacDefaultExtensions.Item(i).m_creator ;
+ return true ;
+ }
+ }
+ return false ;
+}
+
+void wxFileName::MacRegisterDefaultTypeAndCreator( const wxString& ext , wxUint32 type , wxUint32 creator )
+{
+ MacEnsureDefaultExtensionsLoaded();
+ MacDefaultExtensionRecord rec(ext.Lower(), type, creator);
+ gMacDefaultExtensions.Add( rec );