From 5839a6a59a333d912c6ec5a9c9db4fb96f822964 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Sun, 11 Dec 2016 14:45:35 +0100 Subject: [PATCH] GetDataFilePathNull --- src/utils.c | 32 ++++++++++++++++++++++++++++++++ src/utils.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/utils.c b/src/utils.c index ef2ad0f..390529a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -320,6 +320,38 @@ SYMBOL_EXPORT char* GetDataFilePath(struct Game *game, char* filename) { return AddGarbage(game, result); } +SYMBOL_EXPORT char* GetDataFilePathNull(struct Game *game, char* filename) { + + char *result = 0; + + if (al_filename_exists(filename)) { + return AddGarbage(game, strdup(filename)); + } + + { + char origfn[255] = "data/"; + strcat(origfn, filename); + + if (al_filename_exists(origfn)) { + return AddGarbage(game, strdup(origfn)); + } + } + + TestPath(filename, "data/", &result); + TestPath(filename, GetGameName(game, "../share/%s/data/"), &result); + + TestPath(filename, "../data/", &result); +#ifdef ALLEGRO_MACOSX + TestPath(filename, "../Resources/data/", &result); + TestPath(filename, "../Resources/gamestates/", &result); +#endif + + if (!result) { + return filename; + } + return AddGarbage(game, result); +} + ALLEGRO_DEBUG_CHANNEL("libsuperderpy") SYMBOL_EXPORT void PrintConsole(struct Game *game, char* format, ...) { diff --git a/src/utils.h b/src/utils.h index b8abf4e..55590cf 100644 --- a/src/utils.h +++ b/src/utils.h @@ -55,6 +55,7 @@ ALLEGRO_BITMAP* LoadScaledBitmap(struct Game *game, char* filename, int width, i /*! \brief Finds path for data file. */ char* GetDataFilePath(struct Game *game, char* filename); +char* GetDataFilePathNull(struct Game *game, char* filename); char* GetGameName(struct Game *game, char* format);