Add a new function to return a path with correct casing. Remove the get[short/long...
authorBrandon Turner <turnerb7@msu.edu>
Sun, 30 Oct 2005 17:50:03 +0000 (17:50 +0000)
committerBrandon Turner <turnerb7@msu.edu>
Sun, 30 Oct 2005 17:50:03 +0000 (17:50 +0000)
svn path=/trunk/; revision=18889

reactos/subsys/system/cmd/cmd.h
reactos/subsys/system/cmd/internal.c
reactos/subsys/system/cmd/misc.c

index 3185d7d..dc0bd57 100644 (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
index c8e62e8..dad875c 100644 (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) 
@@ -395,19 +395,19 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
                _tcscat(szFinalPath,f.cFileName);      
                
                if ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==  FILE_ATTRIBUTE_DIRECTORY)
-    {                         
+               {                      
                        if(!SetRootPath(szFinalPath))
                        {
                                /* Change for /D */
                                if(bChangeDrive)
-        {   
-           _tcsupr(szFinalPath); 
-           GetLongPathName(szFinalPath, szPath, MAX_PATH);  
-                                        SetCurrentDirectory(szPath);
-        }
+                               {   
+                                       _tcsupr(szFinalPath);   
+                                       GetPathCase(szFinalPath, szPath);
+                                       SetCurrentDirectory(szPath);
+                               }
                                return 0;
                        }
-      
+
                }
        }while(FindNextFile (hFile, &f));
  
index bb71081..d581f62 100644 (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