[v1 2/5] winejoystick.drv: Add functionality to disable joystick via registry
David Lawrie
david.dljunk at gmail.com
Sun Aug 28 01:18:12 CDT 2016
Adds device_disabled_registry, helper functions to shared joystick code
Tested on OS X 10.10.5.
Signed-off-by: David Lawrie <david.dljunk at gmail.com>
---
dlls/winejoystick.drv/joystick.c | 94 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
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.@)
--
1.7.12.4 (Apple Git-37)
More information about the wine-patches
mailing list