|
|
@ -2244,6 +2244,64 @@ bool IsPathFile(const char *path) |
|
|
|
return S_ISREG(result.st_mode); |
|
|
|
} |
|
|
|
|
|
|
|
// Check if fileName is valid for the platform/OS |
|
|
|
bool IsFileNameValid(const char *fileName) |
|
|
|
{ |
|
|
|
bool valid = true; |
|
|
|
|
|
|
|
if ((fileName != NULL) && (fileName[0] != '\0')) |
|
|
|
{ |
|
|
|
int length = strlen(fileName); |
|
|
|
bool allPeriods = true; |
|
|
|
|
|
|
|
for (int i = 0; i < length; i++) |
|
|
|
{ |
|
|
|
// Check invalid characters |
|
|
|
if ((fileName[i] == '<') || |
|
|
|
(fileName[i] == '>') || |
|
|
|
(fileName[i] == ':') || |
|
|
|
(fileName[i] == '\"') || |
|
|
|
(fileName[i] == '/') || |
|
|
|
(fileName[i] == '\\') || |
|
|
|
(fileName[i] == '|') || |
|
|
|
(fileName[i] == '?') || |
|
|
|
(fileName[i] == '*')) { valid = false; break; } |
|
|
|
|
|
|
|
// Check non-glyph characters |
|
|
|
if ((unsigned char)fileName[i] < 32) { valid = false; break; } |
|
|
|
|
|
|
|
// TODO: Check trailing periods/spaces? |
|
|
|
|
|
|
|
// Check if filename is not all periods |
|
|
|
if (fileName[i] != '.') allPeriods = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (allPeriods) valid = false; |
|
|
|
|
|
|
|
/* |
|
|
|
if (valid) |
|
|
|
{ |
|
|
|
// Check invalid DOS names |
|
|
|
if (length >= 3) |
|
|
|
{ |
|
|
|
if (((fileName[0] == 'C') && (fileName[1] == 'O') && (fileName[2] == 'N')) || // CON |
|
|
|
((fileName[0] == 'P') && (fileName[1] == 'R') && (fileName[2] == 'N')) || // PRN |
|
|
|
((fileName[0] == 'A') && (fileName[1] == 'U') && (fileName[2] == 'X')) || // AUX |
|
|
|
((fileName[0] == 'N') && (fileName[1] == 'U') && (fileName[2] == 'L'))) valid = false; // NUL |
|
|
|
} |
|
|
|
|
|
|
|
if (length >= 4) |
|
|
|
{ |
|
|
|
if (((fileName[0] == 'C') && (fileName[1] == 'O') && (fileName[2] == 'M') && ((fileName[3] >= '0') && (fileName[3] <= '9'))) || // COM0-9 |
|
|
|
((fileName[0] == 'L') && (fileName[1] == 'P') && (fileName[2] == 'T') && ((fileName[3] >= '0') && (fileName[3] <= '9')))) valid = false; // LPT0-9 |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
} |
|
|
|
|
|
|
|
return valid; |
|
|
|
} |
|
|
|
|
|
|
|
// Check if a file has been dropped into window |
|
|
|
bool IsFileDropped(void) |
|
|
|
{ |
|
|
|