Source code of Windows XP (NT5)
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.

147 lines
2.7 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*++
  4. Copyright (c) 1991 Microsoft Corporation
  5. Module Name:
  6. delnode.c
  7. Abstract:
  8. Delnode routine for Setup.
  9. Author:
  10. Ted Miller (tedm) August 1992
  11. --*/
  12. //
  13. // Bug whereby \$win_nt$.~ls\os2 directory is not deleted
  14. //
  15. //#define BUG_1818
  16. #ifdef BUG_1818
  17. char auxbuf[256];
  18. #endif
  19. //
  20. // Put these out here so we don't consume huge stack space as we recurse.
  21. //
  22. TCHAR Pattern[MAX_PATH];
  23. WIN32_FIND_DATA FindData;
  24. VOID
  25. DelnodeRoutine(
  26. VOID
  27. )
  28. {
  29. LPTSTR PatternEnd;
  30. HANDLE FindHandle;
  31. //
  32. // Delete each file in the directory, then remove the directory itself.
  33. // If any directories are encountered along the way recurse to delete
  34. // them as they are encountered.
  35. //
  36. PatternEnd = Pattern+lstrlen(Pattern);
  37. lstrcat(Pattern,TEXT("\\*"));
  38. FindHandle = FindFirstFile(Pattern,&FindData);
  39. if(FindHandle != INVALID_HANDLE_VALUE) {
  40. do {
  41. //
  42. // Form the full name of the file we just found.
  43. //
  44. lstrcpy(PatternEnd+1,FindData.cFileName);
  45. //
  46. // Remove read-only atttribute if it's there.
  47. //
  48. if(FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
  49. SetFileAttributes(Pattern,FILE_ATTRIBUTE_NORMAL);
  50. }
  51. if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  52. //
  53. // The current match is a directory. Recurse into it unless
  54. // it's . or ...
  55. //
  56. if(lstrcmp(FindData.cFileName,TEXT("." ))
  57. && lstrcmp(FindData.cFileName,TEXT("..")))
  58. {
  59. DelnodeRoutine();
  60. }
  61. } else {
  62. //
  63. // The current match is not a directory -- so delete it.
  64. //
  65. DeleteFile(Pattern);
  66. }
  67. *(PatternEnd+1) = 0;
  68. } while(FindNextFile(FindHandle,&FindData));
  69. FindClose(FindHandle);
  70. }
  71. //
  72. // Remove the directory we just emptied out.
  73. //
  74. *PatternEnd = 0;
  75. #ifdef BUG_1818
  76. if(!RemoveDirectory(Pattern)) {
  77. ULONG err = GetLastError();
  78. MessageBox(
  79. NULL,
  80. "Leave the machine exactly as it is now and get tedm (x63482).",
  81. "Trying to catch bug 1818",
  82. MB_TASKMODAL | MB_OK | MB_ICONSTOP
  83. );
  84. wsprintf(auxbuf,"Dir: %s\nErr: %lu",Pattern,err);
  85. MessageBox(
  86. NULL,
  87. auxbuf,
  88. "",
  89. MB_TASKMODAL | MB_OK
  90. );
  91. DbgBreakPoint();
  92. }
  93. #endif
  94. RemoveDirectory(Pattern);
  95. }
  96. VOID
  97. DoDelnode(
  98. IN PCHAR Directory
  99. )
  100. {
  101. lstrcpy(Pattern,Directory);
  102. DelnodeRoutine();
  103. }