2003-03-31 19:41:55 +00:00
|
|
|
/*
|
|
|
|
* WineCfg configuration management
|
|
|
|
*
|
|
|
|
* Copyright 2002 Jaco Greeff
|
|
|
|
* Copyright 2003 Dimitrie O. Paun
|
2003-08-30 00:40:46 +00:00
|
|
|
* Copyright 2003 Mike Hearn
|
2003-03-31 19:41:55 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
2003-09-15 22:09:03 +00:00
|
|
|
* TODO: (in rough order of priority)
|
|
|
|
* - A mind bogglingly vast amount of stuff
|
|
|
|
*
|
|
|
|
* - Implement autodetect for drive configuration
|
|
|
|
* - Figure out whether we need the virtual vs real drive selection stuff at the top of the property page
|
|
|
|
* - Implement explicit mode vs instant-apply mode
|
|
|
|
* - DLL editing
|
|
|
|
* - Multimedia page
|
|
|
|
* - Settings migration code (from old configs)
|
2003-09-22 19:26:10 +00:00
|
|
|
* - Clean up resource.h, it's a bog
|
2003-09-15 22:09:03 +00:00
|
|
|
*
|
2003-09-18 04:32:01 +00:00
|
|
|
* Minor things that should be done someday:
|
|
|
|
* - Make the desktop size UI a combo box, with a Custom option, so it's more obvious what you might want to choose here
|
|
|
|
*
|
2003-09-30 00:27:55 +00:00
|
|
|
* BUGS:
|
|
|
|
* - x11drv page triggers key writes on entry
|
|
|
|
*
|
2003-03-31 19:41:55 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
#include <assert.h>
|
2003-03-31 19:41:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <windows.h>
|
2003-04-27 00:33:07 +00:00
|
|
|
#include <winreg.h>
|
|
|
|
#include <wine/debug.h>
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
2003-03-31 19:41:55 +00:00
|
|
|
|
|
|
|
#include "winecfg.h"
|
|
|
|
|
2003-08-30 00:40:46 +00:00
|
|
|
HKEY configKey = NULL;
|
2003-03-31 19:41:55 +00:00
|
|
|
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
int initialize(void) {
|
|
|
|
DWORD res = RegCreateKey(HKEY_LOCAL_MACHINE, WINE_KEY_ROOT, &configKey);
|
|
|
|
if (res != ERROR_SUCCESS) {
|
|
|
|
WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
|
|
|
|
return 1;
|
|
|
|
}
|
2003-03-31 19:41:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
|
2003-04-27 00:33:07 +00:00
|
|
|
/*****************************************************************************
|
2003-08-30 00:27:08 +00:00
|
|
|
* getConfigValue: Retrieves a configuration value from the registry
|
|
|
|
*
|
2003-10-09 04:39:01 +00:00
|
|
|
* const char *subKey : the name of the config section
|
|
|
|
* const char *valueName : the name of the config value
|
|
|
|
* const char *defaultResult : if the key isn't found, return this value instead
|
2003-08-30 00:27:08 +00:00
|
|
|
*
|
2003-09-08 18:58:07 +00:00
|
|
|
* Returns a buffer holding the value if successful, NULL if not. Caller is responsible for freeing the result.
|
2003-08-30 00:27:08 +00:00
|
|
|
*
|
2003-04-27 00:33:07 +00:00
|
|
|
*/
|
2003-10-09 04:39:01 +00:00
|
|
|
char *getConfigValue (const char *subkey, const char *valueName, const char *defaultResult)
|
2003-04-27 00:33:07 +00:00
|
|
|
{
|
2003-09-08 18:58:07 +00:00
|
|
|
char *buffer = NULL;
|
2003-08-30 00:27:08 +00:00
|
|
|
DWORD dataLength;
|
|
|
|
HKEY hSubKey = NULL;
|
2003-09-08 18:58:07 +00:00
|
|
|
DWORD res;
|
2003-04-27 00:33:07 +00:00
|
|
|
|
2003-08-30 00:27:08 +00:00
|
|
|
WINE_TRACE("subkey=%s, valueName=%s, defaultResult=%s\n", subkey, valueName, defaultResult);
|
2003-09-08 18:58:07 +00:00
|
|
|
|
|
|
|
res = RegOpenKeyEx( configKey, subkey, 0, KEY_ALL_ACCESS, &hSubKey );
|
|
|
|
if(res != ERROR_SUCCESS) {
|
2003-04-27 00:33:07 +00:00
|
|
|
if( res==ERROR_FILE_NOT_FOUND )
|
|
|
|
{
|
2003-08-30 00:27:08 +00:00
|
|
|
WINE_TRACE("Section key not present - using default\n");
|
2003-09-08 18:58:07 +00:00
|
|
|
return strdup(defaultResult);
|
2003-04-27 00:33:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-08-30 00:27:08 +00:00
|
|
|
WINE_ERR("RegOpenKey failed on wine config key (res=%ld)\n", res);
|
2003-04-27 00:33:07 +00:00
|
|
|
}
|
|
|
|
goto end;
|
|
|
|
}
|
2003-09-30 00:27:55 +00:00
|
|
|
|
2003-04-27 00:33:07 +00:00
|
|
|
res = RegQueryValueExA( hSubKey, valueName, NULL, NULL, NULL, &dataLength);
|
2003-09-08 18:58:07 +00:00
|
|
|
if( res == ERROR_FILE_NOT_FOUND ) {
|
2003-04-27 00:33:07 +00:00
|
|
|
WINE_TRACE("Value not present - using default\n");
|
2003-09-08 18:58:07 +00:00
|
|
|
buffer = strdup(defaultResult);
|
|
|
|
goto end;
|
|
|
|
} else if( res!=ERROR_SUCCESS ) {
|
2003-08-30 00:27:08 +00:00
|
|
|
WINE_ERR("Couldn't query value's length (res=%ld)\n", res );
|
2003-04-27 00:33:07 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
buffer = malloc(dataLength);
|
2003-04-27 00:33:07 +00:00
|
|
|
if( buffer==NULL )
|
|
|
|
{
|
|
|
|
WINE_ERR("Couldn't allocate %lu bytes for the value\n", dataLength );
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2003-08-30 00:27:08 +00:00
|
|
|
RegQueryValueEx(hSubKey, valueName, NULL, NULL, (LPBYTE)buffer, &dataLength);
|
2003-04-27 00:33:07 +00:00
|
|
|
|
|
|
|
end:
|
2003-08-30 00:27:08 +00:00
|
|
|
if( hSubKey!=NULL )
|
2003-04-27 00:33:07 +00:00
|
|
|
RegCloseKey( hSubKey );
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
return buffer;
|
2003-04-27 00:33:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-08-30 00:27:08 +00:00
|
|
|
/*****************************************************************************
|
2003-09-10 03:41:44 +00:00
|
|
|
* setConfigValue : Sets a configuration key in the registry. Section will be created if it doesn't already exist
|
2003-08-30 00:27:08 +00:00
|
|
|
*
|
|
|
|
* HKEY hCurrent : the registry key that the configuration is rooted at
|
2003-10-09 04:39:01 +00:00
|
|
|
* const char *subKey : the name of the config section
|
|
|
|
* const char *valueName : the name of the config value
|
|
|
|
* const char *value : the value to set the configuration key to
|
2003-08-30 00:27:08 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero otherwise
|
2004-01-07 00:43:40 +00:00
|
|
|
*
|
|
|
|
* If *valueName or *value is NULL, an empty section will be created
|
2003-08-30 00:27:08 +00:00
|
|
|
*/
|
2003-10-09 04:39:01 +00:00
|
|
|
int setConfigValue (const char *subkey, const char *valueName, const char *value) {
|
2003-08-30 00:27:08 +00:00
|
|
|
DWORD res = 1;
|
|
|
|
HKEY key = NULL;
|
|
|
|
|
|
|
|
WINE_TRACE("subkey=%s, valueName=%s, value=%s\n", subkey, valueName, value);
|
2003-09-08 18:58:07 +00:00
|
|
|
|
|
|
|
assert( subkey != NULL );
|
2003-08-30 00:27:08 +00:00
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
res = RegCreateKey(configKey, subkey, &key);
|
2003-08-30 00:27:08 +00:00
|
|
|
if (res != ERROR_SUCCESS) goto end;
|
2004-01-07 00:43:40 +00:00
|
|
|
if (value == NULL || valueName == NULL) goto end;
|
2003-08-30 00:27:08 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
/* returns 0 on success, an HRESULT from the registry funtions otherwise */
|
2003-10-09 04:39:01 +00:00
|
|
|
HRESULT doesConfigValueExist(const char *subkey, const char *valueName) {
|
2003-09-08 18:58:07 +00:00
|
|
|
HRESULT hr;
|
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
WINE_TRACE("subkey=%s, valueName=%s - ", subkey, valueName);
|
|
|
|
|
|
|
|
hr = RegOpenKeyEx(configKey, subkey, 0, KEY_READ, &key);
|
|
|
|
if (hr != S_OK) {
|
|
|
|
WINE_TRACE("no: subkey does not exist\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = RegQueryValueEx(key, valueName, NULL, NULL, NULL, NULL);
|
|
|
|
if (hr != S_OK) {
|
|
|
|
WINE_TRACE("no: key does not exist\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
WINE_TRACE("yes\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* removes the requested value from the registry, however, does not remove the section if empty. Returns S_OK (0) on success. */
|
2003-10-09 04:39:01 +00:00
|
|
|
HRESULT removeConfigValue(const char *subkey, const char *valueName) {
|
2003-09-08 18:58:07 +00:00
|
|
|
HRESULT hr;
|
|
|
|
HKEY key;
|
|
|
|
WINE_TRACE("subkey=%s, valueName=%s\n", subkey, valueName);
|
|
|
|
|
|
|
|
hr = RegOpenKeyEx(configKey, subkey, 0, KEY_READ, &key);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
hr = RegDeleteValue(key, valueName);
|
|
|
|
if (hr != ERROR_SUCCESS) return hr;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2003-09-17 22:40:38 +00:00
|
|
|
/* removes the requested configuration section (subkey) from the registry, assuming it exists */
|
|
|
|
/* this function might be slightly pointless, but in future we may wish to treat recursion specially etc, so we'll keep it for now */
|
|
|
|
HRESULT removeConfigSection(char *section) {
|
|
|
|
HRESULT hr;
|
|
|
|
WINE_TRACE("section=%s\n", section);
|
|
|
|
|
|
|
|
return hr = RegDeleteKey(configKey, section);
|
|
|
|
}
|
|
|
|
|
2003-08-30 00:27:08 +00:00
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
/* ========================================================================= */
|
|
|
|
/* Transaction management code */
|
|
|
|
|
|
|
|
struct transaction *tqhead, *tqtail;
|
|
|
|
int instantApply = 1;
|
|
|
|
|
|
|
|
void destroyTransaction(struct transaction *trans) {
|
|
|
|
assert( trans != NULL );
|
2003-08-30 00:27:08 +00:00
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
WINE_TRACE("destroying %p\n", trans);
|
|
|
|
|
|
|
|
free(trans->section);
|
2003-09-17 22:40:38 +00:00
|
|
|
if (trans->key) free(trans->key);
|
2003-09-08 18:58:07 +00:00
|
|
|
if (trans->newValue) free(trans->newValue);
|
|
|
|
|
|
|
|
if (trans->next) trans->next->prev = trans->prev;
|
|
|
|
if (trans->prev) trans->prev->next = trans->next;
|
|
|
|
if (trans == tqhead) tqhead = NULL;
|
|
|
|
if (trans == tqtail) tqtail = NULL;
|
|
|
|
|
|
|
|
free(trans);
|
|
|
|
}
|
2003-08-30 00:27:08 +00:00
|
|
|
|
2003-10-09 04:39:01 +00:00
|
|
|
void addTransaction(const char *section, const char *key, enum transaction_action action, const char *newValue) {
|
2003-09-17 22:40:38 +00:00
|
|
|
struct transaction *trans = calloc(sizeof(struct transaction),1);
|
2003-08-30 00:27:08 +00:00
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
assert( section != NULL );
|
|
|
|
if (action == ACTION_SET) assert( newValue != NULL );
|
2003-09-17 22:40:38 +00:00
|
|
|
if (action == ACTION_SET) assert( key != NULL );
|
|
|
|
|
2003-09-10 03:41:44 +00:00
|
|
|
trans->section = strdup(section);
|
2003-09-17 22:40:38 +00:00
|
|
|
if (key) trans->key = strdup(key);
|
|
|
|
if (newValue) trans->newValue = strdup(newValue);
|
2003-09-08 18:58:07 +00:00
|
|
|
trans->action = action;
|
|
|
|
|
|
|
|
if (tqtail == NULL) {
|
|
|
|
tqtail = trans;
|
|
|
|
tqhead = tqtail;
|
|
|
|
} else {
|
|
|
|
tqhead->next = trans;
|
|
|
|
trans->prev = tqhead;
|
|
|
|
tqhead = trans;
|
|
|
|
}
|
|
|
|
|
2003-09-10 03:41:44 +00:00
|
|
|
if (instantApply) {
|
|
|
|
processTransaction(trans);
|
|
|
|
destroyTransaction(trans);
|
|
|
|
}
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void processTransaction(struct transaction *trans) {
|
|
|
|
if (trans->action == ACTION_SET) {
|
|
|
|
WINE_TRACE("Setting %s\\%s to '%s'\n", trans->section, trans->key, trans->newValue);
|
|
|
|
setConfigValue(trans->section, trans->key, trans->newValue);
|
|
|
|
} else if (trans->action == ACTION_REMOVE) {
|
2003-09-17 22:40:38 +00:00
|
|
|
if (trans->key) {
|
|
|
|
WINE_TRACE("Removing %s\\%s\n", trans->section, trans->key);
|
|
|
|
removeConfigValue(trans->section, trans->key);
|
|
|
|
} else {
|
|
|
|
/* NULL key means remove that section entirely */
|
|
|
|
WINE_TRACE("Removing section %s\n", trans->section);
|
|
|
|
removeConfigSection(trans->section);
|
|
|
|
}
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
|
|
|
/* TODO: implement notifications here */
|
|
|
|
}
|
|
|
|
|
2003-09-10 03:41:44 +00:00
|
|
|
void processTransQueue(void)
|
|
|
|
{
|
2003-09-08 18:58:07 +00:00
|
|
|
WINE_TRACE("\n");
|
2003-09-10 03:41:44 +00:00
|
|
|
while (tqtail != NULL) {
|
|
|
|
struct transaction *next = tqtail->next;
|
|
|
|
processTransaction(tqtail);
|
|
|
|
destroyTransaction(tqtail);
|
|
|
|
tqtail = next;
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
2003-03-31 19:41:55 +00:00
|
|
|
}
|
2003-09-10 03:41:44 +00:00
|
|
|
|
|
|
|
/* ================================== utility functions ============================ */
|
|
|
|
|
|
|
|
/* returns a string with the window text of the dialog item. user is responsible for freeing the result */
|
|
|
|
char *getDialogItemText(HWND hDlg, WORD controlID) {
|
|
|
|
HWND item = GetDlgItem(hDlg, controlID);
|
|
|
|
int len = GetWindowTextLength(item) + 1;
|
|
|
|
char *result = malloc(len);
|
|
|
|
if (GetWindowText(item, result, len) == 0) return NULL;
|
|
|
|
return result;
|
|
|
|
}
|
2004-05-04 02:56:46 +00:00
|
|
|
|
|
|
|
void PRINTERROR(void)
|
|
|
|
{
|
|
|
|
LPSTR msg;
|
|
|
|
|
|
|
|
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
0, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
|
|
|
|
(LPSTR)&msg, 0, NULL);
|
|
|
|
WINE_TRACE("error: '%s'\n", msg);
|
|
|
|
}
|