From: Holger Schemel Date: Tue, 2 Feb 2016 19:58:26 +0000 (+0100) Subject: fixed backwards compatibility code regarding PCX/PNG file change X-Git-Tag: 4.0.0.0-rc1~92 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=98fa490c2f4f5abcb9cb9571048adc0d5362b195;p=rocksndiamonds.git fixed backwards compatibility code regarding PCX/PNG file change --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index dbc0b307..59c7d1a2 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -776,46 +776,27 @@ char *getPath3(char *path1, char *path2, char *path3) return getStringCat3WithSeparator(path1, path2, path3, STRING_PATH_SEPARATOR); } -char *getImg2(char *path1, char *path2) +static char *getPngOrPcxIfNotExists(char *filename) { - 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); + // switch from PNG to PCX file and vice versa, if file does not exist + // (backwards compatibility with PCX files used in previous versions) - filename = getPath2(path1, path2pcx); - - free(path2pcx); - } + if (!fileExists(filename) && strSuffix(filename, ".png")) + strcpy(&filename[strlen(filename) - 3], "pcx"); + else if (!fileExists(filename) && strSuffix(filename, ".pcx")) + strcpy(&filename[strlen(filename) - 3], "png"); return filename; } -char *getImg3(char *path1, char *path2, char *path3) +char *getImg2(char *path1, char *path2) { - 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 getPngOrPcxIfNotExists(getPath2(path1, path2)); +} - return filename; +char *getImg3(char *path1, char *path2, char *path3) +{ + return getPngOrPcxIfNotExists(getPath3(path1, path2, path3)); } char *getStringCopy(const char *s)