[v2 1/2] winejoystick.drv: Add functionality to disable joystick via registry
David Lawrie
david.dljunk at gmail.com
Mon Aug 29 06:03:07 CDT 2016
Adds device_disabled_registry, helper functions to shared joystick code
Adds advapi32 to Makefile
Tested on OS X 10.10.5.
Signed-off-by: David Lawrie <david.dljunk at gmail.com>
---
dlls/winejoystick.drv/Makefile.in | 2 +-
dlls/winejoystick.drv/joystick.c | 94 +++++++++++++++++++++++++++++++++++++++
dlls/winejoystick.drv/joystick.h | 4 +-
3 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/dlls/winejoystick.drv/Makefile.in b/dlls/winejoystick.drv/Makefile.in
index f6d3052..be06789 100644
--- a/dlls/winejoystick.drv/Makefile.in
+++ b/dlls/winejoystick.drv/Makefile.in
@@ -1,5 +1,5 @@
MODULE = winejoystick.drv
-IMPORTS = winmm user32
+IMPORTS = winmm user32 advapi32
EXTRALIBS = $(IOKIT_LIBS)
C_SRCS = \
diff --git a/dlls/winejoystick.drv/joystick.c b/dlls/winejoystick.drv/joystick.c
index 3e140b9..538799d 100644
--- a/dlls/winejoystick.drv/joystick.c
+++ b/dlls/winejoystick.drv/joystick.c
@@ -21,7 +21,101 @@
*/
#include "joystick.h"
+#include "wine/debug.h"
+#include "winreg.h"
+WINE_DEFAULT_DEBUG_CHANNEL(joystick);
+
+/******************************************************************************
+ * Get the default and the app-specific config keys.
+ */
+BOOL get_app_key(HKEY *defkey, HKEY *appkey)
+{
+ char buffer[MAX_PATH+16];
+ DWORD len;
+
+ *appkey = 0;
+
+ /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
+ if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
+ *defkey = 0;
+
+ len = GetModuleFileNameA(0, buffer, MAX_PATH);
+ if (len && len < MAX_PATH)
+ {
+ HKEY tmpkey;
+
+ /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
+ if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
+ {
+ char *p, *appname = buffer;
+ if ((p = strrchr(appname, '/'))) appname = p + 1;
+ if ((p = strrchr(appname, '\\'))) appname = p + 1;
+ strcat(appname, "\\DirectInput");
+
+ if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
+ RegCloseKey(tmpkey);
+ }
+ }
+
+ return *defkey || *appkey;
+}
+
+/******************************************************************************
+ * Get a config key from either the app-specific or the default config
+ */
+DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
+ char *buffer, DWORD size )
+{
+ if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
+ return 0;
+
+ if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
+ return 0;
+
+ return ERROR_FILE_NOT_FOUND;
+}
+
+/******************************************************************************
+ * Disable joystick based on name
+ */
+BOOL device_disabled_registry(const char* name)
+{
+ static const char disabled_str[] = "disabled";
+ static const char joystick_key[] = "Joysticks";
+ char buffer[MAX_PATH];
+ HKEY hkey, appkey, temp;
+ BOOL do_disable = FALSE;
+
+ get_app_key(&hkey, &appkey);
+
+ /* Joystick settings are in the 'joysticks' subkey */
+ if (appkey)
+ {
+ if (RegOpenKeyA(appkey, joystick_key, &temp)) temp = 0;
+ RegCloseKey(appkey);
+ appkey = temp;
+ }
+ if (hkey)
+ {
+ if (RegOpenKeyA(hkey, joystick_key, &temp)) temp = 0;
+ RegCloseKey(hkey);
+ hkey = temp;
+ }
+
+ /* Look for the "controllername"="disabled" key */
+ if (!get_config_key(hkey, appkey, name, buffer, sizeof(buffer)))
+ if (!strcmp(disabled_str, buffer))
+ {
+ TRACE("Disabling joystick '%s' based on registry key.\n", name);
+ do_disable = TRUE;
+ }
+
+ if (appkey) RegCloseKey(appkey);
+ if (hkey) RegCloseKey(hkey);
+
+ return do_disable;
+}
/**************************************************************************
* DriverProc (JOYSTICK.@)
diff --git a/dlls/winejoystick.drv/joystick.h b/dlls/winejoystick.drv/joystick.h
index 1ec1edb..2c47799 100644
--- a/dlls/winejoystick.drv/joystick.h
+++ b/dlls/winejoystick.drv/joystick.h
@@ -26,7 +26,9 @@
#include "mmddk.h"
#include "winuser.h"
-
+extern BOOL get_app_key(HKEY*, HKEY*) DECLSPEC_HIDDEN;
+extern DWORD get_config_key(HKEY, HKEY, const char*, char*, DWORD) DECLSPEC_HIDDEN;
+BOOL device_disabled_registry(const char* name) DECLSPEC_HIDDEN;
LRESULT driver_open(LPSTR str, DWORD index) DECLSPEC_HIDDEN;
LRESULT driver_close(DWORD_PTR device_id) DECLSPEC_HIDDEN;
LRESULT driver_joyGetDevCaps(DWORD_PTR device_id, JOYCAPSW* caps, DWORD size) DECLSPEC_HIDDEN;
--
1.7.12.4 (Apple Git-37)
More information about the wine-patches
mailing list