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.

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