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.

170 lines
5.3 KiB

  1. #include "wizard.h"
  2. #pragma hdrstop
  3. UNATTEND_ANSWER UnattendAnswerTable[] =
  4. {
  5. { UAA_MODE, SECTION_NAME, KEY_MODE, MODE_NEW, DT_STRING, 0 },
  6. { UAA_PRINTER_NAME, SECTION_NAME, KEY_FAX_PRINTER_NAME, EMPTY_STRING, DT_STRING, 0 },
  7. { UAA_FAX_PHONE, SECTION_NAME, KEY_FAX_NUMBER, EMPTY_STRING, DT_STRING, 0 },
  8. { UAA_USE_EXCHANGE, SECTION_NAME, KEY_USE_EXCHANGE, EMPTY_STRING, DT_BOOLEAN, 0 },
  9. { UAA_DEST_PROFILENAME, SECTION_NAME, KEY_PROFILE_NAME, EMPTY_STRING, DT_STRING, 0 },
  10. { UAA_ROUTE_MAIL, SECTION_NAME, KEY_ROUTE_MAIL, EMPTY_STRING, DT_BOOLEAN, 0 },
  11. { UAA_ROUTE_PROFILENAME, SECTION_NAME, KEY_ROUTE_PROFILENAME, EMPTY_STRING, DT_STRING, 0 },
  12. { UAA_PLATFORM_LIST, SECTION_NAME, KEY_PLATFORMS, EMPTY_STRING, DT_STRING, 0 },
  13. { UAA_ROUTE_PRINT, SECTION_NAME, KEY_ROUTE_PRINT, EMPTY_STRING, DT_BOOLEAN, 0 },
  14. { UAA_DEST_PRINTERLIST, SECTION_NAME, KEY_ROUTE_PRINTERNAME, EMPTY_STRING, DT_STRING, 0 },
  15. { UAA_ACCOUNT_NAME, SECTION_NAME, KEY_ACCOUNT_NAME, EMPTY_STRING, DT_STRING, 0 },
  16. { UAA_PASSWORD, SECTION_NAME, KEY_PASSWORD, EMPTY_STRING, DT_STRING, 0 },
  17. { UAA_FAX_PHONE, SECTION_NAME, KEY_FAX_PHONE, EMPTY_STRING, DT_STRING, 0 },
  18. { UAA_DEST_DIRPATH, SECTION_NAME, KEY_DEST_DIRPATH, EMPTY_STRING, DT_STRING, 0 },
  19. { UAA_ROUTE_FOLDER, SECTION_NAME, KEY_ROUTE_FOLDER, EMPTY_STRING, DT_BOOLEAN, 0 },
  20. { UAA_SERVER_NAME, SECTION_NAME, KEY_SERVER_NAME, EMPTY_STRING, DT_STRING, 0 },
  21. { UAA_SENDER_NAME, SECTION_NAME, KEY_SENDER_NAME, EMPTY_STRING, DT_STRING, 0 },
  22. { UAA_SENDER_FAX_AREA_CODE, SECTION_NAME, KEY_SENDER_FAX_AREA_CODE, EMPTY_STRING, DT_STRING, 0 },
  23. { UAA_SENDER_FAX_NUMBER, SECTION_NAME, KEY_SENDER_FAX_NUMBER, EMPTY_STRING, DT_STRING, 0 }
  24. };
  25. #define NumAnswers (sizeof(UnattendAnswerTable)/sizeof(UNATTEND_ANSWER))
  26. BOOL
  27. UnAttendInitialize(
  28. IN LPWSTR AnswerFile
  29. )
  30. {
  31. DWORD i;
  32. WCHAR Buf[1024];
  33. LPWSTR Sections;
  34. LPWSTR p;
  35. DebugPrint(( L"UnAttendInitialize(): Initializing all answers from the response file [%s]", AnswerFile ));
  36. //
  37. // make sure that there is a fax section in the file
  38. //
  39. i = 4096;
  40. Sections = (LPWSTR) MemAlloc( i * sizeof(TCHAR) );
  41. if (!Sections) {
  42. return FALSE;
  43. }
  44. while( GetPrivateProfileString( NULL, NULL, EMPTY_STRING, Sections, i, AnswerFile ) == i - 2) {
  45. i += 4096;
  46. MemFree( Sections );
  47. Sections = (LPWSTR) MemAlloc( i * sizeof(TCHAR) );
  48. if (!Sections) {
  49. return FALSE;
  50. }
  51. }
  52. p = Sections;
  53. while( *p ) {
  54. if (_tcsicmp( p, SECTION_NAME ) == 0) {
  55. i = 0;
  56. break;
  57. }
  58. p += _tcslen( p ) + 1;
  59. }
  60. MemFree( Sections );
  61. if (i) {
  62. return FALSE;
  63. }
  64. Buf[0] = 0;
  65. GetPrivateProfileString(
  66. SECTION_NAME,
  67. TEXT("SuppressReboot"),
  68. EMPTY_STRING,
  69. Buf,
  70. sizeof(Buf),
  71. AnswerFile
  72. );
  73. if (Buf[0] == L'y' || Buf[0] == L'Y') {
  74. SuppressReboot = TRUE;
  75. }
  76. //
  77. // get the answers
  78. //
  79. for (i=0; i<NumAnswers; i++) {
  80. Buf[0] = 0;
  81. GetPrivateProfileString(
  82. UnattendAnswerTable[i].SectionName,
  83. UnattendAnswerTable[i].KeyName,
  84. UnattendAnswerTable[i].DefaultAnswer,
  85. Buf,
  86. sizeof(Buf),
  87. AnswerFile
  88. );
  89. DebugPrint(( L"%s\t%-30s \"%s\"",
  90. UnattendAnswerTable[i].SectionName,
  91. UnattendAnswerTable[i].KeyName,
  92. Buf
  93. ));
  94. switch(UnattendAnswerTable[i].DataType) {
  95. case DT_STRING:
  96. UnattendAnswerTable[i].Answer.String = StringDup(Buf);
  97. break;
  98. case DT_LONGINT:
  99. UnattendAnswerTable[i].Answer.Num = _wtol(Buf);
  100. break;
  101. case DT_BOOLEAN:
  102. UnattendAnswerTable[i].Answer.Bool = ((Buf[0] == L'y') || (Buf[0] == L'Y'));
  103. break;
  104. }
  105. }
  106. return TRUE;
  107. }
  108. BOOL
  109. UnAttendGetAnswer(
  110. DWORD ControlId,
  111. LPBYTE AnswerBuf,
  112. DWORD AnswerBufSize
  113. )
  114. {
  115. DWORD i;
  116. for (i=0; i<NumAnswers; i++) {
  117. if (UnattendAnswerTable[i].ControlId == ControlId) {
  118. switch(UnattendAnswerTable[i].DataType) {
  119. case DT_STRING:
  120. if (UnattendAnswerTable[i].Answer.String) {
  121. CopyMemory( AnswerBuf, UnattendAnswerTable[i].Answer.String, StringSize(UnattendAnswerTable[i].Answer.String) );
  122. } else {
  123. return FALSE;
  124. }
  125. break;
  126. case DT_LONGINT:
  127. CopyMemory( AnswerBuf, &UnattendAnswerTable[i].Answer.Num, sizeof(LONG) );
  128. break;
  129. case DT_BOOLEAN:
  130. CopyMemory( AnswerBuf, &UnattendAnswerTable[i].Answer.Bool, sizeof(BOOL) );
  131. break;
  132. }
  133. break;
  134. }
  135. }
  136. return TRUE;
  137. }