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.

217 lines
6.6 KiB

  1. //
  2. // WALKPATH.C
  3. //
  4. #include "sigverif.h"
  5. BOOL g_bRecurse = TRUE;
  6. //
  7. // This function takes a directory name and a search pattern and looks for all
  8. // files mathching the pattern.
  9. // If bRecurse is set, then it will add subdirectories to the end of the
  10. // g_lpDirList for subsequent traversal.
  11. //
  12. // In this routine we allocate and fill in some of the lpFileNode values that
  13. // we know about.
  14. //
  15. DWORD
  16. FindFile(
  17. TCHAR *lpDirName,
  18. TCHAR *lpFileName
  19. )
  20. {
  21. DWORD Err = ERROR_SUCCESS;
  22. HANDLE hFind = INVALID_HANDLE_VALUE;
  23. LPFILENODE lpFileNode;
  24. WIN32_FIND_DATA FindFileData;
  25. TCHAR szFullPathName[MAX_PATH];
  26. //
  27. // If the user clicked STOP, then bail immediately!
  28. // If the directory is bogus, then skip to the next one.
  29. //
  30. if (!g_App.bStopScan) {
  31. if (g_bRecurse) {
  32. //
  33. // The user wants to get all the subdirectories as well, so first
  34. // process all of the directories under this path.
  35. //
  36. if (FAILED(StringCchCopy(szFullPathName, cA(szFullPathName), lpDirName)) ||
  37. !pSetupConcatenatePaths(szFullPathName, TEXT("*.*"), cA(szFullPathName), NULL)) {
  38. Err = ERROR_BAD_PATHNAME;
  39. goto clean0;
  40. }
  41. hFind = FindFirstFile(szFullPathName, &FindFileData);
  42. if (hFind != INVALID_HANDLE_VALUE) {
  43. do {
  44. if (lstrcmp(FindFileData.cFileName, TEXT(".")) &&
  45. lstrcmp(FindFileData.cFileName, TEXT("..")) &&
  46. (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  47. if (SUCCEEDED(StringCchCopy(szFullPathName, cA(szFullPathName), lpDirName)) &&
  48. pSetupConcatenatePaths(szFullPathName, FindFileData.cFileName, cA(szFullPathName), NULL)) {
  49. Err = FindFile(szFullPathName, lpFileName);
  50. } else {
  51. Err = ERROR_BAD_PATHNAME;
  52. }
  53. }
  54. } while (!g_App.bStopScan &&
  55. (Err == ERROR_SUCCESS) &&
  56. FindNextFile(hFind, &FindFileData));
  57. FindClose(hFind);
  58. hFind = INVALID_HANDLE_VALUE;
  59. }
  60. }
  61. //
  62. // If we failed to process one of the directories then just bail out
  63. // now.
  64. //
  65. if (Err != ERROR_SUCCESS) {
  66. goto clean0;
  67. }
  68. //
  69. // Process the files in this directory.
  70. //
  71. if (FAILED(StringCchCopy(szFullPathName, cA(szFullPathName), lpDirName)) ||
  72. !pSetupConcatenatePaths(szFullPathName, lpFileName, cA(szFullPathName), NULL)) {
  73. Err = ERROR_BAD_PATHNAME;
  74. goto clean0;
  75. }
  76. hFind = FindFirstFile(szFullPathName, &FindFileData);
  77. if (hFind != INVALID_HANDLE_VALUE) {
  78. do {
  79. //
  80. // While there are more files to be found, keep looking in the
  81. // directory...
  82. //
  83. if (lstrcmp(FindFileData.cFileName, TEXT(".")) &&
  84. lstrcmp(FindFileData.cFileName, TEXT("..")) &&
  85. !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  86. //
  87. // Allocate an lpFileNode, fill it in, and add it to the end
  88. // of g_App.lpFileList
  89. //
  90. // We need to call CharLowerBuff on the file and dir names
  91. // because the catalog files all contain lower-case names
  92. // for the files.
  93. //
  94. lpFileNode = CreateFileNode(lpDirName, FindFileData.cFileName);
  95. if (lpFileNode) {
  96. if (!g_App.lpFileList) {
  97. g_App.lpFileList = lpFileNode;
  98. } else {
  99. g_App.lpFileLast->next = lpFileNode;
  100. }
  101. g_App.lpFileLast = lpFileNode;
  102. //
  103. // Increment the total number of files we've found that
  104. // meet the search criteria.
  105. //
  106. g_App.dwFiles++;
  107. } else {
  108. Err = GetLastError();
  109. }
  110. }
  111. } while (!g_App.bStopScan &&
  112. (Err == ERROR_SUCCESS) &&
  113. FindNextFile(hFind, &FindFileData));
  114. FindClose(hFind);
  115. hFind = INVALID_HANDLE_VALUE;
  116. }
  117. }
  118. clean0:
  119. if (hFind != INVALID_HANDLE_VALUE) {
  120. FindClose(hFind);
  121. hFind = INVALID_HANDLE_VALUE;
  122. }
  123. return Err;
  124. }
  125. //
  126. // Build an g_App.lpFileList given the user settings in the main dialog.
  127. //
  128. DWORD
  129. BuildFileList(
  130. LPTSTR lpPathName
  131. )
  132. {
  133. DWORD Err = ERROR_SUCCESS;
  134. TCHAR FileName[MAX_PATH];
  135. //
  136. // Check if this is a valid starting directory.
  137. // If not, then pop up an error message.
  138. //
  139. if (!SetCurrentDirectory(lpPathName)) {
  140. Err = ERROR_BAD_PATHNAME;
  141. goto clean0;
  142. }
  143. //
  144. // If the "Include Subdirectories" is checked, then bRecurse is TRUE.
  145. //
  146. if (g_App.bSubFolders) {
  147. g_bRecurse = TRUE;
  148. } else {
  149. g_bRecurse = FALSE;
  150. }
  151. //
  152. // Get the search pattern from the resource or the user-specified string
  153. //
  154. if (g_App.bUserScan) {
  155. if (FAILED(StringCchCopy(FileName, cA(FileName), g_App.szScanPattern))) {
  156. //
  157. // This shouldn't happen since we should check the size of
  158. // szScanPattern at the time we read it in from the UI.
  159. //
  160. goto clean0;
  161. }
  162. } else {
  163. MyLoadString(FileName, cA(FileName), IDS_ALL);
  164. }
  165. //
  166. // Process the g_lpDirList as long as the user doesn't click STOP!
  167. //
  168. Err = FindFile(lpPathName, FileName);
  169. clean0:
  170. //
  171. // If there weren't any files found, then let the user know about it.
  172. //
  173. if (!g_App.lpFileList && (Err == ERROR_SUCCESS)) {
  174. MyMessageBoxId(IDS_NOFILES);
  175. }
  176. return Err;
  177. }