Remove from docs / config tool useless / obsoleted options.
[wine] / programs / winecfg / winecfg.c
1 /*
2  * WineCfg configuration management
3  *
4  * Copyright 2002 Jaco Greeff
5  * Copyright 2003 Dimitrie O. Paun
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include <stdio.h>
24 #include <limits.h>
25 #include <windows.h>
26 #include <winreg.h>
27 #include <wine/debug.h>
28
29 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
30
31 #include "winecfg.h"
32
33
34 /*****************************************************************************
35  */
36 WINECFG_DESC* allocConfig(void)
37 {
38     WINECFG_DESC* pWineCfg =  malloc (sizeof (WINECFG_DESC));
39
40     if (!pWineCfg) goto fail;
41     ZeroMemory(pWineCfg, sizeof(*pWineCfg));
42
43     pWineCfg->pDlls = DPA_Create(100);
44     if (!pWineCfg->pDlls) goto fail;
45     pWineCfg->pApps = DPA_Create(100);
46     if (!pWineCfg->pApps) goto fail;
47     
48     return pWineCfg;
49
50 fail:
51     /* FIXME: do something nice */
52     printf("Out of memory");
53     exit(1);
54 }
55
56
57 /*****************************************************************************
58  */
59 int freeConfig (WINECFG_DESC* pCfg)
60 {
61     int i;
62
63     for (i = 0; i < pCfg->pDlls->nItemCount; i++)
64         free (DPA_GetPtr(pCfg->pDlls, i));
65     DPA_Destroy(pCfg->pDlls);
66     
67     for (i = 0; i < pCfg->pApps->nItemCount; i++)
68         free (DPA_GetPtr(pCfg->pApps, i));
69     DPA_Destroy(pCfg->pApps);
70     
71     free (pCfg);
72
73     return 0;
74 }
75
76 /*****************************************************************************
77  */
78 int GetConfigValueSZ (HKEY hCurrent, LPSTR subkey, LPSTR valueName, LPSTR RetVal, 
79                     int length, LPSTR DefRes)
80 {
81     CHAR *buffer=NULL;
82     DWORD dataLength=0;
83     HKEY hSubKey=NULL;
84     DWORD res;
85
86     if( (res=RegOpenKeyEx( hCurrent, subkey, 0, KEY_ALL_ACCESS, &hSubKey ))
87             !=ERROR_SUCCESS )
88     {
89         if( res==ERROR_FILE_NOT_FOUND )
90         {
91             WINE_TRACE("Value not present - using default\n");
92             strncpy( RetVal,DefRes,length);
93             res=TRUE;
94         }
95         else
96         {
97             WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
98             res=FALSE;
99         }
100         goto end;
101     }
102     res = RegQueryValueExA( hSubKey, valueName, NULL, NULL, NULL, &dataLength);
103         if( res==ERROR_FILE_NOT_FOUND )
104     {
105         WINE_TRACE("Value not present - using default\n");
106         strncpy( RetVal,DefRes,length);
107         res=TRUE;
108         goto end;
109     }
110
111     if( res!=ERROR_SUCCESS )
112     {
113         WINE_ERR("Couldn't query value's length (%ld)\n", res );
114         res=FALSE;
115         goto end;
116     }
117
118     buffer=malloc( dataLength );
119     if( buffer==NULL )
120     {
121         WINE_ERR("Couldn't allocate %lu bytes for the value\n", dataLength );
122         res=FALSE;
123         goto end;
124     }
125     
126     RegQueryValueEx( hSubKey, valueName, NULL, NULL, (LPBYTE)buffer, &dataLength);
127     strncpy( RetVal,buffer,length);
128     free(buffer);
129     
130 end:
131    if( hSubKey!=NULL )
132         RegCloseKey( hSubKey );
133
134     return res;
135     
136 }
137
138 /*****************************************************************************
139  * Name       : loadConfig
140  * Description: Loads and populates a configuration structure
141  * Parameters : pCfg
142  * Returns    : 0 on success, -1 otherwise
143  *
144  * FIXME: We are supposed to load these values from the registry.
145  *        This is not active yet, so just setup some (hopefully) 
146  *        sane defaults
147  */
148 int loadConfig (WINECFG_DESC* pCfg)
149 {
150     const DLL_DESC *pDllDefaults;
151     
152     HKEY hSession=NULL;
153     DWORD res;
154
155     if( (res=RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", 0, KEY_ALL_ACCESS, &hSession ))
156             !=ERROR_SUCCESS )
157     {
158         if( res==ERROR_FILE_NOT_FOUND )
159             WINE_ERR("Wine config key does not exist");
160         else
161             WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
162         
163         res=FALSE;
164         return 1;
165     }
166     
167     /* Windows and DOS versions */
168     GetConfigValueSZ(hSession,"Version","Windows",pCfg->szWinVer,MAX_VERSION_LENGTH,"win95");
169     GetConfigValueSZ(hSession,"Version","DOS",pCfg->szDOSVer,MAX_VERSION_LENGTH,"6.22");
170     GetConfigValueSZ(hSession,"Tweak.Layout","WineLook",pCfg->szWinLook,MAX_VERSION_LENGTH,"win95");
171
172     /* System Paths */
173     GetConfigValueSZ(hSession,"Wine","Windows",pCfg->szWinDir,MAX_PATH,"c:\\Windows");
174     GetConfigValueSZ(hSession,"Wine","System",pCfg->szWinSysDir,MAX_PATH,"c:\\Windows\\System");
175     GetConfigValueSZ(hSession,"Wine","Temp",pCfg->szWinTmpDir,MAX_PATH,"c:\\Windows\\Temp");
176     GetConfigValueSZ(hSession,"Wine","Profile",pCfg->szWinProfDir,MAX_PATH,"c:\\Windows\\Profiles\\Administrator");
177     GetConfigValueSZ(hSession,"Wine","Path",pCfg->szWinPath,MAX_PATH,"c:\\Windows;c:\\Windows\\System");
178
179     /* Graphics driver */
180     GetConfigValueSZ(hSession,"Wine","GraphicsDriver",pCfg->szGraphDriver,MAX_NAME_LENGTH,"x11drv");
181     
182     /*
183      * DLL defaults for all applications is built using
184      * the default DLL structure
185      */
186     for (pDllDefaults = getDLLDefaults (); *pDllDefaults->szName; pDllDefaults++)
187     {
188         DLL_DESC *pDll = malloc(sizeof(DLL_DESC));
189         memcpy (pDll, pDllDefaults, sizeof(DLL_DESC));
190         DPA_InsertPtr(pCfg->pDlls, INT_MAX, pDll);
191     }
192
193     /*
194      * Application defaults on a per application
195      * level (if not set, this defaults to what 
196      * is already there)
197      */
198     /* FIXME: TODO */
199
200     /*
201      * X11Drv defaults
202      */
203     strcpy(pCfg->sX11Drv.szX11Display, ":0.0");
204     pCfg->sX11Drv.nSysColors = 100;
205     pCfg->sX11Drv.nPrivateMap = 0;
206     pCfg->sX11Drv.nPerfect = 0;
207     pCfg->sX11Drv.nDepth = 16;
208     pCfg->sX11Drv.nManaged = 1;
209     pCfg->sX11Drv.nDesktopSizeX = 640;
210     pCfg->sX11Drv.nDesktopSizeY = 480;
211     pCfg->sX11Drv.nDGA = 1;
212     pCfg->sX11Drv.nXVidMode = 1;
213     pCfg->sX11Drv.nTakeFocus = 1;
214     pCfg->sX11Drv.nDXGrab = 0;
215     pCfg->sX11Drv.nDoubleBuffered = 0;
216     pCfg->sX11Drv.nSynchronous = 1;
217     
218     RegCloseKey( hSession );
219
220     return 0;
221 }
222
223 /*****************************************************************************
224  * Name: saveConfig
225  * Description: Stores the configuration structure
226  * Parameters : pCfg
227  * Returns    : 0 on success, -1 otherwise
228  *
229  * FIXME: This is where we are to write the changes to the registry.
230  *        This is not setup yet, so do nothing and say ok.
231  */
232 int saveConfig (const WINECFG_DESC* pCfg)
233 {
234     return 0;
235 }