uncpath.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "uncpath.h"
  4. //
  5. // BUGBUG:  Integrate this (or replace it) with the new CPath stuff
  6. //          in pathstr.cpp.  
  7. //
  8. //-----------------------------------------------------------------------------
  9. // class UNCPath
  10. //-----------------------------------------------------------------------------
  11. //
  12. // UNCPath ctor.
  13. // Initialize a UNCPath object with a UNC path string. 
  14. // (i.e. "\worfntspecs" or "\worfntspecsmyfilesfoo.doc")
  15. //
  16. UNCPath::UNCPath(
  17.     LPCTSTR pszUNCPath
  18.     )
  19. {
  20.     *this = pszUNCPath;
  21. }
  22. //
  23. // Retrieve the UNCPath string formatted as "\worfntspecs" or
  24. // "\worfntspecsmyfilesfoo.doc".  Depends on what the object
  25. // was initialized with.
  26. //
  27. void
  28. UNCPath::GetFullPath(
  29.     CString *pstrPath
  30.     ) const
  31. {
  32.     DBGASSERT((NULL != pstrPath));
  33.     if (m_strServer.IsEmpty() || m_strShare.IsEmpty())
  34.     {
  35.         pstrPath->Empty();
  36.     }
  37.     else
  38.     {
  39.         //
  40.         // Add the basic "\servershare" part.
  41.         //
  42.         pstrPath->Format(TEXT("\\%1\%2"), (LPCTSTR)m_strServer, (LPCTSTR)m_strShare);
  43.         if (!m_strPath.IsEmpty())
  44.         {
  45.             //
  46.             // There's a path string.
  47.             //
  48.             *pstrPath += m_strPath;
  49.             if (!m_strFile.IsEmpty())
  50.             {
  51.                 //
  52.                 // There's also a file name.
  53.                 //
  54.                 *pstrPath += CString(TEXT("\"));
  55.                 *pstrPath += m_strFile;
  56.             }
  57.         }
  58.     }
  59. }
  60. UNCPath& 
  61. UNCPath::operator = (
  62.     LPCTSTR pszUNCPath
  63.     )
  64. {
  65.     m_strServer.Empty();
  66.     m_strShare.Empty();
  67.     m_strPath.Empty();
  68.     m_strFile.Empty();
  69.     if (TEXT('\') == *pszUNCPath &&
  70.         TEXT('\') == *(pszUNCPath + 1))
  71.     {
  72.         TCHAR chSaved   = TEXT('');
  73.         LPTSTR pszStart = (LPTSTR)pszUNCPath + 2;
  74.         LPTSTR pszEnd;
  75.         //
  76.         // Get the server name.
  77.         //
  78.         for (pszEnd = pszStart; *pszEnd && TEXT('\') != *pszEnd; pszEnd = CharNext(pszEnd))
  79.             NULL;
  80.             
  81.         SWAP(chSaved, *pszEnd);
  82.         m_strServer = pszStart;
  83.         SWAP(chSaved, *pszEnd);
  84.         if (TEXT('') == *pszEnd)
  85.             return *this;
  86.         //
  87.         // Get the share name.
  88.         //
  89.         pszStart = CharNext(pszEnd);
  90.         for (pszEnd = pszStart; *pszEnd && TEXT('\') != *pszEnd; pszEnd = CharNext(pszEnd))
  91.             NULL;
  92.         SWAP(chSaved, *pszEnd);
  93.         m_strShare = pszStart;
  94.         SWAP(chSaved, *pszEnd);
  95.         if (TEXT('') == *pszEnd)
  96.             return *this;
  97.         //
  98.         // Get the path string.
  99.         //
  100.         LPTSTR pszLastSlash = pszStart;
  101.         for (pszStart = pszEnd; *pszEnd; pszEnd = CharNext(pszEnd))
  102.         {
  103.             if (TEXT('\') == *pszEnd)
  104.                 pszLastSlash = pszEnd;
  105.         }
  106.         pszEnd = pszLastSlash;
  107.         SWAP(chSaved, *pszEnd);
  108.         m_strPath = pszStart;
  109.         SWAP(chSaved, *pszEnd);
  110.         if (TEXT('') == *pszEnd)
  111.             return *this;
  112.         //
  113.         // Get the filename and extension.
  114.         //
  115.         pszStart = CharNext(pszEnd);
  116.         m_strFile = pszStart;
  117.     }
  118.     return *this;
  119. }
  120. bool 
  121. UNCPath::operator == (
  122.     const UNCPath& rhs
  123.     ) const
  124. {
  125.     return ((0 == m_strServer.CompareNoCase(rhs.m_strServer)) &&
  126.             (0 == m_strShare.CompareNoCase(rhs.m_strShare)) &&
  127.             (0 == m_strPath.CompareNoCase(rhs.m_strPath)) &&
  128.             (0 == m_strFile.CompareNoCase(rhs.m_strFile)));
  129. }
  130. bool 
  131. UNCPath::operator < (
  132.     const UNCPath& rhs
  133.     ) const
  134. {
  135.     CString s1, s2;
  136.     GetFullPath(&s1);
  137.     rhs.GetFullPath(&s2);
  138.     return 0 > s1.CompareNoCase(s2);
  139. }