mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
CCommandLine improvements
* Make accessor inline. * Add method 'AppendParametersFromFile' (will be used in a future init refactor).
This commit is contained in:
parent
bb28e160cf
commit
e9518d8ff1
@ -3,16 +3,60 @@
|
|||||||
// Purpose: Command line utilities
|
// Purpose: Command line utilities
|
||||||
//
|
//
|
||||||
//=============================================================================//
|
//=============================================================================//
|
||||||
|
|
||||||
#include "tier0/commandline.h"
|
#include "tier0/commandline.h"
|
||||||
#include "tier1/cvar.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Instance singleton and expose interface to rest of code
|
// Purpose: parses a text file and appends its parameters/values
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
CCommandLine* CommandLine(void)
|
void CCommandLine::AppendParametersFromFile(const char* const pszConfig)
|
||||||
{
|
{
|
||||||
return g_pCmdLine;
|
FILE* const pFile = fopen(pszConfig, "r");
|
||||||
|
if (!pFile)
|
||||||
|
{
|
||||||
|
printf("%s: '%s' does not exist!\n",
|
||||||
|
__FUNCTION__, pszConfig);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char szTextBuf[2048];
|
||||||
|
|
||||||
|
while (fgets(szTextBuf, sizeof(szTextBuf), pFile))
|
||||||
|
{
|
||||||
|
// Trim newlines...
|
||||||
|
size_t nLen = strlen(szTextBuf);
|
||||||
|
if (nLen > 0 && szTextBuf[nLen - 1] == '\n')
|
||||||
|
{
|
||||||
|
szTextBuf[--nLen] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
char* const pSpacePos = strchr(szTextBuf, ' ');
|
||||||
|
const char* pArgValue = "";
|
||||||
|
|
||||||
|
if (pSpacePos)
|
||||||
|
{
|
||||||
|
// Skip space and move to value.
|
||||||
|
*pSpacePos = '\0';
|
||||||
|
char* pArg = pSpacePos + 1;
|
||||||
|
|
||||||
|
// Trim the quotes around the value.
|
||||||
|
if (*pArg == '\"')
|
||||||
|
{
|
||||||
|
pArg++;
|
||||||
|
char* const pEndQuote = strchr(pArg, '\"');
|
||||||
|
|
||||||
|
if (pEndQuote)
|
||||||
|
{
|
||||||
|
*pEndQuote = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pArgValue = pArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandLine()->AppendParm(szTextBuf, pArgValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
class CCommandLine : public ICommandLine // VTABLE @0x141369C78 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
|
class CCommandLine : public ICommandLine // VTABLE @0x141369C78 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
void AppendParametersFromFile(const char* const pszConfig);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -17,7 +20,13 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern CCommandLine* g_pCmdLine;
|
extern CCommandLine* g_pCmdLine;
|
||||||
CCommandLine* CommandLine(void);
|
//-----------------------------------------------------------------------------
|
||||||
|
// Instance singleton and expose interface to rest of code
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
inline CCommandLine* CommandLine(void)
|
||||||
|
{
|
||||||
|
return g_pCmdLine;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
class VCommandLine : public IDetour
|
class VCommandLine : public IDetour
|
||||||
|
Loading…
x
Reference in New Issue
Block a user