2001-12-04 21:46:54 +01:00
|
|
|
/*
|
|
|
|
* an application for displaying Win32 console
|
|
|
|
* registry and init functions
|
|
|
|
*
|
|
|
|
* Copyright 2001 Eric Pouech
|
2002-03-10 00:29:33 +01: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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-12-04 21:46:54 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
2001-12-04 21:46:54 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winecon_private.h"
|
|
|
|
|
2002-05-14 23:45:13 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wineconsole);
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
static const WCHAR wszConsole[] = {'C','o','n','s','o','l','e',0};
|
|
|
|
static const WCHAR wszCursorSize[] = {'C','u','r','s','o','r','S','i','z','e',0};
|
|
|
|
static const WCHAR wszCursorVisible[] = {'C','u','r','s','o','r','V','i','s','i','b','l','e',0};
|
2003-01-09 07:01:51 +01:00
|
|
|
static const WCHAR wszEditionMode[] = {'E','d','i','t','i','o','n','M','o','d','e',0};
|
2002-05-21 20:05:16 +02:00
|
|
|
static const WCHAR wszExitOnDie[] = {'E','x','i','t','O','n','D','i','e',0};
|
2001-12-04 21:46:54 +01:00
|
|
|
static const WCHAR wszFaceName[] = {'F','a','c','e','N','a','m','e',0};
|
|
|
|
static const WCHAR wszFontSize[] = {'F','o','n','t','S','i','z','e',0};
|
|
|
|
static const WCHAR wszFontWeight[] = {'F','o','n','t','W','e','i','g','h','t',0};
|
|
|
|
static const WCHAR wszHistoryBufferSize[] = {'H','i','s','t','o','r','y','B','u','f','f','e','r','S','i','z','e',0};
|
2002-09-04 20:41:52 +02:00
|
|
|
static const WCHAR wszHistoryNoDup[] = {'H','i','s','t','o','r','y','N','o','D','u','p',0};
|
2001-12-04 21:46:54 +01:00
|
|
|
static const WCHAR wszMenuMask[] = {'M','e','n','u','M','a','s','k',0};
|
2002-02-04 19:41:32 +01:00
|
|
|
static const WCHAR wszQuickEdit[] = {'Q','u','i','c','k','E','d','i','t',0};
|
2001-12-04 21:46:54 +01:00
|
|
|
static const WCHAR wszScreenBufferSize[] = {'S','c','r','e','e','n','B','u','f','f','e','r','S','i','z','e',0};
|
|
|
|
static const WCHAR wszScreenColors[] = {'S','c','r','e','e','n','C','o','l','o','r','s',0};
|
|
|
|
static const WCHAR wszWindowSize[] = {'W','i','n','d','o','w','S','i','z','e',0};
|
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
void WINECON_DumpConfig(const char* pfx, const struct config_data* cfg)
|
|
|
|
{
|
2006-10-02 23:22:34 +02:00
|
|
|
WINE_TRACE("%s cell=(%u,%u) cursor=(%d,%d) attr=%02x font=%s/%u hist=%u/%d flags=%c%c msk=%08x sb=(%u,%u) win=(%u,%u)x(%u,%u) edit=%u registry=%s\n",
|
2002-09-04 20:41:52 +02:00
|
|
|
pfx, cfg->cell_width, cfg->cell_height, cfg->cursor_size, cfg->cursor_visible, cfg->def_attr,
|
|
|
|
wine_dbgstr_w(cfg->face_name), cfg->font_weight, cfg->history_size, cfg->history_nodup ? 1 : 2,
|
|
|
|
cfg->quick_edit ? 'Q' : 'q', cfg->exit_on_die ? 'X' : 'x',
|
|
|
|
cfg->menu_mask, cfg->sb_width, cfg->sb_height, cfg->win_pos.X, cfg->win_pos.Y, cfg->win_width, cfg->win_height,
|
2003-01-09 07:01:51 +01:00
|
|
|
cfg->edition_mode,
|
2002-09-04 20:41:52 +02:00
|
|
|
wine_dbgstr_w(cfg->registry));
|
|
|
|
}
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
/******************************************************************
|
2002-09-04 20:41:52 +02:00
|
|
|
* WINECON_CreateKeyName
|
2001-12-04 21:46:54 +01:00
|
|
|
*
|
2002-09-04 20:41:52 +02:00
|
|
|
* Get a proper key name from an appname (mainly convert '\\' to '_')
|
|
|
|
*/
|
|
|
|
static LPWSTR WINECON_CreateKeyName(LPCWSTR kn)
|
|
|
|
{
|
|
|
|
LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(kn) + 1) * sizeof(WCHAR));
|
|
|
|
LPWSTR ptr = ret;
|
|
|
|
|
|
|
|
if (!ptr) WINECON_Fatal("OOM");
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*ptr++ = *kn == '\\' ? '_' : *kn;
|
|
|
|
} while (*kn++ != 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WINECON_RegLoadHelper
|
2001-12-04 21:46:54 +01:00
|
|
|
*
|
2002-09-04 20:41:52 +02:00
|
|
|
* Read the basic configuration from any console key or subkey
|
2001-12-04 21:46:54 +01:00
|
|
|
*/
|
2002-09-04 20:41:52 +02:00
|
|
|
static void WINECON_RegLoadHelper(HKEY hConKey, struct config_data* cfg)
|
2001-12-04 21:46:54 +01:00
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
DWORD count;
|
|
|
|
DWORD val;
|
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszCursorSize, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->cursor_size = val;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszCursorVisible, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->cursor_visible = val;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2003-01-09 07:01:51 +01:00
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszEditionMode, 0, &type, (LPBYTE)&val, &count))
|
2003-01-09 07:01:51 +01:00
|
|
|
cfg->edition_mode = val;
|
|
|
|
|
2002-05-21 20:05:16 +02:00
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszExitOnDie, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->exit_on_die = val;
|
2002-05-21 20:05:16 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
count = sizeof(cfg->face_name);
|
2010-04-28 01:07:32 +02:00
|
|
|
RegQueryValueExW(hConKey, wszFaceName, 0, &type, (LPBYTE)&cfg->face_name, &count);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszFontSize, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
cfg->cell_height = HIWORD(val);
|
|
|
|
cfg->cell_width = LOWORD(val);
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszFontWeight, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->font_weight = val;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszHistoryBufferSize, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->history_size = val;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszHistoryNoDup, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->history_nodup = val;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszMenuMask, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->menu_mask = val;
|
2002-02-04 19:41:32 +01:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszQuickEdit, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->quick_edit = val;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszScreenBufferSize, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
cfg->sb_height = HIWORD(val);
|
|
|
|
cfg->sb_width = LOWORD(val);
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszScreenColors, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->def_attr = val;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
count = sizeof(val);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegQueryValueExW(hConKey, wszWindowSize, 0, &type, (LPBYTE)&val, &count))
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
cfg->win_height = HIWORD(val);
|
|
|
|
cfg->win_width = LOWORD(val);
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
/* win_pos isn't read from registry */
|
2001-12-04 21:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2002-09-04 20:41:52 +02:00
|
|
|
* WINECON_RegLoad
|
2001-12-04 21:46:54 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-09-04 20:41:52 +02:00
|
|
|
void WINECON_RegLoad(const WCHAR* appname, struct config_data* cfg)
|
2001-12-04 21:46:54 +01:00
|
|
|
{
|
|
|
|
HKEY hConKey;
|
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
WINE_TRACE("loading %s registry settings.\n", appname ? wine_dbgstr_w(appname) : "default");
|
|
|
|
|
|
|
|
/* first set default values */
|
|
|
|
cfg->cursor_size = 25;
|
|
|
|
cfg->cursor_visible = 1;
|
|
|
|
cfg->exit_on_die = 1;
|
2002-12-14 00:37:06 +01:00
|
|
|
memset(cfg->face_name, 0, sizeof(cfg->face_name));
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->cell_height = 12;
|
|
|
|
cfg->cell_width = 8;
|
|
|
|
cfg->font_weight = 0;
|
2003-02-24 21:40:20 +01:00
|
|
|
cfg->history_size = 50;
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->history_nodup = 0;
|
|
|
|
cfg->menu_mask = 0;
|
|
|
|
cfg->quick_edit = 0;
|
|
|
|
cfg->sb_height = 25;
|
|
|
|
cfg->sb_width = 80;
|
|
|
|
cfg->def_attr = 0x000F;
|
|
|
|
cfg->win_height = 25;
|
|
|
|
cfg->win_width = 80;
|
2003-05-13 06:47:11 +02:00
|
|
|
cfg->win_pos.X = 0;
|
|
|
|
cfg->win_pos.Y = 0;
|
2003-01-09 07:01:51 +01:00
|
|
|
cfg->edition_mode = 0;
|
2002-09-04 20:41:52 +02:00
|
|
|
cfg->registry = NULL;
|
|
|
|
|
|
|
|
/* then read global settings */
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegOpenKeyW(HKEY_CURRENT_USER, wszConsole, &hConKey))
|
2001-12-04 21:46:54 +01:00
|
|
|
{
|
2002-09-04 20:41:52 +02:00
|
|
|
WINECON_RegLoadHelper(hConKey, cfg);
|
|
|
|
/* if requested, load part related to console title */
|
|
|
|
if (appname)
|
|
|
|
{
|
|
|
|
HKEY hAppKey;
|
|
|
|
|
|
|
|
cfg->registry = WINECON_CreateKeyName(appname);
|
2010-04-28 01:07:32 +02:00
|
|
|
if (!RegOpenKeyW(hConKey, cfg->registry, &hAppKey))
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
WINECON_RegLoadHelper(hAppKey, cfg);
|
|
|
|
RegCloseKey(hAppKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hConKey);
|
2001-12-04 21:46:54 +01:00
|
|
|
}
|
2002-09-04 20:41:52 +02:00
|
|
|
WINECON_DumpConfig("load", cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WINECON_RegSaveHelper
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void WINECON_RegSaveHelper(HKEY hConKey, const struct config_data* cfg)
|
|
|
|
{
|
|
|
|
DWORD val;
|
|
|
|
|
|
|
|
WINECON_DumpConfig("save", cfg);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
val = cfg->cursor_size;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszCursorSize, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
val = cfg->cursor_visible;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszCursorVisible, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2003-01-09 07:01:51 +01:00
|
|
|
val = cfg->edition_mode;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszEditionMode, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2003-01-09 07:01:51 +01:00
|
|
|
|
2002-05-21 20:05:16 +02:00
|
|
|
val = cfg->exit_on_die;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszExitOnDie, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2002-05-21 20:05:16 +02:00
|
|
|
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszFaceName, 0, REG_SZ, (LPBYTE)&cfg->face_name, sizeof(cfg->face_name));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
val = MAKELONG(cfg->cell_width, cfg->cell_height);
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszFontSize, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
val = cfg->font_weight;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszFontWeight, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
val = cfg->history_size;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszHistoryBufferSize, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
val = cfg->history_nodup;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszHistoryNoDup, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2002-09-04 20:41:52 +02:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
val = cfg->menu_mask;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszMenuMask, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
val = cfg->quick_edit;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszQuickEdit, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2002-02-04 19:41:32 +01:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
val = MAKELONG(cfg->sb_width, cfg->sb_height);
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszScreenBufferSize, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
val = cfg->def_attr;
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszScreenColors, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
val = MAKELONG(cfg->win_width, cfg->win_height);
|
2010-04-28 01:07:32 +02:00
|
|
|
RegSetValueExW(hConKey, wszWindowSize, 0, REG_DWORD, (LPBYTE)&val, sizeof(val));
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_RegSave
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void WINECON_RegSave(const struct config_data* cfg)
|
|
|
|
{
|
|
|
|
HKEY hConKey;
|
|
|
|
|
|
|
|
WINE_TRACE("saving registry settings.\n");
|
2010-04-28 01:07:32 +02:00
|
|
|
if (RegCreateKeyW(HKEY_CURRENT_USER, wszConsole, &hConKey))
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("Can't open registry for saving\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cfg->registry)
|
|
|
|
{
|
|
|
|
HKEY hAppKey;
|
|
|
|
|
2010-04-28 01:07:32 +02:00
|
|
|
if (RegCreateKeyW(hConKey, cfg->registry, &hAppKey))
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("Can't open registry for saving\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: maybe only save the values different from the default value ? */
|
|
|
|
WINECON_RegSaveHelper(hAppKey, cfg);
|
|
|
|
RegCloseKey(hAppKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else WINECON_RegSaveHelper(hConKey, cfg);
|
|
|
|
RegCloseKey(hConKey);
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
}
|