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.

677 lines
16 KiB

  1. /* Copyright (c) 1995 Microsoft Corporation */
  2. /*
  3. **-----------------------------------------------------------------------------
  4. ** File: RegFix.c
  5. ** Purpose: Fix up various registry settings for MidiMapper
  6. ** Mod Log: Created by Shawn Brown (11/14/95)
  7. **-----------------------------------------------------------------------------
  8. */
  9. /*
  10. **-----------------------------------------------------------------------------
  11. ** Includes
  12. **-----------------------------------------------------------------------------
  13. */
  14. #include "RegFix.h"
  15. /*
  16. **-----------------------------------------------------------------------------
  17. ** Local Prototypes
  18. **-----------------------------------------------------------------------------
  19. */
  20. BOOL CheckMidiOK (void);
  21. BOOL SetMidiOK (BOOL fOK);
  22. BOOL CheckMidiHeader (void);
  23. BOOL CheckMidiSchemes (void);
  24. BOOL CheckMidiDrivers (void);
  25. BOOL CreateDefMidiHeader (void);
  26. BOOL CreateDefMidiSchemes (void);
  27. BOOL CreateDefMidiDrivers (void);
  28. /*
  29. **-----------------------------------------------------------------------------
  30. ** Local Variables
  31. **-----------------------------------------------------------------------------
  32. */
  33. // Consider - revisit these and make them use the appropriate roots
  34. // from regstr.h
  35. static const TCHAR l_aszMidiMapKey[] = TEXT ("Software\\Microsoft\\Multimedia\\MidiMap");
  36. static const TCHAR l_aszMediaPropKey[] = TEXT ("System\\CurrentControlSet\\Control\\MediaProperties");
  37. static const TCHAR l_aszMediaRsrcKey[] = TEXT ("System\\CurrentControlSet\\Control\\MediaResources");
  38. static const TCHAR l_aszMRMidiKey[] = TEXT ("System\\CurrentControlSet\\Control\\MediaResources\\Midi");
  39. static const TCHAR l_aszSchemesKey[] = TEXT ("System\\CurrentControlSet\\Control\\MediaProperties\\PrivateProperties\\MIDI\\Schemes");
  40. static const TCHAR l_aszMediaKey[] = TEXT ("Media");
  41. static const TCHAR l_aszMIDIKey[] = TEXT ("Midi");
  42. static const TCHAR aszInstrumentKey[] = TEXT ("Instruments");
  43. static const TCHAR aszDrvMIDIKey[] = TEXT ("Drivers\\MIDI");
  44. static const TCHAR aszPrivateKey[] = TEXT ("Private Properties");
  45. static const TCHAR aszDefaultKey[] = TEXT ("Default");
  46. static const TCHAR aszMigratedVal[] = TEXT ("Migrated");
  47. static const TCHAR aszMIDI[] = TEXT ("MIDI");
  48. static const TCHAR aszNULL[] = TEXT ("");
  49. static const TCHAR l_aszOK[] = TEXT ("Validate");
  50. static const TCHAR aszActiveVal[] = TEXT ("Active");
  51. static const TCHAR aszDescripVal[] = TEXT ("Description");
  52. static const TCHAR aszDeviceIDVal[] = TEXT ("DeviceID");
  53. static const TCHAR aszDevNodeVal[] = TEXT ("DevNode");
  54. static const TCHAR aszDriverVal[] = TEXT ("Driver");
  55. static const TCHAR aszFriendlyVal[] = TEXT ("FriendlyName");
  56. static const TCHAR aszMapCfgVal[] = TEXT ("MapperConfig");
  57. static const TCHAR aszSoftwareVal[] = TEXT ("SOFTWAREKEY");
  58. static const TCHAR aszInstallerVal[] = TEXT ("Installer");
  59. static const TCHAR aszChannelsVal[] = TEXT ("Channels");
  60. static const TCHAR aszMIDIClass[] = TEXT ("Midi");
  61. static const TCHAR aszAuxClass[] = TEXT ("Aux");
  62. static const TCHAR aszWaveClass[] = TEXT ("Wave");
  63. static const TCHAR aszMixerClass[] = TEXT ("Mixer");
  64. static const TCHAR aszOne[] = TEXT ("1");
  65. static const TCHAR aszZeroZeroKey[] = TEXT ("00");
  66. /*
  67. **-----------------------------------------------------------------------------
  68. ** Name: CheckRegistry
  69. ** Purpose:
  70. ** Mod Log: Created by Shawn Brown (11/95)
  71. **-----------------------------------------------------------------------------
  72. */
  73. BOOL CheckRegistry (BOOL fForceUpdate)
  74. {
  75. if (!fForceUpdate)
  76. {
  77. // Check OK flag
  78. if (CheckMidiOK())
  79. return TRUE;
  80. }
  81. // Fix up Header
  82. if (! CheckMidiHeader())
  83. return FALSE;
  84. // Fix up schemes
  85. if (! CheckMidiSchemes ())
  86. return FALSE;
  87. // Fix up drivers
  88. if (! CheckMidiDrivers ())
  89. return FALSE;
  90. // All done, set OK flag
  91. SetMIDIOK (TRUE);
  92. return TRUE;
  93. }
  94. /*
  95. **-----------------------------------------------------------------------------
  96. ** Name: CheckMidiOK
  97. ** Purpose: Simple quick check to see if everything is OK
  98. ** Mod Log: Created by Shawn Brown (11/95)
  99. **-----------------------------------------------------------------------------
  100. */
  101. BOOL CheckMidiOK (void)
  102. {
  103. HKEY hKey;
  104. LONG lResult;
  105. DWORD dwType;
  106. DWORD dwVal;
  107. DWORD cbSize;
  108. lResult = RegOpenEx (HKEY_CURRENT_USER, l_aszMidiMapKey,
  109. 0, KEY_ALL_ACCESS, &hKey);
  110. if (ERROR_SUCCESS != lResult)
  111. return FALSE;
  112. dwType = REG_DWORD;
  113. cbSize = sizeof (DWORD);
  114. lResult = RegQueryValueEx (hKey, l_aszOK, NULL, &dwType,
  115. (LPBYTE)(LPDWORD)&dwVal, &cbSize);
  116. if (ERROR_SUCCESS != lResult)
  117. {
  118. RegCloseKey (hKey);
  119. return FALSE;
  120. }
  121. RegCloseKey (hKey);
  122. if (0 == dwVal)
  123. return FALSE;
  124. return TRUE;
  125. } // End CheckMidiOK
  126. /*
  127. **-----------------------------------------------------------------------------
  128. ** Name: SetMidiOK
  129. ** Purpose: Set OK value
  130. ** Mod Log: Created by Shawn Brown (11/95)
  131. **-----------------------------------------------------------------------------
  132. */
  133. BOOL SetMidiOK (BOOL fOK)
  134. {
  135. HKEY hKey;
  136. LONG lResult;
  137. DWORD dwType;
  138. DWORD dwVal;
  139. DWORD cbSize;
  140. lResult = RegOpenEx (HKEY_CURRENT_USER, l_aszMidiMapKey,
  141. 0, KEY_ALL_ACCESS, &hKey);
  142. if (ERROR_SUCCESS != lResult)
  143. return FALSE;
  144. dwType = REG_DWORD;
  145. dwVal = (DWORD)fOK;
  146. cbSize = sizeof (DWORD);
  147. lResult = RegSetValueEx (hKey, l_aszOK, 0, &dwType,
  148. (LPBYTE)(LPDWORD)&dwVal, &cbSize);
  149. if (ERROR_SUCCESS != lResult)
  150. {
  151. RegCloseKey (hKey);
  152. return FALSE;
  153. }
  154. RegCloseKey (hKey);
  155. return TRUE;
  156. } // End SetMidiOK
  157. /*
  158. **-----------------------------------------------------------------------------
  159. ** Name: CheckHeader
  160. ** Purpose: do we have a valid Midi Header ?!?
  161. ** Mod Log: Created by Shawn Brown (11/95)
  162. **-----------------------------------------------------------------------------
  163. */
  164. BOOL CheckMidiHeader (void)
  165. {
  166. return CreateDefMidiHeader ();
  167. } // End CheckMidiHeader
  168. /*
  169. **-----------------------------------------------------------------------------
  170. ** Name: CreateDefMidiHeader
  171. ** Purpose:
  172. ** Mod Log: Created by Shawn Brown (11/95)
  173. **-----------------------------------------------------------------------------
  174. */
  175. BOOL CreateDefaultHeader (void)
  176. {
  177. } // End CreateDefaultHeader
  178. /*
  179. **-----------------------------------------------------------------------------
  180. ** Name: IsMIDIDriver
  181. ** Purpose:
  182. ** Mod Log: Created by Shawn Brown (11/95)
  183. **-----------------------------------------------------------------------------
  184. */
  185. BOOL IsMIDIDriver (
  186. LPCTSTR pszDriverName) // IN: driver name
  187. {
  188. UINT cNumDrivers;
  189. UINT ii;
  190. TCHAR szDriver[MAX_PATH];
  191. // Look for the MIDI driver
  192. cNumDrivers = midiOutGetNumDevs ();
  193. for (ii = 0; ii < cNumDrivers; ii++)
  194. {
  195. if (! GetDriverName (aszMIDI, ii, szDriver, MAX_PATH))
  196. continue;
  197. if (0 == lstrcmpi (pszDriverName, szDriver))
  198. return TRUE;
  199. } // End for
  200. // Look for the MIDI driver
  201. cNumDrivers = midiInGetNumDevs ();
  202. for (ii = 0; ii < cNumDrivers; ii++)
  203. {
  204. if (! GetDriverName (aszMIDI, ii, szDriver, MAX_PATH))
  205. continue;
  206. if (0 == lstrcmpi (pszDriverName, szDriver))
  207. return TRUE;
  208. } // End for
  209. return FALSE;
  210. } // End IsMIDIDriver
  211. /*
  212. **-----------------------------------------------------------------------------
  213. ** Name: IsMigrated
  214. ** Purpose:
  215. ** Mod Log: Created by Shawn Brown (11/95)
  216. **-----------------------------------------------------------------------------
  217. */
  218. BOOL IsMigrated (UINT uDeviceID)
  219. {
  220. TCHAR szDriver[MAX_PATH];
  221. TCHAR szBuffer[MAX_PATH];
  222. HKEY hDriverKey;
  223. DWORD cbSize;
  224. // Get Driver
  225. if (! GetDriverName (aszMIDI, uDeviceID, szDriver, MAX_PATH))
  226. return FALSE;
  227. // Open Driver Key
  228. wsprintf (szBuffer, TEXT ("%s\\%s<%04ld>"), aszMRMidiKey, szDriver, uDeviceID);
  229. if (ERROR_SUCCESS != RegOpenKeyEx (HKEY_LOCAL_MACHINE, szBuffer,
  230. 0, KEY_ALL_ACCESS, &hDriverKey))
  231. return FALSE;
  232. // Get Migrated Value
  233. // The mere existence of the Migrated value indicates
  234. // we have already successfully migrated this driver
  235. cbSize = sizeof(szBuffer);
  236. if (ERROR_SUCCESS != RegQueryValueEx (hDriverKey, aszMigratedVal,
  237. NULL, NULL, (LPBYTE)szBuffer, &cbSize))
  238. {
  239. RegCloseKey (hDriverKey);
  240. return FALSE;
  241. }
  242. RegCloseKey (hDriverKey);
  243. return TRUE;
  244. } // End IsMigrated
  245. /*
  246. **-----------------------------------------------------------------------------
  247. ** Name: MigrateNewMIDIDriver
  248. ** Purpose:
  249. ** Mod Log: Created by Shawn Brown (11/95)
  250. **-----------------------------------------------------------------------------
  251. */
  252. BOOL MigrateNewMIDIDriver (
  253. UINT uDeviceID) // IN: MIDI Driver device ID
  254. {
  255. TCHAR szDriver[MAX_PATH];
  256. TCHAR szFriend[MAX_PATH];
  257. TCHAR szDescrip[MAX_PATH];
  258. TCHAR szBuffer[MAX_PATH];
  259. DWORD cOut;
  260. MIDIOUTCAPS moc;
  261. DWORD dwDisposition;
  262. DWORD cbSize;
  263. DWORD dwVal;
  264. HKEY hMIDIKey = NULL;
  265. HKEY hDriverKey = NULL;
  266. HKEY hInstrumentKey = NULL;
  267. HKEY hKey = NULL;
  268. BOOL fResult = FALSE;
  269. cOut = midiOutGetNumDevs ();
  270. if (uDeviceID >= cOut)
  271. return FALSE;
  272. // Get Driver
  273. if (! GetDriverName (aszMIDI, uDeviceID, szDriver, MAX_PATH))
  274. return FALSE;
  275. // Get Friendly Name
  276. if (! GetDriverFriendlyName (aszMIDI, uDeviceID, szFriend, MAX_PATH))
  277. {
  278. lstrcpy (szFriend, szDriver);
  279. }
  280. // Get Description
  281. if (MMSYSERR_NOERROR != midiOutGetDevCaps (uDeviceID, &moc, sizeof(moc)))
  282. return FALSE;
  283. if (moc.szPname[0] == 0)
  284. {
  285. lstrcpy (szDescrip, szDriver);
  286. }
  287. else
  288. {
  289. lstrcpy (szDescrip, moc.szPname);
  290. }
  291. // Open key, create it if it doesn't already exist
  292. if (ERROR_SUCCESS != RegCreateKeyEx (HKEY_LOCAL_MACHINE, aszMRMidiKey,
  293. 0, NULL, 0, KEY_ALL_ACCESS, NULL,
  294. &hMIDIKey, NULL))
  295. {
  296. return FALSE;
  297. }
  298. // Create new driver key
  299. wsprintf (szBuffer, TEXT ("%s<%04ld>"), szDriver, uDeviceID);
  300. if (ERROR_SUCCESS != RegCreateKeyEx (hMIDIKey, szBuffer,
  301. 0, NULL, 0, KEY_ALL_ACCESS, NULL,
  302. &hDriverKey, &dwDisposition))
  303. {
  304. goto lblCLEANUP;
  305. }
  306. RegCloseKey (hMIDIKey);
  307. hMIDIKey = NULL;
  308. //
  309. // Set Driver Values
  310. //
  311. // Set Active = "1" value
  312. cbSize = sizeof (aszOne);
  313. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszActiveVal, 0,
  314. REG_SZ, (LPBYTE)aszOne, cbSize))
  315. {
  316. goto lblCLEANUP;
  317. }
  318. // Set Description = szDescrip value
  319. cbSize = (lstrlen (szDescrip) + 1) * sizeof(TCHAR);
  320. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszDescripVal, 0,
  321. REG_SZ, (LPBYTE)szDescrip, cbSize))
  322. {
  323. goto lblCLEANUP;
  324. }
  325. // Set DeviceID = "" value
  326. cbSize = (lstrlen (aszNULL) + 1) * sizeof(TCHAR);
  327. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszDeviceIDVal, 0,
  328. REG_SZ, (LPBYTE)aszNULL, cbSize))
  329. {
  330. goto lblCLEANUP;
  331. }
  332. // Set DevNode = value
  333. cbSize = 0;
  334. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszDeviceIDVal, 0,
  335. REG_BINARY, (LPBYTE)NULL, cbSize))
  336. {
  337. goto lblCLEANUP;
  338. }
  339. // Set Driver = szDriver
  340. cbSize = (lstrlen (szDriver) + 1) * sizeof(TCHAR);
  341. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszDriverVal, 0,
  342. REG_SZ, (LPBYTE)szDriver, cbSize))
  343. {
  344. goto lblCLEANUP;
  345. }
  346. // Set FriendlyName
  347. cbSize = (lstrlen (szFriend) + 1) * sizeof(TCHAR);
  348. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszFriendlyVal, 0,
  349. REG_SZ, (LPBYTE)szFriend, cbSize))
  350. {
  351. goto lblCLEANUP;
  352. }
  353. // Set Mapper Config
  354. cbSize = sizeof(DWORD);
  355. dwVal = 0;
  356. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszMapCfgVal, 0,
  357. REG_DWORD, (LPBYTE)&dwVal, cbSize))
  358. {
  359. goto lblCLEANUP;
  360. }
  361. // Set SOFTWARE value
  362. wsprintf (szBuffer, TEXT("%s\\%04ld"), aszServiceKey, uDeviceID);
  363. cbSize = (lstrlen (szBuffer) + 1) * sizeof(TCHAR);
  364. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszSoftwareVal, 0,
  365. REG_SZ, (LPBYTE)szBuffer, cbSize))
  366. {
  367. goto lblCLEANUP;
  368. }
  369. // Create Instruments Key
  370. if (ERROR_SUCCESS != RegCreateKeyEx (hDriverKey, aszInstrumentKey, 0, NULL,
  371. 0, KEY_ALL_ACCESS, NULL,
  372. &hInstrumentKey, &dwDisposition))
  373. {
  374. goto lblCLEANUP;
  375. }
  376. RegCloseKey (hInstrumentKey);
  377. hInstrumentKey = NULL;
  378. // Create Services\Class\Media\0001\Drivers\midi key
  379. // Open key, create it if it doesn't already exist
  380. // wsprintf (szBuffer, TEXT("%s\\%04ld\\%s"), aszServiceKey, uDeviceID, aszDrvMIDIKey);
  381. // if (ERROR_SUCCESS != RegCreateKeyEx (HKEY_LOCAL_MACHINE, szBuffer,
  382. // 0, NULL, 0, KEY_ALL_ACCESS, NULL,
  383. // &hMIDIKey, NULL))
  384. // {
  385. // goto lblCLEANUP;
  386. // }
  387. // Create
  388. // Set MIGRATED value
  389. // NOTE: this is always the very last thing to do to indicate successful migration
  390. cbSize = (lstrlen (aszOne) + 1) * sizeof(TCHAR);
  391. if (ERROR_SUCCESS != RegSetValueEx (hDriverKey, aszMigratedVal, 0, REG_SZ, (LPBYTE)aszOne, cbSize))
  392. {
  393. goto lblCLEANUP;
  394. }
  395. // Success
  396. fResult = TRUE;
  397. lblCLEANUP:
  398. if (hInstrumentKey)
  399. RegCloseKey (hInstrumentKey);
  400. if (hDriverKey)
  401. RegCloseKey (hDriverKey);
  402. if (hMIDIKey)
  403. RegCloseKey (hMIDIKey);
  404. return fResult;
  405. } // End MigrateNewMIDIDriver
  406. /*
  407. **-----------------------------------------------------------------------------
  408. ** Name: CreateDefaultMIDISchemes
  409. ** Purpose:
  410. ** Mod Log: Created by Shawn Brown (11/95)
  411. **-----------------------------------------------------------------------------
  412. */
  413. BOOL CreateDefaultMIDISchemes (void)
  414. {
  415. HKEY hSchemeKey;
  416. HKEY hDefaultKey;
  417. HKEY hZeroKey;
  418. DWORD dwVal;
  419. DWORD cbSize;
  420. // Create MIDI Schemes key
  421. if (ERROR_SUCCESS != RegCreateKeyEx (HKEY_LOCAL_MACHINE, aszMIDISchemesKey,
  422. 0, NULL, 0, KEY_ALL_ACCESS, NULL,
  423. &hSchemeKey, NULL))
  424. {
  425. return FALSE;
  426. }
  427. // Create Default Key
  428. if (ERROR_SUCCESS != RegCreateKeyEx (hSchemeKey, aszDefaultKey,
  429. 0, NULL, 0, KEY_ALL_ACCESS, NULL,
  430. &hDefaultKey, NULL))
  431. {
  432. RegCloseKey (hSchemeKey);
  433. return FALSE;
  434. }
  435. RegCloseKey (hSchemeKey);
  436. // Create 00 Key
  437. if (ERROR_SUCCESS != RegCreateKeyEx (hDefaultKey, aszZeroZeroKey,
  438. 0, NULL, 0, KEY_ALL_ACCESS, NULL,
  439. &hZeroKey, NULL))
  440. {
  441. RegCloseKey (hDefaultKey);
  442. return FALSE;
  443. }
  444. RegCloseKey (hDefaultKey);
  445. // Create Default Channels Value
  446. dwVal = 0x0000FFFF;
  447. cbSize = sizeof(DWORD);
  448. if (ERROR_SUCCESS != RegSetValueEx (hZeroKey, aszChannelsVal, 0,
  449. REG_DWORD, (LPBYTE)&dwVal, cbSize))
  450. {
  451. RegCloseKey (hZeroKey);
  452. return FALSE;
  453. }
  454. RegCloseKey (hZeroKey);
  455. // Success
  456. return TRUE;
  457. } // End CreateDefaultMIDISchemes
  458. /*
  459. **-----------------------------------------------------------------------------
  460. ** Name: MigrateExistingMIDISchemes
  461. ** Purpose:
  462. ** Mod Log: Created by Shawn Brown (11/95)
  463. **-----------------------------------------------------------------------------
  464. */
  465. BOOL MigrateExistingMIDISchemes (void)
  466. {
  467. return TRUE;
  468. } // End MigrateExistingMIDISchemes
  469. /*
  470. **-----------------------------------------------------------------------------
  471. ** Name: MigrateMIDIDrivers
  472. ** Purpose:
  473. ** Mod Log: Created by Shawn Brown (11/95)
  474. **-----------------------------------------------------------------------------
  475. */
  476. BOOL MigrateMIDIDrivers (void)
  477. {
  478. UINT cOut;
  479. UINT ii;
  480. BOOL fResult = TRUE;
  481. if (! CreateDefaultMIDISchemes ())
  482. {
  483. return FALSE;
  484. }
  485. if (! MigrateExistingMIDISchemes ())
  486. {
  487. return FALSE;
  488. }
  489. cOut = midiOutGetNumDevs ();
  490. if (cOut == 0L)
  491. return FALSE;
  492. for (ii = 0; ii < cOut; ii++)
  493. {
  494. if (IsMigrated (ii))
  495. continue;
  496. if (! MigrateNewMIDIDriver (ii))
  497. fResult = FALSE;
  498. }
  499. return fResult;
  500. } // End MigrateMIDIDrivers
  501. /*
  502. **-----------------------------------------------------------------------------
  503. ** Name: DumpDeviceCaps
  504. ** Purpose:
  505. ** Mod Log: Created by Shawn Brown (11/95)
  506. **-----------------------------------------------------------------------------
  507. */
  508. BOOL DumpMidiOutDeviceCaps (UINT uDeviceID, LPSTR pszBuff, UINT cchLen)
  509. {
  510. static const aszMMicrosoft[] = TEXT ("Microsoft(TM)");
  511. static const aszMMUnknown[] =
  512. MIDIOUTCAPS moc;
  513. MMRESULT mmr;
  514. DWORD wMid;
  515. DWORD wPid;
  516. DWORD dwVerHigh, dwVerLow;
  517. LPTSTR pszName;
  518. WORD wTechnology;
  519. WORD wVoices;
  520. WORD wNotes;
  521. WORD wChannelMask;
  522. DWORD dwSupport;
  523. mmr = midiOutGetDevCaps (uDeviceId, &moc, sizeof(moc));
  524. if (MMSYSERR_NOERROR != mmr)
  525. return FALSE;
  526. return TRUE;
  527. } // End DumpDeviceCaps
  528. /*
  529. **-----------------------------------------------------------------------------
  530. ** End of File
  531. **-----------------------------------------------------------------------------
  532. */