Procházet zdrojové kódy

Fixes #179
* Resolves NPC files not being loaded if the one before failed to load on Windows OS.
Thanks to @Lemongrass3110!

aleos89 před 9 roky
rodič
revize
a6811c7c18
1 změnil soubory, kde provedl 39 přidání a 19 odebrání
  1. 39 19
      src/common/utils.c

+ 39 - 19
src/common/utils.c

@@ -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;
-
-    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;
-    }
+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;
+	}
+
+	return 0;
 }
 
 static char* checkpath(char *path, const char*srcpath)