From fb3a04d5da2aef5854e4b72407adbb3a83a7d686 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sat, 30 May 2015 22:20:29 +0200 Subject: [PATCH] add access to location where findfile() found the file "findfilelocation" contains the location, where the file was found. Not a nice solution, but nice enough :) Note: if the location is FFL_WORKDIR, the existence of the file has not actually been checked yet. --- source/src/stream.cpp | 5 +++++ source/src/tools.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/source/src/stream.cpp b/source/src/stream.cpp index abf56d4d..8eb215df 100644 --- a/source/src/stream.cpp +++ b/source/src/stream.cpp @@ -217,12 +217,15 @@ void addpackagedir(const char *dir) } } +int findfilelocation; + const char *findfile(const char *filename, const char *mode) { while(filename[0] == PATHDIV) filename++; // skip leading pathdiv while(!strncmp(".." PATHDIVS, filename, 3)) filename += 3; // skip leading "../" (don't allow access to files below "AC root dir") static string s; formatstring(s)("%s%s", homedir, filename); // homedir may be "" + findfilelocation = FFL_HOME; if(homedir[0] && fileexists(s, mode)) return s; if(mode[0]=='w' || mode[0]=='a') { // create missing directories, if necessary @@ -240,9 +243,11 @@ const char *findfile(const char *filename, const char *mode) } loopv(packagedirs) { + findfilelocation++; formatstring(s)("%s%s", packagedirs[i], filename); if(fileexists(s, mode)) return s; } + findfilelocation = FFL_WORKDIR; return filename; } diff --git a/source/src/tools.h b/source/src/tools.h index b0a65d71..e4d473cf 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -953,6 +953,8 @@ extern bool createdir(const char *path); extern size_t fixpackagedir(char *dir); extern void sethomedir(const char *dir); extern void addpackagedir(const char *dir); +extern int findfilelocation; +enum { FFL_WORKDIR = -1, FFL_HOME = 0 }; extern const char *findfile(const char *filename, const char *mode); extern int getfilesize(const char *filename); extern stream *openrawfile(const char *filename, const char *mode);