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.

350 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. setupdat.c
  5. Abstract:
  6. Module containing implementation for OcFillInSetupData, which the
  7. common OC Manager library will call to fill in the environment-dependent
  8. SETUP_DATA structure.
  9. Author:
  10. tedm 30-Sep-1996
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include <lmcons.h>
  16. #include <lmserver.h>
  17. #include <lmapibuf.h>
  18. UINT
  19. pDetermineProductType(
  20. VOID
  21. );
  22. #ifdef UNICODE
  23. VOID
  24. OcFillInSetupDataA(
  25. OUT PSETUP_DATAA SetupData
  26. )
  27. /*++
  28. Routine Description:
  29. Routine to fill in the ANSI SETUP_DATA structure in the Unicode build.
  30. This routine is merely a thunk to the Unicode implementation.
  31. Arguments:
  32. SetupData - receives various environment-specific values relating
  33. to the OC Manager's operation.
  34. Return Value:
  35. None.
  36. --*/
  37. {
  38. SETUP_DATAW data;
  39. OcFillInSetupDataW(&data);
  40. SetupData->SetupMode = data.SetupMode;
  41. SetupData->ProductType = data.ProductType;
  42. SetupData->OperationFlags = data.OperationFlags;
  43. WideCharToMultiByte(
  44. CP_ACP,
  45. 0,
  46. data.SourcePath,
  47. -1,
  48. SetupData->SourcePath,
  49. sizeof(SetupData->SourcePath),
  50. NULL,
  51. NULL
  52. );
  53. WideCharToMultiByte(
  54. CP_ACP,
  55. 0,
  56. data.UnattendFile,
  57. -1,
  58. SetupData->UnattendFile,
  59. sizeof(SetupData->UnattendFile),
  60. NULL,
  61. NULL
  62. );
  63. }
  64. #endif
  65. #ifdef UNICODE
  66. VOID
  67. OcFillInSetupDataW(
  68. OUT PSETUP_DATAW SetupData
  69. )
  70. #else
  71. VOID
  72. OcFillInSetupDataA(
  73. OUT PSETUP_DATAA SetupData
  74. )
  75. #endif
  76. /*++
  77. Routine Description:
  78. Routine to fill in the SETUP_DATA structure in the "native"
  79. character width.
  80. Arguments:
  81. SetupData - receives various environment-specific values relating
  82. to the OC Manager's operation.
  83. Return Value:
  84. None.
  85. --*/
  86. {
  87. TCHAR str[4];
  88. SetupData->SetupMode = (ULONG)SETUPMODE_UNKNOWN;
  89. SetupData->ProductType = pDetermineProductType();
  90. //
  91. // Set up source path stuff, unattend file.
  92. //
  93. lstrcpy(SetupData->SourcePath,SourcePath);
  94. lstrcpy(SetupData->UnattendFile,UnattendPath);
  95. //
  96. // Set miscellaneous bit flags and fields.
  97. //
  98. SetupData->OperationFlags = SETUPOP_STANDALONE;
  99. if(bUnattendInstall) {
  100. SetupData->OperationFlags |= SETUPOP_BATCH;
  101. }
  102. //
  103. // Which files are available?
  104. //
  105. #if defined(_AMD64_)
  106. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL | SETUPOP_AMD64_FILES_AVAIL;
  107. #elif defined(_X86_)
  108. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL;
  109. #elif defined(_IA64_)
  110. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL | SETUPOP_IA64_FILES_AVAIL;
  111. #else
  112. #error "No Target Architecture"
  113. #endif
  114. }
  115. UINT
  116. pDetermineProductType(
  117. VOID
  118. )
  119. /*++
  120. Routine Description:
  121. Determine the product type suitable for use in the SETUP_DATA structure.
  122. On Win95 this is always PRODUCT_WORKSTATION. On NT we check the registry
  123. and use other methods to distinguish among workstation and 3 flavors
  124. of server.
  125. Arguments:
  126. None.
  127. Return Value:
  128. Value suitable for use in the ProductType field of the SETUP_DATA structure.
  129. --*/
  130. {
  131. UINT ProductType;
  132. HKEY hKey;
  133. LONG l;
  134. DWORD Type;
  135. TCHAR Buffer[512];
  136. DWORD BufferSize;
  137. PSERVER_INFO_101 ServerInfo;
  138. HMODULE NetApiLib;
  139. NET_API_STATUS
  140. (NET_API_FUNCTION *xNetServerGetInfo)(
  141. IN LPTSTR servername,
  142. IN DWORD level,
  143. OUT LPBYTE *bufptr
  144. );
  145. NET_API_STATUS
  146. (NET_API_FUNCTION *xNetApiBufferFree)(
  147. IN LPVOID Buffer
  148. );
  149. //
  150. // Assume workstation.
  151. //
  152. ProductType = PRODUCT_WORKSTATION;
  153. if(IS_NT()) {
  154. //
  155. // Look in registry to determine workstation, standalone server, or DC.
  156. //
  157. l = RegOpenKeyEx(
  158. HKEY_LOCAL_MACHINE,
  159. TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
  160. 0,
  161. KEY_QUERY_VALUE,
  162. &hKey
  163. );
  164. if(l == NO_ERROR) {
  165. BufferSize = sizeof(Buffer);
  166. l = RegQueryValueEx(hKey,TEXT("ProductType"),NULL,&Type,(LPBYTE)Buffer,&BufferSize);
  167. if((l == NO_ERROR) && (Type == REG_SZ)) {
  168. //
  169. // Check for standalone server or DC server.
  170. //
  171. if(!lstrcmpi(Buffer,TEXT("SERVERNT"))) {
  172. ProductType = PRODUCT_SERVER_STANDALONE;
  173. } else {
  174. if(!lstrcmpi(Buffer,TEXT("LANMANNT"))) {
  175. //
  176. // PDC or BDC -- determine which. Assume PDC in case of failure.
  177. //
  178. ProductType = PRODUCT_SERVER_PRIMARY;
  179. if(NetApiLib = LoadLibrary(TEXT("NETAPI32"))) {
  180. if(((FARPROC)xNetServerGetInfo = GetProcAddress(NetApiLib,"NetServerGetInfo"))
  181. && ((FARPROC)xNetApiBufferFree = GetProcAddress(NetApiLib,"NetApiBufferFree"))
  182. && (xNetServerGetInfo(NULL,101,(LPBYTE *)&ServerInfo) == 0)) {
  183. if(ServerInfo->sv101_type & SV_TYPE_DOMAIN_BAKCTRL) {
  184. ProductType = PRODUCT_SERVER_SECONDARY;
  185. }
  186. xNetApiBufferFree(ServerInfo);
  187. }
  188. FreeLibrary(NetApiLib);
  189. }
  190. }
  191. }
  192. }
  193. RegCloseKey(hKey);
  194. }
  195. }
  196. return(ProductType);
  197. }
  198. INT
  199. OcLogError(
  200. IN OcErrorLevel Level,
  201. IN LPCTSTR FormatString,
  202. ...
  203. )
  204. {
  205. TCHAR str[4096];
  206. TCHAR tmp[64];
  207. TCHAR Title[256];
  208. va_list arglist;
  209. UINT Icon;
  210. va_start(arglist,FormatString);
  211. wvsprintf(str,FormatString,arglist);
  212. va_end(arglist);
  213. // In Batch mode don't display UI
  214. if ( Level & OcErrBatch ) {
  215. pDbgPrintEx(
  216. DPFLTR_SETUP_ID,
  217. DPFLTR_INFO_LEVEL,
  218. "sysocmgr: %S\n",
  219. str
  220. );
  221. return IDOK;
  222. }
  223. //
  224. // Mask off lower byte to allow us to pass
  225. // Addtionall "icon" information
  226. //
  227. switch( Level & OcErrMask ) {
  228. case OcErrLevInfo:
  229. Icon = MB_ICONINFORMATION;
  230. break;
  231. case OcErrLevWarning:
  232. case OcErrLevError:
  233. Icon = MB_ICONWARNING;
  234. break;
  235. case OcErrTrace:
  236. pDbgPrintEx(
  237. DPFLTR_SETUP_ID,
  238. DPFLTR_INFO_LEVEL,
  239. "sysocmgr: %S\n",
  240. str
  241. );
  242. return(IDOK);
  243. break;
  244. default:
  245. Icon = MB_ICONERROR;
  246. break;
  247. }
  248. pDbgPrintEx(
  249. DPFLTR_SETUP_ID,
  250. DPFLTR_ERROR_LEVEL,
  251. "sysocmgr: level 0x%08x error: %S\n",
  252. Level,
  253. str
  254. );
  255. //
  256. // If no additional Icon information is specified that's ok since
  257. // MB_OK is default
  258. //
  259. Icon |= (Level & ~OcErrMask);
  260. if ((Level & OcErrMask) < OcErrLevError)
  261. return IDOK;
  262. LoadString(hInst,AppTitleStringId,Title,sizeof(Title)/sizeof(TCHAR));
  263. return MessageBox(NULL,str,Title,Icon | MB_TASKMODAL | MB_SETFOREGROUND);
  264. }