1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile syssound.c:
|
---|
4 | * this has code for querying and manipulating the
|
---|
5 | * system sounds, which are stored in MMPM.INI in
|
---|
6 | * the MMOS2 directory. Also, we have support for
|
---|
7 | * manipulating Warp 4 sound schemes in here too.
|
---|
8 | * This code works on Warp 3 also.
|
---|
9 | *
|
---|
10 | * Usage: All OS/2 programs.
|
---|
11 | *
|
---|
12 | * Some of this code used to be in XWorkplace's main\common.c,
|
---|
13 | * as far as the regular system sounds were concerned.
|
---|
14 | * However, all this code has been greatly reworked
|
---|
15 | * and extended with V0.9.0.
|
---|
16 | *
|
---|
17 | * <B>About system sound configuration data</B>
|
---|
18 | *
|
---|
19 | * The current system sounds are stored in ?:\MMOS2\MMPM.INI.
|
---|
20 | *
|
---|
21 | * These are the general flags in the "MMPM2_AlarmSoundsData"
|
---|
22 | * application:
|
---|
23 | * -- If "EnableSounds" is FALSE, all system sounds are disabled.
|
---|
24 | * This defaults to TRUE (tested).
|
---|
25 | * -- If "ApplyVolumeToAll" is TRUE, the same volume is used for
|
---|
26 | * all sounds. This defaults to FALSE (tested).
|
---|
27 | * -- If ApplyVolumeToAll is TRUE, "Volume" is used for the
|
---|
28 | * global volume. Otherwise, the individual sound volumes
|
---|
29 | * (below) will be used.
|
---|
30 | *
|
---|
31 | * "MMPM2_AlarmSounds" then has all the system sounds. The keys
|
---|
32 | * in that application are numerical indices, which are listed
|
---|
33 | * in syssound.h.
|
---|
34 | *
|
---|
35 | * Each sound data block in there consists of three elements:
|
---|
36 | + soundfile#description#volume
|
---|
37 | * where "description" is what is listed in the "Sound" object.
|
---|
38 | * "volume" is only used when "ApplyVolumeToAll" (above) is FALSE.
|
---|
39 | *
|
---|
40 | * We have functions in this code file for decoding/setting this
|
---|
41 | * (sndParseSoundData, sndQuerySystemSound, sndWriteSoundData,
|
---|
42 | * sndSetSystemSound).
|
---|
43 | *
|
---|
44 | * By contrast (and for no real reason), Warp 4 stores the
|
---|
45 | * "sound schemes" in OS2SYS.INI. I stuck with that for compatibility,
|
---|
46 | * although this prevents several users from having different
|
---|
47 | * sound schemes. What the heck.
|
---|
48 | *
|
---|
49 | * Anyways, the "PM_SOUND_SCHEMES_LIST" application is a directory of
|
---|
50 | * schemes, which in turn point to other applications in OS2SYS.INI
|
---|
51 | * which have the actual sound scheme data. All these applications
|
---|
52 | * appear to start with "PM_SOUND_xxx" by convention.
|
---|
53 | *
|
---|
54 | * Note that as opposed to the sound data in MMPM.INI, only the
|
---|
55 | * sound file name is stored here (not the three elements as
|
---|
56 | * described above). We slightly extend that mechanism to add an
|
---|
57 | * additional volume data field after the first null byte. This
|
---|
58 | * allows the default WPSound object to still be able to read
|
---|
59 | * the sound scheme data (it apparently uses PrfQueryProfileString)
|
---|
60 | * while the XWorkplace sound object replacement (XWPSound) can
|
---|
61 | * still store volume data as well.
|
---|
62 | *
|
---|
63 | * I have created more functions in this code file to easily load and
|
---|
64 | * store sound schemes (sndDoesSchemeExist, sndCreateSoundScheme,
|
---|
65 | * sndLoadSoundScheme, sndDestroySoundScheme).
|
---|
66 | *
|
---|
67 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
68 | * numbering.
|
---|
69 | *
|
---|
70 | *@@header "helpers\syssound.h"
|
---|
71 | *@@added V0.9.0 [umoeller]
|
---|
72 | */
|
---|
73 |
|
---|
74 | #define OS2EMX_PLAIN_CHAR
|
---|
75 | // this is needed for "os2emx.h"; if this is defined,
|
---|
76 | // emx will define PSZ as _signed_ char, otherwise
|
---|
77 | // as unsigned char
|
---|
78 |
|
---|
79 | #define INCL_DOSERRORS
|
---|
80 | #define INCL_WINSHELLDATA
|
---|
81 | #include <os2.h>
|
---|
82 |
|
---|
83 | #include <stdlib.h>
|
---|
84 | #include <stdio.h>
|
---|
85 | #include <string.h>
|
---|
86 |
|
---|
87 | #include "setup.h" // code generation and debugging options
|
---|
88 |
|
---|
89 | #include "helpers\dosh.h"
|
---|
90 | #include "helpers\prfh.h"
|
---|
91 |
|
---|
92 | #include "helpers\syssound.h"
|
---|
93 |
|
---|
94 | #pragma hdrstop
|
---|
95 |
|
---|
96 | /*
|
---|
97 | *@@category: Helpers\Profile (INI) helpers\System sounds
|
---|
98 | * see syssound.c.
|
---|
99 | */
|
---|
100 |
|
---|
101 | /*
|
---|
102 | *@@ sndParseSoundData:
|
---|
103 | * this helper func splits the system sound data
|
---|
104 | * passed to it into three buffers.
|
---|
105 | * Each key data in there has the following format:
|
---|
106 | + soundfile#description#volume.
|
---|
107 | *
|
---|
108 | * This is copied into the three specified buffers.
|
---|
109 | * You can set any buffer pointer to NULL if you're
|
---|
110 | * not interested in that data.
|
---|
111 | *
|
---|
112 | * Returns the number of items successfully parsed,
|
---|
113 | * which should be 3.
|
---|
114 | *
|
---|
115 | *@@added V0.9.0 [umoeller]
|
---|
116 | */
|
---|
117 |
|
---|
118 | ULONG sndParseSoundData(PSZ pszSoundData, // in: INI data from MMPM.INI
|
---|
119 | PSZ pszDescr, // out: sound description, as displayed
|
---|
120 | // in the "Sound" object (ptr may be NULL)
|
---|
121 | PSZ pszFile, // out: sound file to (ptr may be NULL)
|
---|
122 | PULONG pulVolume) // out: sound volume (0-100). Note:
|
---|
123 | // this always returns the individual sound volume,
|
---|
124 | // even if "Global volume" is set in MMPM.INI.
|
---|
125 | {
|
---|
126 | PSZ p1 = pszSoundData, p2;
|
---|
127 | ULONG ulrc = 0;
|
---|
128 | // get sound file
|
---|
129 | p2 = strchr(p1, '#');
|
---|
130 | if (p2)
|
---|
131 | {
|
---|
132 | ulrc++;
|
---|
133 | if (pszFile)
|
---|
134 | {
|
---|
135 | strncpy(pszFile, p1, p2-p1);
|
---|
136 | pszFile[p2-p1] = '\0';
|
---|
137 | }
|
---|
138 | p1 = p2+1;
|
---|
139 |
|
---|
140 | // get sound description
|
---|
141 | p2 = strchr(p1, '#');
|
---|
142 | if (p2)
|
---|
143 | {
|
---|
144 | ulrc++;
|
---|
145 | if (pszDescr)
|
---|
146 | {
|
---|
147 | strncpy(pszDescr, p1, p2-p1);
|
---|
148 | pszDescr[p2-p1] = '\0';
|
---|
149 | }
|
---|
150 | p1 = p2+1;
|
---|
151 |
|
---|
152 | // get volume (0-100)
|
---|
153 | if (pulVolume)
|
---|
154 | {
|
---|
155 | // individual volume settings per sound
|
---|
156 | sscanf(p1, "%lu", pulVolume);
|
---|
157 | ulrc++;
|
---|
158 | }
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | return (ulrc);
|
---|
163 | }
|
---|
164 |
|
---|
165 | /*
|
---|
166 | *@@ sndQueryMmpmIniPath:
|
---|
167 | * writes the full path of MMPM.INI into
|
---|
168 | * the specified buffer (e.g. C:\MMOS2\MMPM.INI).
|
---|
169 | *
|
---|
170 | *@@added V0.9.10 (2001-04-16) [umoeller]
|
---|
171 | */
|
---|
172 |
|
---|
173 | VOID sndQueryMmpmIniPath(PSZ pszMMPM) // out: fully q'fied MMPM.INI
|
---|
174 | {
|
---|
175 | PSZ pszMMPMPath = getenv("MMBASE"); // V0.9.6 (2000-10-16) [umoeller]
|
---|
176 | if (pszMMPMPath)
|
---|
177 | {
|
---|
178 | // variable set:
|
---|
179 | PSZ p;
|
---|
180 |
|
---|
181 | strcpy(pszMMPM, pszMMPMPath); // V0.9.7 (2000-12-17) [umoeller]
|
---|
182 |
|
---|
183 | // kill semicolon if present
|
---|
184 | p = strchr(pszMMPM, ';');
|
---|
185 | if (p)
|
---|
186 | *p = 0;
|
---|
187 |
|
---|
188 | strcat(pszMMPM, "\\MMPM.INI");
|
---|
189 | }
|
---|
190 | else
|
---|
191 | // variable not set (shouldn't happen): try boot drive
|
---|
192 | sprintf(pszMMPM, "%c:\\MMOS2\\MMPM.INI", doshQueryBootDrive());
|
---|
193 | }
|
---|
194 |
|
---|
195 | /*
|
---|
196 | *@@ sndOpenMmpmIni:
|
---|
197 | * this opens \MMOS2\MMPM.INI on the
|
---|
198 | * boot drive and returns the profile
|
---|
199 | * handle (or NULLHANDLE upon errors).
|
---|
200 | * Use PrfCloseProfile to close the
|
---|
201 | * profile again.
|
---|
202 | *
|
---|
203 | *@@added V0.9.1 (99-12-19) [umoeller]
|
---|
204 | *@@changed V0.9.6 (2000-10-16) [umoeller]: now using MMBASE environment variable
|
---|
205 | *@@changed V0.9.6 (2000-10-16) [umoeller]: added proper HAB param
|
---|
206 | *@@changed V0.9.7 (2000-12-17) [umoeller]: fixed broken MMBASE handling
|
---|
207 | */
|
---|
208 |
|
---|
209 | HINI sndOpenMmpmIni(HAB hab)
|
---|
210 | {
|
---|
211 | HAB habDesktop = WinQueryAnchorBlock(HWND_DESKTOP);
|
---|
212 | CHAR szMMPM[CCHMAXPATH];
|
---|
213 | HINI hini = NULLHANDLE;
|
---|
214 |
|
---|
215 | sndQueryMmpmIniPath(szMMPM);
|
---|
216 |
|
---|
217 | hini = PrfOpenProfile(habDesktop, szMMPM);
|
---|
218 | return (hini);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /*
|
---|
222 | *@@ sndQuerySystemSound:
|
---|
223 | * this gets a system sound from the MMPM.INI file.
|
---|
224 | * usIndex must be the sound to query. The following
|
---|
225 | * MMSOUND_* IDs are declared in syssound.h:
|
---|
226 | *
|
---|
227 | * Default system sounds (syssound.h):
|
---|
228 | * -- MMSOUND_WARNING 0
|
---|
229 | * -- MMSOUND_INFORMATION 1
|
---|
230 | * -- MMSOUND_ERROR 2
|
---|
231 | * -- MMSOUND_ANIMATEOPEN 3
|
---|
232 | * -- MMSOUND_ANIMATECLOSE 4
|
---|
233 | * -- MMSOUND_DRAG 5
|
---|
234 | * -- MMSOUND_DROP 6
|
---|
235 | * -- MMSOUND_SYSTEMSTARTUP 7
|
---|
236 | * -- MMSOUND_SHUTDOWN 8
|
---|
237 | * -- MMSOUND_SHREDDER 9
|
---|
238 | * -- MMSOUND_LOCKUP 10
|
---|
239 | * -- MMSOUND_ALARMCLOCK 11
|
---|
240 | * -- MMSOUND_PRINTERROR 12
|
---|
241 | *
|
---|
242 | * BTW, these values match those of the WinAlarm call
|
---|
243 | * (WA_* values), but only the first three are documented
|
---|
244 | * in PMREF and pmwin.h (WA_WARNING, WA_NOTE, WA_ERROR).
|
---|
245 | *
|
---|
246 | * New XWorkplace system sounds:
|
---|
247 | * -- MMSOUND_XFLD_SHUTDOWN 555
|
---|
248 | * -- MMSOUND_XFLD_RESTARTWPS 556
|
---|
249 | * -- MMSOUND_XFLD_CTXTOPEN 558
|
---|
250 | * -- MMSOUND_XFLD_CTXTSELECT 559
|
---|
251 | * -- MMSOUND_XFLD_CNRDBLCLK 560
|
---|
252 | *
|
---|
253 | * The string buffers are recommended to be at least
|
---|
254 | * CCHMAXPATH in size.
|
---|
255 | *
|
---|
256 | *@@changed V0.9.0 [umoeller]: this used to be cmnQuerySystemSound
|
---|
257 | *@@changed V0.9.0 [umoeller]: exported stuff to sndParseSoundData
|
---|
258 | *@@changed V0.9.6 (2000-10-16) [umoeller]: added proper HAB param
|
---|
259 | */
|
---|
260 |
|
---|
261 | BOOL sndQuerySystemSound(HAB hab, // in: caller's anchor block
|
---|
262 | USHORT usIndex, // in: sound index to query
|
---|
263 | PSZ pszDescr, // out: sound description, as displayed
|
---|
264 | // in the "Sound" object (ptr may be NULL)
|
---|
265 | PSZ pszFile, // out: sound file to (ptr may be NULL)
|
---|
266 | PULONG pulVolume) // out: sound volume (0-100).
|
---|
267 | // If the "Global volume" flag is
|
---|
268 | // set in MMPM.INI, this will return the global
|
---|
269 | // volume instead. Ptr may be NULL also.
|
---|
270 | {
|
---|
271 | BOOL rc = FALSE;
|
---|
272 | HINI hiniMMPM = sndOpenMmpmIni(hab);
|
---|
273 |
|
---|
274 | #ifdef DEBUG_SOUNDS
|
---|
275 | _Pmpf((__FUNCTION__ ": entering, hiniMMPM is 0x%lX", hiniMMPM));
|
---|
276 | #endif
|
---|
277 |
|
---|
278 | if (hiniMMPM)
|
---|
279 | {
|
---|
280 | CHAR szData[1000];
|
---|
281 | CHAR szData2[100];
|
---|
282 | CHAR szKey[10];
|
---|
283 | sprintf(szKey, "%d", usIndex);
|
---|
284 | PrfQueryProfileString(hiniMMPM,
|
---|
285 | MMINIKEY_SOUNDSETTINGS, "EnableSounds",
|
---|
286 | "TRUE", // default string
|
---|
287 | szData2, sizeof(szData2));
|
---|
288 | #ifdef DEBUG_SOUNDS
|
---|
289 | _Pmpf((" sounds enabled: %s", szData2));
|
---|
290 | #endif
|
---|
291 | if (strcmp(szData2, "TRUE") == 0)
|
---|
292 | // sounds enabled at all?
|
---|
293 | if (PrfQueryProfileString(hiniMMPM,
|
---|
294 | MMINIKEY_SYSSOUNDS, szKey,
|
---|
295 | ".",
|
---|
296 | szData, sizeof(szData)-1) > 3)
|
---|
297 | {
|
---|
298 | sndParseSoundData(szData,
|
---|
299 | pszDescr,
|
---|
300 | pszFile,
|
---|
301 | pulVolume);
|
---|
302 |
|
---|
303 | // if "global volume" has been enabled,
|
---|
304 | // we do not return the value specified
|
---|
305 | // here, but the global value
|
---|
306 | PrfQueryProfileString(hiniMMPM,
|
---|
307 | MMINIKEY_SOUNDSETTINGS, "ApplyVolumeToAll",
|
---|
308 | "FALSE",
|
---|
309 | szData2, sizeof(szData2));
|
---|
310 | if (strcmp(szData2, "FALSE") != 0)
|
---|
311 | {
|
---|
312 | // global volume setting for all sounds
|
---|
313 | PrfQueryProfileString(hiniMMPM,
|
---|
314 | MMINIKEY_SOUNDSETTINGS, "Volume",
|
---|
315 | "100",
|
---|
316 | szData2, sizeof(szData2));
|
---|
317 | sscanf(szData2, "%lu", pulVolume);
|
---|
318 | }
|
---|
319 |
|
---|
320 | rc = TRUE;
|
---|
321 | }
|
---|
322 |
|
---|
323 | PrfCloseProfile(hiniMMPM);
|
---|
324 | }
|
---|
325 |
|
---|
326 | return (rc);
|
---|
327 | }
|
---|
328 |
|
---|
329 | /*
|
---|
330 | *@@ sndWriteSoundData:
|
---|
331 | * this sets a system sound in MMPM.INI.
|
---|
332 | * Gets called by sndSetSystemSound. As opposed
|
---|
333 | * to that function, this needs the profile handle
|
---|
334 | * of MMPM.INI.
|
---|
335 | *
|
---|
336 | * If (pszDescr == NULL), that sound entry is removed.
|
---|
337 | *
|
---|
338 | * Returns the return value of PrfWriteProfileString.
|
---|
339 | *
|
---|
340 | *@@added V0.9.0 [umoeller]
|
---|
341 | *@@changed V0.9.1 (99-12-30) [umoeller]: added delete support
|
---|
342 | *@@changed V0.9.6 (2000-10-16) [umoeller]: added MMPM/2 notify
|
---|
343 | */
|
---|
344 |
|
---|
345 | BOOL sndWriteSoundData(HINI hiniMMPM, // in: MMPM.INI handle (from sndOpenMmpmIni)
|
---|
346 | USHORT usIndex, // in: sound index
|
---|
347 | PSZ pszDescr, // in: sound name or NULL for removal
|
---|
348 | PSZ pszFile, // in: sound file
|
---|
349 | ULONG ulVolume) // in: sound volume
|
---|
350 | {
|
---|
351 | BOOL brc = FALSE;
|
---|
352 | CHAR szKey[10];
|
---|
353 |
|
---|
354 | sprintf(szKey, "%d", usIndex);
|
---|
355 | if (pszDescr)
|
---|
356 | {
|
---|
357 | CHAR szData[1000];
|
---|
358 | // format: soundfile#description#volume
|
---|
359 | sprintf(szData, "%s#%s#%lu", pszFile, pszDescr, ulVolume);
|
---|
360 | brc = PrfWriteProfileString(hiniMMPM,
|
---|
361 | MMINIKEY_SYSSOUNDS, szKey,
|
---|
362 | szData);
|
---|
363 | }
|
---|
364 | else
|
---|
365 | // pszDescr == NULL:
|
---|
366 | // delete entry
|
---|
367 | brc = PrfWriteProfileString(hiniMMPM,
|
---|
368 | MMINIKEY_SYSSOUNDS, szKey,
|
---|
369 | NULL);
|
---|
370 |
|
---|
371 | if (brc)
|
---|
372 | // success:
|
---|
373 | if (usIndex < 100)
|
---|
374 | // one of the default OS/2 sounds has changed:
|
---|
375 | // we then need to notify MMPM/2...
|
---|
376 | // this is done by calling WinAlarm with 1000+index!
|
---|
377 | // sick stuff..
|
---|
378 | WinAlarm(HWND_DESKTOP, usIndex+1000); // V0.9.6 (2000-10-16) [umoeller]
|
---|
379 |
|
---|
380 | return (brc);
|
---|
381 | }
|
---|
382 |
|
---|
383 | /*
|
---|
384 | *@@ sndSetSystemSound:
|
---|
385 | * this sets a system sound in MMPM.INI by
|
---|
386 | * calling sndWriteSoundData.
|
---|
387 | * Returns FALSE if an error occured.
|
---|
388 | *
|
---|
389 | * See sndQuerySystemSound for the parameters.
|
---|
390 | *
|
---|
391 | *@@changed V0.9.0 [umoeller]: this used to be cmnSetSystemSound
|
---|
392 | *@@changed V0.9.0 [umoeller]: exported stuff to sndWriteSoundData
|
---|
393 | *@@changed V0.9.6 (2000-10-16) [umoeller]: added proper HAB param
|
---|
394 | */
|
---|
395 |
|
---|
396 | BOOL sndSetSystemSound(HAB hab,
|
---|
397 | USHORT usIndex,
|
---|
398 | PSZ pszDescr,
|
---|
399 | PSZ pszFile,
|
---|
400 | ULONG ulVolume)
|
---|
401 | {
|
---|
402 | BOOL brc = FALSE;
|
---|
403 | HINI hiniMMPM = sndOpenMmpmIni(hab);
|
---|
404 | if (hiniMMPM)
|
---|
405 | {
|
---|
406 | brc = sndWriteSoundData(hiniMMPM, usIndex, pszDescr, pszFile, ulVolume);
|
---|
407 | PrfCloseProfile(hiniMMPM);
|
---|
408 | }
|
---|
409 | return (brc);
|
---|
410 | }
|
---|
411 |
|
---|
412 | /*
|
---|
413 | *@@ sndDoesSchemeExist:
|
---|
414 | * returns TRUE if pszScheme already exists
|
---|
415 | * in OS2SYS.INI.
|
---|
416 | *
|
---|
417 | *@@added V0.9.0 [umoeller]
|
---|
418 | */
|
---|
419 |
|
---|
420 | BOOL sndDoesSchemeExist(PSZ pszScheme)
|
---|
421 | {
|
---|
422 | // check in OS2SYS.INI's scheme list whether that
|
---|
423 | // scheme exists already
|
---|
424 | PSZ pszExisting = prfhQueryProfileData(HINI_SYSTEM,
|
---|
425 | MMINIKEY_SOUNDSCHEMES, // "PM_SOUND_SCHEMES_LIST"
|
---|
426 | pszScheme,
|
---|
427 | NULL);
|
---|
428 | if (pszExisting)
|
---|
429 | {
|
---|
430 | free(pszExisting);
|
---|
431 | return (TRUE);
|
---|
432 | }
|
---|
433 |
|
---|
434 | return (FALSE);
|
---|
435 | }
|
---|
436 |
|
---|
437 | /*
|
---|
438 | *@@ sndCreateSoundScheme:
|
---|
439 | * this creates a new sound scheme and copies
|
---|
440 | * the current data in MMPM.INI into it.
|
---|
441 | * No check is made for whether that sound
|
---|
442 | * scheme exists already (use sndDoesSchemeExist
|
---|
443 | * for that). Data is overwritten without further
|
---|
444 | * discussion.
|
---|
445 | *
|
---|
446 | * Returns:
|
---|
447 | * -- NO_ERROR
|
---|
448 | * -- ERROR_INVALID_HANDLE: hiniMMPM invalid
|
---|
449 | * -- ERROR_NO_DATA: scheme not found.
|
---|
450 | *
|
---|
451 | *@@added V0.9.0 [umoeller]
|
---|
452 | */
|
---|
453 |
|
---|
454 | APIRET sndCreateSoundScheme(HINI hiniMMPM, // in: MMPM.INI handle (from sndOpenMmpmIni)
|
---|
455 | PSZ pszNewScheme) // in: name of new scheme
|
---|
456 | {
|
---|
457 | APIRET arc = NO_ERROR;
|
---|
458 | CHAR szNewAppName[200] = "PM_SOUNDS_";
|
---|
459 |
|
---|
460 | // create a unique new application name for
|
---|
461 | // this scheme in OS2SYS.INI (this is how
|
---|
462 | // Warp 4 apparently does it)
|
---|
463 | strcat(szNewAppName, pszNewScheme); // PM_SOUNDS_blahblah
|
---|
464 | strupr(szNewAppName); // PM_SOUNDS_BLAHBLAH
|
---|
465 |
|
---|
466 | if (hiniMMPM)
|
---|
467 | {
|
---|
468 | // get applications list for sounds list in MMPM.INI
|
---|
469 | PSZ pszKeysList = NULL;
|
---|
470 | if (!(arc = prfhQueryKeysForApp(hiniMMPM,
|
---|
471 | MMINIKEY_SYSSOUNDS, // "MMPM2_AlarmSounds"
|
---|
472 | &pszKeysList)))
|
---|
473 | {
|
---|
474 | PSZ pKey2 = pszKeysList;
|
---|
475 |
|
---|
476 | CHAR szFile[CCHMAXPATH+50];
|
---|
477 | ULONG ulVolume,
|
---|
478 | ulKeyLen;
|
---|
479 |
|
---|
480 | while (*pKey2 != 0)
|
---|
481 | {
|
---|
482 | // now copy this key to the new sound scheme;
|
---|
483 | // however, we can't just copy the whole key,
|
---|
484 | // but need to extract the file name and
|
---|
485 | // volume first.
|
---|
486 | // Warp 4 normally _only_ stores the file name
|
---|
487 | // in the sound schemes. Since we want the
|
---|
488 | // volume also, we add a null char after the
|
---|
489 | // file name and append the volume...
|
---|
490 |
|
---|
491 | PSZ pSoundData = prfhQueryProfileData(hiniMMPM,
|
---|
492 | MMINIKEY_SYSSOUNDS, // "MMPM2_AlarmSounds"
|
---|
493 | pKey2,
|
---|
494 | NULL);
|
---|
495 | if (pSoundData)
|
---|
496 | {
|
---|
497 | sndParseSoundData(pSoundData,
|
---|
498 | NULL, // we don't need the description
|
---|
499 | szFile,
|
---|
500 | &ulVolume);
|
---|
501 | ulKeyLen = strlen(szFile)+1; // go beyond null byte
|
---|
502 | ulKeyLen += sprintf(szFile+ulKeyLen,
|
---|
503 | "%lu",
|
---|
504 | ulVolume) + 1;
|
---|
505 | // and write to OS2SYS.INI
|
---|
506 | PrfWriteProfileData(HINI_SYSTEM,
|
---|
507 | szNewAppName,
|
---|
508 | pKey2,
|
---|
509 | szFile,
|
---|
510 | ulKeyLen);
|
---|
511 |
|
---|
512 | free(pSoundData);
|
---|
513 | } // end if (pSoundData)
|
---|
514 |
|
---|
515 | pKey2 += strlen(pKey2)+1;
|
---|
516 | } // end while (*pKey2 != 0)
|
---|
517 |
|
---|
518 | free (pszKeysList);
|
---|
519 |
|
---|
520 | // finally, store new scheme in schemes list
|
---|
521 | PrfWriteProfileString(HINI_SYSTEM,
|
---|
522 | MMINIKEY_SOUNDSCHEMES, // "PM_SOUND_SCHEMES_LIST"
|
---|
523 | pszNewScheme, // key is scheme name
|
---|
524 | szNewAppName); // data is new OS2SYS.INI application
|
---|
525 | }
|
---|
526 | else
|
---|
527 | arc = ERROR_NO_DATA;
|
---|
528 | }
|
---|
529 | else
|
---|
530 | arc = ERROR_INVALID_HANDLE;
|
---|
531 |
|
---|
532 | return (arc);
|
---|
533 | }
|
---|
534 |
|
---|
535 | /*
|
---|
536 | *@@ sndLoadSoundScheme:
|
---|
537 | * this loads the data in pszScheme (OS2SYS.INI)
|
---|
538 | * into MMPM.INI. Existing sound data
|
---|
539 | * in that profile will be overwritten.
|
---|
540 | *
|
---|
541 | * Note: Only those sounds in MMPM.INI will be
|
---|
542 | * overwritten for which a corresponding entry
|
---|
543 | * in the sound scheme exists. If it doesn't,
|
---|
544 | * the data in MMPM.INI for _that_ sound only
|
---|
545 | * will _not_ be changed. In other words, existing
|
---|
546 | * sound data will be merged with the scheme data.
|
---|
547 | *
|
---|
548 | * If you don't like this, delete the whole
|
---|
549 | * "MMPM2_AlarmSounds" application in MMPM.INI
|
---|
550 | * before calling this function.
|
---|
551 | *
|
---|
552 | * Returns:
|
---|
553 | * -- NO_ERROR
|
---|
554 | * -- ERROR_INVALID_HANDLE: hiniMMPM invalid
|
---|
555 | * -- ERROR_NO_DATA: scheme not found.
|
---|
556 | * -- ERROR_BAD_FORMAT: error in MMPM.INI data.
|
---|
557 | *
|
---|
558 | *@@added V0.9.0 [umoeller]
|
---|
559 | *@@changed V0.9.1 (99-12-20) [umoeller]: fixed memory leak
|
---|
560 | *@@changed V0.9.6 (2000-10-16) [umoeller]: added MMPM/2 notify
|
---|
561 | */
|
---|
562 |
|
---|
563 | APIRET sndLoadSoundScheme(HINI hiniMMPM, // in: HINI of ?:\MMOS2\MMPM.INI (PrfOpenProfile)
|
---|
564 | PSZ pszScheme) // in: scheme name
|
---|
565 | {
|
---|
566 | APIRET arc = NO_ERROR;
|
---|
567 |
|
---|
568 | #ifdef DEBUG_SOUNDS
|
---|
569 | _Pmpf(("Entering sndLoadSoundScheme"));
|
---|
570 | #endif
|
---|
571 |
|
---|
572 | if (hiniMMPM)
|
---|
573 | {
|
---|
574 | // check in OS2SYS.INI's scheme list whether that
|
---|
575 | // scheme exists already
|
---|
576 | PSZ pszSchemeAppName = prfhQueryProfileData(HINI_SYSTEM,
|
---|
577 | MMINIKEY_SOUNDSCHEMES, // "PM_SOUND_SCHEMES_LIST"
|
---|
578 | pszScheme,
|
---|
579 | NULL);
|
---|
580 | #ifdef DEBUG_SOUNDS
|
---|
581 | _Pmpf((" pszSchemeAppName: %s", pszSchemeAppName));
|
---|
582 | #endif
|
---|
583 |
|
---|
584 | if (pszSchemeAppName)
|
---|
585 | {
|
---|
586 | // now copy keys from OS2SYS.INI to MMPM.INI;
|
---|
587 | // since OS2SYS.INI _only_ has the file name
|
---|
588 | // (and _maybe_ the individual volume, if it
|
---|
589 | // was us who created the sound scheme --
|
---|
590 | // see sndCreateSoundScheme above), we need
|
---|
591 | // to go thru the MMPM.INI (!) sounds lists
|
---|
592 | // and merge the data in there with the
|
---|
593 | // corresponding sound data for the current
|
---|
594 | // scheme...
|
---|
595 |
|
---|
596 | // get applications list for sounds list in MMPM.INI
|
---|
597 | PSZ pszMMPMKeysList = NULL;
|
---|
598 | if (!(arc = prfhQueryKeysForApp(hiniMMPM,
|
---|
599 | MMINIKEY_SYSSOUNDS,// "MMPM2_AlarmSounds"
|
---|
600 | &pszMMPMKeysList)))
|
---|
601 | {
|
---|
602 | PSZ pMMPMKey2 = pszMMPMKeysList,
|
---|
603 | pMMPMSoundData,
|
---|
604 | pSchemeSoundData;
|
---|
605 |
|
---|
606 | CHAR szDescription[300]; // from MMPM.INI
|
---|
607 | CHAR szFile[CCHMAXPATH+50]; // from OS2SYS.INI
|
---|
608 | ULONG ulVolume; // from MMPM.INI _or_ OS2SYS.INI
|
---|
609 | CHAR szData[1000];
|
---|
610 |
|
---|
611 | // go thru keys (numbers)
|
---|
612 | while (*pMMPMKey2 != 0)
|
---|
613 | {
|
---|
614 | ULONG cbSchemeSoundData = 0,
|
---|
615 | cbSchemeSoundFile = 0;
|
---|
616 |
|
---|
617 | pMMPMSoundData = prfhQueryProfileData(hiniMMPM,
|
---|
618 | MMINIKEY_SYSSOUNDS, // "MMPM2_AlarmSounds"
|
---|
619 | pMMPMKey2,
|
---|
620 | NULL);
|
---|
621 | pSchemeSoundData = prfhQueryProfileData(HINI_SYSTEM,
|
---|
622 | pszSchemeAppName,
|
---|
623 | pMMPMKey2,
|
---|
624 | &cbSchemeSoundData);
|
---|
625 |
|
---|
626 | if ((pMMPMSoundData) && (pSchemeSoundData))
|
---|
627 | {
|
---|
628 | sndParseSoundData(pMMPMSoundData,
|
---|
629 | szDescription,
|
---|
630 | NULL, // we don't need the file
|
---|
631 | &ulVolume);
|
---|
632 | // now overwrite this data with scheme data
|
---|
633 | strcpy(szFile,
|
---|
634 | pSchemeSoundData); // up to first null byte
|
---|
635 | cbSchemeSoundFile = strlen(pSchemeSoundData)+1;
|
---|
636 | if (cbSchemeSoundData > cbSchemeSoundFile)
|
---|
637 | // this means we have an additional volume string
|
---|
638 | // after the null byte (sndCreateSoundScheme);
|
---|
639 | // copy it
|
---|
640 | sscanf(pSchemeSoundData + cbSchemeSoundFile,
|
---|
641 | "%lu",
|
---|
642 | &ulVolume);
|
---|
643 |
|
---|
644 | // and write data to MMPM.INI
|
---|
645 | // format: soundfile#description#volume
|
---|
646 | sprintf(szData, "%s#%s#%lu", szFile, szDescription, ulVolume);
|
---|
647 | if (PrfWriteProfileString(hiniMMPM,
|
---|
648 | MMINIKEY_SYSSOUNDS, // "MMPM2_AlarmSounds"
|
---|
649 | pMMPMKey2, // key (decimal number)
|
---|
650 | szData))
|
---|
651 | {
|
---|
652 | // success:
|
---|
653 | USHORT usIndex = atoi(pMMPMKey2);
|
---|
654 | if (usIndex < 100)
|
---|
655 | // this was one of the default OS/2 sounds:
|
---|
656 | // notify MMPM/2 of the change... see sndWriteSoundData
|
---|
657 | // V0.9.6 (2000-10-16) [umoeller]
|
---|
658 | WinAlarm(HWND_DESKTOP, usIndex+1000);
|
---|
659 | }
|
---|
660 | }
|
---|
661 |
|
---|
662 | if (pMMPMSoundData)
|
---|
663 | free(pMMPMSoundData);
|
---|
664 | if (pSchemeSoundData)
|
---|
665 | free(pSchemeSoundData);
|
---|
666 |
|
---|
667 | pMMPMKey2 += strlen(pMMPMKey2)+1;
|
---|
668 | } // end while (*pMMPMKey2 != 0)
|
---|
669 |
|
---|
670 | free (pszMMPMKeysList);
|
---|
671 | }
|
---|
672 | else
|
---|
673 | arc = ERROR_BAD_FORMAT;
|
---|
674 |
|
---|
675 | free(pszSchemeAppName);
|
---|
676 | } // end if (pszSchemeAppName)
|
---|
677 | else
|
---|
678 | arc = ERROR_NO_DATA;
|
---|
679 | }
|
---|
680 | else
|
---|
681 | arc = ERROR_INVALID_HANDLE;
|
---|
682 |
|
---|
683 | #ifdef DEBUG_SOUNDS
|
---|
684 | _Pmpf(("End of sndLoadSoundScheme, arc: %d", arc));
|
---|
685 | #endif
|
---|
686 | return (arc);
|
---|
687 | }
|
---|
688 |
|
---|
689 | /*
|
---|
690 | *@@ sndDestroySoundScheme:
|
---|
691 | * destroys pszScheme in OS2SYS.INI;
|
---|
692 | * returns TRUE is pszScheme was found
|
---|
693 | * and deleted.
|
---|
694 | *
|
---|
695 | * See xsound.c for explanations.
|
---|
696 | *
|
---|
697 | * Returns:
|
---|
698 | * -- NO_ERROR
|
---|
699 | * -- ERROR_NO_DATA: scheme not found.
|
---|
700 | *
|
---|
701 | *@@added V0.9.0 [umoeller]
|
---|
702 | */
|
---|
703 |
|
---|
704 | APIRET sndDestroySoundScheme(PSZ pszScheme)
|
---|
705 | {
|
---|
706 | APIRET arc = NO_ERROR;
|
---|
707 |
|
---|
708 | // check in OS2SYS.INI's scheme list whether that
|
---|
709 | // scheme exists already
|
---|
710 | PSZ pszExisting = prfhQueryProfileData(HINI_SYSTEM,
|
---|
711 | MMINIKEY_SOUNDSCHEMES, // "PM_SOUND_SCHEMES_LIST"
|
---|
712 | pszScheme,
|
---|
713 | NULL);
|
---|
714 | if (pszExisting)
|
---|
715 | {
|
---|
716 | // delete whole existing PM_SOUNDS_BLAHBLAH application
|
---|
717 | PrfWriteProfileString(HINI_SYSTEM,
|
---|
718 | pszExisting, // application
|
---|
719 | NULL,
|
---|
720 | NULL);
|
---|
721 | // and delete entry in sound schemes list
|
---|
722 | PrfWriteProfileString(HINI_SYSTEM,
|
---|
723 | MMINIKEY_SOUNDSCHEMES, // "PM_SOUND_SCHEMES_LIST"
|
---|
724 | pszScheme,
|
---|
725 | NULL);
|
---|
726 | free(pszExisting);
|
---|
727 | }
|
---|
728 | else
|
---|
729 | arc = ERROR_NO_DATA;
|
---|
730 |
|
---|
731 | return (arc);
|
---|
732 | }
|
---|
733 |
|
---|
734 |
|
---|