Quit client when existing config file cannot be loaded

When the configuration file exists but cannot be loaded, the client continues to launch. When closing, the client then saves the default config and overwrites the existing config that could not be loaded.

This is prevented by quitting the client with an error message popup when the config exists but cannot be loaded.

Closes #3843.
This commit is contained in:
Robert Müller 2023-05-09 23:18:52 +02:00
parent d9307ca756
commit cda3575d10
4 changed files with 19 additions and 10 deletions

View file

@ -4683,7 +4683,13 @@ int main(int argc, const char **argv)
// execute config file
if(pStorage->FileExists(CONFIG_FILE, IStorage::TYPE_ALL))
{
pConsole->ExecuteFile(CONFIG_FILE);
if(!pConsole->ExecuteFile(CONFIG_FILE))
{
const char *pError = "Failed to load config from '" CONFIG_FILE "'.";
dbg_msg("client", "%s", pError);
pClient->ShowMessageBox("Config File Error", pError);
return -1;
}
}
// execute autoexec file

View file

@ -109,7 +109,7 @@ public:
virtual void ExecuteLine(const char *pStr, int ClientID = -1, bool InterpretSemicolons = true) = 0;
virtual void ExecuteLineFlag(const char *pStr, int FlasgMask, int ClientID = -1, bool InterpretSemicolons = true) = 0;
virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientID = -1, bool InterpretSemicolons = true) = 0;
virtual void ExecuteFile(const char *pFilename, int ClientID = -1, bool LogFailure = false, int StorageType = IStorage::TYPE_ALL) = 0;
virtual bool ExecuteFile(const char *pFilename, int ClientID = -1, bool LogFailure = false, int StorageType = IStorage::TYPE_ALL) = 0;
virtual char *Format(char *pBuf, int Size, const char *pFrom, const char *pStr) = 0;
virtual void Print(int Level, const char *pFrom, const char *pStr, ColorRGBA PrintColor = gs_ConsoleDefaultColor) const = 0;

View file

@ -622,15 +622,15 @@ void CConsole::ExecuteLineFlag(const char *pStr, int FlagMask, int ClientID, boo
m_FlagMask = Temp;
}
void CConsole::ExecuteFile(const char *pFilename, int ClientID, bool LogFailure, int StorageType)
bool CConsole::ExecuteFile(const char *pFilename, int ClientID, bool LogFailure, int StorageType)
{
// make sure that this isn't being executed already
for(CExecFile *pCur = m_pFirstExec; pCur; pCur = pCur->m_pPrev)
if(str_comp(pFilename, pCur->m_pFilename) == 0)
return;
return false;
if(!m_pStorage)
return;
return false;
// push this one to the stack
CExecFile ThisFile;
@ -642,20 +642,22 @@ void CConsole::ExecuteFile(const char *pFilename, int ClientID, bool LogFailure,
// exec the file
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ | IOFLAG_SKIP_BOM, StorageType);
char aBuf[128];
bool Success = false;
char aBuf[32 + IO_MAX_PATH_LENGTH];
if(File)
{
char *pLine;
CLineReader Reader;
str_format(aBuf, sizeof(aBuf), "executing '%s'", pFilename);
Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
CLineReader Reader;
Reader.Init(File);
char *pLine;
while((pLine = Reader.Get()))
ExecuteLine(pLine, ClientID);
io_close(File);
Success = true;
}
else if(LogFailure)
{
@ -664,6 +666,7 @@ void CConsole::ExecuteFile(const char *pFilename, int ClientID, bool LogFailure,
}
m_pFirstExec = pPrev;
return Success;
}
void CConsole::Con_Echo(IResult *pResult, void *pUserData)

View file

@ -214,7 +214,7 @@ public:
bool LineIsValid(const char *pStr) override;
void ExecuteLine(const char *pStr, int ClientID = -1, bool InterpretSemicolons = true) override;
void ExecuteLineFlag(const char *pStr, int FlagMask, int ClientID = -1, bool InterpretSemicolons = true) override;
void ExecuteFile(const char *pFilename, int ClientID = -1, bool LogFailure = false, int StorageType = IStorage::TYPE_ALL) override;
bool ExecuteFile(const char *pFilename, int ClientID = -1, bool LogFailure = false, int StorageType = IStorage::TYPE_ALL) override;
char *Format(char *pBuf, int Size, const char *pFrom, const char *pStr) override;
void Print(int Level, const char *pFrom, const char *pStr, ColorRGBA PrintColor = gs_ConsoleDefaultColor) const override;