From: Holger Schemel Date: Sat, 24 Apr 2021 23:50:32 +0000 (+0200) Subject: added functions to handle score cache files and directories X-Git-Tag: 4.3.0.0~177 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=1132b3459c27c42c2796afe58f59dcf5930df394;p=rocksndiamonds.git added functions to handle score cache files and directories --- diff --git a/src/libgame/setup.c b/src/libgame/setup.c index dbfec24d..1d3be4fa 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -88,6 +88,16 @@ static char *getLevelClassDescription(TreeInfo *ti) return "Unknown Level Class"; } +static char *getCacheDir(void) +{ + static char *cache_dir = NULL; + + if (cache_dir == NULL) + cache_dir = getPath2(getMainUserGameDataDir(), CACHE_DIRECTORY); + + return cache_dir; +} + static char *getScoreDir(char *level_subdir) { static char *score_dir = NULL; @@ -114,6 +124,27 @@ static char *getScoreDir(char *level_subdir) return score_dir; } +static char *getScoreCacheDir(char *level_subdir) +{ + static char *score_dir = NULL; + static char *score_level_dir = NULL; + char *score_subdir = SCORES_DIRECTORY; + + if (score_dir == NULL) + score_dir = getPath2(getCacheDir(), score_subdir); + + if (level_subdir != NULL) + { + checked_free(score_level_dir); + + score_level_dir = getPath2(score_dir, level_subdir); + + return score_level_dir; + } + + return score_dir; +} + static char *getScoreTapeDir(char *level_subdir, int nr) { static char *score_tape_dir = NULL; @@ -169,16 +200,6 @@ static char *getLevelSetupDir(char *level_subdir) return levelsetup_dir; } -static char *getCacheDir(void) -{ - static char *cache_dir = NULL; - - if (cache_dir == NULL) - cache_dir = getPath2(getMainUserGameDataDir(), CACHE_DIRECTORY); - - return cache_dir; -} - static char *getNetworkDir(void) { static char *network_dir = NULL; @@ -607,6 +628,21 @@ char *getScoreFilename(int nr) return filename; } +char *getScoreCacheFilename(int nr) +{ + static char *filename = NULL; + char basename[MAX_FILENAME_LEN]; + + checked_free(filename); + + sprintf(basename, "%03d.%s", nr, SCOREFILE_EXTENSION); + + // used instead of "leveldir_current->subdir" (for network games) + filename = getPath2(getScoreCacheDir(levelset.identifier), basename); + + return filename; +} + char *getScoreTapeBasename(char *name) { static char basename[MAX_FILENAME_LEN]; @@ -1116,6 +1152,14 @@ void InitScoreDirectory(char *level_subdir) createDirectory(getScoreDir(level_subdir), "level score", permissions); } +void InitScoreCacheDirectory(char *level_subdir) +{ + createDirectory(getMainUserGameDataDir(), "main user data", PERMS_PRIVATE); + createDirectory(getCacheDir(), "cache data", PERMS_PRIVATE); + createDirectory(getScoreCacheDir(NULL), "main score", PERMS_PRIVATE); + createDirectory(getScoreCacheDir(level_subdir), "level score", PERMS_PRIVATE); +} + void InitScoreTapeDirectory(char *level_subdir, int nr) { int permissions = (program.global_scores ? PERMS_PUBLIC : PERMS_PRIVATE); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index b84bb822..da6c3f9f 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -266,6 +266,7 @@ char *getProgramConfigFilename(char *); char *getTapeFilename(int); char *getSolutionTapeFilename(int); char *getScoreFilename(int); +char *getScoreCacheFilename(int); char *getScoreTapeBasename(char *); char *getScoreTapeFilename(char *, int); char *getSetupFilename(void); @@ -286,6 +287,7 @@ char *getCustomMusicDirectory(void); void InitTapeDirectory(char *); void InitScoreDirectory(char *); +void InitScoreCacheDirectory(char *); void InitScoreTapeDirectory(char *, int); void InitUserLevelDirectory(char *); void InitNetworkLevelDirectory(char *);