Leaked source code of windows server 2003
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.

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