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.

211 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. signcabs.c
  5. Abstract:
  6. Signcabs enumerates all of the cabinet files in a directory, expands them, and creates the .lst file
  7. neeeded by the build signing tools.
  8. Author:
  9. Marc R. Whitten (marcw) 31-Jul-1998
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. BOOL
  14. Init (
  15. VOID
  16. )
  17. {
  18. HINSTANCE hInstance;
  19. hInstance = GetModuleHandle (NULL);
  20. return TRUE;
  21. }
  22. VOID
  23. Terminate (
  24. VOID
  25. )
  26. {
  27. HINSTANCE hInstance;
  28. hInstance = GetModuleHandle (NULL);
  29. }
  30. BOOL
  31. pDeleteAllFiles (
  32. IN PCWSTR DirPath
  33. )
  34. {
  35. TREE_ENUM e;
  36. BOOL dirsFirst = FALSE;
  37. if (EnumFirstFileInTree (&e, DirPath, TEXT("*"), dirsFirst)) {
  38. do {
  39. if (e.Directory) {
  40. pDeleteAllFiles (e.FullPath);
  41. SetFileAttributes (e.FullPath, FILE_ATTRIBUTE_NORMAL);
  42. RemoveDirectory (e.FullPath);
  43. }
  44. else {
  45. SetFileAttributes (e.FullPath, FILE_ATTRIBUTE_NORMAL);
  46. DeleteFile (e.FullPath);
  47. }
  48. } while (EnumNextFileInTree (&e));
  49. }
  50. return TRUE;
  51. }
  52. void
  53. usage (
  54. VOID
  55. )
  56. {
  57. printf (
  58. "Command Line Usage:\n"
  59. "signcabs [-ch] [filedir] [tempdir]\n\n"
  60. " -c - Clean out temporary directory if it exists.\n"
  61. " -h - This message.\n"
  62. " filedir - Directory containing files to be processed.\n"
  63. " tempdir - Directory to store results.\n"
  64. );
  65. }
  66. INT
  67. __cdecl
  68. wmain (
  69. INT argc,
  70. WCHAR *argv[]
  71. )
  72. {
  73. PWSTR tempDir = NULL;
  74. PWSTR fileDir = NULL;
  75. TREE_ENUM e;
  76. HANDLE h = INVALID_HANDLE_VALUE;
  77. PWSTR listFilePath;
  78. BOOL clean = FALSE;
  79. INT i;
  80. if (!Init()) {
  81. wprintf (L"Unable to initialize!\n");
  82. return 255;
  83. }
  84. //
  85. // Parse command line.
  86. //
  87. for (i = 1; i < argc; i++) {
  88. if (argv[i][0] == L'-' || argv[i][0] == L'\\') {
  89. switch (argv[i][1]) {
  90. case L'c': case L'C':
  91. clean = TRUE;
  92. break;
  93. default:
  94. usage();
  95. return 0;
  96. break;
  97. }
  98. }
  99. else if (!fileDir) {
  100. fileDir = argv[i];
  101. }
  102. else if (!tempDir) {
  103. tempDir = argv[i];
  104. }
  105. else {
  106. usage();
  107. return 0;
  108. }
  109. }
  110. //
  111. // One of the nice things about writing the tool is that you get to create silly
  112. // defaults that only work for you.
  113. //
  114. if (!tempDir) tempDir = L"e:\\signcabs";
  115. if (!fileDir) fileDir = L"e:\\nt\\private\\redist\\migdlls\\mapi";
  116. //
  117. // First, check to see if the temporary directory exists.
  118. //
  119. if (CreateDirectory (tempDir, NULL) == 0) {
  120. if (GetLastError () == ERROR_ALREADY_EXISTS) {
  121. if (clean) {
  122. pDeleteAllFiles (tempDir);
  123. }
  124. }
  125. else {
  126. wprintf (L"SIGNCABS: Cannot create directory %ws. (gle: %d)\n", tempDir, GetLastError ());
  127. }
  128. }
  129. wprintf (L"SIGNCABS: Creating .lst file for all cabs found under %ws.\n",fileDir);
  130. if (!ExpandAllFiles (fileDir, tempDir)) {
  131. wprintf (L"SIGNCABS: Error while expanding cabinet files from %ws to %ws (%d)\n",fileDir, tempDir, GetLastError ());
  132. }
  133. //
  134. // Now, enumerate through all of the files and create the lst file.
  135. //
  136. listFilePath = JoinPaths (tempDir, L"cabs.lst");
  137. h = CreateFile (listFilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  138. if (h == INVALID_HANDLE_VALUE) {
  139. wprintf (L"SIGNCABS: Error while trying to create %ws. (%d)\n", listFilePath, GetLastError());
  140. return GetLastError();
  141. }
  142. FreePathString (listFilePath);
  143. if (EnumFirstFileInTree (&e, tempDir, TEXT("*"), FALSE)) {
  144. do {
  145. if (!e.Directory) {
  146. WriteFileString (h, L"<hash>");
  147. WriteFileString (h, e.FullPath);
  148. WriteFileString (h, L"=");
  149. WriteFileString (h, e.FullPath);
  150. WriteFileString (h, L"\r\n");
  151. }
  152. } while (EnumNextFileInTree (&e));
  153. }
  154. CloseHandle (h);
  155. wprintf (L"SIGNCABS: Done.\n");
  156. Terminate();
  157. return 0;
  158. }