[winecfg 1.1] Implement saveConfigValue(), style changes, code cleanup, UI alignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(resubmitting with the old registry key, I hadn't realised there was
already a convention in use for this stuff. Is Wine\Wine actually used
at all yet?)

I've also found out how to make evo not wrap patches, so I don't need to
attach them anymore. If this new way isn't OK for whatever reason let me
know.

Finally, I should probably detail The Plan here. It's simple:

1) Merge in Marks work, submit a patch that disables all controls (grays
them out) that don't actually do anything, ie all of them.

2) Introduce some kind of global flag, maybe a config.h switch, maybe an
exported variable (which is best?) that controls whether the
configuration is read from the registry or config file. As patches are
submitted to make Wine read the registry as well as the config file, the
controls in winecfg would be re-enabled so people can test it. Once all
the settings have been dual-purposed in this way, we can write a bit of
migration code so people upgrading have their configurations copied into
the registry, then throw the switch.

3) Profit!!! (sorry, couldn't resist....)

Does that sound OK Alexandre, or did you have different ideas?

ChangeLog:
- Correct return code of loadConfig()
- Make the registry key used a constant
- Made code slightly more consistant with itself
- Some style changes, expanding out variable names, whitespace, removing unnecessary variable initializers and hungarian notation etc
- Replace dialog box with a FIXME in WinMain() to warn of incompleteness
- Implement saveConfigValue()
- Hook up support for save/load of WinVer

? programs/winecfg/foo
? programs/winecfg/wrc.tab.res.lHWoeU
Index: programs/winecfg/En.rc
===================================================================
RCS file: /home/wine/wine/programs/winecfg/En.rc,v
retrieving revision 1.1
diff -u -r1.1 En.rc
--- programs/winecfg/En.rc	23 Jun 2003 18:15:15 -0000	1.1
+++ programs/winecfg/En.rc	26 Aug 2003 14:07:48 -0000
@@ -63,11 +63,11 @@
 STYLE WS_CHILD | WS_DISABLED
 FONT 8, "MS Sans Serif"
 BEGIN
-    EDITTEXT        IDC_SYSCOLORS,100,41,40,14,ES_AUTOHSCROLL | ES_NUMBER
+    EDITTEXT        IDC_SYSCOLORS,100,41,40,12,ES_AUTOHSCROLL | ES_NUMBER
     CONTROL         "Use a private color map",IDC_PRIVATEMAP,"Button",
-                    BS_AUTOCHECKBOX | WS_TABSTOP,17,62,91,10
+                    BS_AUTOCHECKBOX | WS_TABSTOP,15,62,91,10
     CONTROL         "Favor correctness over speed",IDC_PERFECTGRAPH,"Button",
-                    BS_AUTOCHECKBOX | WS_TABSTOP,17,76,117,10
+                    BS_AUTOCHECKBOX | WS_TABSTOP,15,76,117,10
     CONTROL         "Use XFree DGA extension",IDC_XDGA,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,141,62,97,10
     CONTROL         "Use XFree Shm extension",IDC_XSHM,"Button",
@@ -79,7 +79,7 @@
     GROUPBOX        "Render Settings",IDC_STATIC,8,4,244,90
     LTEXT           "The driver color and render settings are used to optimise the way in which colors and applications are displayed.",
                     IDC_STATIC,15,17,228,22
-    LTEXT           "Allocated system colors:",IDC_STATIC,17,43,76,8
+    LTEXT           "Allocated system colors:",IDC_STATIC,15,43,76,8
     GROUPBOX        "Wine Desktop",IDC_STATIC,8,99,244,83
     LTEXT           "Wine can be setup to emulate a windows desktop, or can be run in ""Managed"" mode (default) where the default X11 windows manager/environment is resposible for placing the windows.",
                     IDC_STATIC,15,112,228,28
Index: programs/winecfg/main.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/main.c,v
retrieving revision 1.3
diff -u -r1.3 main.c
--- programs/winecfg/main.c	25 Aug 2003 23:50:50 -0000	1.3
+++ programs/winecfg/main.c	26 Aug 2003 14:07:49 -0000
@@ -27,11 +27,14 @@
 #include <commctrl.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <wine/debug.h>
 
 #include "properties.h"
 #include "resource.h"
 #include "winecfg.h"
 
+WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
+
 WINECFG_DESC sCfg;
 
 void CALLBACK
@@ -97,17 +100,31 @@
 INT_PTR CALLBACK
 GeneralDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
-    switch (uMsg)
-    {
-    case WM_INITDIALOG:
-	initGeneralDlg (hDlg);
-	break;
-
-    case WM_COMMAND:
-	break;
-
-    default:
-	break;
+    switch (uMsg) {
+	
+	case WM_INITDIALOG:
+	    initGeneralDlg (hDlg);
+	    break;
+
+	case WM_COMMAND:
+	    switch (LOWORD(wParam)) {
+		case IDC_WINVER: if (HIWORD(wParam) == CBN_SELCHANGE) {
+		    /* user changed the wine version combobox */
+		    int selection = SendDlgItemMessage( hDlg, IDC_WINVER, CB_GETCURSEL, 0, 0);
+		    const VERSION_DESC *desc = getWinVersions();
+
+		    while (selection > 0) {
+			desc++; selection--;
+		    }
+		    strcpy(sCfg.szWinVer, desc->szVersion);
+		}
+	        break;
+	    }
+	    break;
+	    
+	default:
+	    break;
+	    
     }
     return FALSE;
 }
@@ -266,9 +283,11 @@
 int WINAPI
 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
 {
-    /* Until winecfg is fully functional, warn users that it is incomplete and doesn't do anything */
-    MessageBox(NULL, "The winecfg tool is not yet complete, and does not actually alter your configuration. If you want to alter the way Wine works, look in the ~/.wine/config file for more information.", "winecfg", MB_OK | MB_ICONWARNING);
 
+    /* Until winecfg is fully functional, warn users that it is incomplete and doesn't do anything */
+    WINE_FIXME("The winecfg tool is not yet complete, and does not actually alter your configuration.\n");
+    WINE_FIXME("If you want to alter the way Wine works, look in the ~/.wine/config file for more information.");
+    
     /*
      * Load the configuration from registry
      */
@@ -279,7 +298,12 @@
      * for the Wine Configuration property sheet
      */
     InitCommonControls ();
-    doPropertySheet (hInstance, NULL);
+    if (doPropertySheet (hInstance, NULL) >= 0) {
+	WINE_TRACE("OK\n");
+	saveConfig(&sCfg);
+    } else
+	WINE_TRACE("Cancel\n");
+    
     ExitProcess (0);
 
     return 0;
Index: programs/winecfg/winecfg.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/winecfg.c,v
retrieving revision 1.4
diff -u -r1.4 winecfg.c
--- programs/winecfg/winecfg.c	15 Aug 2003 03:50:48 -0000	1.4
+++ programs/winecfg/winecfg.c	26 Aug 2003 14:07:50 -0000
@@ -74,44 +74,53 @@
 }
 
 /*****************************************************************************
+ * getConfigValue: Retrieves a configuration value from the registry
+ *
+ * HKEY  hCurrent : the registry key that the configuration is rooted at
+ * char *subKey : the name of the config section
+ * char *valueName : the name of the config value
+ * char *retVal : pointer to the start of a buffer that has room for >= length chars
+ * int   length : length of the buffer pointed to by retVal
+ * char *defaultResult : if the key isn't found, return this value instead
+ *
+ * Returns 0 upon success, non-zero otherwise
+ *
  */
-int GetConfigValueSZ (HKEY hCurrent, LPSTR subkey, LPSTR valueName, LPSTR RetVal, 
-                    int length, LPSTR DefRes)
+int getConfigValue (HKEY hCurrent, char *subkey, char *valueName, char *retVal, int length, char *defaultResult)
 {
-    CHAR *buffer=NULL;
-    DWORD dataLength=0;
-    HKEY hSubKey=NULL;
-    DWORD res;
+    CHAR *buffer;
+    DWORD dataLength;
+    HKEY hSubKey = NULL;
+    DWORD res = 1; /* assume failure */
 
+    WINE_TRACE("subkey=%s, valueName=%s, defaultResult=%s\n", subkey, valueName, defaultResult);
+    
     if( (res=RegOpenKeyEx( hCurrent, subkey, 0, KEY_ALL_ACCESS, &hSubKey ))
             !=ERROR_SUCCESS )
     {
         if( res==ERROR_FILE_NOT_FOUND )
         {
-            WINE_TRACE("Value not present - using default\n");
-            strncpy( RetVal,DefRes,length);
-            res=TRUE;
+            WINE_TRACE("Section key not present - using default\n");
+            strncpy(retVal, defaultResult, length);
         }
         else
         {
-            WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
-            res=FALSE;
+            WINE_ERR("RegOpenKey failed on wine config key (res=%ld)\n", res);
         }
         goto end;
     }
+    
     res = RegQueryValueExA( hSubKey, valueName, NULL, NULL, NULL, &dataLength);
-        if( res==ERROR_FILE_NOT_FOUND )
+    if( res == ERROR_FILE_NOT_FOUND )
     {
         WINE_TRACE("Value not present - using default\n");
-        strncpy( RetVal,DefRes,length);
-        res=TRUE;
+        strncpy(retVal, defaultResult, length);
         goto end;
     }
 
     if( res!=ERROR_SUCCESS )
     {
-        WINE_ERR("Couldn't query value's length (%ld)\n", res );
-        res=FALSE;
+        WINE_ERR("Couldn't query value's length (res=%ld)\n", res );
         goto end;
     }
 
@@ -119,16 +128,16 @@
     if( buffer==NULL )
     {
         WINE_ERR("Couldn't allocate %lu bytes for the value\n", dataLength );
-        res=FALSE;
         goto end;
     }
     
-    RegQueryValueEx( hSubKey, valueName, NULL, NULL, (LPBYTE)buffer, &dataLength);
-    strncpy( RetVal,buffer,length);
+    RegQueryValueEx(hSubKey, valueName, NULL, NULL, (LPBYTE)buffer, &dataLength);
+    strncpy(retVal, buffer, length);
     free(buffer);
+    res = 0;
     
 end:
-   if( hSubKey!=NULL )
+    if( hSubKey!=NULL )
         RegCloseKey( hSubKey );
 
     return res;
@@ -136,6 +145,37 @@
 }
 
 /*****************************************************************************
+ * setConfigValue : Sets a configuration key in the registry
+ *
+ * HKEY  hCurrent : the registry key that the configuration is rooted at
+ * char *subKey : the name of the config section
+ * char *valueName : the name of the config value
+ * char *value : the value to set the configuration key to
+ *
+ * Returns 0 on success, non-zero otherwise
+ *
+ */
+int setConfigValue (HKEY hCurrent, char *subkey, char *valueName, const char *value) {
+    DWORD res = 1;
+    HKEY key = NULL;
+
+    WINE_TRACE("subkey=%s, valueName=%s, value=%s\n", subkey, valueName, value);
+    
+    res = RegCreateKey(hCurrent, subkey, &key);
+    if (res != ERROR_SUCCESS) goto end;
+
+    res = RegSetValueEx(key, valueName, 0, REG_SZ, value, strlen(value) + 1);
+    if (res != ERROR_SUCCESS) goto end;
+
+    res = 0;
+end:
+    if (key) RegCloseKey(key);
+    if (res != 0) WINE_ERR("Unable to set configuration key %s in section %s to %s, res=%ld\n", valueName, subkey, value, res);
+    return res;
+}
+
+
+/*****************************************************************************
  * Name       : loadConfig
  * Description: Loads and populates a configuration structure
  * Parameters : pCfg
@@ -152,32 +192,29 @@
     HKEY hSession=NULL;
     DWORD res;
 
-    if( (res=RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", 0, KEY_ALL_ACCESS, &hSession ))
-            !=ERROR_SUCCESS )
+    WINE_TRACE("\n");
+
+    res = RegCreateKey(HKEY_LOCAL_MACHINE, WINEHQ_KEY_ROOT, &hSession);
+    if (res != ERROR_SUCCESS)
     {
-        if( res==ERROR_FILE_NOT_FOUND )
-            WINE_ERR("Wine config key does not exist");
-        else
-            WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
-        
-        res=FALSE;
-        return 1;
+        WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
+        return -1;
     }
-    
+
     /* Windows and DOS versions */
-    GetConfigValueSZ(hSession,"Version","Windows",pCfg->szWinVer,MAX_VERSION_LENGTH,"win95");
-    GetConfigValueSZ(hSession,"Version","DOS",pCfg->szDOSVer,MAX_VERSION_LENGTH,"6.22");
-    GetConfigValueSZ(hSession,"Tweak.Layout","WineLook",pCfg->szWinLook,MAX_VERSION_LENGTH,"win95");
+    getConfigValue(hSession, "Version", "Windows", pCfg->szWinVer, MAX_VERSION_LENGTH, "win95");
+    getConfigValue(hSession, "Version", "DOS", pCfg->szDOSVer, MAX_VERSION_LENGTH, "6.22");
+    getConfigValue(hSession, "Tweak.Layout", "WineLook", pCfg->szWinLook, MAX_VERSION_LENGTH, "win95");
 
     /* System Paths */
-    GetConfigValueSZ(hSession,"Wine","Windows",pCfg->szWinDir,MAX_PATH,"c:\\Windows");
-    GetConfigValueSZ(hSession,"Wine","System",pCfg->szWinSysDir,MAX_PATH,"c:\\Windows\\System");
-    GetConfigValueSZ(hSession,"Wine","Temp",pCfg->szWinTmpDir,MAX_PATH,"c:\\Windows\\Temp");
-    GetConfigValueSZ(hSession,"Wine","Profile",pCfg->szWinProfDir,MAX_PATH,"c:\\Windows\\Profiles\\Administrator");
-    GetConfigValueSZ(hSession,"Wine","Path",pCfg->szWinPath,MAX_PATH,"c:\\Windows;c:\\Windows\\System");
+    getConfigValue(hSession, "Wine", "Windows", pCfg->szWinDir, MAX_PATH, "c:\\Windows");
+    getConfigValue(hSession, "Wine", "System", pCfg->szWinSysDir, MAX_PATH, "c:\\Windows\\System");
+    getConfigValue(hSession, "Wine", "Temp", pCfg->szWinTmpDir, MAX_PATH, "c:\\Windows\\Temp");
+    getConfigValue(hSession, "Wine", "Profile", pCfg->szWinProfDir, MAX_PATH, "c:\\Windows\\Profiles\\Administrator");
+    getConfigValue(hSession, "Wine", "Path", pCfg->szWinPath, MAX_PATH, "c:\\Windows;c:\\Windows\\System");
 
     /* Graphics driver */
-    GetConfigValueSZ(hSession,"Wine","GraphicsDriver",pCfg->szGraphDriver,MAX_NAME_LENGTH,"x11drv");
+    getConfigValue(hSession, "Wine", "GraphicsDriver", pCfg->szGraphDriver, MAX_NAME_LENGTH, "x11drv");
     
     /*
      * DLL defaults for all applications is built using
@@ -221,9 +258,8 @@
 }
 
 /*****************************************************************************
- * Name: saveConfig
- * Description: Stores the configuration structure
- * Parameters : pCfg
+ * saveConfig : Stores the configuration structure
+ *
  * Returns    : 0 on success, -1 otherwise
  *
  * FIXME: This is where we are to write the changes to the registry.
@@ -231,5 +267,20 @@
  */
 int saveConfig (const WINECFG_DESC* pCfg)
 {
+    HKEY key;
+    DWORD res;
+
+    WINE_TRACE("\n");
+    
+    res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WINEHQ_KEY_ROOT, 0, KEY_ALL_ACCESS, &key);
+    if (res != ERROR_SUCCESS) {
+	WINE_ERR("Failed to open Wine config registry branch, res=%ld\n", res);
+	return -1;
+    }
+
+    /* Windows and DOS versions */
+    setConfigValue(key, "Version", "Windows", pCfg->szWinVer);
+    
+    WINE_FIXME("We don't write out the entire configuration yet\n");
     return 0;
 }
Index: programs/winecfg/winecfg.h
===================================================================
RCS file: /home/wine/wine/programs/winecfg/winecfg.h,v
retrieving revision 1.1
diff -u -r1.1 winecfg.h
--- programs/winecfg/winecfg.h	31 Mar 2003 19:41:55 -0000	1.1
+++ programs/winecfg/winecfg.h	26 Aug 2003 14:07:50 -0000
@@ -51,4 +51,6 @@
 int loadConfig(WINECFG_DESC *pCfg);
 int saveConfig(const WINECFG_DESC *pCfg);
 
+#define WINEHQ_KEY_ROOT "Software\\Wine\\Wine\\Config"
+
 #endif




[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux