Logging: Log full file names of opened GRFs

This commit is contained in:
Jonathan G Rennison
2019-12-11 20:34:04 +00:00
parent fe9b024f1a
commit 6ada7c3c7f
5 changed files with 33 additions and 18 deletions

View File

@@ -245,14 +245,14 @@ static void FioFreeHandle()
* @param filename Name of the file at the disk.
* @param subdir The sub directory to search this file in.
*/
void FioOpenFile(uint slot, const char *filename, Subdirectory subdir)
void FioOpenFile(uint slot, const char *filename, Subdirectory subdir, char **output_filename)
{
FILE *f;
#if defined(LIMITED_FDS)
FioFreeHandle();
#endif /* LIMITED_FDS */
f = FioFOpenFile(filename, "rb", subdir);
f = FioFOpenFile(filename, "rb", subdir, nullptr, output_filename);
if (f == nullptr) usererror("Cannot open file '%s'", filename);
long pos = ftell(f);
if (pos < 0) usererror("Cannot read file '%s'", filename);
@@ -395,7 +395,7 @@ char *FioGetDirectory(char *buf, const char *last, Subdirectory subdir)
return buf;
}
static FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subdirectory subdir, size_t *filesize)
static FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subdirectory subdir, size_t *filesize, char **output_filename)
{
#if defined(_WIN32) && defined(UNICODE)
/* fopen is implemented as a define with ellipses for
@@ -430,6 +430,9 @@ static FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath s
*filesize = ftell(f);
fseek(f, 0, SEEK_SET);
}
if (output_filename != nullptr) {
*output_filename = (f != nullptr) ? stredup(buf, lastof(buf)) : nullptr;
}
return f;
}
@@ -460,7 +463,7 @@ FILE *FioFOpenFileTar(TarFileListEntry *entry, size_t *filesize)
* @param subdir Subdirectory to open.
* @return File handle of the opened file, or \c nullptr if the file is not available.
*/
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize)
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize, char **output_filename)
{
FILE *f = nullptr;
Searchpath sp;
@@ -468,7 +471,7 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir,
assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY);
FOR_ALL_SEARCHPATHS(sp) {
f = FioFOpenFileSp(filename, mode, sp, subdir, filesize);
f = FioFOpenFileSp(filename, mode, sp, subdir, filesize, output_filename);
if (f != nullptr || subdir == NO_DIRECTORY) break;
}
@@ -501,6 +504,9 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir,
TarFileList::iterator it = _tar_filelist[subdir].find(resolved_name);
if (it != _tar_filelist[subdir].end()) {
f = FioFOpenFileTar(&((*it).second), filesize);
if (output_filename != nullptr && f != nullptr) {
*output_filename = str_fmt("%s" PATHSEP "%s", ((*it).second).tar_filename, filename);
}
}
}
@@ -509,15 +515,15 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir,
if (f == nullptr && subdir != NO_DIRECTORY) {
switch (subdir) {
case BASESET_DIR:
f = FioFOpenFile(filename, mode, OLD_GM_DIR, filesize);
f = FioFOpenFile(filename, mode, OLD_GM_DIR, filesize, output_filename);
if (f != nullptr) break;
FALLTHROUGH;
case NEWGRF_DIR:
f = FioFOpenFile(filename, mode, OLD_DATA_DIR, filesize);
f = FioFOpenFile(filename, mode, OLD_DATA_DIR, filesize, output_filename);
break;
default:
f = FioFOpenFile(filename, mode, NO_DIRECTORY, filesize);
f = FioFOpenFile(filename, mode, NO_DIRECTORY, filesize, output_filename);
break;
}
}