// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "filename.h"
#endif
#endif
#ifdef __EMX__
+#include <os2.h>
#define MAX_PATH _MAX_PATH
#endif
const wxString& cwd,
wxPathFormat format)
{
+ // deal with env vars renaming first as this may seriously change the path
+ if ( flags & wxPATH_NORM_ENV_VARS )
+ {
+ wxString pathOrig = GetFullPath(format);
+ wxString path = wxExpandEnvVars(pathOrig);
+ if ( path != pathOrig )
+ {
+ Assign(path);
+ }
+ }
+
+
// the existing path components
wxArrayString dirs = GetDirs();
}
}
- if ( flags & wxPATH_NORM_ENV_VARS )
- {
- dir = wxExpandEnvVars(dir);
- }
-
if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
{
dir.MakeLower();
// path components manipulation
// ----------------------------------------------------------------------------
+/* static */ bool wxFileName::IsValidDirComponent(const wxString& dir)
+{
+ if ( dir.empty() )
+ {
+ wxFAIL_MSG( _T("empty directory passed to wxFileName::InsertDir()") );
+
+ return false;
+ }
+
+ const size_t len = dir.length();
+ for ( size_t n = 0; n < len; n++ )
+ {
+ if ( dir[n] == GetVolumeSeparator() || IsPathSeparator(dir[n]) )
+ {
+ wxFAIL_MSG( _T("invalid directory component in wxFileName") );
+
+ return false;
+ }
+ }
+
+ return true;
+}
+
void wxFileName::AppendDir( const wxString &dir )
{
- m_dirs.Add( dir );
+ if ( IsValidDirComponent(dir) )
+ m_dirs.Add( dir );
}
void wxFileName::PrependDir( const wxString &dir )
{
- m_dirs.Insert( dir, 0 );
+ InsertDir(0, dir);
}
void wxFileName::InsertDir( int before, const wxString &dir )
{
- m_dirs.Insert( dir, before );
+ if ( IsValidDirComponent(dir) )
+ m_dirs.Insert( dir, before );
}
void wxFileName::RemoveDir( int pos )
fullpath += wxGetVolumeString(GetVolume(), format);
}
- // the leading character
- switch ( format )
+ const size_t dirCount = m_dirs.GetCount();
+ if ( dirCount )
{
- case wxPATH_MAC:
- if ( m_relative )
- fullpath += wxFILE_SEP_PATH_MAC;
- break;
+ // the leading character
+ switch ( format )
+ {
+ case wxPATH_MAC:
+ if ( m_relative )
+ fullpath += wxFILE_SEP_PATH_MAC;
+ break;
- case wxPATH_DOS:
- if (!m_relative)
- fullpath += wxFILE_SEP_PATH_DOS;
- break;
+ case wxPATH_DOS:
+ if ( !m_relative )
+ fullpath += wxFILE_SEP_PATH_DOS;
+ break;
- default:
- wxFAIL_MSG( wxT("Unknown path format") );
- // fall through
+ default:
+ wxFAIL_MSG( wxT("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('~') )
+ case wxPATH_UNIX:
+ if ( !m_relative )
{
- fullpath += wxFILE_SEP_PATH_UNIX;
+ // normally the absolute file names start with a slash
+ // with one exception: the ones like "~/foo.bar" don't
+ // have it
+ if ( m_dirs[0u] != _T('~') )
+ {
+ fullpath += wxFILE_SEP_PATH_UNIX;
+ }
}
- }
- break;
+ 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;
- }
+ 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
- size_t dirCount = m_dirs.GetCount();
- if ( dirCount )
- {
+ // then concatenate all the path components using the path separator
if ( format == wxPATH_VMS )
{
fullpath += wxT('[');
fullpath += wxT(']');
}
}
+ else // no directories
+ {
+ // still append path separator if requested
+ if ( flags & wxPATH_GET_SEPARATOR )
+ fullpath += GetPathSeparator(format);
+ }
return fullpath;
}
ok = ::GetShortPathName
(
path,
- pathOut.GetWriteBuf(sz),
+ wxStringBuffer(pathOut, sz),
sz
) != 0;
- pathOut.UngetWriteBuf();
}
if (ok)
return pathOut;
ok = (*s_pfnGetLongPathName)
(
path,
- pathOut.GetWriteBuf(sz),
+ wxStringBuffer(pathOut, sz),
sz
) != 0;
- pathOut.UngetWriteBuf();
-
success = true;
}
}
fullpath[posFirstSlash] = wxFILE_SEP_DSK;
// UNC paths are always absolute, right? (FIXME)
- fullpath.insert(posFirstSlash + 1, wxFILE_SEP_PATH_DOS);
+ fullpath.insert(posFirstSlash + 1, 1, wxFILE_SEP_PATH_DOS);
}
}
}