Applied patch [ 601072 ] wxFileName::GetLongPath error & fix

By Michael Fielding (mfielding)

When using wxFileName::MakeRelativeTo with a new base of "x:\", the result is incorrect. It works fine when there is a subdirectory after x:\. I tracked this to a bug in GetLongPath; here is the fix.

Also, GetLongPath will now try and get as much long path as it can, failing only when part of the path cannot be found. eg

x:\existi~1\file not existing.new becomes
x:\existing directory\filenotexisting.new

instead of just staying the same.

Also, MakeRelative no longer makes filenames lowercase when it normalises them.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16886 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2002-08-31 11:42:12 +00:00
parent af49c4b8a2
commit b5b62eea2d

View File

@@ -971,8 +971,8 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format)
// get cwd only once - small time saving // get cwd only once - small time saving
wxString cwd = wxGetCwd(); wxString cwd = wxGetCwd();
Normalize(wxPATH_NORM_ALL, cwd, format); Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
fnBase.Normalize(wxPATH_NORM_ALL, cwd, format); fnBase.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
bool withCase = IsCaseSensitive(format); bool withCase = IsCaseSensitive(format);
@@ -1029,8 +1029,8 @@ bool wxFileName::SameAs(const wxFileName &filepath, wxPathFormat format)
// get cwd only once - small time saving // get cwd only once - small time saving
wxString cwd = wxGetCwd(); wxString cwd = wxGetCwd();
fn1.Normalize(wxPATH_NORM_ALL, cwd, format); fn1.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
fn2.Normalize(wxPATH_NORM_ALL, cwd, format); fn2.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
if ( fn1.GetFullPath() == fn2.GetFullPath() ) if ( fn1.GetFullPath() == fn2.GetFullPath() )
return TRUE; return TRUE;
@@ -1362,6 +1362,12 @@ wxString wxFileName::GetLongPath() const
WIN32_FIND_DATA findFileData; WIN32_FIND_DATA findFileData;
HANDLE hFind; HANDLE hFind;
if ( HasVolume() )
pathOut = GetVolume() +
GetVolumeSeparator(wxPATH_DOS) +
GetPathSeparator(wxPATH_DOS);
else
pathOut = wxEmptyString; pathOut = wxEmptyString;
wxArrayString dirs = GetDirs(); wxArrayString dirs = GetDirs();
@@ -1380,7 +1386,8 @@ wxString wxFileName::GetLongPath() const
if ( tmpPath.empty() ) if ( tmpPath.empty() )
continue; continue;
if ( tmpPath.Last() == wxT(':') ) // can't see this being necessary? MF
if ( tmpPath.Last() == GetVolumeSeparator(wxPATH_DOS) )
{ {
// Can't pass a drive and root dir to FindFirstFile, // Can't pass a drive and root dir to FindFirstFile,
// so continue to next dir // so continue to next dir
@@ -1392,8 +1399,12 @@ wxString wxFileName::GetLongPath() const
hFind = ::FindFirstFile(tmpPath, &findFileData); hFind = ::FindFirstFile(tmpPath, &findFileData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
{ {
// Error: return immediately with the original path // Error: most likely reason is that path doesn't exist, so
return path; // append any unprocessed parts and return
for ( i += 1; i < count; i++ )
tmpPath += wxFILE_SEP_PATH + dirs[i];
return tmpPath;
} }
pathOut += findFileData.cFileName; pathOut += findFileData.cFileName;