Skip to content

Commit

Permalink
Merge branch 'feature/no-registry' of ssh://github.com/taeber/AppleWi…
Browse files Browse the repository at this point in the history
…n into taeber-feature/no-registry
  • Loading branch information
tomcw committed Apr 3, 2020
2 parents 1739a84 + c7d2fef commit 2fa22d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
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 @@ -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);
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);
}

0 comments on commit 2fa22d2

Please sign in to comment.