X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=file.c;h=efd08e5a0f23ac78f9444312349de8779c8ce4d8;hp=ee14299b6df62773a055330d11b2f4fa8cb7b0b9;hb=HEAD;hpb=af711b4e66c96c112086a442ea09094643bd8d71 diff --git a/file.c b/file.c index ee14299..5f6204d 100644 --- a/file.c +++ b/file.c @@ -19,19 +19,53 @@ #include #include #include -#include +#ifndef WIN32 +# include +#endif #include #include #include "common.h" -#include "config.h" +#include "vorconfig.h" #include "file.h" +#ifdef WIN32 + +#define DATA_DIR "data\\" + +char * +add_data_path(char *filename) +{ + char *s; + if(!filename) return filename; + s = malloc(sizeof(DATA_DIR)+strlen(filename)); + if(s) { + strcpy(s, DATA_DIR); + strcpy(s+sizeof(DATA_DIR)-1, filename); + } + return s; +} + +bool +find_files(void) +{ + return true; +} + +FILE * +open_score_file(char *mode) +{ + return fopen("scores", mode); +} + + +#else /* !WIN32 */ + + char *g_data_dir; char *g_score_file; -mode_t g_score_mask; -char * +static char * add_path(char *path, char *file) { char *s; @@ -54,46 +88,54 @@ add_data_path(char *filename) return add_path(g_data_dir, filename); } -int +static bool is_dir(char *dirname) { struct stat buf; - stat(dirname, &buf); + if(stat(dirname, &buf)) { + return false; + } return S_ISDIR(buf.st_mode); } -int +static bool is_file(char *filename) { struct stat buf; - stat(filename, &buf); + if(stat(filename, &buf)) { + return false; + } return S_ISREG(buf.st_mode); } -int +static bool find_data_dir(void) { int i; char *data_options[3] = { - "./data", getenv("VOR_DATA"), + "data", DATA_PREFIX }; for(i=0; i<3; i++) { if(!data_options[i]) continue; g_data_dir = strdup(data_options[i]); - if(is_dir(g_data_dir)) return true; + if(is_dir(g_data_dir)) { + char *s = add_path(g_data_dir, "b_variations.png"); + if(s) if(is_file(s)) + return true; + } } fprintf(stderr, "Can't find VoR data! Tried:\n"); for(i=0; i<3; i++) { - fprintf(stderr, "\t%s\n", data_options[i]); + if(data_options[i]) fprintf(stderr, "\t%s\n", data_options[i]); } return false; } -int +static bool find_score_file(void) { char *dir, *s; @@ -105,30 +147,21 @@ find_score_file(void) s = add_path(dir, ".vor-scores"); if(s) { g_score_file = s; - g_score_mask = 0177; - return is_file(s); + return true; } else return false; } -int +bool find_files(void) { - int r; - r = find_data_dir(); - find_score_file(); - return r; + return find_data_dir() && find_score_file(); } FILE * open_score_file(char *mode) { - mode_t old_mask; - FILE *f; - if(!g_score_file) return NULL; - - old_mask = umask(g_score_mask); - f = fopen(g_score_file, mode); - umask(old_mask); - return f; + return fopen(g_score_file, mode); } + +#endif /* !WIN32 */