From b73a3329528fbb47ef8b296879d953155255daeb Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 8 Mar 2014 00:57:24 +0000 Subject: [PATCH] [Add] Allow reading ldata-version by default. --- src/conf.c | 12 ++++++++++-- src/lephisto.h | 6 ++++-- src/lfile.c | 7 +++---- src/nebulae.c | 3 ++- src/player.c | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/conf.c b/src/conf.c index 9fb5142..8cd6fff 100644 --- a/src/conf.c +++ b/src/conf.c @@ -13,6 +13,7 @@ #include "input.h" #include "music.h" #include "nebulae.h" +#include "lfile.h" #include "conf.h" #define conf_loadInt(n,i) \ @@ -79,10 +80,17 @@ static void print_usage(char** argv) { LOG(" -v - Print the version and exit"); } -/* Set the default configuration. */ +char dataVersion[PATH_MAX]; +/** + * @brief Set the default configuration. + */ void conf_setDefaults(void) { /* Global. */ - data = DATA_DEF; + if(lfile_fileExists("%s-%d.%d.%d", DATA_NAME, VMAJOR, VMINOR, VREV)) { + snprintf(dataVersion, 128, "%s-%d.%d.%d", DATA_NAME, VMAJOR, VMINOR, VREV); + data = dataVersion; + } else + data = DATA_DEF; /* GL. */ gl_screen.w = 800; gl_screen.h = 600; diff --git a/src/lephisto.h b/src/lephisto.h index 058beb3..42cd41e 100644 --- a/src/lephisto.h +++ b/src/lephisto.h @@ -17,10 +17,12 @@ #define MAX(x,y) (((x)>(y))?(x):(y)) /**< Return maximum. */ #define MIN(x,y) (((x)>(y))?(y):(x)) /**< Return minumum. */ -#define pow2(x) ((x)*(x)) /**< ^2 */ +#define pow2(x) ((x)*(x)) /**< ^2 */ + +#define DATA_NAME "ldata" /**M Default data name. */ #ifndef DATA_DEF -#define DATA_DEF "ldata" /**< Default data packfile. */ +#define DATA_DEF DATA_NAME /**< Default data packfile. */ #endif extern char* data; /**< Modifiable datafile. */ #define DATA data /**< Standard data file to use. */ diff --git a/src/lfile.c b/src/lfile.c index 4396874..c0195e2 100644 --- a/src/lfile.c +++ b/src/lfile.c @@ -93,7 +93,7 @@ int lfile_dirMakeExist(const char* path) { * @return 1 if file exists, 0 if it doesn't or -1 on error. */ int lfile_fileExists(const char* path, ...) { - char file[PATH_MAX], name[PATH_MAX]; + char file[PATH_MAX]; va_list ap; size_t l; @@ -101,12 +101,11 @@ int lfile_fileExists(const char* path, ...) { if(path == NULL) return -1; else { /* Get the message. */ va_start(ap, path); - vsnprintf(name, PATH_MAX-l, path, ap); - l = strlen(name); + vsnprintf(file, PATH_MAX-l, path, ap); + l = strlen(file); va_end(ap); } - snprintf(file, PATH_MAX, "%s%s", lfile_basePath(), name); #ifdef LINUX struct stat buf; diff --git a/src/nebulae.c b/src/nebulae.c index e8d4f7d..9851e05 100644 --- a/src/nebulae.c +++ b/src/nebulae.c @@ -542,7 +542,8 @@ static void nebu_generatePuffs(void) { * @return 0 on success. */ static int nebu_checkCompat(const char* file) { - if(lfile_fileExists(file) == 0) /* First check to see if file exists. */ + /* First check to see if file exists. */ + if(lfile_fileExists("%s%s", lfile_basePath(), file) == 0) return -1; return 0; } diff --git a/src/player.c b/src/player.c index 395e171..3572df5 100644 --- a/src/player.c +++ b/src/player.c @@ -264,7 +264,7 @@ void player_new(void) { return; } - if(lfile_fileExists("saves/%s.ls", player_name)) { + if(lfile_fileExists("%ssaves/%s.ls", lfile_basePath(), player_name)) { r = dialogue_YesNo("Overwrite", "You already have a pilot named %s. Overwrite?", player_name); if(r == 0) {