JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
bump version to 0.5.8
[vor.git] / file.c
diff --git a/file.c b/file.c
index 0c6177f..5f6204d 100644 (file)
--- a/file.c
+++ b/file.c
 #include <unistd.h>
 
 #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;
@@ -45,7 +77,7 @@ add_path(char *path, char *file)
        s = malloc(2+plen+flen);
        if(!s) return NULL;
        memcpy(s, path, plen);
-       s[plen] = PATH_SEPARATOR;
+       s[plen] = '/';
        memcpy(s+plen+1, file, flen+1);
        return s;
 }
@@ -56,47 +88,27 @@ add_data_path(char *filename)
        return add_path(g_data_dir, filename);
 }
 
-#ifdef WIN32
-
-bool
-is_dir(char *dirname)
-{
-       WIN32_FILE_ATTRIBUTE_DATA buf;
-       if(!GetFileAttributesEx(dirname, GetFileExInfoStandard, &buf))
-               return false;
-       return buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
-}
-
-bool
-is_file(char *filename)
-{
-       WIN32_FILE_ATTRIBUTE_DATA buf;
-       if(!GetFileAttributesEx(filename, GetFileExInfoStandard, &buf))
-               return false;
-       return buf.dwFileAttributes & FILE_ATTRIBUTE_NORMAL;
-}
-
-#else /* !WIN32 */
-
-bool
+static bool
 is_dir(char *dirname)
 {
        struct stat buf;
-       stat(dirname, &buf);
+       if(stat(dirname, &buf)) {
+               return false;
+       }
        return S_ISDIR(buf.st_mode);
 }
 
-bool
+static bool
 is_file(char *filename)
 {
        struct stat buf;
-       stat(filename, &buf);
+       if(stat(filename, &buf)) {
+               return false;
+       }
        return S_ISREG(buf.st_mode);
 }
 
-#endif /* !WIN32 */
-
-bool
+static bool
 find_data_dir(void)
 {
        int i;
@@ -109,17 +121,21 @@ find_data_dir(void)
        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;
 }
 
-bool
+static bool
 find_score_file(void)
 {
        char *dir, *s;
@@ -131,7 +147,6 @@ find_score_file(void)
        s = add_path(dir, ".vor-scores");
        if(s) {
                g_score_file = s;
-               g_score_mask = 0177;
                return true;
        } else return false;
 }
@@ -145,13 +160,8 @@ find_files(void)
 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 */