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.

186 lines
3.8 KiB

  1. #include <iostream.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <windows.h>
  6. #include <winbase.h>
  7. const DWORD MaxStrLength = 256;
  8. const char ComponentSectionTitle[] = "[Components]";
  9. /*++
  10. Description:
  11. Program to do setup testing automatically
  12. Argument:
  13. argv[1]: test case directory
  14. argv[2]: Windows NT installation directory, where server is to be installed
  15. argv[3]: generate the test case from a standalone test case
  16. Return value:
  17. None
  18. --*/
  19. void main(int argc, char *argv[])
  20. {
  21. bool bFromStandalone;
  22. char pchTestCaseDir[MaxStrLength];
  23. char pchNTDir[MaxStrLength];
  24. char pchOcFileName[MaxStrLength];
  25. char pchSysocFileName[MaxStrLength];
  26. LPSTR lpBuffer;
  27. if (argc != 3 && argc != 4){
  28. cout << "Usage: " << argv[0] << " TestCaseDir NTDir IfFromStandalone" << endl;
  29. exit(1);
  30. }
  31. if (argc == 4){
  32. bFromStandalone = true;
  33. cout << "Start test from a standalone test case is not supported yet" << endl;
  34. }
  35. else{
  36. bFromStandalone = false;
  37. }
  38. // Now we need to form an absolute path.
  39. // It is assumed that test case directory is relative to the current directory
  40. // and NT directory is an absolute path
  41. strcpy(pchNTDir, argv[2]);
  42. strcpy(pchTestCaseDir, argv[1]);
  43. if (pchNTDir[strlen(pchNTDir)-1] == '\\'){
  44. strcat(pchNTDir, "system32\\");
  45. }
  46. else{
  47. strcat(pchNTDir, "\\system32\\");
  48. }
  49. lpBuffer = (LPSTR)malloc(sizeof(char) * MaxStrLength);
  50. GetCurrentDirectory(MaxStrLength, lpBuffer);
  51. if (lpBuffer[strlen(lpBuffer) - 1] != '\\'){
  52. strcat(lpBuffer, "\\");
  53. }
  54. strcat(lpBuffer, pchTestCaseDir);
  55. strcpy(pchTestCaseDir, lpBuffer);
  56. free(lpBuffer);
  57. if (pchTestCaseDir[strlen(pchTestCaseDir) - 1] != '\\'){
  58. strcat(pchTestCaseDir, "\\");
  59. }
  60. // Now we will open oc.inf from test directory
  61. // and sysoc.inf from NT directory
  62. // and put something from oc.inf into sysoc.inf
  63. strcpy(pchOcFileName, pchTestCaseDir);
  64. strcat(pchOcFileName, "oc.inf");
  65. strcpy(pchSysocFileName, pchNTDir);
  66. strcat(pchSysocFileName, "sysoc.inf");
  67. FILE *pfSysoc, *pfOc, *pfTemp;
  68. if ((pfSysoc = fopen(pchSysocFileName, "r")) == NULL){
  69. cout << "Error opening sysoc.inf " << endl;
  70. exit(1);
  71. }
  72. if ((pfOc = fopen(pchOcFileName, "r")) == NULL){
  73. cout << "Error opening oc.inf " << endl;
  74. exit(1);
  75. }
  76. if ((pfTemp = fopen("temp.inf", "w")) == NULL){
  77. cout << "Error opening temp.inf " << endl;
  78. exit(1);
  79. }
  80. char pchOcLine[MaxStrLength];
  81. char pchSysocLine[MaxStrLength];
  82. bool bNotFound = true;
  83. while (fgets(pchSysocLine, MaxStrLength, pfSysoc) != NULL){
  84. fputs(pchSysocLine, pfTemp);
  85. if (strstr(pchSysocLine, ComponentSectionTitle) != NULL){
  86. // Read from oc.inf and paste important information
  87. bNotFound = true;
  88. while (fgets(pchOcLine, MaxStrLength, pfOc) != NULL){
  89. if (bNotFound){
  90. if (strstr(pchOcLine, ComponentSectionTitle) == NULL){
  91. continue;
  92. }
  93. else{
  94. bNotFound = false;
  95. }
  96. }
  97. else{
  98. if (pchOcLine[0] != '['){
  99. fputs(pchOcLine, pfTemp);
  100. }
  101. else{
  102. bNotFound = true;
  103. }
  104. }
  105. }
  106. fclose(pfOc);
  107. }
  108. }
  109. fclose(pfSysoc);
  110. fclose(pfTemp);
  111. // Now copy the temporary file onto sysoc.inf
  112. char pchCmdLine[MaxStrLength];
  113. sprintf(pchCmdLine, "copy temp.inf %s /Y", pchSysocFileName);
  114. system(pchCmdLine);
  115. system("del temp.inf");
  116. // We are now done with the file stuff
  117. // We will begin copying files
  118. sprintf(pchCmdLine, "copy %s*.dll %s /Y", pchTestCaseDir, pchNTDir);
  119. system(pchCmdLine);
  120. // We will assume it is not from a standalone.
  121. //if (!bFromStandalone || true){
  122. sprintf(pchCmdLine, "copy %s*.inf %s /Y", pchTestCaseDir, pchNTDir);
  123. system(pchCmdLine);
  124. //}
  125. exit(0);
  126. }