Add a new function to return a path with correct casing. Remove the get[short/long]pathname hack that was there before to do it.

svn path=/trunk/; revision=18889
This commit is contained in:
Brandon Turner 2005-10-30 17:50:03 +00:00
parent 23d5494796
commit 7aebf134dc
3 changed files with 50 additions and 9 deletions

View file

@ -300,6 +300,7 @@ BOOL IsValidPathName (LPCTSTR);
BOOL IsExistingFile (LPCTSTR);
BOOL IsExistingDirectory (LPCTSTR);
BOOL FileGetString (HANDLE, LPTSTR, INT);
VOID GetPathCase(TCHAR *, TCHAR *);
#define PROMPT_NO 0
#define PROMPT_YES 1

View file

@ -241,8 +241,8 @@ BOOL SetRootPath(TCHAR *InPath)
/* The use of both of these together will correct the case of a path
where as one alone or GetFullPath will not. Exameple:
c:\windows\SYSTEM32 => C:\WINDOWS\system32 */
GetShortPathName(OutPathTemp, OutPathTemp2, MAX_PATH);
GetLongPathName(OutPathTemp2, OutPath, MAX_PATH);
GetFullPathName(OutPathTemp, MAX_PATH, OutPathTemp2, NULL);
GetPathCase(OutPathTemp2, OutPath);
fail = SetCurrentDirectory(OutPath);
if (!fail)
@ -402,7 +402,7 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
if(bChangeDrive)
{
_tcsupr(szFinalPath);
GetLongPathName(szFinalPath, szPath, MAX_PATH);
GetPathCase(szFinalPath, szPath);
SetCurrentDirectory(szPath);
}
return 0;

View file

@ -68,6 +68,46 @@ TCHAR cgetchar (VOID)
#endif /* _UNICODE */
}
/*
* Takes a path in and returns it with the correct case of the letters
*/
VOID GetPathCase( TCHAR * Path, TCHAR * OutPath)
{
INT i = 0;
_tcscpy(OutPath, _T(""));
TCHAR TempPath[MAX_PATH];
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
_tcscpy(TempPath, _T(""));
for(i = 0; i < _tcslen(Path); i++)
{
if(Path[i] != _T('\\'))
{
_tcsncat(TempPath, &Path[i], 1);
if(i != _tcslen(Path) - 1)
continue;
}
/* Handle the base part of the path different.
Because if you put it into findfirstfile, it will
return your current folder */
if(_tcslen(TempPath) == 2 && TempPath[1] == _T(':'))
{
_tcscat(OutPath, TempPath);
_tcscat(OutPath, _T("\\"));
_tcscat(TempPath, _T("\\"));
}
else
{
hFind = FindFirstFile(TempPath,&FindFileData);
_tcscat(TempPath, _T("\\"));
_tcscat(OutPath, FindFileData.cFileName);
_tcscat(OutPath, _T("\\"));
CloseHandle(hFind);
}
}
}
/*
* Check if Ctrl-Break was pressed during the last calls