From f3e217c0c7cddf5653f2c5ff1afc3f659b75370b Mon Sep 17 00:00:00 2001
From: Roman Dadkov <cunning@etersoft.ru>
Date: Wed, 14 Sep 2011 12:23:13 +0400
Subject: [PATCH] [Wine-patches] [eterhack] eterbug #6916. Tab to control the
 loading of key drivers

---
 dlls/comctl32/propsheet.c    |    5 +++
 po/ru.po                     |   26 ++++++++++++++++++-
 programs/winecfg/Makefile.in |    1 +
 programs/winecfg/main.c      |   10 +++++++
 programs/winecfg/resource.h  |   10 +++++++
 programs/winecfg/winecfg.c   |   56 ++++++++++++++++++++++++++++++++++++-----
 programs/winecfg/winecfg.h   |    9 ++++++
 programs/winecfg/winecfg.rc  |   20 +++++++++++++++
 8 files changed, 129 insertions(+), 8 deletions(-)

diff --git a/dlls/comctl32/propsheet.c b/dlls/comctl32/propsheet.c
index e6d2d30..78eacfb 100644
--- a/dlls/comctl32/propsheet.c
+++ b/dlls/comctl32/propsheet.c
@@ -70,6 +70,8 @@
 #include "wine/debug.h"
 #include "wine/unicode.h"
 
+#include "../../programs/winecfg/dnglch.h"
+
 /******************************************************************************
  * Data structures
  */
@@ -3132,6 +3134,9 @@ static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
     case IDOK:
     case IDC_APPLY_BUTTON:
 	{
+	    if(FixedChange() != 0)
+	        if (MessageBoxA(NULL, "To adoptional changes need close all Wine programs.\n\n Do it now?", "Configuration was change", MB_YESNO | MB_ICONQUESTION) == IDYES)
+                     InitiateSystemShutdownExW(NULL, NULL, 0, TRUE, FALSE);
 	    HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
 
 	    if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
diff --git a/po/ru.po b/po/ru.po
index a7e257a..f652f67 100644
--- a/po/ru.po
+++ b/po/ru.po
@@ -8636,7 +8636,7 @@ msgstr ""
 msgid "%s      %s      %s      Open resources: %lu\n"
 msgstr "%s      %s         %s      Открытых ресурсов: %lu\n"
 
-#: net.rc:44
+#: net.rc:44 winecfg.rc:101
 msgid "OK"
 msgstr ""
 
@@ -11459,3 +11459,27 @@ msgstr ""
 "[/D | /D:m-d-y] Копирует только новые файлы или те, которые были изменены\n"
 "после указанной даты. Если дата не указана, копирует только\n"
 "те файлы, которые новее в исходной папке.\n"
+
+#: winecfg.rc:33
+msgid "Dongles"
+msgstr "Ключи защиты"
+
+#: winecfg.rc:90
+msgid " Loading dongles drivers "
+msgstr "Загрузка драйверов ключей"
+
+#: winecfg.rc:91
+msgid "Listview"
+msgstr ""
+
+#: winecfg.rc:93 winecfg.rc:99
+msgid "Load"
+msgstr "Загружать"
+
+#: winecfg.rc:94 winecfg.rc:100
+msgid "Do not load"
+msgstr "Не загружать"
+
+#: winecfg.rc:102
+msgid "Dongle not found"
+msgstr "Ключ не найден"
\ No newline at end of file
diff --git a/programs/winecfg/Makefile.in b/programs/winecfg/Makefile.in
index 5d4e499..cb9a664 100644
--- a/programs/winecfg/Makefile.in
+++ b/programs/winecfg/Makefile.in
@@ -7,6 +7,7 @@ C_SRCS = \
 	appdefaults.c \
 	audio.c \
 	drive.c \
+	dongleui.c \
 	drivedetect.c \
 	driveui.c \
 	libraries.c \
diff --git a/programs/winecfg/main.c b/programs/winecfg/main.c
index b7f9331..129dc09 100644
--- a/programs/winecfg/main.c
+++ b/programs/winecfg/main.c
@@ -134,6 +134,16 @@ doPropertySheet (HINSTANCE hInstance, HWND hOwner)
     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
     psp[pg].dwFlags = PSP_USETITLE;
     psp[pg].hInstance = hInstance;
+    psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DONGLECFG);
+    psp[pg].u2.pszIcon = NULL;
+    psp[pg].pfnDlgProc = DongleDlgProc;
+    psp[pg].pszTitle =  load_string (IDS_TAB_DONGLES);
+    psp[pg].lParam = 0;
+    pg++;
+
+    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
+    psp[pg].dwFlags = PSP_USETITLE;
+    psp[pg].hInstance = hInstance;
     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
     psp[pg].u2.pszIcon = NULL;
     psp[pg].pfnDlgProc = AudioDlgProc;
diff --git a/programs/winecfg/resource.h b/programs/winecfg/resource.h
index 24eaec4..369036a 100644
--- a/programs/winecfg/resource.h
+++ b/programs/winecfg/resource.h
@@ -242,3 +242,13 @@
 
 #define IDC_WINVER_LAUNCH            8439
 
+/* Dongles tab */
+#define IDS_TAB_DONGLES              9435
+#define IDD_DONGLECFG                9436
+#define IDC_LIST_DONGLES             9437
+#define IDC_DONGLE_LOAD              9438
+#define IDC_DONGLE_UNLOAD            9439
+#define IDC_BUTTON_LOAD              9440
+#define IDC_BUTTON_UNLOAD            9441
+#define IDC_DONGLE_OK                9442
+#define IDC_DONGLE_NOTFOUND          9443
\ No newline at end of file
diff --git a/programs/winecfg/winecfg.c b/programs/winecfg/winecfg.c
index cdf3a84..4af3242 100644
--- a/programs/winecfg/winecfg.c
+++ b/programs/winecfg/winecfg.c
@@ -103,15 +103,15 @@ WCHAR* load_string (UINT id)
  * not. Caller is responsible for releasing the result.
  *
  */
-static WCHAR *get_config_key (HKEY root, const WCHAR *subkey, const WCHAR *name, const WCHAR *def)
+static void *get_config_key (HKEY root, const WCHAR *subkey, const WCHAR *name, const void *def, DWORD type)
 {
     LPWSTR buffer = NULL;
     DWORD len;
     HKEY hSubKey = NULL;
     DWORD res;
 
-    WINE_TRACE("subkey=%s, name=%s, def=%s\n", wine_dbgstr_w(subkey),
-               wine_dbgstr_w(name), wine_dbgstr_w(def));
+    WINE_TRACE("subkey=%s, name=%s, def=%p, type=%d\n", wine_dbgstr_w(subkey),
+               wine_dbgstr_w(name), def, type);
 
     res = RegOpenKeyExW(root, subkey, 0, MAXIMUM_ALLOWED, &hSubKey);
     if (res != ERROR_SUCCESS)
@@ -119,7 +119,10 @@ static WCHAR *get_config_key (HKEY root, const WCHAR *subkey, const WCHAR *name,
         if (res == ERROR_FILE_NOT_FOUND)
         {
             WINE_TRACE("Section key not present - using default\n");
-            return def ? strdupW(def) : NULL;
+            if (!def) return NULL;
+            if (type == REG_SZ) return strdupW(def);
+            if (type == REG_DWORD) return memdup(def, sizeof(DWORD));
+            return NULL;
         }
         else
         {
@@ -132,8 +135,12 @@ static WCHAR *get_config_key (HKEY root, const WCHAR *subkey, const WCHAR *name,
     if (res == ERROR_FILE_NOT_FOUND)
     {
         WINE_TRACE("Value not present - using default\n");
-        buffer = def ? strdupW(def) : NULL;
-	goto end;
+        if (def)
+        {
+            if (type == REG_SZ) buffer = strdupW(def);
+            else if (type == REG_DWORD) buffer = memdup(def, sizeof(DWORD));
+        }
+        goto end;
     } else if (res != ERROR_SUCCESS)
     {
         WINE_ERR("Couldn't query value's length (res=%d)\n", res);
@@ -274,7 +281,7 @@ WCHAR *get_reg_keyW(HKEY root, const WCHAR *path, const WCHAR *name, const WCHAR
     }
 
     /* no, so get from the registry */
-    val = get_config_key(root, path, name, def);
+    val = get_config_key(root, path, name, def, REG_SZ);
 
     WINE_TRACE("returning %s\n", wine_dbgstr_w(val));
 
@@ -318,6 +325,41 @@ char *get_reg_key(HKEY root, const char *path, const char *name, const char *def
     return szRet;
 }
 
+DWORD get_reg_key_dwordW(HKEY root, const WCHAR *path, const WCHAR *name, DWORD def)
+{
+    struct list *cursor;
+    struct setting *s;
+    DWORD *val, ret = 0;
+
+    WINE_TRACE("path=%s, name=%s, def=%d\n", wine_dbgstr_w(path),
+               wine_dbgstr_w(name), def);
+
+    /* check if it's in the list */
+    LIST_FOR_EACH( cursor, settings )
+    {
+        s = LIST_ENTRY(cursor, struct setting, entry);
+
+        if (root != s->root) continue;
+        if (lstrcmpiW(path, s->path) != 0) continue;
+        if (!s->name) continue;
+        if (lstrcmpiW(name, s->name) != 0) continue;
+
+        if (s->value) ret = *(DWORD *)s->value;
+        WINE_TRACE("found %s:%s in settings list, returning %d\n",
+                   wine_dbgstr_w(path), wine_dbgstr_w(name), ret);
+        return ret;
+    }
+
+    /* no, so get from the registry */
+    val = get_config_key(root, path, name, &def, REG_DWORD);
+    ret = *val;
+    HeapFree(GetProcessHeap(), 0, val);
+
+    WINE_TRACE("returning %d\n", ret);
+
+    return ret;
+}
+
 /**
  * Used to set a registry key.
  *
diff --git a/programs/winecfg/winecfg.h b/programs/winecfg/winecfg.h
index 1959409..5729c5e 100644
--- a/programs/winecfg/winecfg.h
+++ b/programs/winecfg/winecfg.h
@@ -53,6 +53,7 @@ extern WCHAR* current_app; /* NULL means editing global settings  */
 
 void set_reg_keyW(HKEY root, const WCHAR *path, const WCHAR *name, const WCHAR *value);
 void set_reg_key_dwordW(HKEY root, const WCHAR *path, const WCHAR *name, DWORD value);
+DWORD get_reg_key_dwordW(HKEY root, const WCHAR *path, const WCHAR *name, DWORD def);
 WCHAR *get_reg_keyW(HKEY root, const WCHAR *path, const WCHAR *name, const WCHAR *def);
 
 void set_reg_key(HKEY root, const char *path, const char *name, const char *value);
@@ -82,6 +83,7 @@ void set_window_title(HWND dialog);
 /* Window procedures */
 INT_PTR CALLBACK GraphDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK DriveDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK DongleDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK DriveEditDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK LibrariesDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -149,6 +151,13 @@ static inline WCHAR *strdupU2W(const char *unix_str)
     return unicode_str;
 }
 
+static inline void *memdup(const void *data, size_t len)
+{
+    void *ptr = HeapAlloc(GetProcessHeap(), 0, len);
+    if (ptr) return memcpy(ptr, data, len);
+    return NULL;
+}
+
 static inline char *get_text(HWND dialog, WORD id)
 {
     HWND item = GetDlgItem(dialog, id);
diff --git a/programs/winecfg/winecfg.rc b/programs/winecfg/winecfg.rc
index bbd7842..841f4f2 100644
--- a/programs/winecfg/winecfg.rc
+++ b/programs/winecfg/winecfg.rc
@@ -30,6 +30,7 @@ BEGIN
     IDS_TAB_APPLICATIONS    "Applications"
     IDS_TAB_DLLS            "Libraries"
     IDS_TAB_DRIVES          "Drives"
+    IDS_TAB_DONGLES         "Dongles"
     IDS_CHOOSE_PATH         "Select the Unix target directory, please."
     IDS_HIDE_ADVANCED       "Hide &Advanced"
     IDS_SHOW_ADVANCED       "Show &Advanced"
@@ -82,6 +83,25 @@ BEGIN
     IDS_NO_DRIVE_C              "You don't have a drive C. This is not so great.\n\nRemember to click 'Add' in the Drives tab to create one!\n"
 END
 
+IDD_DONGLECFG DIALOG DISCARDABLE  0, 0, 260, 250
+STYLE WS_CHILD | WS_DISABLED
+FONT 8, "MS Shell Dlg"
+BEGIN
+    GROUPBOX        " Loading dongles drivers ",IDC_STATIC,8,4,244,240
+    CONTROL         "Listview",IDC_LIST_DONGLES,"SysListView32",LVS_REPORT | LVS_AUTOARRANGE | LVS_ALIGNLEFT |
+    LVS_SINGLESEL | WS_BORDER | WS_TABSTOP | LVS_NOCOLUMNHEADER , 15,18,232,150
+    PUSHBUTTON      "Load",IDC_BUTTON_LOAD,91,172,75,14
+    PUSHBUTTON      "Do not load",IDC_BUTTON_UNLOAD,171,172,75,14
+END
+
+STRINGTABLE DISCARDABLE
+BEGIN
+    IDC_DONGLE_LOAD             "Load"
+    IDC_DONGLE_UNLOAD           "Do not load"
+    IDC_DONGLE_OK               "OK"
+    IDC_DONGLE_NOTFOUND         "Dongle not found"
+END
+
 STRINGTABLE
 BEGIN
     IDS_ACCEL_FULL              "Full"
-- 
1.7.6.1
