From: Holger Schemel Date: Tue, 18 Jun 2024 20:02:41 +0000 (+0200) Subject: moved code to check for file in level directories to separate function X-Git-Tag: 4.4.0.0-test-2~2 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=681df696173f472fe28e49b9e8e01b34dc34629b;p=rocksndiamonds.git moved code to check for file in level directories to separate function --- diff --git a/src/files.c b/src/files.c index 1fe2d954..5c4209d7 100644 --- a/src/files.c +++ b/src/files.c @@ -2929,26 +2929,7 @@ char *getLocalLevelTemplateFilename(void) char *getGlobalLevelTemplateFilename(void) { - // global variable "leveldir_current" must be modified in the loop below - LevelDirTree *leveldir_current_last = leveldir_current; - char *filename = NULL; - - // check for template level in path from current to topmost tree node - - while (leveldir_current != NULL) - { - filename = getDefaultLevelFilename(-1); - - if (fileExists(filename)) - break; - - leveldir_current = leveldir_current->node_parent; - } - - // restore global variable "leveldir_current" modified in above loop - leveldir_current = leveldir_current_last; - - return filename; + return getFilenameFromCurrentLevelDirUpward(LEVELTEMPLATE_FILENAME); } static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 4104a042..53659bdd 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -797,6 +797,32 @@ char *getEditorSetupFilename(void) return filename; } +char *getFilenameFromCurrentLevelDirUpward(char *basename) +{ + // global variable "leveldir_current" must be modified in the loop below + LevelDirTree *leveldir_current_last = leveldir_current; + static char *filename = NULL; + + // check for filename in path from current to topmost tree node + + while (leveldir_current != NULL) + { + checked_free(filename); + + filename = getPath2(getCurrentLevelDir(), basename); + + if (fileExists(filename)) + break; + + leveldir_current = leveldir_current->node_parent; + } + + // restore global variable "leveldir_current" modified in above loop + leveldir_current = leveldir_current_last; + + return filename; +} + char *getHelpAnimFilename(void) { static char *filename = NULL; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index c7a53302..5692c9da 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -279,6 +279,7 @@ char *getSetupFilename(void); char *getDefaultSetupFilename(void); char *getPlatformSetupFilename(void); char *getEditorSetupFilename(void); +char *getFilenameFromCurrentLevelDirUpward(char *); char *getHelpAnimFilename(void); char *getHelpTextFilename(void); char *getLevelSetInfoFilename(int);