diff options
| author | relnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f> | 2003-01-08 09:05:22 +0000 |
|---|---|---|
| committer | relnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f> | 2003-01-08 09:05:22 +0000 |
| commit | 8efed35df02822682576bae088f5b6a5c78e8dc9 (patch) | |
| tree | da099501696fe5456a95e85c98d5b746176419ee /Source/Support.cpp | |
| parent | 9c22203ab6b1f6f61ec4b7c52a7c9c51da9e5844 (diff) | |
| download | blackshades-8efed35df02822682576bae088f5b6a5c78e8dc9.tar.gz | |
start of serialization
git-svn-id: svn://svn.icculus.org/blackshades/trunk@44 5198baeb-e213-0410-be47-fc2ff85ca46f
Diffstat (limited to 'Source/Support.cpp')
| -rw-r--r-- | Source/Support.cpp | 103 |
1 files changed, 97 insertions, 6 deletions
diff --git a/Source/Support.cpp b/Source/Support.cpp index 16c6876..e07c86e 100644 --- a/Source/Support.cpp +++ b/Source/Support.cpp @@ -2,6 +2,7 @@ #include "Files.h" #include <sys/types.h> +#include <dirent.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> @@ -55,6 +56,89 @@ STUB_FUNCTION; #define MAX_PATH 256 #endif +static int find_filename(char *filename) +{ + char *ptr; + char *cur; + char *next; + DIR *dir; + struct dirent *dirent; + + if (access(filename, R_OK) == 0) { + return 1; + } + + ptr = filename; + + while (*ptr) { + if (ptr == filename || *ptr == '/') { + cur = ptr+1; + if (*cur == 0) { + /* hit the end */ + break; + } + + next = strchr(cur, '/'); + + if (ptr != filename) { + *ptr = 0; + } + + if (next) { + *next = 0; + } + + if (ptr == filename && *ptr == '/') { + dir = opendir("/"); + } else { + dir = opendir(filename); + } + + if (dir == NULL) { + if (ptr != filename) { + *ptr = '/'; + } + + if (next) { + *next = 0; + } + + return 0; + } + + while ((dirent = readdir(dir)) != NULL) { + if (strcasecmp(cur, dirent->d_name) == 0 + && (dirent->d_type == DT_UNKNOWN || + (dirent->d_type == DT_DIR && next != NULL))) { + strcpy(cur, dirent->d_name); + break; + } + } + + closedir(dir); + + if (ptr != filename) { + *ptr = '/'; + } + + if (next) { + *next = '/'; + ptr = next; + } else { + ptr++; + } + } else { + ptr++; + } + } + + if (access(filename, R_OK) == 0) { + return 1; + } + + return 0; +} + static void fix_filename(const char *original, char *fixed) { const char *start; @@ -65,12 +149,7 @@ static void fix_filename(const char *original, char *fixed) if (original[0] == ':') { start = &original[1]; } - - /* - here would be stuff to check where the file is, - including the game root and the user local dir - */ - + fixed[MAX_PATH-1] = 0; strncpy(fixed, start, MAX_PATH); @@ -89,6 +168,18 @@ static void fix_filename(const char *original, char *fixed) fixed[i] = '/'; } } + + /* + here we would try to see if the file is available (game dir), + else try another dir + + really, this function also needs a flag to indicate whether + it should only go to local (write) or both (read) + */ + + if (find_filename(fixed) == 0) { + fprintf(stderr, "find failed: %s\n", fixed); + } } /* |
