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.

897 lines
23 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. hwprof.c
  5. Abstract:
  6. Hardware profile merge code
  7. Author:
  8. Jim Schmidt (jimschm) 29-May-1997
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. #include "mergep.h"
  13. HASHTABLE g_SoftwareDefaultListHash = NULL;
  14. typedef struct _HARDWARE_PROFILE {
  15. DWORD NumberOnWin9x;
  16. } HARDWARE_PROFILE, *PHARDWARE_PROFILE;
  17. GROWLIST g_HardwareProfileList = GROWLIST_INIT;
  18. BOOL
  19. pCreateDefaultKey (
  20. LPCTSTR BaseRegStr
  21. );
  22. BOOL
  23. pCopyHwProfileProperties (
  24. IN DWORD ProfileSrcId,
  25. IN DWORD ProfileDestId
  26. );
  27. FILTERRETURN
  28. pHwProfileEnumFilter (
  29. IN CPDATAOBJECT SrcObjectPtr,
  30. IN CPDATAOBJECT Unused, OPTIONAL
  31. IN FILTERTYPE FilterType,
  32. IN LPVOID FilterArg OPTIONAL
  33. );
  34. BOOL
  35. pCopyHwProfileConfigData (
  36. IN DWORD ProfileSrcId,
  37. IN DWORD ProfileDestId
  38. );
  39. VOID
  40. pDeleteProfilesConfigValues(
  41. IN DWORD ConfigNumber
  42. );
  43. BOOL
  44. pDeleteDefaultKey (
  45. IN LPCTSTR BaseRegStr
  46. );
  47. DWORD
  48. pGetCurrentConfig (
  49. VOID
  50. );
  51. BOOL
  52. pCopyCurrentConfig (
  53. VOID
  54. );
  55. VOID
  56. pProcessSoftwareDefaultList(
  57. IN HINF InfFile,
  58. IN PCTSTR Section
  59. );
  60. VOID
  61. pFreeSoftwareDefaultList(
  62. VOID
  63. );
  64. VOID
  65. pMigrateHardwareProfiles(
  66. VOID
  67. );
  68. BOOL
  69. CopyHardwareProfiles (
  70. IN HINF InfFile
  71. )
  72. {
  73. BOOL b;
  74. DATAOBJECT Win9xOb;
  75. //
  76. // Move current hardware profile into Default key
  77. //
  78. if (!pCreateDefaultKey (S_IDCONFIGDB_HW_KEY)) {
  79. LOG ((LOG_ERROR, "Unable to complete CopyHardwareProfiles"));
  80. return FALSE;
  81. }
  82. if (!pCreateDefaultKey (S_NT_CONFIG_KEY)) {
  83. LOG ((LOG_ERROR, "Unable to complete CopyHardwareProfiles (2)"));
  84. return FALSE;
  85. }
  86. //
  87. // Enumerate all Win9x hardware profiles and copy each one
  88. //
  89. pProcessSoftwareDefaultList(InfFile, S_MERGE_WIN9X_SUPPRESS_SFT_D);
  90. b = CreateObjectStruct (S_9X_CONFIG_KEY S_TREE, &Win9xOb, WIN95OBJECT);
  91. MYASSERT(b);
  92. b = FILTER_RETURN_FAIL != CopyObject (&Win9xOb,
  93. NULL,
  94. pHwProfileEnumFilter,
  95. (PVOID)pGetCurrentConfig());
  96. pFreeSoftwareDefaultList();
  97. pMigrateHardwareProfiles();
  98. //
  99. // Clean up Default key
  100. //
  101. pDeleteDefaultKey (S_IDCONFIGDB_HW_KEY);
  102. pDeleteDefaultKey (S_NT_CONFIG_KEY);
  103. //
  104. // Set the current config value
  105. //
  106. // b = pCopyCurrentConfig();
  107. FreeObjectStruct (&Win9xOb);
  108. return b;
  109. }
  110. FILTERRETURN
  111. pHwProfileSuppressFilter (
  112. IN CPDATAOBJECT SrcObjectPtr,
  113. IN CPDATAOBJECT DestObjectPtr, OPTIONAL
  114. IN FILTERTYPE FilterType,
  115. IN LPVOID UnusedArg OPTIONAL
  116. )
  117. {
  118. TCHAR ObStr[MAX_ENCODED_RULE];
  119. LPTSTR p;
  120. TCHAR Node[MEMDB_MAX];
  121. if (FilterType == FILTER_CREATE_KEY) {
  122. // Create empty key is unnecessary
  123. return FILTER_RETURN_HANDLED;
  124. }
  125. else if (FilterType == FILTER_KEY_ENUM ||
  126. FilterType == FILTER_PROCESS_VALUES ||
  127. FilterType == FILTER_VALUENAME_ENUM
  128. ) {
  129. // Make p point to HKLM\Config\0001\...
  130. CreateObjectString (SrcObjectPtr, ObStr);
  131. p = ObStr;
  132. // Make p point to \Config\0001\subkey
  133. p = _tcschr (p, TEXT('\\'));
  134. if (p) {
  135. // Make p point to \0001\subkey
  136. p = _tcschr (_tcsinc (p), TEXT('\\'));
  137. if (p) {
  138. // Make p point to \subkey
  139. p = _tcschr (_tcsinc (p), TEXT('\\'));
  140. if (p) {
  141. // Make p point to subkey
  142. p = _tcsinc (p);
  143. } else {
  144. p = S_EMPTY;
  145. }
  146. }
  147. }
  148. if (!p) {
  149. DEBUGMSG ((
  150. DBG_WHOOPS,
  151. "pHwProfileSuppressFilter: Not a hardware profile key: %s",
  152. ObStr
  153. ));
  154. return FILTER_RETURN_FAIL;
  155. }
  156. //
  157. // If an entry exists in memdb's HKCC category, we have a
  158. // suppression match
  159. //
  160. wsprintf (Node, TEXT("HKCC\\%s"), p);
  161. if (MemDbGetValue (Node, NULL)) {
  162. return FILTER_RETURN_HANDLED;
  163. }
  164. }
  165. return FILTER_RETURN_CONTINUE;
  166. }
  167. VOID
  168. pProcessSoftwareDefaultList(
  169. IN HINF InfFile,
  170. IN PCTSTR Section
  171. )
  172. {
  173. INFCONTEXT ic;
  174. TCHAR SrcObjectStr[MAX_ENCODED_RULE];
  175. g_SoftwareDefaultListHash = HtAllocW();
  176. if(!g_SoftwareDefaultListHash){
  177. LOG ((LOG_ERROR, "pProcessSoftwareDefaultList: Can't create hash table"));
  178. return;
  179. }
  180. if(SetupFindFirstLine (InfFile, Section, NULL, &ic)){
  181. do{
  182. if(SetupGetStringField (&ic, 1, SrcObjectStr, MAX_ENCODED_RULE, NULL)){
  183. FixUpUserSpecifiedObject(SrcObjectStr);
  184. HtAddString(g_SoftwareDefaultListHash, SrcObjectStr);
  185. }
  186. else{
  187. LOG ((LOG_ERROR, "pProcessSoftwareDefaultList: syntax error in line %u of section %s in wkstamig.inf",
  188. ic.Line, Section));
  189. }
  190. } while (SetupFindNextLine (&ic, &ic));
  191. }
  192. else{
  193. DEBUGMSG ((DBG_VERBOSE, "pProcessSoftwareDefaultList: Section %s can't be found", Section));
  194. }
  195. }
  196. VOID
  197. pFreeSoftwareDefaultList(
  198. VOID
  199. )
  200. {
  201. INFCONTEXT ic;
  202. TCHAR SrcObjectStr[MAX_ENCODED_RULE];
  203. if(g_SoftwareDefaultListHash){
  204. HtFree(g_SoftwareDefaultListHash);
  205. g_SoftwareDefaultListHash = NULL;
  206. }
  207. }
  208. FILTERRETURN
  209. pHwSoftwareDefaultDetectFilter (
  210. IN CPDATAOBJECT SrcObjectPtr,
  211. IN CPDATAOBJECT DestObjectPtr, OPTIONAL
  212. IN FILTERTYPE FilterType,
  213. IN LPVOID Arg
  214. )
  215. {
  216. TCHAR ObStr[MAX_ENCODED_RULE];
  217. LPTSTR p;
  218. TCHAR Node[MEMDB_MAX];
  219. BOOL * notDefault;
  220. if(!Arg){
  221. MYASSERT(FALSE);
  222. return FILTER_RETURN_FAIL;
  223. }
  224. notDefault = Arg;
  225. if (FilterType == FILTER_VALUENAME_ENUM){
  226. // Make p point to HKLM\Config\0001\...
  227. CreateObjectString (SrcObjectPtr, ObStr);
  228. p = ObStr;
  229. // Make p point to \Config\0001\Software\subkey
  230. p = _tcschr (p, TEXT('\\'));
  231. if (p) {
  232. // Make p point to \0001\Software\subkey
  233. p = _tcschr (_tcsinc (p), TEXT('\\'));
  234. if (p) {
  235. // Make p point to \Software\subkey
  236. p = _tcschr (_tcsinc (p), TEXT('\\'));
  237. if (p) {
  238. // Make p point to \subkey
  239. p = _tcschr (_tcsinc (p), TEXT('\\'));
  240. if (p) {
  241. // Make p point to subkey
  242. p = _tcsinc (p);
  243. } else {
  244. p = S_EMPTY;
  245. }
  246. }
  247. }
  248. }
  249. if (!p) {
  250. DEBUGMSG ((
  251. DBG_ERROR,
  252. "pHwSoftwareDefaultDetectFilter: Not a hardware profile key: %s",
  253. ObStr
  254. ));
  255. return FILTER_RETURN_FAIL;
  256. }
  257. //
  258. // If an entry exists in memdb's HKCC category, we have a
  259. // suppression match
  260. //
  261. wsprintf (Node, TEXT("HKCC\\Software\\%s"), p);
  262. if(MemDbGetValue(Node, NULL)) {
  263. return FILTER_RETURN_CONTINUE;
  264. }
  265. wsprintf (Node, TEXT("HKCCS\\%s"), p);
  266. if(HtFindString(g_SoftwareDefaultListHash, Node)){
  267. return FILTER_RETURN_CONTINUE;
  268. }
  269. DEBUGMSG((DBG_VERBOSE, "pHwSoftwareDefaultDetectFilter(%s): not-default profile", Node));
  270. *notDefault = TRUE;
  271. return FILTER_RETURN_FAIL;
  272. }
  273. return FILTER_RETURN_CONTINUE;
  274. }
  275. BOOL
  276. pIsSoftwareBranchDefault(
  277. IN DWORD ConfigNumber
  278. )
  279. {
  280. BOOL b;
  281. DATAOBJECT Win9xOb;
  282. TCHAR keyName[MAX_TCHAR_PATH];
  283. BOOL notDefault;
  284. wsprintf(keyName, S_9X_CONFIG_MASK S_SOFTWARE S_TREE, ConfigNumber);
  285. b = CreateObjectStruct(keyName, &Win9xOb, WIN95OBJECT);
  286. MYASSERT(b);
  287. if(!b){
  288. return TRUE;
  289. }
  290. notDefault = FALSE;
  291. CopyObject(&Win9xOb,
  292. NULL,
  293. pHwSoftwareDefaultDetectFilter,
  294. (PVOID)&notDefault);
  295. FreeObjectStruct(&Win9xOb);
  296. return !notDefault;
  297. }
  298. FILTERRETURN
  299. pHwProfileEnumFilter (
  300. IN CPDATAOBJECT SrcObjectPtr,
  301. IN CPDATAOBJECT Unused, OPTIONAL
  302. IN FILTERTYPE FilterType,
  303. IN LPVOID FilterArg OPTIONAL
  304. )
  305. {
  306. LPCTSTR p;
  307. DWORD CurrentConfig = (DWORD)FilterArg;
  308. HARDWARE_PROFILE hardwareProfile;
  309. MYASSERT(CurrentConfig);
  310. if (FilterType == FILTER_KEY_ENUM) {
  311. // Make p point to 0001\Subkey
  312. p = _tcschr (SrcObjectPtr->KeyPtr->KeyString, TEXT('\\'));
  313. if (!p) {
  314. // Object string is premature -- keep enumerating
  315. return FILTER_RETURN_CONTINUE;
  316. } else {
  317. p = _tcsinc (p);
  318. }
  319. // Get current configuration number
  320. hardwareProfile.NumberOnWin9x = _ttoi (p);
  321. MYASSERT(hardwareProfile.NumberOnWin9x);
  322. if(hardwareProfile.NumberOnWin9x == CurrentConfig){
  323. if(GrowListGetSize(&g_HardwareProfileList)){
  324. GrowListInsert(&g_HardwareProfileList, 0, (PBYTE)&hardwareProfile, sizeof(hardwareProfile));
  325. }
  326. else{
  327. GrowListAppend(&g_HardwareProfileList, (PBYTE)&hardwareProfile, sizeof(hardwareProfile));
  328. }
  329. }
  330. else if(!pIsSoftwareBranchDefault(hardwareProfile.NumberOnWin9x)){
  331. GrowListAppend(&g_HardwareProfileList, (PBYTE)&hardwareProfile, sizeof(hardwareProfile));
  332. }
  333. }
  334. return FILTER_RETURN_HANDLED;
  335. }
  336. /*
  337. The current hardware profile is used as the "default" hardware
  338. profile. The Windows NT key Hardware Profiles\0001 is renamed
  339. to Hardware Profiles\Default for temporary use.
  340. The Windows NT defaults are used as the base of all upgraded profiles.
  341. For each hardware profile on Windows 9x, a Hardware Profiles\<n> key
  342. is created, where <n> is the numeric identifier of the Windows 9x
  343. hardware profile. All values and subkeys of Hardware Profiles\Default
  344. are copied to this new key.
  345. The Windows 9x settings are copied to NT. For each hardware profile
  346. on Windows 9x, the entire registry tree in Config\<n> is copied to
  347. Hardware Profiles\<n>, where <n> is the four-digit hardware profile
  348. numeric identifier.
  349. The default settings are deleted. Setup removes the Hardware
  350. Profiles\Default key.
  351. */
  352. BOOL
  353. pCreateDefaultKey (
  354. LPCTSTR BaseRegStr
  355. )
  356. {
  357. DATAOBJECT SrcOb, DestOb;
  358. TCHAR SrcObStr[MAX_ENCODED_RULE];
  359. TCHAR DestObStr[MAX_ENCODED_RULE];
  360. BOOL b;
  361. wsprintf (SrcObStr, TEXT("%s\\%s\\*") , BaseRegStr, S_HW_ID_0001);
  362. b = CreateObjectStruct (SrcObStr, &SrcOb, WINNTOBJECT);
  363. MYASSERT(b);
  364. wsprintf (DestObStr, TEXT("%s\\%s\\*"), BaseRegStr, S_HW_DEFAULT);
  365. b = CreateObjectStruct (DestObStr, &DestOb, WINNTOBJECT);
  366. MYASSERT(b);
  367. b = RenameDataObject (&SrcOb, &DestOb);
  368. FreeObjectStruct (&SrcOb);
  369. FreeObjectStruct (&DestOb);
  370. if (!b) {
  371. LOG ((LOG_ERROR, "CreateDefaultKey: Could not rename %s to %s", SrcObStr, DestObStr));
  372. }
  373. return b;
  374. }
  375. VOID
  376. pDeleteProfilesConfigValues(
  377. IN DWORD ConfigNumber
  378. )
  379. {
  380. DATAOBJECT Object;
  381. TCHAR ObStr[MAX_ENCODED_RULE];
  382. BOOL bResult;
  383. UINT i;
  384. static PCTSTR ObjectsValue[] = {
  385. TEXT("Aliasable"),
  386. TEXT("Cloned"),
  387. TEXT("HwProfileGuid")
  388. };
  389. for(i = 0; i < ARRAYSIZE(ObjectsValue); i++){
  390. wsprintf (ObStr, S_NT_HW_ID_MASK TEXT("\\[%s]"), ConfigNumber, ObjectsValue[i]);
  391. bResult = CreateObjectStruct (ObStr, &Object, WINNTOBJECT);
  392. if(!bResult){
  393. MYASSERT(FALSE);
  394. continue;
  395. }
  396. bResult = DeleteDataObjectValue (&Object);
  397. MYASSERT(bResult);
  398. FreeObjectStruct (&Object);
  399. }
  400. return;
  401. }
  402. BOOL
  403. pDeleteDefaultKey (
  404. IN LPCTSTR BaseRegStr
  405. )
  406. {
  407. DATAOBJECT Object;
  408. TCHAR ObStr[MAX_ENCODED_RULE];
  409. BOOL b;
  410. wsprintf (ObStr, TEXT("%s\\%s\\*"), BaseRegStr, S_HW_DEFAULT);
  411. b = CreateObjectStruct (ObStr, &Object, WINNTOBJECT);
  412. MYASSERT(b);
  413. b = DeleteDataObject (&Object);
  414. FreeObjectStruct (&Object);
  415. if (!b) {
  416. LOG ((LOG_ERROR, "CreateDefaultKey: Could not delete %s", ObStr));
  417. }
  418. return b;
  419. }
  420. BOOL
  421. pCopyHwProfileConfigData (
  422. IN DWORD ProfileSrcId,
  423. IN DWORD ProfileDestId
  424. )
  425. {
  426. DATAOBJECT DefaultOb, SrcConfigOb, DestOb;
  427. BOOL b;
  428. TCHAR Buf[MAX_TCHAR_PATH];
  429. ZeroMemory (&DefaultOb, sizeof (DefaultOb));
  430. ZeroMemory (&SrcConfigOb, sizeof (SrcConfigOb));
  431. ZeroMemory (&DestOb, sizeof (DestOb));
  432. //
  433. // DefaultOb struct points to the default NT hardware profile
  434. // configuration (i.e. HKLM\System\CCS\Hardware Profiles\Default)
  435. //
  436. b = CreateObjectStruct (S_NT_DEFAULT_HW_KEY S_TREE, &DefaultOb, WINNTOBJECT);
  437. MYASSERT(b);
  438. //
  439. // SrcConfigOb struct points to the reg key holding the Win9x
  440. // configuration settings (i.e. HKLM\Config\<ProfileId>)
  441. //
  442. wsprintf (Buf, S_9X_CONFIG_MASK S_TREE, ProfileSrcId);
  443. b = b && CreateObjectStruct (Buf, &SrcConfigOb, WIN95OBJECT);
  444. MYASSERT(b);
  445. //
  446. // DestOb struct points to the reg key to receive combined WinNT
  447. // and Win9x settings (i.e. HKLM\System\CCS\Hardware Profiles\<n>)
  448. //
  449. wsprintf (Buf, S_NT_CONFIG_MASK S_TREE, ProfileDestId);
  450. b = b && CreateObjectStruct (Buf, &DestOb, WINNTOBJECT);
  451. MYASSERT(b);
  452. //
  453. // Copy defaults to new profile, then copy Win9x settings as well
  454. //
  455. if (b) {
  456. b = FILTER_RETURN_FAIL != CopyObject (&DefaultOb, &DestOb, NULL, NULL);
  457. if (!b) {
  458. LOG ((LOG_ERROR, "pCopyHwProfileConfigData: Unable to copy defaults"));
  459. }
  460. }
  461. if (b) {
  462. b = FILTER_RETURN_FAIL != CopyObject (&SrcConfigOb, &DestOb,
  463. pHwProfileSuppressFilter, NULL);
  464. if (!b) {
  465. LOG ((LOG_ERROR, "Copy Hardware Profile: Unable to copy Win9x settings"));
  466. }
  467. }
  468. //
  469. // Cleanup
  470. //
  471. FreeObjectStruct (&DefaultOb);
  472. FreeObjectStruct (&SrcConfigOb);
  473. FreeObjectStruct (&DestOb);
  474. return b;
  475. }
  476. BOOL
  477. pCopyHwProfileProperties (
  478. IN DWORD ProfileSrcId,
  479. IN DWORD ProfileDestId
  480. )
  481. {
  482. DATAOBJECT DefaultOb, NameOb, DestOb;
  483. BOOL b;
  484. TCHAR Buf[MAX_TCHAR_PATH];
  485. ZeroMemory (&DefaultOb, sizeof (DefaultOb));
  486. ZeroMemory (&NameOb, sizeof (NameOb));
  487. ZeroMemory (&DestOb, sizeof (DestOb));
  488. //
  489. // DefaultOb struct points to the default NT hardware profile
  490. // properties
  491. //
  492. b = CreateObjectStruct (S_NT_DEFAULT_HW_ID_KEY S_TREE, &DefaultOb, WINNTOBJECT);
  493. MYASSERT(b);
  494. //
  495. // NameOb struct points to the reg key holding FriendlyName<n>
  496. // (i.e. HKLM\System\CCS\Control\IDConfigDB)
  497. //
  498. b = b && CreateObjectStruct (S_BASE_IDCONFIGDB_KEY, &NameOb, WIN95OBJECT);
  499. MYASSERT(b);
  500. //
  501. // DestOb struct points to the reg key to receive FriendlyName
  502. // and PreferenceOrder (i.e. HKLM\System\CCS\Control\IDConfigDB\Hardware
  503. // Profiles\<ProfileId>)
  504. //
  505. wsprintf (Buf, S_NT_HW_ID_MASK S_TREE, ProfileDestId);
  506. b = b && CreateObjectStruct (Buf, &DestOb, WINNTOBJECT);
  507. MYASSERT(b);
  508. //
  509. // Copy default settings to dest object
  510. //
  511. if (b) {
  512. b = FILTER_RETURN_FAIL != CopyObject (&DefaultOb, &DestOb, NULL, NULL);
  513. if (!b) {
  514. LOG ((LOG_ERROR, "Object copy failed"));
  515. }
  516. DEBUGMSG_IF ((!b, DBG_ERROR, "pCopyHwProfileProperties: Cannot copy, source=%s", DebugEncoder (&DefaultOb)));
  517. DEBUGMSG_IF ((!b, DBG_ERROR, "pCopyHwProfileProperties: Cannot copy, dest=%s", DebugEncoder (&DestOb)));
  518. }
  519. //
  520. // Copy FriendlyName and PreferenceOrder values to dest object
  521. //
  522. // Obtain FriendlyName<n>
  523. if (b) {
  524. wsprintf (Buf, S_FRIENDLYNAME_SPRINTF, ProfileSrcId);
  525. SetRegistryValueName (&NameOb, Buf);
  526. b = ReadObject (&NameOb);
  527. if (!b) {
  528. LOG ((LOG_ERROR, "Copy Hardware Profile Properties: Cannot obtain friendly name"));
  529. }
  530. }
  531. // Copy data to dest object struct
  532. if (b) {
  533. SetRegistryType (&DestOb, REG_SZ);
  534. b = ReplaceValue (&DestOb, NameOb.Value.Buffer, NameOb.Value.Size);
  535. if (!b) {
  536. LOG ((LOG_ERROR, "Copy Hardware Profile Properites: Cannot replace value data"));
  537. }
  538. }
  539. // Write dest object
  540. if (b) {
  541. SetRegistryValueName (&DestOb, S_FRIENDLYNAME);
  542. b = WriteObject (&DestOb);
  543. if (!b) {
  544. LOG ((LOG_ERROR, "Copy Hardware Profile Properties: Cannot write object"));
  545. }
  546. DEBUGMSG_IF ((!b, DBG_ERROR, "pCopyHwProfileProperties: Cannot write %s", DebugEncoder (&DestOb)));
  547. }
  548. // Set preference order in dest object struct
  549. if (b) {
  550. SetRegistryType (&DestOb, REG_DWORD);
  551. ProfileDestId--;
  552. b = ReplaceValue (&DestOb, (LPBYTE) &ProfileDestId, sizeof(ProfileDestId));
  553. if (!b) {
  554. LOG ((LOG_ERROR, "Copy Hardware Profile Properties: Cannot set preference order value data"));
  555. }
  556. DEBUGMSG_IF ((!b, DBG_ERROR, "pCopyHwProfileProperties: Cannot set preference order value data"));
  557. }
  558. // Write dest object
  559. if (b) {
  560. SetRegistryValueName (&DestOb, S_PREFERENCEORDER);
  561. b = WriteObject (&DestOb);
  562. if (!b) {
  563. LOG ((LOG_ERROR, "Copy Hardware Profile Properties: Cannot write object"));
  564. }
  565. DEBUGMSG_IF ((!b, DBG_ERROR, "pCopyHwProfileProperties: Cannot write %s", DebugEncoder (&DestOb)));
  566. }
  567. //
  568. // Cleanup
  569. //
  570. FreeObjectStruct (&DefaultOb);
  571. FreeObjectStruct (&NameOb);
  572. FreeObjectStruct (&DestOb);
  573. return b;
  574. }
  575. DWORD
  576. pGetCurrentConfig (
  577. VOID
  578. )
  579. {
  580. DATAOBJECT SrcOb;
  581. BOOL b;
  582. DWORD dwCurrentConfig = 1;
  583. b = CreateObjectStruct (S_CURRENT_CONFIG, &SrcOb, WIN95OBJECT);
  584. MYASSERT(b);
  585. if (ReadObject (&SrcOb)) {
  586. if (IsRegistryTypeSpecified (&SrcOb) && SrcOb.Type == REG_SZ) {
  587. //
  588. // Set destination's object to a REG_DWORD equivalent of
  589. // the Win9x REG_SZ setting
  590. //
  591. dwCurrentConfig = _ttoi ((LPCTSTR) SrcOb.Value.Buffer);
  592. if(!dwCurrentConfig){
  593. dwCurrentConfig = 1;
  594. MYASSERT(FALSE);
  595. }
  596. DEBUGMSG ((DBG_VERBOSE, "pGetCurrentConfig: %d", dwCurrentConfig));
  597. }
  598. else {
  599. LOG ((
  600. LOG_ERROR,
  601. "Get Current Config: Read unexpected data type from registry in object"
  602. ));
  603. DEBUGMSG ((
  604. DBG_ERROR,
  605. "pGetCurrentConfig: Read unexpected data type from registry in %s",
  606. DebugEncoder (&SrcOb)
  607. ));
  608. }
  609. }
  610. else {
  611. LOG ((
  612. LOG_ERROR,
  613. "Get Current Config: Could not read object"
  614. ));
  615. DEBUGMSG ((
  616. DBG_ERROR,
  617. "pGetCurrentConfig: Could not read %s",
  618. DebugEncoder (&SrcOb)
  619. ));
  620. }
  621. FreeObjectStruct (&SrcOb);
  622. return dwCurrentConfig;
  623. }
  624. BOOL
  625. pCopyCurrentConfig (
  626. VOID
  627. )
  628. {
  629. DATAOBJECT SrcOb, DestOb;
  630. BOOL b;
  631. DWORD d;
  632. b = CreateObjectStruct (S_CURRENT_CONFIG, &SrcOb, WIN95OBJECT);
  633. MYASSERT(b);
  634. b = CreateObjectStruct (S_CURRENT_CONFIG, &DestOb, WINNTOBJECT);
  635. MYASSERT(b);
  636. b = ReadObject (&SrcOb);
  637. if (b) {
  638. if (IsRegistryTypeSpecified (&SrcOb) && SrcOb.Type == REG_SZ) {
  639. //
  640. // Set destination's object to a REG_DWORD equivalent of
  641. // the Win9x REG_SZ setting
  642. //
  643. d = _ttoi ((LPCTSTR) SrcOb.Value.Buffer);
  644. b = ReplaceValue (&DestOb, (LPBYTE) &d, sizeof(d));
  645. if (b) {
  646. SetRegistryType (&DestOb, REG_DWORD);
  647. b = WriteObject (&DestOb);
  648. if (!b) {
  649. LOG ((
  650. LOG_ERROR,
  651. "Copy Current Config: Could not write object"
  652. ));
  653. }
  654. DEBUGMSG_IF ((
  655. !b,
  656. DBG_ERROR,
  657. "pCopyCurrentConfig: Could not write %s",
  658. DebugEncoder (&DestOb)
  659. ));
  660. }
  661. else {
  662. LOG ((LOG_ERROR, "Copy Current Config: Unable to replace value"));
  663. DEBUGMSG ((DBG_ERROR, "pCopyCurrentConfig: Unable to replace value"));
  664. }
  665. }
  666. else {
  667. LOG ((
  668. LOG_ERROR,
  669. "Copy Current Config: Read unexpected data type from registry in object"
  670. ));
  671. DEBUGMSG ((
  672. DBG_ERROR,
  673. "pCopyCurrentConfig: Read unexpected data type from registry in %s",
  674. DebugEncoder (&SrcOb)
  675. ));
  676. }
  677. }
  678. else {
  679. LOG ((
  680. LOG_ERROR,
  681. "Copy Current Config: Could not read object"
  682. ));
  683. DEBUGMSG ((
  684. DBG_ERROR,
  685. "pCopyCurrentConfig: Could not read %s",
  686. DebugEncoder (&SrcOb)
  687. ));
  688. }
  689. FreeObjectStruct (&SrcOb);
  690. FreeObjectStruct (&DestOb);
  691. return b;
  692. }
  693. VOID
  694. pMigrateHardwareProfiles(
  695. VOID
  696. )
  697. {
  698. PHARDWARE_PROFILE hardwareProfile;
  699. UINT destHWProfileNumber;
  700. UINT itemCount;
  701. BOOL b;
  702. for(destHWProfileNumber = 1, itemCount = GrowListGetSize(&g_HardwareProfileList);
  703. destHWProfileNumber <= itemCount;
  704. destHWProfileNumber++){
  705. hardwareProfile = (PHARDWARE_PROFILE)GrowListGetItem(&g_HardwareProfileList, destHWProfileNumber - 1);
  706. MYASSERT(hardwareProfile);
  707. //
  708. // Process hardware profile ID entry
  709. //
  710. b = pCopyHwProfileProperties(hardwareProfile->NumberOnWin9x, destHWProfileNumber);
  711. if (!b) {
  712. LOG ((LOG_ERROR, "Unable to continue processing hardware profile %04u->%04u", hardwareProfile->NumberOnWin9x, destHWProfileNumber));
  713. }
  714. //
  715. // Process hardware profile configuration entries
  716. //
  717. if (b) {
  718. b = pCopyHwProfileConfigData(hardwareProfile->NumberOnWin9x, destHWProfileNumber);
  719. if (!b) {
  720. LOG ((LOG_ERROR, "Unable to complete processing hardware profile %04u->%04u", hardwareProfile->NumberOnWin9x, destHWProfileNumber));
  721. }
  722. }
  723. if(1 != destHWProfileNumber){
  724. pDeleteProfilesConfigValues(destHWProfileNumber);
  725. }
  726. }
  727. FreeGrowList(&g_HardwareProfileList);
  728. }