Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of an INI-file instead of the Registry #757

Merged
merged 1 commit into from Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions help/CommandLine.html
Expand Up @@ -11,6 +11,8 @@ <h2 style="COLOR: rgb(0,128,0)">Command line</h2>
<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>
Expand Down
13 changes: 13 additions & 0 deletions source/Applewin.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -1386,6 +1388,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);
Expand Down
24 changes: 24 additions & 0 deletions source/Registry.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -122,3 +145,4 @@ void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value) {
StringCbPrintf(buffer, 32, "%d", value);
RegSaveString(section, key, peruser, buffer);
}