2006-02-25 20:50:29 +00:00
|
|
|
/*
|
|
|
|
AppleWin : An Apple //e emulator for Windows
|
|
|
|
|
|
|
|
Copyright (C) 1994-1996, Michael O'Brien
|
|
|
|
Copyright (C) 1999-2001, Oliver Schmidt
|
|
|
|
Copyright (C) 2002-2005, Tom Charlesworth
|
2007-04-01 15:24:52 +00:00
|
|
|
Copyright (C) 2006-2007, Tom Charlesworth, Michael Pohoreski
|
2006-02-25 20:50:29 +00:00
|
|
|
|
|
|
|
AppleWin is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
AppleWin 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with AppleWin; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Description: Registry module
|
|
|
|
*
|
|
|
|
* Author: Various
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
2010-02-14 21:11:26 +00:00
|
|
|
|
2020-11-11 21:15:27 +00:00
|
|
|
#include "Registry.h"
|
2020-11-26 21:50:06 +00:00
|
|
|
#include "CmdLine.h"
|
2020-02-10 02:18:31 +00:00
|
|
|
|
|
|
|
namespace _ini {
|
|
|
|
//===========================================================================
|
2021-08-29 10:39:51 +00:00
|
|
|
BOOL RegLoadString(LPCTSTR section, LPCTSTR key, BOOL /*peruser*/, LPTSTR buffer, DWORD chars)
|
2020-02-10 02:18:31 +00:00
|
|
|
{
|
|
|
|
DWORD n = GetPrivateProfileString(section, key, NULL, buffer, chars, g_sConfigFile.c_str());
|
|
|
|
return n > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
2021-08-29 10:39:51 +00:00
|
|
|
void RegSaveString(LPCTSTR section, LPCTSTR key, BOOL /*peruser*/, const std::string& buffer)
|
2020-02-10 02:18:31 +00:00
|
|
|
{
|
|
|
|
BOOL updated = WritePrivateProfileString(section, key, buffer.c_str(), g_sConfigFile.c_str());
|
|
|
|
_ASSERT(updated || GetLastError() == 0);
|
|
|
|
}
|
2021-08-29 10:39:51 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
void RegDeleteString(LPCTSTR section, BOOL /*peruser*/)
|
|
|
|
{
|
|
|
|
BOOL updated = WritePrivateProfileString(section, NULL, NULL, g_sConfigFile.c_str());
|
|
|
|
_ASSERT(updated || GetLastError() == 0);
|
|
|
|
}
|
2020-02-10 02:18:31 +00:00
|
|
|
}
|
2006-02-25 20:50:29 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
2019-08-09 03:50:29 +00:00
|
|
|
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars)
|
|
|
|
{
|
2020-02-10 02:18:31 +00:00
|
|
|
if (!g_sConfigFile.empty())
|
|
|
|
return _ini::RegLoadString(section, key, peruser, buffer, chars);
|
|
|
|
|
2019-08-09 03:50:29 +00:00
|
|
|
TCHAR fullkeyname[256];
|
|
|
|
StringCbPrintf(fullkeyname, 256, TEXT("Software\\AppleWin\\CurrentVersion\\%s"), section);
|
|
|
|
|
|
|
|
BOOL success = FALSE;
|
|
|
|
HKEY keyhandle;
|
|
|
|
LSTATUS status = RegOpenKeyEx(
|
|
|
|
(peruser ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE),
|
|
|
|
fullkeyname,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&keyhandle);
|
2021-08-29 10:39:51 +00:00
|
|
|
if (status == ERROR_SUCCESS)
|
2019-08-09 03:50:29 +00:00
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
DWORD size = chars;
|
|
|
|
status = RegQueryValueEx(keyhandle, key, NULL, &type, (LPBYTE)buffer, &size);
|
|
|
|
if (status == 0 && size != 0)
|
|
|
|
success = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(keyhandle);
|
|
|
|
|
|
|
|
return success;
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
2019-08-09 03:50:29 +00:00
|
|
|
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars, LPCTSTR defaultValue)
|
|
|
|
{
|
|
|
|
BOOL success = RegLoadString(section, key, peruser, buffer, chars);
|
|
|
|
if (!success)
|
|
|
|
StringCbCopy(buffer, chars, defaultValue);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD* value) {
|
|
|
|
TCHAR buffer[32];
|
|
|
|
if (!RegLoadString(section, key, peruser, buffer, 32))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = (DWORD)_ttoi(buffer);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD* value, DWORD defaultValue) {
|
|
|
|
BOOL success = RegLoadValue(section, key, peruser, value);
|
|
|
|
if (!success)
|
|
|
|
*value = defaultValue;
|
|
|
|
return success;
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
2019-09-07 18:37:19 +00:00
|
|
|
void RegSaveString (LPCTSTR section, LPCTSTR key, BOOL peruser, const std::string & buffer) {
|
2020-02-10 02:18:31 +00:00
|
|
|
if (!g_sConfigFile.empty())
|
|
|
|
return _ini::RegSaveString(section, key, peruser, buffer);
|
|
|
|
|
2019-08-09 03:50:29 +00:00
|
|
|
TCHAR fullkeyname[256];
|
|
|
|
StringCbPrintf(fullkeyname, 256, TEXT("Software\\AppleWin\\CurrentVersion\\%s"), section);
|
|
|
|
|
|
|
|
HKEY keyhandle;
|
|
|
|
DWORD disposition;
|
|
|
|
LSTATUS status = RegCreateKeyEx(
|
|
|
|
(peruser ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE),
|
|
|
|
fullkeyname,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_READ | KEY_WRITE,
|
|
|
|
(LPSECURITY_ATTRIBUTES)NULL,
|
|
|
|
&keyhandle,
|
|
|
|
&disposition);
|
2021-08-29 10:39:51 +00:00
|
|
|
if (status == ERROR_SUCCESS)
|
2019-08-09 03:50:29 +00:00
|
|
|
{
|
|
|
|
RegSetValueEx(
|
|
|
|
keyhandle,
|
|
|
|
key,
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
2019-09-07 18:37:19 +00:00
|
|
|
(CONST LPBYTE)buffer.c_str(),
|
|
|
|
(buffer.size() + 1) * sizeof(TCHAR));
|
2019-08-09 03:50:29 +00:00
|
|
|
RegCloseKey(keyhandle);
|
|
|
|
}
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value) {
|
2019-08-09 03:50:29 +00:00
|
|
|
TCHAR buffer[32] = TEXT("");
|
|
|
|
StringCbPrintf(buffer, 32, "%d", value);
|
|
|
|
RegSaveString(section, key, peruser, buffer);
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
2020-02-10 02:18:31 +00:00
|
|
|
|
2021-08-29 10:39:51 +00:00
|
|
|
//===========================================================================
|
|
|
|
static std::string& RegGetSlotSection(UINT slot)
|
|
|
|
{
|
|
|
|
static std::string section;
|
2021-09-17 19:43:10 +00:00
|
|
|
if (slot == SLOT_AUX)
|
|
|
|
{
|
|
|
|
section = REG_CONFIG_SLOT_AUX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
section = REG_CONFIG_SLOT;
|
|
|
|
section += (char)('0' + slot);
|
|
|
|
}
|
2021-08-29 10:39:51 +00:00
|
|
|
return section;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string& RegGetConfigSlotSection(UINT slot)
|
|
|
|
{
|
|
|
|
static std::string section;
|
|
|
|
section = REG_CONFIG "\\";
|
|
|
|
section += RegGetSlotSection(slot);
|
|
|
|
return section;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegDeleteConfigSlotSection(UINT slot)
|
|
|
|
{
|
|
|
|
BOOL peruser = TRUE;
|
|
|
|
|
|
|
|
if (!g_sConfigFile.empty())
|
|
|
|
{
|
2021-09-17 19:43:10 +00:00
|
|
|
std::string& section = RegGetConfigSlotSection(slot);
|
2021-08-29 10:39:51 +00:00
|
|
|
return _ini::RegDeleteString(section.c_str(), peruser);
|
|
|
|
}
|
|
|
|
|
|
|
|
TCHAR fullkeyname[256];
|
|
|
|
StringCbPrintf(fullkeyname, 256, TEXT("Software\\AppleWin\\CurrentVersion\\%s"), REG_CONFIG);
|
|
|
|
|
|
|
|
HKEY keyhandle;
|
|
|
|
LSTATUS status = RegOpenKeyEx(
|
|
|
|
(peruser ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE),
|
|
|
|
fullkeyname,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&keyhandle);
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
{
|
2021-09-17 19:43:10 +00:00
|
|
|
std::string& section = RegGetSlotSection(slot);
|
|
|
|
LSTATUS status2 = RegDeleteKey(keyhandle, section.c_str());
|
2021-09-10 12:57:55 +00:00
|
|
|
if (status2 != ERROR_SUCCESS && status2 != ERROR_FILE_NOT_FOUND)
|
2021-08-29 10:39:51 +00:00
|
|
|
_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(keyhandle);
|
|
|
|
}
|
2021-09-17 19:43:10 +00:00
|
|
|
|
|
|
|
void RegSetConfigSlotNewCardType(UINT slot, SS_CARDTYPE type)
|
|
|
|
{
|
|
|
|
RegDeleteConfigSlotSection(slot);
|
|
|
|
|
|
|
|
std::string regSection;
|
|
|
|
regSection = RegGetConfigSlotSection(slot);
|
|
|
|
|
|
|
|
RegSaveValue(regSection.c_str(), REGVALUE_CARD_TYPE, TRUE, type);
|
|
|
|
}
|