X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4175794e0361c78ad63984cd01e4378677803dbc..e1b93ccbdce1d7b757f6d6180b710214e6277a00:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index be964d3111..05a84579cf 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -146,7 +146,7 @@ public: m_hFile = ::CreateFile ( filename, // name - mode == Read ? GENERIC_READ // access mask + mode == Read ? GENERIC_READ // access mask : GENERIC_WRITE, 0, // no sharing NULL, // no secutity attr @@ -415,7 +415,7 @@ void wxFileName::Assign(const wxString& fullpathOrig, _T("the path shouldn't contain file name nor extension") ); #else // !__WXDEBUG__ - SplitPath(fullname, NULL /* no path */, &name, &ext, format); + SplitPath(fullname, NULL /* no path */, &name, &ext, format); SplitPath(fullpath, &volume, &path, NULL, NULL, format); #endif // __WXDEBUG__/!__WXDEBUG__ @@ -751,10 +751,10 @@ bool wxFileName::Mkdir( const wxString& dir, int perm, int flags ) filename.AssignDir(dir); wxString currPath; - if ( filename.HasVolume()) - { + if ( filename.HasVolume()) + { currPath << wxGetVolumeString(filename.GetVolume(), wxPATH_NATIVE); - } + } wxArrayString dirs = filename.GetDirs(); size_t count = dirs.GetCount(); @@ -912,6 +912,11 @@ bool wxFileName::Normalize(int flags, m_ext.MakeLower(); } + // we do have the path now + // + // NB: need to do this before (maybe) calling Assign() below + m_relative = FALSE; + #if defined(__WIN32__) if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) ) { @@ -919,9 +924,6 @@ bool wxFileName::Normalize(int flags, } #endif // Win32 - // we do have the path now - m_relative = FALSE; - return TRUE; } @@ -991,7 +993,7 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format) if ( m_dirs.IsEmpty() && IsDir() ) { m_dirs.Add(_T('.')); - } + } } m_relative = TRUE; @@ -1144,20 +1146,40 @@ wxString wxFileName::GetPath( int flags, wxPathFormat format ) const } // the leading character - if ( format == wxPATH_MAC ) - { - if ( m_relative ) - fullpath += wxFILE_SEP_PATH_MAC; - } - else if ( format == wxPATH_DOS ) + switch ( format ) { - if (!m_relative) - fullpath += wxFILE_SEP_PATH_DOS; - } - else if ( format == wxPATH_UNIX ) - { - if (!m_relative) - fullpath += wxFILE_SEP_PATH_UNIX; + case wxPATH_MAC: + if ( m_relative ) + fullpath += wxFILE_SEP_PATH_MAC; + break; + + case wxPATH_DOS: + if (!m_relative) + fullpath += wxFILE_SEP_PATH_DOS; + break; + + default: + wxFAIL_MSG( _T("unknown path format") ); + // fall through + + case wxPATH_UNIX: + if ( !m_relative ) + { + // normally the absolute file names starts with a slash with + // one exception: file names like "~/foo.bar" don't have it + if ( m_dirs.IsEmpty() || m_dirs[0u] != _T('~') ) + { + fullpath += wxFILE_SEP_PATH_UNIX; + } + } + break; + + case wxPATH_VMS: + // no leading character here but use this place to unset + // wxPATH_GET_SEPARATOR flag: under VMS it doesn't make sense as, + // if I understand correctly, there should never be a dot before + // the closing bracket + flags &= ~wxPATH_GET_SEPARATOR; } // then concatenate all the path components using the path separator @@ -1174,9 +1196,15 @@ wxString wxFileName::GetPath( int flags, wxPathFormat format ) const switch (format) { case wxPATH_MAC: - if (m_dirs[i] == wxT(".")) - break; - if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing + if ( m_dirs[i] == wxT(".") ) + { + // skip appending ':', this shouldn't be done in this + // case as "::" is interpreted as ".." under Unix + continue; + } + + // convert back from ".." to nothing + if ( m_dirs[i] != wxT("..") ) fullpath += m_dirs[i]; break; @@ -1191,12 +1219,14 @@ wxString wxFileName::GetPath( int flags, wxPathFormat format ) const case wxPATH_VMS: // TODO: What to do with ".." under VMS - if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing + + // convert back from ".." to nothing + if ( m_dirs[i] != wxT("..") ) fullpath += m_dirs[i]; break; } - if ( i != dirCount - 1 ) + if ( (flags & wxPATH_GET_SEPARATOR) || (i != dirCount - 1) ) fullpath += GetPathSeparator(format); } @@ -1206,11 +1236,6 @@ wxString wxFileName::GetPath( int flags, wxPathFormat format ) const } } - if ( (flags & wxPATH_GET_SEPARATOR) && !fullpath.empty() ) - { - fullpath += GetPathSeparator(format); - } - return fullpath; } @@ -1269,6 +1294,9 @@ wxString wxFileName::GetLongPath() const if ( !s_triedToLoad ) { + // suppress the errors about missing GetLongPathName[AW] + wxLogNull noLog; + s_triedToLoad = TRUE; wxDynamicLibrary dllKernel(_T("kernel32")); if ( dllKernel.IsLoaded() ) @@ -1306,6 +1334,7 @@ wxString wxFileName::GetLongPath() const } } } + if (success) return pathOut; #endif // wxUSE_DYNAMIC_LOADER @@ -1649,16 +1678,16 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess, FILETIME ftAccess, ftCreate, ftWrite; if ( ::GetFileTime(fh, - dtMod ? &ftCreate : NULL, + dtCreate ? &ftCreate : NULL, dtAccess ? &ftAccess : NULL, - dtCreate ? &ftWrite : NULL) ) + dtMod ? &ftWrite : NULL) ) { - if ( dtMod ) - ConvertFileTimeToWx(dtMod, ftCreate); + if ( dtCreate ) + ConvertFileTimeToWx(dtCreate, ftCreate); if ( dtAccess ) ConvertFileTimeToWx(dtAccess, ftAccess); - if ( dtCreate ) - ConvertFileTimeToWx(dtCreate, ftWrite); + if ( dtMod ) + ConvertFileTimeToWx(dtMod, ftWrite); return TRUE; } @@ -1675,41 +1704,64 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess, #ifdef __WXMAC__ const short kMacExtensionMaxLength = 16 ; -typedef struct +class MacDefaultExtensionRecord { +public : + MacDefaultExtensionRecord() + { + m_ext[0] = 0 ; + m_type = m_creator = NULL ; + } + MacDefaultExtensionRecord( const MacDefaultExtensionRecord& from ) + { + strcpy( m_ext , from.m_ext ) ; + m_type = from.m_type ; + m_creator = from.m_creator ; + } + MacDefaultExtensionRecord( char * extension , OSType type , OSType creator ) + { + strncpy( m_ext , extension , kMacExtensionMaxLength ) ; + m_ext[kMacExtensionMaxLength] = 0 ; + m_type = type ; + m_creator = creator ; + } char m_ext[kMacExtensionMaxLength] ; OSType m_type ; OSType m_creator ; -} MacDefaultExtensionRecord ; +} ; #include "wx/dynarray.h" WX_DECLARE_OBJARRAY(MacDefaultExtensionRecord, MacDefaultExtensionArray) ; + +bool gMacDefaultExtensionsInited = false ; + #include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(MacDefaultExtensionArray) ; + +WX_DEFINE_EXPORTED_OBJARRAY(MacDefaultExtensionArray) ; MacDefaultExtensionArray gMacDefaultExtensions ; -bool gMacDefaultExtensionsInited = false ; static void MacEnsureDefaultExtensionsLoaded() { if ( !gMacDefaultExtensionsInited ) { + // load the default extensions - MacDefaultExtensionRecord defaults[] = + MacDefaultExtensionRecord defaults[1] = { - { "txt" , 'TEXT' , 'ttxt' } , - + MacDefaultExtensionRecord( "txt" , 'TEXT' , 'ttxt' ) , + } ; // we could load the pc exchange prefs here too - + for ( int i = 0 ; i < WXSIZEOF( defaults ) ; ++i ) { gMacDefaultExtensions.Add( defaults[i] ) ; - } + } gMacDefaultExtensionsInited = true ; } } -bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) +bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) { FInfo fndrInfo ; FSSpec spec ; @@ -1723,7 +1775,7 @@ bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) return true ; } -bool wxFileName::MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) +bool wxFileName::MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) { FInfo fndrInfo ; FSSpec spec ; @@ -1747,7 +1799,7 @@ bool wxFileName::MacSetDefaultTypeAndCreator() return false; } -bool wxFileName::MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator ) +bool wxFileName::MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator ) { MacEnsureDefaultExtensionsLoaded() ; wxString extl = ext.Lower() ;