Fixed a couple of races with exiting threads in suspend_for_ptrace().
[wine/gsoc_dplay.git] / programs / winecfg / winecfg.c
blob52efa9311aafbd3c8a0be163e9051736d5ea3efe
1 /*
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
23 #include <stdio.h>
24 #include <limits.h>
25 #include <windows.h>
26 #include <winreg.h>
27 #include <wine/debug.h>
29 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
31 #include "winecfg.h"
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;
48 return pWineCfg;
50 fail:
51 /* FIXME: do something nice */
52 printf("Out of memory");
53 exit(1);
57 /*****************************************************************************
59 int freeConfig (WINECFG_DESC* pCfg)
61 int i;
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);
71 free (pCfg);
73 return 0;
76 /*****************************************************************************
78 int GetConfigValueSZ (HKEY hCurrent, LPSTR subkey, LPSTR valueName, LPSTR RetVal,
79 int length, LPSTR DefRes)
81 CHAR *buffer=NULL;
82 DWORD dataLength=0;
83 HKEY hSubKey=NULL;
84 DWORD res;
86 if( (res=RegOpenKeyEx( hCurrent, subkey, 0, KEY_ALL_ACCESS, &hSubKey ))
87 !=ERROR_SUCCESS )
89 if( res==ERROR_FILE_NOT_FOUND )
91 WINE_TRACE("Value not present - using default\n");
92 strncpy( RetVal,DefRes,length);
93 res=TRUE;
95 else
97 WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
98 res=FALSE;
100 goto end;
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);
107 res=TRUE;
108 goto end;
111 if( res!=ERROR_SUCCESS )
113 WINE_ERR("Couldn't query value's length (%ld)\n", res );
114 res=FALSE;
115 goto end;
118 buffer=malloc( dataLength );
119 if( buffer==NULL )
121 WINE_ERR("Couldn't allocate %lu bytes for the value\n", dataLength );
122 res=FALSE;
123 goto end;
126 RegQueryValueEx( hSubKey, valueName, NULL, NULL, (LPBYTE)buffer, &dataLength);
127 strncpy( RetVal,buffer,length);
128 free(buffer);
130 end:
131 if( hSubKey!=NULL )
132 RegCloseKey( hSubKey );
134 return res;
138 /*****************************************************************************
139 * Name : loadConfig
140 * Description: Loads and populates a configuration structure
141 * Parameters : pCfg
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)
146 * sane defaults
148 int loadConfig (WINECFG_DESC* pCfg)
150 const DLL_DESC *pDllDefaults;
152 HKEY hSession=NULL;
153 DWORD res;
155 if( (res=RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", 0, KEY_ALL_ACCESS, &hSession ))
156 !=ERROR_SUCCESS )
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);
163 res=FALSE;
164 return 1;
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");
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");
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
196 * is already there)
198 /* FIXME: TODO */
201 * X11Drv defaults
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 );
223 return 0;
226 /*****************************************************************************
227 * Name: saveConfig
228 * Description: Stores the configuration structure
229 * Parameters : pCfg
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)
237 return 0;