Move filename clearing function to base lib

This commit is contained in:
Redix 2017-09-28 15:59:30 +02:00
parent 5721612761
commit a3a82b6571
4 changed files with 26 additions and 20 deletions

View file

@ -2011,6 +2011,17 @@ void str_sanitize(char *str_in)
}
}
void str_sanitize_filename(char *str_in)
{
unsigned char *str = (unsigned char *)str_in;
while(*str)
{
if(*str < 32 || *str == '\\' || *str == '/' || *str == '|' || *str == ':' || *str == '*' || *str == '?' || *str == '<' || *str == '>' || *str == '"')
*str = ' ';
str++;
}
}
char *str_skip_to_whitespace(char *str)
{
while(*str && (*str != ' ' && *str != '\t' && *str != '\n'))

View file

@ -847,6 +847,18 @@ void str_sanitize_cc(char *str);
*/
void str_sanitize(char *str);
/*
Function: str_sanitize_filename
Replaces all invalid filename characters with whitespace.
Parameters:
str - String to sanitize.
Remarks:
- The strings are treated as zero-termineted strings.
*/
void str_sanitize_filename(char *str);
/*
Function: str_skip_to_whitespace
Skips leading non-whitespace characters(all but ' ', '\t', '\n', '\r').

View file

@ -3596,22 +3596,12 @@ const char *CClient::GetCurrentMapPath()
return m_aCurrentMapPath;
}
void ClearFilename(char *pStr)
{
while(*pStr)
{
if(*pStr == '\\' || *pStr == '/' || *pStr == '|' || *pStr == ':' || *pStr == '*' || *pStr == '?' || *pStr == '<' || *pStr == '>' || *pStr == '"')
*pStr = '%';
pStr++;
}
}
void CClient::RaceRecord_GetName(char *pBuf, int Size, int Time)
{
// check the player name
char aPlayerName[MAX_NAME_LENGTH];
str_copy(aPlayerName, g_Config.m_PlayerName, sizeof(aPlayerName));
ClearFilename(aPlayerName);
str_sanitize_filename(aPlayerName);
if(Time < 0)
str_format(pBuf, Size, "%s_tmp_%d", m_aCurrentMap, pid());
@ -3653,7 +3643,7 @@ void CClient::Ghost_GetPath(char *pBuf, int Size, const char *pPlayerName, int T
// check the player name
char aPlayerName[MAX_NAME_LENGTH];
str_copy(aPlayerName, pPlayerName, sizeof(aPlayerName));
ClearFilename(aPlayerName);
str_sanitize_filename(aPlayerName);
if(Time < 0)
str_format(pBuf, Size, "ghosts/%s_%s_%08x_tmp_%d.gho", m_aCurrentMap, aPlayerName, m_pMap->Crc(), pid());

View file

@ -176,14 +176,7 @@ bool CRaceDemo::CheckDemo(int Time) const
{
char aPlayerName[MAX_NAME_LENGTH];
str_copy(aPlayerName, g_Config.m_PlayerName, sizeof(aPlayerName));
char *pStr = aPlayerName;
while(*pStr)
{
if(*pStr == '\\' || *pStr == '/' || *pStr == '|' || *pStr == ':' || *pStr == '*' || *pStr == '?' || *pStr == '<' || *pStr == '>' || *pStr == '"')
*pStr = '%';
pStr++;
}
str_sanitize_filename(aPlayerName);
if(!str_find(pDemoName, aPlayerName))
continue;