[Add] Allow reading ldata-version by default.

This commit is contained in:
Allanis 2014-03-08 00:57:24 +00:00
parent 567ccb8d59
commit b73a332952
5 changed files with 20 additions and 10 deletions

View File

@ -13,6 +13,7 @@
#include "input.h" #include "input.h"
#include "music.h" #include "music.h"
#include "nebulae.h" #include "nebulae.h"
#include "lfile.h"
#include "conf.h" #include "conf.h"
#define conf_loadInt(n,i) \ #define conf_loadInt(n,i) \
@ -79,9 +80,16 @@ static void print_usage(char** argv) {
LOG(" -v - Print the version and exit"); LOG(" -v - Print the version and exit");
} }
/* Set the default configuration. */ char dataVersion[PATH_MAX];
/**
* @brief Set the default configuration.
*/
void conf_setDefaults(void) { void conf_setDefaults(void) {
/* Global. */ /* Global. */
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; data = DATA_DEF;
/* GL. */ /* GL. */
gl_screen.w = 800; gl_screen.w = 800;

View File

@ -19,8 +19,10 @@
#define pow2(x) ((x)*(x)) /**< ^2 */ #define pow2(x) ((x)*(x)) /**< ^2 */
#define DATA_NAME "ldata" /**M Default data name. */
#ifndef DATA_DEF #ifndef DATA_DEF
#define DATA_DEF "ldata" /**< Default data packfile. */ #define DATA_DEF DATA_NAME /**< Default data packfile. */
#endif #endif
extern char* data; /**< Modifiable datafile. */ extern char* data; /**< Modifiable datafile. */
#define DATA data /**< Standard data file to use. */ #define DATA data /**< Standard data file to use. */

View File

@ -93,7 +93,7 @@ int lfile_dirMakeExist(const char* path) {
* @return 1 if file exists, 0 if it doesn't or -1 on error. * @return 1 if file exists, 0 if it doesn't or -1 on error.
*/ */
int lfile_fileExists(const char* path, ...) { int lfile_fileExists(const char* path, ...) {
char file[PATH_MAX], name[PATH_MAX]; char file[PATH_MAX];
va_list ap; va_list ap;
size_t l; size_t l;
@ -101,12 +101,11 @@ int lfile_fileExists(const char* path, ...) {
if(path == NULL) return -1; if(path == NULL) return -1;
else { /* Get the message. */ else { /* Get the message. */
va_start(ap, path); va_start(ap, path);
vsnprintf(name, PATH_MAX-l, path, ap); vsnprintf(file, PATH_MAX-l, path, ap);
l = strlen(name); l = strlen(file);
va_end(ap); va_end(ap);
} }
snprintf(file, PATH_MAX, "%s%s", lfile_basePath(), name);
#ifdef LINUX #ifdef LINUX
struct stat buf; struct stat buf;

View File

@ -542,7 +542,8 @@ static void nebu_generatePuffs(void) {
* @return 0 on success. * @return 0 on success.
*/ */
static int nebu_checkCompat(const char* file) { 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 -1;
return 0; return 0;
} }

View File

@ -264,7 +264,7 @@ void player_new(void) {
return; return;
} }
if(lfile_fileExists("saves/%s.ls", player_name)) { if(lfile_fileExists("%ssaves/%s.ls", lfile_basePath(), player_name)) {
r = dialogue_YesNo("Overwrite", r = dialogue_YesNo("Overwrite",
"You already have a pilot named %s. Overwrite?", player_name); "You already have a pilot named %s. Overwrite?", player_name);
if(r == 0) { if(r == 0) {