more fixes for volume names handling

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12783 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-12-01 02:28:51 +00:00
parent 1918b6f789
commit 52dbd056d2
2 changed files with 83 additions and 47 deletions

View File

@@ -129,8 +129,7 @@ public:
Assign(_T(""), path, name, ext, format);
}
void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE)
{ Assign(dir, _T(""), format); }
void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE);
// assorted assignment operators

View File

@@ -244,14 +244,20 @@ void wxFileName::Assign(const wxString& fullpath,
Assign(volume, path, name, ext, format);
}
void wxFileName::Assign(const wxString& path,
void wxFileName::Assign(const wxString& fullpath,
const wxString& fullname,
wxPathFormat format)
{
wxString name, ext;
wxString volume, path, name, ext;
SplitPath(fullname, NULL /* no path */, &name, &ext, format);
SplitPath(fullpath, &volume, &path, NULL, NULL, format);
Assign(path, name, ext, format);
Assign(volume, path, name, ext, format);
}
void wxFileName::AssignDir(const wxString& dir, wxPathFormat format)
{
Assign(dir, _T(""), format);
}
void wxFileName::Clear()
@@ -429,6 +435,20 @@ bool wxFileName::Normalize(wxPathNormalize flags,
curDir.AssignCwd();
else
curDir.AssignDir(cwd);
// the path may be not absolute because it doesn't have the volume name
// but in this case we shouldn't modify the directory components of it
// but just set the current volume
if ( !HasVolume() && curDir.HasVolume() )
{
SetVolume(curDir.GetVolume());
if ( IsAbsolute() )
{
// yes, it was the case - we don't need curDir then
curDir.Clear();
}
}
}
// handle ~ stuff under Unix only
@@ -446,6 +466,7 @@ bool wxFileName::Normalize(wxPathNormalize flags,
}
}
// transform relative path into abs one
if ( curDir.IsOk() )
{
wxArrayString dirsNew = curDir.GetDirs();
@@ -508,12 +529,12 @@ bool wxFileName::Normalize(wxPathNormalize flags,
m_ext.MakeLower();
}
#if defined(__WXMSW__) && defined(__WIN32__)
if (flags & wxPATH_NORM_LONG)
#if defined(__WIN32__)
if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) )
{
Assign(GetLongPath());
}
#endif
#endif // Win32
return TRUE;
}
@@ -556,19 +577,10 @@ bool wxFileName::IsAbsolute( wxPathFormat format )
return FALSE;
}
switch ( GetFormat(format) )
format = GetFormat(format);
if ( format == wxPATH_UNIX )
{
case wxPATH_DOS:
case wxPATH_VMS:
case wxPATH_MAC:
// must have the drive
return !m_volume.empty();
default:
wxFAIL_MSG( _T("unknown wxPATH_XXX style") );
// fall through
case wxPATH_UNIX:
const wxString& str = m_dirs[0u];
if ( str.empty() )
{
@@ -582,6 +594,29 @@ bool wxFileName::IsAbsolute( wxPathFormat format )
return IsPathSeparator(ch, format) || ch == _T('~');
}
else // !Unix
{
// must have the drive
if ( m_volume.empty() )
return FALSE;
switch ( format )
{
default:
wxFAIL_MSG( _T("unknown wxPATH_XXX style") );
// fall through
case wxPATH_DOS:
return m_dirs[0u].empty();
case wxPATH_VMS:
// TODO: what is the relative path format here?
return TRUE;
case wxPATH_MAC:
return !m_dirs[0u].empty();
}
}
}
/* static */
@@ -808,9 +843,10 @@ wxString wxFileName::GetShortPath() const
// Return the long form of the path (returns identity on non-Windows platforms)
wxString wxFileName::GetLongPath() const
{
#if defined(__WXMSW__) && defined(__WIN32__) && !defined(__WXMICROWIN__)
wxString path(GetFullPath());
wxString pathOut;
wxString pathOut,
path = GetFullPath();
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
bool success = FALSE;
// VZ: this code was disabled, why?
@@ -876,16 +912,19 @@ wxString wxFileName::GetLongPath() const
wxArrayString dirs = GetDirs();
dirs.Add(GetFullName());
size_t count = dirs.GetCount();
size_t i;
wxString tmpPath;
for ( i = 0; i < count; i++ )
size_t count = dirs.GetCount();
for ( size_t i = 0; i < count; i++ )
{
// We're using pathOut to collect the long-name path,
// but using a temporary for appending the last path component which may be short-name
// We're using pathOut to collect the long-name path, but using a
// temporary for appending the last path component which may be
// short-name
tmpPath = pathOut + dirs[i];
if ( tmpPath.empty() )
continue;
if ( tmpPath.Last() == wxT(':') )
{
// Can't pass a drive and root dir to FindFirstFile,
@@ -901,8 +940,7 @@ wxString wxFileName::GetLongPath() const
// Error: return immediately with the original path
return path;
}
else
{
pathOut += findFileData.cFileName;
if ( (i < (count-1)) )
pathOut += wxFILE_SEP_PATH;
@@ -910,12 +948,11 @@ wxString wxFileName::GetLongPath() const
::FindClose(hFind);
}
}
}
#else // !Win32
pathOut = path;
#endif // Win32/!Win32
return pathOut;
#else
return GetFullPath();
#endif
}
wxPathFormat wxFileName::GetFormat( wxPathFormat format )