* Resolves NPC files not being loaded if the one before failed to load on Windows OS.
Thanks to @Lemongrass3110!
This commit is contained in:
aleos89 2016-02-06 09:36:36 -05:00
parent 8e283d2a00
commit a6811c7c18

View File

@ -142,13 +142,28 @@ void findfile(const char *p, const char *pat, void (func)(const char*))
return;
}
int check_filepath(const char* filepath){
/**
* Check if the path is a directory or file
* @param filepath: Location of file
* @return 0 = Error
* 1 = Directory
* 2 = File
* 3 = File but doesn't exist
*/
int check_filepath(const char* filepath)
{
DWORD Attribute;
if( Attribute = GetFileAttributes(filepath) ){
if( (Attribute & INVALID_FILE_ATTRIBUTES) && GetLastError() == ERROR_FILE_NOT_FOUND ) return 3;
else if( Attribute & FILE_ATTRIBUTE_DIRECTORY ) return 1;
else return 2;
if (Attribute = GetFileAttributes(filepath)) {
if ((Attribute&INVALID_FILE_ATTRIBUTES) && GetLastError() == ERROR_FILE_NOT_FOUND) {
SetLastError(0);
return 3;
} else if (Attribute&FILE_ATTRIBUTE_DIRECTORY)
return 1;
else
return 2;
}
return 0;
}
@ -156,23 +171,28 @@ int check_filepath(const char* filepath){
#define MAX_DIR_PATH 2048
/**
* Check if the path is a directory or file
* @param filepath
* @return 1=dir, 2=file, 3=else, 0=error
* @param filepath: Location of file
* @return 0 = Error
* 1 = Directory
* 2 = File
* 3 = Neither a file or directory
*/
int check_filepath(const char* filepath){
struct stat s;
int check_filepath(const char* filepath)
{
struct stat s;
if( stat(filepath,&s) == 0 ){
if( s.st_mode & S_IFDIR ) return 1;
else if( s.st_mode & S_IFREG )return 2;
else return 3;
}
else {
return 0;
}
if (stat(filepath, &s) == 0) {
if (s.st_mode&S_IFDIR)
return 1;
else if (s.st_mode&S_IFREG)
return 2;
else
return 3;
}
return 0;
}
static char* checkpath(char *path, const char*srcpath)