- Validate File Path and add '/' when saving JSON file
This commit is contained in:
Charl Wentzel
2017-06-22 17:21:28 +02:00
parent 9677052042
commit 706cd9caf6

View File

@@ -65,12 +65,25 @@ bool CJSONparse::WriteToScreen( const char * BasePath, const int Indent )
bool CJSONparse::WriteToFile( const char * BasePath, const char * Path, const char * FileName, const int Indent ) bool CJSONparse::WriteToFile( const char * BasePath, const char * Path, const char * FileName, const int Indent )
{ {
char FilePath[250] = ""; char FilePath[250] = "";
int PathLen = 0;
// Validate
if (!FileName) {
Error = true;
sprintf( ErrorText, "No File name specified" );
return false;
}
// Build file name // Build file name
if (Path) if (Path && *Path) {
strcpy( FilePath, Path ); strcpy( FilePath, Path );
strcat( FilePath, FileName ); PathLen = strlen( FilePath );
if (FilePath[PathLen] != '/') {
FilePath[PathLen++] = '/';
}
}
strcpy( &FilePath[PathLen], FileName );
// Read file // Read file
return WriteToFile( BasePath, FilePath, Indent ); return WriteToFile( BasePath, FilePath, Indent );