[WINMM] Lookup driver info in the registry as well

Dimitrie O. Paun dpaun at rogers.com
Tue Jun 29 00:35:59 CDT 2004


Similar to my previous patch, this adds registry support
to winmm. Again, when we get .ini mappings, we can simply
remove the *Profile* calls, and just stick the the registry.

ChangeLog
    Lookup driver information in registry and system.ini.
    Make the code inspect the registry/system.ini at call
    time, rather then initialization time.
    Code cleanups.


Index: dlls/winmm/driver.c
===================================================================
RCS file: /var/cvs/wine/dlls/winmm/driver.c,v
retrieving revision 1.26
diff -u -r1.26 driver.c
--- dlls/winmm/driver.c	1 Jan 2004 00:07:14 -0000	1.26
+++ dlls/winmm/driver.c	27 Apr 2004 13:40:16 -0000
@@ -29,12 +29,15 @@
 #include "wingdi.h"
 #include "winuser.h"
 #include "winnls.h"
+#include "winreg.h"
 #include "mmddk.h"
 #include "winemm.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(driver);
 
+#define HKLM_BASE "Software\\Microsoft\\Windows NT\\CurrentVersion"
+
 static LPWINE_DRIVER   lpDrvItemList  /* = NULL */;
 
 WINE_MMTHREAD*  (*pFnGetMMThread16)(UINT16 h) /* = NULL */;
@@ -206,7 +209,21 @@
  */
 BOOL	DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz)
 {
-    /* should also do some registry diving */
+    HKEY	hKey, hSecKey;
+    DWORD	bufLen, lRet;
+
+    lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, HKLM_BASE, 0, KEY_QUERY_VALUE, &hKey);
+    if (lRet == ERROR_SUCCESS) {
+	lRet = RegOpenKeyExA(hKey, sectName, 0, KEY_QUERY_VALUE, &hSecKey);
+	if (lRet == ERROR_SUCCESS) {
+	    lRet = RegQueryValueExA(hSecKey, keyName, 0, 0, buf, &bufLen);
+	    RegCloseKey( hSecKey );
+	}
+        RegCloseKey( hKey );
+    }
+    if (lRet == ERROR_SUCCESS) return TRUE;
+    /* default to system.ini if we can't find it in the registry,
+     * to support native installations where system.ini is still used */
     return GetPrivateProfileStringA(sectName, keyName, "", buf, sz, "SYSTEM.INI");
 }
 
Index: dlls/winmm/mci.c
===================================================================
RCS file: /var/cvs/wine/dlls/winmm/mci.c,v
retrieving revision 1.52
diff -u -r1.52 mci.c
--- dlls/winmm/mci.c	5 Apr 2004 20:16:11 -0000	1.52
+++ dlls/winmm/mci.c	29 Jun 2004 05:29:52 -0000
@@ -57,9 +57,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(mci);
 
-static	int			MCI_InstalledCount;
-static  LPSTR                   MCI_lpInstallNames /* = NULL */;
-
 WINMM_MapType  (*pFnMciMapMsg16To32A)  (WORD,WORD,DWORD*) /* = NULL */;
 WINMM_MapType  (*pFnMciUnMapMsg16To32A)(WORD,WORD,DWORD) /* = NULL */;
 WINMM_MapType  (*pFnMciMapMsg32ATo16)  (WORD,WORD,DWORD,DWORD*) /* = NULL */;
@@ -68,6 +65,9 @@
 /* First MCI valid device ID (0 means error) */
 #define MCI_MAGIC 0x0001
 
+/* MCI settings */
+#define HKLM_MCI "Software\\Microsoft\\Windows NT\\CurrentVersion\\MCI"
+
 /* dup a string and uppercase it */
 inline static LPSTR str_dup_upper( LPCSTR str )
 {
@@ -1435,8 +1435,10 @@
  */
 static	DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParms)
 {
-    DWORD		ret = MCIERR_INVALID_DEVICE_ID;
+    DWORD		ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
+    CHAR		buf[2048], *s = buf, *p;
     LPWINE_MCIDRIVER	wmd;
+    HKEY		hKey;
 
     if (lpParms == NULL)			return MCIERR_NULL_PARAMETER_BLOCK;
 
@@ -1445,41 +1447,39 @@
 
     switch (dwFlags & ~MCI_SYSINFO_OPEN) {
     case MCI_SYSINFO_QUANTITY:
-	{
-	    DWORD	cnt = 0;
-
-	    if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST ||
-		lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
-		if (dwFlags & MCI_SYSINFO_OPEN) {
-		    TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
-		    EnterCriticalSection(&WINMM_IData->cs);
-		    for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
-			cnt++;
-		    }
-		    LeaveCriticalSection(&WINMM_IData->cs);
-		} else {
-		    TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
-		    cnt = MCI_InstalledCount;
+	if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
+	    if (dwFlags & MCI_SYSINFO_OPEN) {
+		TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
+		EnterCriticalSection(&WINMM_IData->cs);
+		for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
+		    cnt++;
 		}
+		LeaveCriticalSection(&WINMM_IData->cs);
 	    } else {
-		if (dwFlags & MCI_SYSINFO_OPEN) {
-		    TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
-			  lpParms->wDeviceType);
-		    EnterCriticalSection(&WINMM_IData->cs);
-		    for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
-			if (wmd->wType == lpParms->wDeviceType)
-			    cnt++;
-		    }
-		    LeaveCriticalSection(&WINMM_IData->cs);
-		} else {
-		    TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
-			  lpParms->wDeviceType);
-		    FIXME("Don't know how to get # of MCI devices of a given type\n");
-		    cnt = 1;
+		TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
+		if (RegOpenKeyExA( HKEY_LOCAL_MACHINE, HKLM_MCI,
+			  	   0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
+		    RegQueryInfoKeyA( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
+		    RegCloseKey( hKey );
 		}
+		if (GetPrivateProfileStringA("mci", 0, "", buf, sizeof(buf), "system.ini"))
+		    for(s = buf; *s; s += strlen(s) + 1) cnt++;
+	    }
+	} else {
+	    if (dwFlags & MCI_SYSINFO_OPEN) {
+		TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
+		EnterCriticalSection(&WINMM_IData->cs);
+		for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
+		    if (wmd->wType == lpParms->wDeviceType) cnt++;
+		}
+		LeaveCriticalSection(&WINMM_IData->cs);
+	    } else {
+		TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
+		FIXME("Don't know how to get # of MCI devices of a given type\n");
+		cnt = 1;
 	    }
-	    *(DWORD*)lpParms->lpstrReturn = cnt;
 	}
+	*(DWORD*)lpParms->lpstrReturn = cnt;
 	TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
 	ret = MCI_INTEGER_RETURNED;
 	break;
@@ -1499,14 +1499,29 @@
 	if (dwFlags & MCI_SYSINFO_OPEN) {
 	    FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
 	    ret = MCIERR_UNRECOGNIZED_COMMAND;
-	} else if (lpParms->dwNumber > MCI_InstalledCount) {
-	    ret = MCIERR_OUTOFRANGE;
 	} else {
-	    DWORD	count = lpParms->dwNumber;
-	    LPSTR	ptr = MCI_lpInstallNames;
-
-	    while (--count > 0) ptr += strlen(ptr) + 1;
-	    ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, ptr);
+	    s = 0;
+	    DWORD lRet = RegOpenKeyExA( HKEY_LOCAL_MACHINE, HKLM_MCI, 0, KEY_QUERY_VALUE, &hKey );
+	    if (lRet == ERROR_SUCCESS) {
+		lRet = RegQueryInfoKeyA( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
+		if (lRet == ERROR_SUCCESS && lpParms->dwNumber <= cnt) {
+    		    DWORD bufLen = sizeof(buf);
+		    lRet = RegEnumKeyExA(hKey, lpParms->dwNumber - 1, buf, &bufLen, 0, 0, 0, 0);
+		    if (lRet == ERROR_SUCCESS) s = buf;
+		}
+	        RegCloseKey( hKey );
+	    }
+	    if (!s) {
+		if (GetPrivateProfileStringA("mci", 0, "", buf, sizeof(buf), "system.ini")) {
+		    for(p = buf; *p; p += strlen(s) + 1, cnt++) {
+			if (cnt == lpParms->dwNumber - 1) {
+			    s = p;
+			    break;
+			}
+		    }
+		}
+	    }
+	    ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, s) : MCIERR_OUTOFRANGE;
 	}
 	TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
 	break;
@@ -1725,53 +1740,3 @@
     return LOWORD(dwRet);
 }
 
-/**************************************************************************
- * 			MCI_Init			[internal]
- *
- * Initializes the MCI internal variables.
- *
- */
-BOOL MCI_Init(void)
-{
-    LPSTR	ptr1, ptr2;
-    HKEY	hWineConf;
-    HKEY	hkey;
-    DWORD	err;
-    DWORD 	type;
-    DWORD 	count = 2048;
-
-    MCI_InstalledCount = 0;
-    ptr1 = MCI_lpInstallNames = HeapAlloc(GetProcessHeap(), 0, count);
-
-    if (!MCI_lpInstallNames)
-	return FALSE;
-
-    /* FIXME: should do also some registry diving here ? */
-    if (!(err = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", &hWineConf)) &&
-	!(err = RegOpenKeyA(hWineConf, "options", &hkey))) {
-	err = RegQueryValueExA(hkey, "mci", 0, &type, MCI_lpInstallNames, &count);
-	RegCloseKey(hkey);
-
-    }
-    if (!err) {
-	TRACE("Wine => '%s' \n", ptr1);
-	while ((ptr2 = strchr(ptr1, ':')) != 0) {
-	    *ptr2++ = 0;
-	    TRACE("---> '%s' \n", ptr1);
-	    MCI_InstalledCount++;
-	    ptr1 = ptr2;
-	}
-	MCI_InstalledCount++;
-	TRACE("---> '%s' \n", ptr1);
-	ptr1 += strlen(ptr1) + 1;
-    } else {
-	GetPrivateProfileStringA("mci", NULL, "", MCI_lpInstallNames, count, "SYSTEM.INI");
-	while (strlen(ptr1) > 0) {
-	    TRACE("---> '%s' \n", ptr1);
-	    ptr1 += strlen(ptr1) + 1;
-	    MCI_InstalledCount++;
-	}
-    }
-    RegCloseKey(hWineConf);
-    return TRUE;
-}
Index: dlls/winmm/winemm.h
===================================================================
RCS file: /var/cvs/wine/dlls/winmm/winemm.h,v
retrieving revision 1.56
diff -u -r1.56 winemm.h
--- dlls/winmm/winemm.h	1 Jun 2004 19:40:48 -0000	1.56
+++ dlls/winmm/winemm.h	2 Jun 2004 04:13:01 -0000
@@ -243,7 +243,6 @@
 void            MMDRV_InstallMap(unsigned int, MMDRV_MAPFUNC, MMDRV_UNMAPFUNC,
                                  MMDRV_MAPFUNC, MMDRV_UNMAPFUNC, LPDRVCALLBACK);
 
-BOOL    	MCI_Init(void);
 WINE_MCIDRIVER* MCI_GetDriver(UINT16 uDevID);
 UINT		MCI_GetDriverFromString(LPCSTR str);
 DWORD		MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr);
Index: dlls/winmm/winmm.c
===================================================================
RCS file: /var/cvs/wine/dlls/winmm/winmm.c,v
retrieving revision 1.37
diff -u -r1.37 winmm.c
--- dlls/winmm/winmm.c	14 Jun 2004 16:53:59 -0000	1.37
+++ dlls/winmm/winmm.c	16 Jun 2004 01:05:34 -0000
@@ -182,7 +182,7 @@
 
 	if (!WINMM_CreateIData(hInstDLL))
 	    return FALSE;
-        if (!MCI_Init() || !MMDRV_Init()) {
+        if (!MMDRV_Init()) {
             WINMM_DeleteIData();
             return FALSE;
 	}



More information about the wine-patches mailing list