2 * WineCfg configuration management
4 * Copyright 2002 Jaco Greeff
5 * Copyright 2003 Dimitrie O. Paun
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.
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.
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
27 #include <wine/debug.h>
29 WINE_DEFAULT_DEBUG_CHANNEL(winecfg
);
34 /*****************************************************************************
36 WINECFG_DESC
* allocConfig(void)
38 WINECFG_DESC
* pWineCfg
= malloc (sizeof (WINECFG_DESC
));
40 if (!pWineCfg
) goto fail
;
41 ZeroMemory(pWineCfg
, sizeof(*pWineCfg
));
43 pWineCfg
->pDlls
= DPA_Create(100);
44 if (!pWineCfg
->pDlls
) goto fail
;
45 pWineCfg
->pApps
= DPA_Create(100);
46 if (!pWineCfg
->pApps
) goto fail
;
51 /* FIXME: do something nice */
52 printf("Out of memory");
57 /*****************************************************************************
59 int freeConfig (WINECFG_DESC
* pCfg
)
63 for (i
= 0; i
< pCfg
->pDlls
->nItemCount
; i
++)
64 free (DPA_GetPtr(pCfg
->pDlls
, i
));
65 DPA_Destroy(pCfg
->pDlls
);
67 for (i
= 0; i
< pCfg
->pApps
->nItemCount
; i
++)
68 free (DPA_GetPtr(pCfg
->pApps
, i
));
69 DPA_Destroy(pCfg
->pApps
);
76 /*****************************************************************************
78 int GetConfigValueSZ (HKEY hCurrent
, LPSTR subkey
, LPSTR valueName
, LPSTR RetVal
,
79 int length
, LPSTR DefRes
)
86 if( (res
=RegOpenKeyEx( hCurrent
, subkey
, 0, KEY_ALL_ACCESS
, &hSubKey
))
89 if( res
==ERROR_FILE_NOT_FOUND
)
91 WINE_TRACE("Value not present - using default\n");
92 strncpy( RetVal
,DefRes
,length
);
97 WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res
);
102 res
= RegQueryValueExA( hSubKey
, valueName
, NULL
, NULL
, NULL
, &dataLength
);
103 if( res
==ERROR_FILE_NOT_FOUND
)
105 WINE_TRACE("Value not present - using default\n");
106 strncpy( RetVal
,DefRes
,length
);
111 if( res
!=ERROR_SUCCESS
)
113 WINE_ERR("Couldn't query value's length (%ld)\n", res
);
118 buffer
=malloc( dataLength
);
121 WINE_ERR("Couldn't allocate %lu bytes for the value\n", dataLength
);
126 RegQueryValueEx( hSubKey
, valueName
, NULL
, NULL
, (LPBYTE
)buffer
, &dataLength
);
127 strncpy( RetVal
,buffer
,length
);
132 RegCloseKey( hSubKey
);
138 /*****************************************************************************
140 * Description: Loads and populates a configuration structure
142 * Returns : 0 on success, -1 otherwise
144 * FIXME: We are supposed to load these values from the registry.
145 * This is not active yet, so just setup some (hopefully)
148 int loadConfig (WINECFG_DESC
* pCfg
)
150 const DLL_DESC
*pDllDefaults
;
155 if( (res
=RegOpenKeyEx( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config", 0, KEY_ALL_ACCESS
, &hSession
))
158 if( res
==ERROR_FILE_NOT_FOUND
)
159 WINE_ERR("Wine config key does not exist");
161 WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res
);
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");
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");
179 /* Graphics driver */
180 GetConfigValueSZ(hSession
,"Wine","GraphicsDriver",pCfg
->szGraphDriver
,MAX_NAME_LENGTH
,"x11drv");
183 * DLL defaults for all applications is built using
184 * the default DLL structure
186 for (pDllDefaults
= getDLLDefaults (); *pDllDefaults
->szName
; pDllDefaults
++)
188 DLL_DESC
*pDll
= malloc(sizeof(DLL_DESC
));
189 memcpy (pDll
, pDllDefaults
, sizeof(DLL_DESC
));
190 DPA_InsertPtr(pCfg
->pDlls
, INT_MAX
, pDll
);
194 * Application defaults on a per application
195 * level (if not set, this defaults to what
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
.nXShm
= 1;
213 pCfg
->sX11Drv
.nXVidMode
= 1;
214 pCfg
->sX11Drv
.nTakeFocus
= 1;
215 pCfg
->sX11Drv
.nDXGrab
= 0;
216 pCfg
->sX11Drv
.nDoubleBuffered
= 0;
217 pCfg
->sX11Drv
.nTextCP
= 0;
218 pCfg
->sX11Drv
.nXVideoPort
= 43;
219 pCfg
->sX11Drv
.nSynchronous
= 1;
221 RegCloseKey( hSession
);
226 /*****************************************************************************
228 * Description: Stores the configuration structure
230 * Returns : 0 on success, -1 otherwise
232 * FIXME: This is where we are to write the changes to the registry.
233 * This is not setup yet, so do nothing and say ok.
235 int saveConfig (const WINECFG_DESC
* pCfg
)