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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user