Fixes for image loading switches (-d1,-d2,-h1,-h2,-s5d1,-s5d2):
. support relative paths (#663) . updated the current directory with the path for each loaded image (#663) & saving state (#691) . added a new switch -current-dir <path>
This commit is contained in:
parent
f238be27e8
commit
41203f5d2d
|
@ -82,6 +82,7 @@ AppMode_e g_nAppMode = MODE_LOGO;
|
|||
static bool g_bLoadedSaveState = false;
|
||||
static bool g_bSysClkOK = false;
|
||||
|
||||
std::string g_sStartDir; // NB. AppleWin.exe maybe relative to this! (GH#663)
|
||||
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
|
||||
|
@ -541,7 +542,8 @@ void EnterMessageLoop(void)
|
|||
}
|
||||
|
||||
//===========================================================================
|
||||
void GetProgramDirectory(void)
|
||||
|
||||
static void GetProgramDirectory(void)
|
||||
{
|
||||
TCHAR programDir[MAX_PATH];
|
||||
GetModuleFileName((HINSTANCE)0, programDir, MAX_PATH);
|
||||
|
@ -1141,19 +1143,27 @@ static std::string GetFullPath(LPCSTR szFileName)
|
|||
}
|
||||
else
|
||||
{
|
||||
// Rel pathname
|
||||
char szCWD[_MAX_PATH] = {0};
|
||||
if (!GetCurrentDirectory(sizeof(szCWD), szCWD))
|
||||
return "";
|
||||
|
||||
strPathName = szCWD;
|
||||
strPathName.append("\\");
|
||||
// Rel pathname (GH#663)
|
||||
strPathName = g_sStartDir;
|
||||
strPathName.append(szFileName);
|
||||
}
|
||||
|
||||
return strPathName;
|
||||
}
|
||||
|
||||
static void SetCurrentDir(std::string pathname)
|
||||
{
|
||||
// Due to the order HDDs/disks are inserted, then s7 insertions take priority over s6 & s5; and d2 takes priority over d1:
|
||||
// . if -s6[dN] and -hN are specified, then g_sCurrentDir will be set to the HDD image's path
|
||||
// . if -s5[dN] and -s6[dN] are specified, then g_sCurrentDir will be set to the s6 image's path
|
||||
// . if -[sN]d1 and -[sN]d2 are specified, then g_sCurrentDir will be set to the d2 image's path
|
||||
// This is purely dependent on the current order of InsertFloppyDisks() & InsertHardDisks() - ie. very brittle!
|
||||
// . better to use -current-dir to be explicit
|
||||
std::size_t found = pathname.find_last_of("\\");
|
||||
std::string path = pathname.substr(0, found);
|
||||
SetCurrentImageDir(path);
|
||||
}
|
||||
|
||||
static bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName)
|
||||
{
|
||||
Disk2InterfaceCard& disk2Card = dynamic_cast<Disk2InterfaceCard&>(g_CardMgr.GetRef(slot));
|
||||
|
@ -1162,7 +1172,10 @@ static bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName)
|
|||
if (strPathName.empty()) return false;
|
||||
|
||||
ImageError_e Error = disk2Card.InsertDisk(nDrive, strPathName.c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE);
|
||||
return Error == eIMAGE_ERROR_NONE;
|
||||
bool res = (Error == eIMAGE_ERROR_NONE);
|
||||
if (res)
|
||||
SetCurrentDir(strPathName);
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool DoHardDiskInsert(const int nDrive, LPCSTR szFileName)
|
||||
|
@ -1171,7 +1184,10 @@ static bool DoHardDiskInsert(const int nDrive, LPCSTR szFileName)
|
|||
if (strPathName.empty()) return false;
|
||||
|
||||
BOOL bRes = HD_Insert(nDrive, strPathName.c_str());
|
||||
return bRes ? true : false;
|
||||
bool res = (bRes == TRUE);
|
||||
if (res)
|
||||
SetCurrentDir(strPathName);
|
||||
return res;
|
||||
}
|
||||
|
||||
static void InsertFloppyDisks(const UINT slot, LPSTR szImageName_drive[NUM_DRIVES], bool& bBoot)
|
||||
|
@ -1349,15 +1365,22 @@ struct CmdLine
|
|||
VideoRefreshRate_e newVideoRefreshRate;
|
||||
double clockMultiplier;
|
||||
eApple2Type model;
|
||||
std::string strCurrentDir;
|
||||
};
|
||||
|
||||
static CmdLine g_cmdLine;
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
|
||||
{
|
||||
char startDir[_MAX_PATH];
|
||||
GetCurrentDirectory(sizeof(startDir), startDir);
|
||||
g_sStartDir = startDir;
|
||||
if (*(g_sStartDir.end()-1) != '\\') g_sStartDir += '\\';
|
||||
|
||||
if (!ProcessCmdLine(lpCmdLine))
|
||||
return 0;
|
||||
|
||||
LogFileOutput("g_sStartDir = %s\n", g_sStartDir.c_str());
|
||||
GetAppleWinVersion();
|
||||
OneTimeInitialization(passinstance);
|
||||
|
||||
|
@ -1773,6 +1796,12 @@ static bool ProcessCmdLine(LPSTR lpCmdLine)
|
|||
{
|
||||
g_cmdLine.bBoot = true;
|
||||
}
|
||||
else if (strcmp(lpCmdLine, "-current-dir") == 0)
|
||||
{
|
||||
lpCmdLine = GetCurrArg(lpNextArg);
|
||||
lpNextArg = GetNextArg(lpNextArg);
|
||||
g_cmdLine.strCurrentDir = lpCmdLine;
|
||||
}
|
||||
else // unsupported
|
||||
{
|
||||
LogFileOutput("Unsupported arg: %s\n", lpCmdLine);
|
||||
|
@ -2003,6 +2032,10 @@ static void RepeatInitialization(void)
|
|||
HD_SetEnabled(false); // Disable HDD controller, but don't persist this to Registry/conf.ini (consistent with other '-sn empty' cmds)
|
||||
}
|
||||
|
||||
// Set *after* InsertFloppyDisks() & InsertHardDisks(), which both update g_sCurrentDir
|
||||
if (!g_cmdLine.strCurrentDir.empty())
|
||||
SetCurrentImageDir(g_cmdLine.strCurrentDir);
|
||||
|
||||
MemInitialize();
|
||||
LogFileOutput("Main: MemInitialize()\n");
|
||||
|
||||
|
|
Loading…
Reference in New Issue