X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=259fb4dede6a1f3a41bf0fcf34e3cffffafa8d0d;hb=98c00f2bbb6bbb40e6ac5f989963638122acd17c;hp=cd9d3e93cf7e3a477db76ebb5a1684255fed46ee;hpb=b26f8fb0a937290a3e3f8241a5765556f437ab2a;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index cd9d3e93..259fb4de 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -606,6 +606,48 @@ char *getPath3(char *path1, char *path2, char *path3) return getStringCat3WithSeparator(path1, path2, path3, STRING_PATH_SEPARATOR); } +char *getImg2(char *path1, char *path2) +{ + char *filename = getPath2(path1, path2); + + if (!fileExists(filename) && strSuffix(path2, ".png")) + { + // backward compatibility: if PNG file not found, check for PCX file + char *path2pcx = getStringCopy(path2); + + strcpy(&path2pcx[strlen(path2pcx) - 3], "pcx"); + + free(filename); + + filename = getPath2(path1, path2pcx); + + free(path2pcx); + } + + return filename; +} + +char *getImg3(char *path1, char *path2, char *path3) +{ + char *filename = getPath3(path1, path2, path3); + + if (!fileExists(filename) && strSuffix(path3, ".png")) + { + // backward compatibility: if PNG file not found, check for PCX file + char *path3pcx = getStringCopy(path3); + + strcpy(&path3pcx[strlen(path3pcx) - 3], "pcx"); + + free(filename); + + filename = getPath3(path1, path2, path3pcx); + + free(path3pcx); + } + + return filename; +} + char *getStringCopy(const char *s) { char *s_copy; @@ -760,7 +802,6 @@ void GetOptions(char *argv[], options.network = FALSE; options.verbose = FALSE; options.debug = FALSE; - options.debug_x11_sync = FALSE; #if 1 options.verbose = TRUE; @@ -888,10 +929,6 @@ void GetOptions(char *argv[], { options.debug = TRUE; } - else if (strncmp(option, "-debug-x11-sync", option_len) == 0) - { - options.debug_x11_sync = TRUE; - } else if (strncmp(option, "-verbose", option_len) == 0) { options.verbose = TRUE; @@ -1010,6 +1047,9 @@ void Error(int mode, char *format, ...) if (mode & ERR_WARN) fprintf_nonewline(program.error_file, "warning: "); + if (mode & ERR_EXIT) + fprintf_nonewline(program.error_file, "fatal error: "); + va_start(ap, format); vfprintf_newline(program.error_file, format, ap); va_end(ap); @@ -2211,7 +2251,9 @@ boolean directoryExists(char *dir_name) if (dir_name == NULL) return FALSE; - boolean success = (access(dir_name, F_OK) == 0); + struct stat file_status; + boolean success = (stat(dir_name, &file_status) == 0 && + (file_status.st_mode & S_IFMT) == S_IFDIR); #if defined(PLATFORM_ANDROID) if (!success) @@ -2299,40 +2341,37 @@ boolean fileHasSuffix(char *basename, char *suffix) return FALSE; } -static boolean FileCouldBeArtwork(char *basename) +static boolean FileCouldBeArtwork(char *filename) { + char *basename = getBaseNamePtr(filename); + return (!strEqual(basename, ".") && !strEqual(basename, "..") && !fileHasSuffix(basename, "txt") && - !fileHasSuffix(basename, "conf")); + !fileHasSuffix(basename, "conf") && + !directoryExists(filename)); } boolean FileIsGraphic(char *filename) { - char *basename = getBaseNamePtr(filename); - - return FileCouldBeArtwork(basename); + return FileCouldBeArtwork(filename); } boolean FileIsSound(char *filename) { - char *basename = getBaseNamePtr(filename); - - return FileCouldBeArtwork(basename); + return FileCouldBeArtwork(filename); } boolean FileIsMusic(char *filename) { - char *basename = getBaseNamePtr(filename); - - return FileCouldBeArtwork(basename); + return FileCouldBeArtwork(filename); } -boolean FileIsArtworkType(char *basename, int type) +boolean FileIsArtworkType(char *filename, int type) { - if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(basename)) || - (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(basename)) || - (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(basename))) + if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(filename)) || + (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(filename)) || + (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(filename))) return TRUE; return FALSE;