Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. enumdir.cpp
  5. Abstract:
  6. Directory enumerations object implementation. Caller instantiates a instance
  7. of this object with a root directory path. The object will return all the
  8. sibbling files as a URL.
  9. Author:
  10. Michael Cheuk (mcheuk)
  11. Project:
  12. Link Checker
  13. Revision History:
  14. --*/
  15. #include "stdafx.h"
  16. #include "enumdir.h"
  17. #include "lcmgr.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. CEnumerateDirTree::CEnumerateDirTree(
  24. CVirtualDirInfo DirInfo
  25. )
  26. /*++
  27. Routine Description:
  28. Constructor.
  29. Arguments:
  30. DirInfo - // root virtual directory to start with
  31. Return Value:
  32. N/A
  33. --*/
  34. {
  35. m_hFind = INVALID_HANDLE_VALUE;
  36. try
  37. {
  38. m_VirtualDirInfoList.AddTail(DirInfo);
  39. }
  40. catch(CMemoryException* pEx)
  41. {
  42. pEx->Delete();
  43. TRACE(_T("CEnumerateDirTree::CEnumerateDirTree() - fail to add to VirtualDirInfoList\n"));
  44. }
  45. } // CEnumerateDirTree::CEnumerateDirTree
  46. CEnumerateDirTree::~CEnumerateDirTree(
  47. )
  48. /*++
  49. Routine Description:
  50. Destructor.
  51. Arguments:
  52. N/A
  53. Return Value:
  54. N/A
  55. --*/
  56. {
  57. if(m_hFind != INVALID_HANDLE_VALUE)
  58. {
  59. FindClose(m_hFind);
  60. }
  61. } // CEnumerateDirTree::~CEnumerateDirTree
  62. BOOL
  63. CEnumerateDirTree::Next(
  64. CString& strURL
  65. )
  66. /*++
  67. Routine Description:
  68. Get the next URL
  69. Arguments:
  70. N/A
  71. Return Value:
  72. N/A
  73. --*/
  74. {
  75. WIN32_FIND_DATA FindData;
  76. // Loop if 1. the find handle is valid
  77. // or 2. the directory stack is not empty
  78. while(m_hFind != INVALID_HANDLE_VALUE || m_VirtualDirInfoList.GetCount() > 0)
  79. {
  80. // If we do not have a valid handle
  81. if(m_hFind == INVALID_HANDLE_VALUE)
  82. {
  83. // get the dir from the stack
  84. m_VirtualDirInfo = m_VirtualDirInfoList.GetHead();
  85. m_VirtualDirInfoList.RemoveHead();
  86. if(SetCurrentDirectory(m_VirtualDirInfo.GetPath()))
  87. {
  88. // Find the first one from the new dir
  89. m_hFind = FindFirstFile(_T("*.*"), &FindData);
  90. }
  91. }
  92. else
  93. {
  94. if(!FindNextFile(m_hFind, &FindData))
  95. {
  96. FindClose(m_hFind);
  97. m_hFind = INVALID_HANDLE_VALUE;
  98. }
  99. }
  100. // If we find a valid file
  101. if(m_hFind != INVALID_HANDLE_VALUE)
  102. {
  103. // It is a directory
  104. if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  105. {
  106. // It is a valid directory
  107. if(FindData.cFileName != _tcsstr(FindData.cFileName, _T("..\0")) &&
  108. FindData.cFileName != _tcsstr(FindData.cFileName, _T(".\0")) )
  109. {
  110. CVirtualDirInfo NewDirInfo;
  111. NewDirInfo.SetAlias( m_VirtualDirInfo.GetAlias() + FindData.cFileName + _TCHAR('/') );
  112. NewDirInfo.SetPath( m_VirtualDirInfo.GetPath() + FindData.cFileName + _TCHAR('\\') );
  113. m_VirtualDirInfoList.AddTail(NewDirInfo);
  114. }
  115. }
  116. // It is a file
  117. else
  118. {
  119. strURL = _T("http://") + GetLinkCheckerMgr().GetUserOptions().GetHostName() + m_VirtualDirInfo.GetAlias() + FindData.cFileName;
  120. return TRUE;
  121. }
  122. }
  123. }
  124. return FALSE;
  125. } // CEnumerateDirTree::Next