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.

983 lines
29 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. mmedia.c
  5. Abstract:
  6. Multimedia settings migration functions for Win95
  7. Author:
  8. Calin Negreanu (calinn) 02-Dec-1997
  9. Revision History:
  10. Ovidiu Temereanca (ovidiut) 29-Jan-1999
  11. --*/
  12. #include "pch.h"
  13. #include "mmediap.h"
  14. POOLHANDLE g_MmediaPool = NULL;
  15. #define MM_POOLGETMEM(STRUCT, COUNT) \
  16. (COUNT * sizeof(STRUCT) < 1024) ? \
  17. (STRUCT*) PoolMemGetMemory (g_MmediaPool, COUNT * sizeof(STRUCT)) : \
  18. NULL
  19. static PCTSTR g_UserData = NULL;
  20. static HKEY g_UserRoot = NULL;
  21. BOOL
  22. pSaveSystemValue (
  23. IN PCTSTR KeyName,
  24. IN PCTSTR Field, OPTIONAL
  25. IN PCTSTR StrValue, OPTIONAL
  26. IN DWORD NumValue OPTIONAL
  27. )
  28. {
  29. return MemDbSetValueEx (
  30. MEMDB_CATEGORY_MMEDIA_SYSTEM,
  31. KeyName,
  32. Field,
  33. StrValue,
  34. NumValue,
  35. NULL);
  36. }
  37. BOOL
  38. pSaveSystemBinaryValue (
  39. IN PCTSTR KeyName,
  40. IN PCTSTR Field, OPTIONAL
  41. IN PCBYTE Data,
  42. IN DWORD DataSize
  43. )
  44. {
  45. return MemDbSetBinaryValueEx (
  46. MEMDB_CATEGORY_MMEDIA_SYSTEM,
  47. KeyName,
  48. Field,
  49. Data,
  50. DataSize,
  51. NULL);
  52. }
  53. BOOL
  54. pSaveMMSystemMixerSettings (
  55. VOID
  56. )
  57. {
  58. UINT MixerID, MixerMaxID;
  59. HMIXER mixer;
  60. MIXERCAPS mixerCaps;
  61. MIXERLINE mixerLine, mixerLineSource;
  62. MIXERLINECONTROLS mixerLineControls;
  63. MIXERCONTROL* pmxControl;
  64. MIXERCONTROLDETAILS mixerControlDetails;
  65. MMRESULT rc;
  66. DWORD Dest, Src, Control;
  67. TCHAR MixerKey[MAX_PATH], LineKey[MAX_PATH], SrcKey[MAX_PATH], SubKey[MAX_PATH];
  68. DWORD ValuesCount;
  69. MixerMaxID = mixerGetNumDevs ();
  70. pSaveSystemValue (S_MIXERNUMDEVS, NULL, NULL, MixerMaxID);
  71. for (MixerID = 0; MixerID < MixerMaxID; MixerID++) {
  72. rc = mixerGetDevCaps (MixerID, &mixerCaps, sizeof (MIXERCAPS));
  73. if (rc != MMSYSERR_NOERROR) {
  74. DEBUGMSG ((DBG_MMEDIA, "mixerGetDevCaps failed for mixer %lu [rc=%#X]. No settings will be preserved.", MixerID, rc));
  75. continue;
  76. }
  77. rc = mixerOpen (&mixer, MixerID, 0L, 0L, MIXER_OBJECTF_MIXER);
  78. if (rc != MMSYSERR_NOERROR) {
  79. DEBUGMSG ((DBG_MMEDIA, "mixerOpen failed for mixer %lu [rc=%#X]. No settings will be preserved.", MixerID, rc));
  80. continue;
  81. }
  82. wsprintf (MixerKey, S_MIXERID, MixerID);
  83. pSaveSystemValue (MixerKey, S_NUMLINES, NULL, mixerCaps.cDestinations);
  84. for (Dest = 0; Dest < mixerCaps.cDestinations; Dest++) {
  85. ZeroMemory (&mixerLine, sizeof (MIXERLINE));
  86. mixerLine.cbStruct = sizeof (MIXERLINE);
  87. mixerLine.dwDestination = Dest;
  88. rc = mixerGetLineInfo ((HMIXEROBJ)mixer, &mixerLine, MIXER_GETLINEINFOF_DESTINATION);
  89. if (rc == MMSYSERR_NOERROR) {
  90. wsprintf (LineKey, S_LINEID, Dest);
  91. if (mixerLine.cControls > 0) {
  92. //
  93. // get all control values for the destination
  94. //
  95. ZeroMemory (&mixerLineControls, sizeof (MIXERLINECONTROLS));
  96. mixerLineControls.cbStruct = sizeof (MIXERLINECONTROLS);
  97. mixerLineControls.dwLineID = mixerLine.dwLineID;
  98. mixerLineControls.cControls = mixerLine.cControls;
  99. mixerLineControls.cbmxctrl = sizeof (MIXERCONTROL);
  100. mixerLineControls.pamxctrl = MM_POOLGETMEM (MIXERCONTROL, mixerLineControls.cControls);
  101. if (mixerLineControls.pamxctrl) {
  102. rc = mixerGetLineControls((HMIXEROBJ)mixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
  103. if (rc == MMSYSERR_NOERROR) {
  104. pSaveSystemValue (MixerKey, LineKey, S_NUMCONTROLS, mixerLine.cControls);
  105. for (
  106. Control = 0, pmxControl = mixerLineControls.pamxctrl;
  107. Control < mixerLineControls.cControls;
  108. Control++, pmxControl++
  109. ) {
  110. ZeroMemory (&mixerControlDetails, sizeof (MIXERCONTROLDETAILS));
  111. mixerControlDetails.cbStruct = sizeof (MIXERCONTROLDETAILS);
  112. mixerControlDetails.dwControlID = pmxControl->dwControlID;
  113. mixerControlDetails.cMultipleItems = pmxControl->cMultipleItems;
  114. mixerControlDetails.cChannels = mixerLine.cChannels;
  115. if (pmxControl->fdwControl & MIXERCONTROL_CONTROLF_UNIFORM) {
  116. mixerControlDetails.cChannels = 1;
  117. }
  118. ValuesCount = mixerControlDetails.cChannels;
  119. if (pmxControl->fdwControl & MIXERCONTROL_CONTROLF_MULTIPLE) {
  120. ValuesCount *= mixerControlDetails.cMultipleItems;
  121. }
  122. mixerControlDetails.cbDetails = sizeof (DWORD);
  123. mixerControlDetails.paDetails = MM_POOLGETMEM (DWORD, ValuesCount);
  124. if (mixerControlDetails.paDetails) {
  125. rc = mixerGetControlDetails ((HMIXEROBJ)mixer, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE);
  126. if (rc == MMSYSERR_NOERROR) {
  127. wsprintf (SubKey, TEXT("%s\\%lu"), LineKey, Control);
  128. pSaveSystemBinaryValue (
  129. MixerKey,
  130. SubKey,
  131. mixerControlDetails.paDetails,
  132. mixerControlDetails.cbDetails * ValuesCount
  133. );
  134. } else {
  135. DEBUGMSG ((DBG_MMEDIA, "mixerGetControlDetails failed for mixer %lu, Line=%lu, Ctl=%lu [rc=%#X]", MixerID, Dest, Control, rc));
  136. }
  137. }
  138. }
  139. } else {
  140. DEBUGMSG ((DBG_MMEDIA, "mixerGetLineControls failed for mixer %lu, Line=%#X [rc=%#X].", MixerID, mixerLineControls.dwLineID, rc));
  141. }
  142. }
  143. }
  144. //
  145. // get this information for all source connections
  146. //
  147. pSaveSystemValue (MixerKey, LineKey, S_NUMSOURCES, mixerLine.cConnections);
  148. for (Src = 0; Src < mixerLine.cConnections; Src++) {
  149. ZeroMemory (&mixerLineSource, sizeof (MIXERLINE));
  150. mixerLineSource.cbStruct = sizeof(MIXERLINE);
  151. mixerLineSource.dwDestination = Dest;
  152. mixerLineSource.dwSource = Src;
  153. rc = mixerGetLineInfo((HMIXEROBJ)mixer, &mixerLineSource, MIXER_GETLINEINFOF_SOURCE);
  154. if (rc == MMSYSERR_NOERROR) {
  155. wsprintf (SrcKey, S_SRCID, Src);
  156. if (mixerLineSource.cControls > 0) {
  157. //
  158. // get all control values
  159. //
  160. ZeroMemory (&mixerLineControls, sizeof (MIXERLINECONTROLS));
  161. mixerLineControls.cbStruct = sizeof (MIXERLINECONTROLS);
  162. mixerLineControls.dwLineID = mixerLineSource.dwLineID;
  163. mixerLineControls.cControls = mixerLineSource.cControls;
  164. mixerLineControls.cbmxctrl = sizeof (MIXERCONTROL);
  165. mixerLineControls.pamxctrl = MM_POOLGETMEM (MIXERCONTROL, mixerLineControls.cControls);
  166. if (mixerLineControls.pamxctrl) {
  167. rc = mixerGetLineControls((HMIXEROBJ)mixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
  168. if (rc == MMSYSERR_NOERROR) {
  169. wsprintf (SubKey, TEXT("%s\\%s"), SrcKey, S_NUMCONTROLS);
  170. pSaveSystemValue (
  171. MixerKey,
  172. LineKey,
  173. SubKey,
  174. mixerLineSource.cControls
  175. );
  176. for (
  177. Control = 0, pmxControl = mixerLineControls.pamxctrl;
  178. Control < mixerLineControls.cControls;
  179. Control++, pmxControl++
  180. ) {
  181. ZeroMemory (&mixerControlDetails, sizeof (MIXERCONTROLDETAILS));
  182. mixerControlDetails.cbStruct = sizeof (MIXERCONTROLDETAILS);
  183. mixerControlDetails.dwControlID = pmxControl->dwControlID;
  184. mixerControlDetails.cMultipleItems = pmxControl->cMultipleItems;
  185. mixerControlDetails.cChannels = mixerLineSource.cChannels;
  186. if (pmxControl->fdwControl & MIXERCONTROL_CONTROLF_UNIFORM) {
  187. mixerControlDetails.cChannels = 1;
  188. }
  189. ValuesCount = mixerControlDetails.cChannels;
  190. if (pmxControl->fdwControl & MIXERCONTROL_CONTROLF_MULTIPLE) {
  191. ValuesCount *= mixerControlDetails.cMultipleItems;
  192. }
  193. mixerControlDetails.cbDetails = sizeof (DWORD);
  194. mixerControlDetails.paDetails = MM_POOLGETMEM (DWORD, ValuesCount);
  195. if (mixerControlDetails.paDetails) {
  196. rc = mixerGetControlDetails ((HMIXEROBJ)mixer, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE);
  197. if (rc == MMSYSERR_NOERROR) {
  198. wsprintf (SubKey, TEXT("%s\\%s\\%lu"), LineKey, SrcKey, Control);
  199. pSaveSystemBinaryValue (
  200. MixerKey,
  201. SubKey,
  202. mixerControlDetails.paDetails,
  203. mixerControlDetails.cbDetails * ValuesCount
  204. );
  205. } else {
  206. DEBUGMSG ((DBG_MMEDIA, "mixerGetControlDetails failed for mixer %lu, Line=%lu, Src=%lu, Ctl=%lu [rc=%#X]", MixerID, Dest, Src, Control, rc));
  207. }
  208. }
  209. }
  210. } else {
  211. DEBUGMSG ((DBG_MMEDIA, "mixerGetLineControls failed for mixer %lu, Src=%lu, Line=%#X [rc=%#X].", MixerID, Src, mixerLineControls.dwLineID, rc));
  212. }
  213. }
  214. }
  215. } else {
  216. DEBUGMSG ((DBG_MMEDIA, "mixerGetLineInfo failed for mixer %lu, Src=%lu [rc=%#X].", MixerID, Src, rc));
  217. }
  218. }
  219. } else {
  220. DEBUGMSG ((DBG_MMEDIA, "mixerGetLineInfo failed for mixer %lu [rc=%#X]. No settings will be preserved.", MixerID, rc));
  221. }
  222. }
  223. mixerClose (mixer);
  224. }
  225. return TRUE;
  226. }
  227. BOOL
  228. pGetSoftwareKey (
  229. OUT LPTSTR SoftwareKey,
  230. IN DWORD MaxKeyLen,
  231. IN DWORD DeviceID,
  232. IN HKEY WaveDevices
  233. )
  234. {
  235. TCHAR Buffer[MAX_PATH];
  236. DWORD Type, Len;
  237. HKEY Device;
  238. BOOL b;
  239. LONG rc;
  240. Len = sizeof (Buffer);
  241. rc = RegEnumKeyEx (WaveDevices, DeviceID++, Buffer, &Len, NULL, NULL, NULL, NULL);
  242. if (rc != ERROR_SUCCESS) {
  243. return FALSE;
  244. }
  245. rc = TrackedRegOpenKeyEx (WaveDevices, Buffer, 0, KEY_READ, &Device);
  246. if (rc != ERROR_SUCCESS) {
  247. return FALSE;
  248. }
  249. rc = RegQueryValueEx (
  250. Device,
  251. S_SOFTWAREKEY,
  252. NULL,
  253. &Type,
  254. (LPBYTE)SoftwareKey,
  255. &MaxKeyLen
  256. );
  257. b = (rc == ERROR_SUCCESS) && (Type == REG_SZ);
  258. CloseRegKey (Device);
  259. return b;
  260. }
  261. VOID
  262. pSaveDeviceDSSettings (
  263. IN DWORD DeviceID,
  264. IN HKEY Device
  265. )
  266. {
  267. TCHAR MemDBKey[MAX_PATH];
  268. DWORD Type, Len, Value;
  269. HKEY Key;
  270. LONG rc;
  271. wsprintf (MemDBKey, S_WAVEID, DeviceID);
  272. //
  273. // DirectSound props
  274. //
  275. rc = TrackedRegOpenKeyEx (Device, S_DSMIXERDEFAULTS, 0, KEY_READ, &Key);
  276. if (rc == ERROR_SUCCESS) {
  277. Len = sizeof (Value);
  278. rc = RegQueryValueEx (Key, S_ACCELERATION, NULL, &Type, (LPBYTE)&Value, &Len);
  279. if (rc == ERROR_SUCCESS && (Type == REG_DWORD)) {
  280. pSaveSystemValue (MemDBKey, S_DIRECTSOUND, S_ACCELERATION, Value);
  281. }
  282. Len = sizeof (Value);
  283. rc = RegQueryValueEx (Key, S_SRCQUALITY, NULL, &Type, (LPBYTE)&Value, &Len);
  284. if (rc == ERROR_SUCCESS && (Type == REG_DWORD)) {
  285. pSaveSystemValue (MemDBKey, S_DIRECTSOUND, S_SRCQUALITY, Value);
  286. }
  287. CloseRegKey (Key);
  288. }
  289. rc = TrackedRegOpenKeyEx (Device, S_DSSPEAKERCONFIG, 0, KEY_READ, &Key);
  290. if (rc == ERROR_SUCCESS) {
  291. Len = sizeof (Value);
  292. rc = RegQueryValueEx (Key, S_SPEAKERCONFIG, NULL, &Type, (LPBYTE)&Value, &Len);
  293. if (rc == ERROR_SUCCESS && (Type == REG_DWORD)) {
  294. pSaveSystemValue (MemDBKey, S_DIRECTSOUND, S_SPEAKERCONFIG, Value);
  295. }
  296. CloseRegKey (Key);
  297. }
  298. rc = TrackedRegOpenKeyEx (Device, S_DSSPEAKERTYPE, 0, KEY_READ, &Key);
  299. if (rc == ERROR_SUCCESS) {
  300. Len = sizeof (Value);
  301. rc = RegQueryValueEx (Key, S_SPEAKERTYPE, NULL, &Type, (LPBYTE)&Value, &Len);
  302. if (rc == ERROR_SUCCESS && (Type == REG_DWORD)) {
  303. pSaveSystemValue (MemDBKey, S_DIRECTSOUND, S_SPEAKERTYPE, Value);
  304. }
  305. CloseRegKey (Key);
  306. }
  307. //
  308. // DirectSoundCapture props
  309. //
  310. rc = TrackedRegOpenKeyEx (Device, S_DSCMIXERDEFAULTS, 0, KEY_READ, &Key);
  311. if (rc == ERROR_SUCCESS) {
  312. Len = sizeof (Value);
  313. rc = RegQueryValueEx (Key, S_ACCELERATION, NULL, &Type, (LPBYTE)&Value, &Len);
  314. if (rc == ERROR_SUCCESS && (Type == REG_DWORD)) {
  315. pSaveSystemValue (MemDBKey, S_DIRECTSOUNDCAPTURE, S_ACCELERATION, Value);
  316. }
  317. Len = sizeof (Value);
  318. rc = RegQueryValueEx (Key, S_SRCQUALITY, NULL, &Type, (LPBYTE)&Value, &Len);
  319. if (rc == ERROR_SUCCESS && (Type == REG_DWORD)) {
  320. pSaveSystemValue (MemDBKey, S_DIRECTSOUNDCAPTURE, S_SRCQUALITY, Value);
  321. }
  322. CloseRegKey (Key);
  323. }
  324. }
  325. BOOL
  326. pSaveMMSystemDirectSound (
  327. VOID
  328. )
  329. {
  330. HKEY WaveDevices, Device;
  331. DWORD NumDevs;
  332. DWORD DeviceID;
  333. TCHAR SoftwareKey[MAX_PATH];
  334. LONG rc;
  335. rc = TrackedRegOpenKeyEx (
  336. HKEY_LOCAL_MACHINE,
  337. S_SKEY_WAVEDEVICES,
  338. 0,
  339. KEY_READ,
  340. &WaveDevices
  341. );
  342. if (rc == ERROR_SUCCESS) {
  343. if (GetRegSubkeysCount (WaveDevices, &NumDevs, NULL)) {
  344. pSaveSystemValue (S_WAVENUMDEVS, NULL, NULL, NumDevs);
  345. for (DeviceID = 0; DeviceID < NumDevs; DeviceID++) {
  346. if (pGetSoftwareKey (SoftwareKey, sizeof (SoftwareKey), DeviceID, WaveDevices)) {
  347. //
  348. // got the key, go get DirectSound values
  349. //
  350. rc = TrackedRegOpenKeyEx (
  351. HKEY_LOCAL_MACHINE,
  352. SoftwareKey,
  353. 0,
  354. KEY_READ,
  355. &Device
  356. );
  357. if (rc == ERROR_SUCCESS) {
  358. pSaveDeviceDSSettings (DeviceID, Device);
  359. CloseRegKey (Device);
  360. }
  361. }
  362. }
  363. }
  364. CloseRegKey (WaveDevices);
  365. }
  366. return TRUE;
  367. }
  368. BOOL
  369. pSaveMMSystemCDSettings (
  370. VOID
  371. )
  372. {
  373. HKEY cdKey;
  374. HKEY unitKey;
  375. PBYTE cdRomNumber = NULL;
  376. PBYTE cdRomVolume = NULL;
  377. PBYTE cdRomVolInc = NULL;
  378. TCHAR unitKeyStr [MAX_TCHAR_PATH];
  379. cdKey = OpenRegKey (HKEY_LOCAL_MACHINE, S_SKEY_CDAUDIO);
  380. if (cdKey != NULL) {
  381. cdRomNumber = GetRegValueBinary (cdKey, S_DEFAULTDRIVE);
  382. if (cdRomNumber != NULL) {
  383. pSaveSystemValue (S_CDROM, S_DEFAULTDRIVE, NULL, *cdRomNumber);
  384. wsprintf (unitKeyStr, S_SKEY_CDUNIT, *cdRomNumber);
  385. unitKey = OpenRegKey (HKEY_LOCAL_MACHINE, unitKeyStr);
  386. if (unitKey != NULL) {
  387. cdRomVolume = GetRegValueBinary (unitKey, S_VOLUMESETTINGS);
  388. if (cdRomVolume != NULL) {
  389. pSaveSystemValue (S_CDROM, S_VOLUMESETTINGS, NULL, *(cdRomVolume + 4));
  390. MemFreeWrapper (cdRomVolume);
  391. }
  392. CloseRegKey (unitKey);
  393. }
  394. MemFreeWrapper (cdRomNumber);
  395. }
  396. CloseRegKey (cdKey);
  397. }
  398. return TRUE;
  399. }
  400. BOOL
  401. pSaveMMSystemMCISoundSettings (
  402. VOID
  403. )
  404. {
  405. TCHAR Buffer[MAX_PATH];
  406. PTSTR p;
  407. PCTSTR infName;
  408. DWORD Chars;
  409. infName = JoinPaths (g_WinDir, S_SYSTEM_INI);
  410. Chars = GetPrivateProfileString (
  411. S_MCI,
  412. S_WAVEAUDIO,
  413. TEXT(""),
  414. Buffer,
  415. MAX_PATH,
  416. infName
  417. );
  418. if (Chars > 0) {
  419. //
  420. // skip driver name
  421. //
  422. p = Buffer;
  423. while (*p && (*p != TEXT(' ') && *p != TEXT('\t'))) {
  424. p++;
  425. }
  426. //
  427. // skip white spaces
  428. //
  429. while (*p && (*p == TEXT(' ') || *p == TEXT('\t'))) {
  430. p++;
  431. }
  432. if (*p) {
  433. //
  434. // save this param; legal values for NT driver are 2-9
  435. //
  436. if (*(p + 1) == 0 && *p >= TEXT('2') && *p <= TEXT('9')) {
  437. pSaveSystemValue (S_MCI, S_WAVEAUDIO, NULL, *p - TEXT('0'));
  438. }
  439. }
  440. }
  441. FreePathString (infName);
  442. return TRUE;
  443. }
  444. BOOL
  445. pSaveUserValue (
  446. IN PCTSTR KeyName,
  447. IN PCTSTR Field, OPTIONAL
  448. IN PCTSTR StrValue, OPTIONAL
  449. IN DWORD NumValue OPTIONAL
  450. )
  451. {
  452. return MemDbSetValueEx (
  453. g_UserData,
  454. KeyName,
  455. Field,
  456. StrValue,
  457. NumValue,
  458. NULL
  459. );
  460. }
  461. BOOL
  462. pSaveMMUserPreferredOnly (
  463. VOID
  464. )
  465. {
  466. HKEY soundMapperKey;
  467. PDWORD preferredOnly;
  468. soundMapperKey = OpenRegKey (g_UserRoot, S_SKEY_SOUNDMAPPER);
  469. if (soundMapperKey != NULL) {
  470. preferredOnly = GetRegValueDword (soundMapperKey, S_PREFERREDONLY);
  471. if (preferredOnly != NULL) {
  472. pSaveUserValue (S_AUDIO, S_PREFERREDONLY, NULL, *preferredOnly);
  473. MemFreeWrapper (preferredOnly);
  474. }
  475. CloseRegKey (soundMapperKey);
  476. }
  477. return TRUE;
  478. }
  479. BOOL
  480. pSaveMMUserShowVolume (
  481. VOID
  482. )
  483. {
  484. HKEY sysTrayKey;
  485. PDWORD showVolume;
  486. BOOL ShowVolume;
  487. sysTrayKey = OpenRegKey (g_UserRoot, S_SKEY_SYSTRAY);
  488. if (sysTrayKey != NULL) {
  489. showVolume = GetRegValueDword (sysTrayKey, S_SERVICES);
  490. if (showVolume != NULL) {
  491. ShowVolume = (*showVolume & SERVICE_SHOWVOLUME) != 0;
  492. pSaveUserValue (S_AUDIO, S_SHOWVOLUME, NULL, ShowVolume);
  493. MemFreeWrapper (showVolume);
  494. }
  495. CloseRegKey (sysTrayKey);
  496. }
  497. return TRUE;
  498. }
  499. BOOL
  500. pSaveMMUserVideoSettings (
  501. VOID
  502. )
  503. {
  504. HKEY videoSetKey;
  505. PDWORD videoSettings;
  506. videoSetKey = OpenRegKey (g_UserRoot, S_SKEY_VIDEOUSER);
  507. if (videoSetKey != NULL) {
  508. videoSettings = GetRegValueDword (videoSetKey, S_DEFAULTOPTIONS);
  509. if (videoSettings != NULL) {
  510. pSaveUserValue (S_VIDEO, S_VIDEOSETTINGS, NULL, *videoSettings);
  511. MemFreeWrapper (videoSettings);
  512. }
  513. CloseRegKey (videoSetKey);
  514. }
  515. return TRUE;
  516. }
  517. BOOL
  518. pSaveMMUserPreferredPlayback (
  519. VOID
  520. )
  521. {
  522. HKEY soundMapperKey;
  523. PTSTR playbackStr;
  524. UINT waveOutNumDevs, waveCrt;
  525. WAVEOUTCAPS waveOutCaps;
  526. MMRESULT waveOutResult;
  527. soundMapperKey = OpenRegKey (g_UserRoot, S_SKEY_SOUNDMAPPER);
  528. if (soundMapperKey != NULL) {
  529. if (ISMEMPHIS()) {
  530. playbackStr = GetRegValueString (soundMapperKey, S_USERPLAYBACK);
  531. } else {
  532. playbackStr = GetRegValueString (soundMapperKey, S_PLAYBACK);
  533. }
  534. if (playbackStr != NULL) {
  535. if (playbackStr [0] != 0) {
  536. waveOutNumDevs = waveOutGetNumDevs();
  537. if (waveOutNumDevs > 1) {
  538. //
  539. // try to match string with one returned by waveOutGetDevCaps
  540. //
  541. pSaveSystemValue (S_WAVEOUTNUMDEVS, NULL, NULL, waveOutNumDevs);
  542. for (waveCrt = 0; waveCrt < waveOutNumDevs; waveCrt++) {
  543. waveOutResult = waveOutGetDevCaps (waveCrt, &waveOutCaps, sizeof (waveOutCaps));
  544. if (waveOutResult == MMSYSERR_NOERROR &&
  545. StringIMatch (playbackStr, waveOutCaps.szPname)
  546. ) {
  547. pSaveUserValue (S_AUDIO, S_PREFERREDPLAY, NULL, waveCrt);
  548. break;
  549. }
  550. }
  551. }
  552. }
  553. MemFreeWrapper (playbackStr);
  554. }
  555. CloseRegKey (soundMapperKey);
  556. }
  557. return TRUE;
  558. }
  559. BOOL
  560. pSaveMMUserPreferredRecord (
  561. VOID
  562. )
  563. {
  564. HKEY soundMapperKey;
  565. PTSTR recordStr;
  566. UINT waveInNumDevs, waveCrt;
  567. WAVEINCAPS waveInCaps;
  568. MMRESULT waveInResult;
  569. soundMapperKey = OpenRegKey (g_UserRoot, S_SKEY_SOUNDMAPPER);
  570. if (soundMapperKey != NULL) {
  571. if (ISMEMPHIS()) {
  572. recordStr = GetRegValueString (soundMapperKey, S_USERRECORD);
  573. } else {
  574. recordStr = GetRegValueString (soundMapperKey, S_RECORD);
  575. }
  576. if (recordStr != NULL) {
  577. if (recordStr [0] != 0) {
  578. waveInNumDevs = waveInGetNumDevs();
  579. if (waveInNumDevs > 1) {
  580. //
  581. // try to match string with one returned by waveInGetDevCaps
  582. //
  583. pSaveSystemValue (S_WAVEINNUMDEVS, NULL, NULL, waveInNumDevs);
  584. for (waveCrt = 0; waveCrt < waveInNumDevs; waveCrt++) {
  585. waveInResult = waveInGetDevCaps (waveCrt, &waveInCaps, sizeof (waveInCaps));
  586. if (waveInResult == MMSYSERR_NOERROR &&
  587. StringIMatch (recordStr, waveInCaps.szPname)
  588. ) {
  589. pSaveUserValue (S_AUDIO, S_PREFERREDREC, NULL, waveCrt);
  590. break;
  591. }
  592. }
  593. }
  594. }
  595. MemFreeWrapper (recordStr);
  596. }
  597. CloseRegKey (soundMapperKey);
  598. }
  599. return TRUE;
  600. }
  601. BOOL
  602. pSaveMMUserSndVol32 (
  603. VOID
  604. )
  605. {
  606. HKEY VolControl, Options, MixerKey;
  607. PDWORD Style, Value;
  608. BOOL ShowAdvanced;
  609. UINT MixerID, MixerMaxID;
  610. MIXERCAPS mixerCaps;
  611. TCHAR MixerNum[MAX_PATH];
  612. TCHAR Buffer[MAX_PATH];
  613. DWORD Len, NumEntries, Index;
  614. LONG rc;
  615. Options = OpenRegKey (g_UserRoot, S_SKEY_VOLCTL_OPTIONS);
  616. if (Options != NULL) {
  617. Style = GetRegValueDword (Options, S_STYLE);
  618. if (Style != NULL) {
  619. ShowAdvanced = (*Style & STYLE_SHOWADVANCED) != 0;
  620. pSaveUserValue (S_SNDVOL32, S_SHOWADVANCED, NULL, ShowAdvanced);
  621. MemFreeWrapper (Style);
  622. }
  623. CloseRegKey (Options);
  624. }
  625. //
  626. // save window position for each mixer device
  627. //
  628. VolControl = OpenRegKey (g_UserRoot, S_SKEY_VOLUMECONTROL);
  629. if (VolControl != NULL) {
  630. if (GetRegSubkeysCount (VolControl, &NumEntries, NULL)) {
  631. MixerMaxID = mixerGetNumDevs ();
  632. for (MixerID = 0; MixerID < MixerMaxID; MixerID++) {
  633. rc = mixerGetDevCaps (MixerID, &mixerCaps, sizeof (MIXERCAPS));
  634. if (rc == MMSYSERR_NOERROR) {
  635. //
  636. // find corresponding subkey
  637. //
  638. wsprintf (MixerNum, S_MIXERID, MixerID);
  639. for (Index = 0; Index < NumEntries; Index++) {
  640. Len = sizeof (Buffer);
  641. rc = RegEnumKeyEx (VolControl, Index, Buffer, &Len, NULL, NULL, NULL, NULL);
  642. if (rc != ERROR_SUCCESS) {
  643. continue;
  644. }
  645. if (StringMatch (Buffer, mixerCaps.szPname)) {
  646. //
  647. // this is the one
  648. //
  649. MixerKey = OpenRegKey (VolControl, Buffer);
  650. if (MixerKey) {
  651. Value = GetRegValueDword (MixerKey, S_X);
  652. if (Value) {
  653. pSaveUserValue (S_SNDVOL32, MixerNum, S_X, *Value);
  654. MemFreeWrapper (Value);
  655. }
  656. Value = GetRegValueDword (MixerKey, S_Y);
  657. if (Value) {
  658. pSaveUserValue (S_SNDVOL32, MixerNum, S_Y, *Value);
  659. MemFreeWrapper (Value);
  660. }
  661. CloseRegKey (MixerKey);
  662. }
  663. break;
  664. }
  665. }
  666. }
  667. }
  668. }
  669. CloseRegKey (VolControl);
  670. }
  671. return TRUE;
  672. }
  673. #define DEFMAC(Item) pSave##Item,
  674. static MM_SETTING_ACTION g_MMSaveSystemSettings [] = {
  675. MM_SYSTEM_SETTINGS
  676. };
  677. static MM_SETTING_ACTION g_MMSaveUserSettings [] = {
  678. MM_USER_SETTINGS
  679. };
  680. #undef DEFMAC
  681. BOOL
  682. pSaveMMSettings_System (
  683. VOID
  684. )
  685. {
  686. int i;
  687. g_MmediaPool = PoolMemInitNamedPool ("MMedia9x");
  688. if (!g_MmediaPool) {
  689. return FALSE;
  690. }
  691. for (i = 0; i < sizeof (g_MMSaveSystemSettings) / sizeof (MM_SETTING_ACTION); i++) {
  692. (*g_MMSaveSystemSettings[i]) ();
  693. }
  694. PoolMemDestroyPool (g_MmediaPool);
  695. g_MmediaPool = NULL;
  696. return TRUE;
  697. }
  698. BOOL
  699. pSaveMMSettings_User (
  700. PCTSTR UserName,
  701. HKEY UserRoot
  702. )
  703. {
  704. int i;
  705. if (!UserName || UserName[0] == 0) {
  706. return TRUE;
  707. }
  708. MYASSERT (g_UserData == NULL);
  709. g_UserData = JoinPaths (MEMDB_CATEGORY_MMEDIA_USERS, UserName);
  710. g_UserRoot = UserRoot;
  711. __try {
  712. for (i = 0; i < sizeof (g_MMSaveUserSettings) / sizeof (MM_SETTING_ACTION); i++) {
  713. (*g_MMSaveUserSettings[i]) ();
  714. }
  715. }
  716. __finally {
  717. FreePathString (g_UserData);
  718. g_UserData = NULL;
  719. g_UserRoot = NULL;
  720. }
  721. return TRUE;
  722. }
  723. DWORD
  724. SaveMMSettings_System (
  725. IN DWORD Request
  726. )
  727. {
  728. switch (Request) {
  729. case REQUEST_QUERYTICKS:
  730. return TICKS_SAVE_MM_SETTINGS_SYSTEM;
  731. case REQUEST_RUN:
  732. if (!pSaveMMSettings_System ()) {
  733. return GetLastError ();
  734. }
  735. break;
  736. default:
  737. DEBUGMSG ((DBG_ERROR, "Bad parameter in SaveMMSettings_System"));
  738. }
  739. return ERROR_SUCCESS;
  740. }
  741. DWORD
  742. SaveMMSettings_User (
  743. IN DWORD Request,
  744. IN PUSERENUM EnumPtr
  745. )
  746. {
  747. switch (Request) {
  748. case REQUEST_QUERYTICKS:
  749. return TICKS_SAVE_MM_SETTINGS_USER;
  750. case REQUEST_BEGINUSERPROCESSING:
  751. //
  752. // No initialization needed.
  753. //
  754. break;
  755. case REQUEST_RUN:
  756. if (!pSaveMMSettings_User (EnumPtr -> UserName, EnumPtr -> UserRegKey )) {
  757. return GetLastError ();
  758. }
  759. break;
  760. case REQUEST_ENDUSERPROCESSING:
  761. //
  762. // No cleanup needed.
  763. //
  764. break;
  765. default:
  766. DEBUGMSG ((DBG_ERROR, "Bad parameter in SaveMMSettings_User"));
  767. }
  768. return ERROR_SUCCESS;
  769. }