Allow use of an INI-file instead of the Registry for configuration (PR #757)

This commit is contained in:
tomcw 2020-04-03 21:41:43 +01:00
commit 1cd466bed3
3 changed files with 39 additions and 0 deletions

View File

@ -11,6 +11,8 @@
<p style="FONT-WEIGHT: bold">AppleWin can be driven from the command line as
follows:
</p>
-conf &lt;pathname&gt;<br>
Use an INI file for configuration instead of the Registry.<br>
-d1 &lt;pathname&gt;<br>
Start with a floppy disk in slot 6 drive-1 (and auto power-on the Apple II).<br>
NB. -s6d1 has the meaning same as -d1.<br><br>

View File

@ -85,6 +85,8 @@ static bool g_bSysClkOK = false;
std::string g_sProgramDir; // Directory of where AppleWin executable resides
std::string g_sDebugDir; // TODO: Not currently used
std::string g_sScreenShotDir; // TODO: Not currently used
std::string g_sConfigFile; // INI file to use instead of Registry
bool g_bCapturePrintScreenKey = true;
static bool g_bHookSystemKey = true;
static bool g_bHookAltTab = false;
@ -1388,6 +1390,17 @@ static bool ProcessCmdLine(LPSTR lpCmdLine)
{
g_bRegisterFileTypes = false;
}
else if (strcmp(lpCmdLine, "-conf") == 0)
{
lpCmdLine = GetCurrArg(lpNextArg);
lpNextArg = GetNextArg(lpNextArg);
char buf[MAX_PATH];
DWORD res = GetFullPathName(lpCmdLine, MAX_PATH, buf, NULL);
if (res == 0)
LogFileOutput("Failed to open configuration file: %s\n", lpCmdLine);
else
g_sConfigFile = buf;
}
else if (strcmp(lpCmdLine, "-d1") == 0)
{
lpCmdLine = GetCurrArg(lpNextArg);

View File

@ -28,10 +28,30 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "StdAfx.h"
extern std::string g_sConfigFile;
namespace _ini {
//===========================================================================
BOOL RegLoadString(LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars)
{
DWORD n = GetPrivateProfileString(section, key, NULL, buffer, chars, g_sConfigFile.c_str());
return n > 0;
}
//===========================================================================
void RegSaveString(LPCTSTR section, LPCTSTR key, BOOL peruser, const std::string& buffer)
{
BOOL updated = WritePrivateProfileString(section, key, buffer.c_str(), g_sConfigFile.c_str());
_ASSERT(updated || GetLastError() == 0);
}
}
//===========================================================================
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars)
{
if (!g_sConfigFile.empty())
return _ini::RegLoadString(section, key, peruser, buffer, chars);
TCHAR fullkeyname[256];
StringCbPrintf(fullkeyname, 256, TEXT("Software\\AppleWin\\CurrentVersion\\%s"), section);
@ -88,6 +108,9 @@ BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD* value, DWO
//===========================================================================
void RegSaveString (LPCTSTR section, LPCTSTR key, BOOL peruser, const std::string & buffer) {
if (!g_sConfigFile.empty())
return _ini::RegSaveString(section, key, peruser, buffer);
TCHAR fullkeyname[256];
StringCbPrintf(fullkeyname, 256, TEXT("Software\\AppleWin\\CurrentVersion\\%s"), section);
@ -122,3 +145,4 @@ void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value) {
StringCbPrintf(buffer, 32, "%d", value);
RegSaveString(section, key, peruser, buffer);
}