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.

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