Logging: Log full file names of opened GRFs
This commit is contained in:
@@ -245,14 +245,14 @@ static void FioFreeHandle()
|
|||||||
* @param filename Name of the file at the disk.
|
* @param filename Name of the file at the disk.
|
||||||
* @param subdir The sub directory to search this file in.
|
* @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;
|
FILE *f;
|
||||||
|
|
||||||
#if defined(LIMITED_FDS)
|
#if defined(LIMITED_FDS)
|
||||||
FioFreeHandle();
|
FioFreeHandle();
|
||||||
#endif /* LIMITED_FDS */
|
#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);
|
if (f == nullptr) usererror("Cannot open file '%s'", filename);
|
||||||
long pos = ftell(f);
|
long pos = ftell(f);
|
||||||
if (pos < 0) usererror("Cannot read file '%s'", filename);
|
if (pos < 0) usererror("Cannot read file '%s'", filename);
|
||||||
@@ -395,7 +395,7 @@ char *FioGetDirectory(char *buf, const char *last, Subdirectory subdir)
|
|||||||
return buf;
|
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)
|
#if defined(_WIN32) && defined(UNICODE)
|
||||||
/* fopen is implemented as a define with ellipses for
|
/* 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);
|
*filesize = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
if (output_filename != nullptr) {
|
||||||
|
*output_filename = (f != nullptr) ? stredup(buf, lastof(buf)) : nullptr;
|
||||||
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +463,7 @@ FILE *FioFOpenFileTar(TarFileListEntry *entry, size_t *filesize)
|
|||||||
* @param subdir Subdirectory to open.
|
* @param subdir Subdirectory to open.
|
||||||
* @return File handle of the opened file, or \c nullptr if the file is not available.
|
* @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;
|
FILE *f = nullptr;
|
||||||
Searchpath sp;
|
Searchpath sp;
|
||||||
@@ -468,7 +471,7 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir,
|
|||||||
assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY);
|
assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY);
|
||||||
|
|
||||||
FOR_ALL_SEARCHPATHS(sp) {
|
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;
|
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);
|
TarFileList::iterator it = _tar_filelist[subdir].find(resolved_name);
|
||||||
if (it != _tar_filelist[subdir].end()) {
|
if (it != _tar_filelist[subdir].end()) {
|
||||||
f = FioFOpenFileTar(&((*it).second), filesize);
|
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) {
|
if (f == nullptr && subdir != NO_DIRECTORY) {
|
||||||
switch (subdir) {
|
switch (subdir) {
|
||||||
case BASESET_DIR:
|
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;
|
if (f != nullptr) break;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case NEWGRF_DIR:
|
case NEWGRF_DIR:
|
||||||
f = FioFOpenFile(filename, mode, OLD_DATA_DIR, filesize);
|
f = FioFOpenFile(filename, mode, OLD_DATA_DIR, filesize, output_filename);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
f = FioFOpenFile(filename, mode, NO_DIRECTORY, filesize);
|
f = FioFOpenFile(filename, mode, NO_DIRECTORY, filesize, output_filename);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ byte FioReadByte();
|
|||||||
uint16 FioReadWord();
|
uint16 FioReadWord();
|
||||||
uint32 FioReadDword();
|
uint32 FioReadDword();
|
||||||
void FioCloseAll();
|
void FioCloseAll();
|
||||||
void FioOpenFile(uint slot, const char *filename, Subdirectory subdir);
|
void FioOpenFile(uint slot, const char *filename, Subdirectory subdir, char **output_filename = nullptr);
|
||||||
void FioReadBlock(void *ptr, size_t size);
|
void FioReadBlock(void *ptr, size_t size);
|
||||||
void FioSkipBytes(int n);
|
void FioSkipBytes(int n);
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ static inline bool IsValidSearchPath(Searchpath sp)
|
|||||||
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
|
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
|
||||||
|
|
||||||
void FioFCloseFile(FILE *f);
|
void FioFCloseFile(FILE *f);
|
||||||
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = nullptr);
|
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = nullptr, char **output_filename = nullptr);
|
||||||
bool FioCheckFileExists(const char *filename, Subdirectory subdir);
|
bool FioCheckFileExists(const char *filename, Subdirectory subdir);
|
||||||
char *FioGetFullPath(char *buf, const char *last, Searchpath sp, Subdirectory subdir, const char *filename);
|
char *FioGetFullPath(char *buf, const char *last, Searchpath sp, Subdirectory subdir, const char *filename);
|
||||||
char *FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const char *filename);
|
char *FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const char *filename);
|
||||||
|
@@ -386,7 +386,7 @@ void CDECL _intl_grfmsg(int severity, const char *str, ...)
|
|||||||
vseprintf(buf, lastof(buf), str, va);
|
vseprintf(buf, lastof(buf), str, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
DEBUG(grf, severity, "[%s:%d] %s", _cur.grfconfig->filename, _cur.nfo_line, buf);
|
DEBUG(grf, severity, "[%s:%d] %s", _cur.grfconfig->GetDisplayPath(), _cur.nfo_line, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6814,7 +6814,7 @@ static void ScanInfo(ByteReader *buf)
|
|||||||
|
|
||||||
if (grf_version < 2 || grf_version > 8) {
|
if (grf_version < 2 || grf_version > 8) {
|
||||||
SetBit(_cur.grfconfig->flags, GCF_INVALID);
|
SetBit(_cur.grfconfig->flags, GCF_INVALID);
|
||||||
DEBUG(grf, 0, "%s: NewGRF \"%s\" (GRFID %08X) uses GRF version %d, which is incompatible with this version of OpenTTD.", _cur.grfconfig->filename, name, BSWAP32(grfid), grf_version);
|
DEBUG(grf, 0, "%s: NewGRF \"%s\" (GRFID %08X) uses GRF version %d, which is incompatible with this version of OpenTTD.", _cur.grfconfig->GetDisplayPath(), name, BSWAP32(grfid), grf_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
|
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
|
||||||
@@ -7519,7 +7519,7 @@ static void GRFInhibit(ByteReader *buf)
|
|||||||
|
|
||||||
/* Unset activation flag */
|
/* Unset activation flag */
|
||||||
if (file != nullptr && file != _cur.grfconfig) {
|
if (file != nullptr && file != _cur.grfconfig) {
|
||||||
grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename);
|
grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->GetDisplayPath());
|
||||||
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_FORCEFULLY_DISABLED, file);
|
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_FORCEFULLY_DISABLED, file);
|
||||||
error->data = stredup(_cur.grfconfig->GetName());
|
error->data = stredup(_cur.grfconfig->GetName());
|
||||||
}
|
}
|
||||||
@@ -9922,13 +9922,15 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, S
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FioOpenFile(file_index, filename, subdir);
|
free(config->full_filename);
|
||||||
|
config->full_filename = nullptr;
|
||||||
|
FioOpenFile(file_index, filename, subdir, &(config->full_filename));
|
||||||
_cur.file_index = file_index; // XXX
|
_cur.file_index = file_index; // XXX
|
||||||
_palette_remap_grf[_cur.file_index] = (config->palette & GRFP_USE_MASK);
|
_palette_remap_grf[_cur.file_index] = (config->palette & GRFP_USE_MASK);
|
||||||
|
|
||||||
_cur.grfconfig = config;
|
_cur.grfconfig = config;
|
||||||
|
|
||||||
DEBUG(grf, 2, "LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
|
DEBUG(grf, 2, "LoadNewGRFFile: Reading NewGRF-file '%s'", config->GetDisplayPath());
|
||||||
|
|
||||||
_cur.grf_container_ver = GetGRFContainerVersion();
|
_cur.grf_container_ver = GetGRFContainerVersion();
|
||||||
if (_cur.grf_container_ver == 0) {
|
if (_cur.grf_container_ver == 0) {
|
||||||
|
@@ -108,6 +108,7 @@ GRFConfig::~GRFConfig()
|
|||||||
free(this->filename);
|
free(this->filename);
|
||||||
delete this->error;
|
delete this->error;
|
||||||
}
|
}
|
||||||
|
free(this->full_filename);
|
||||||
this->name->Release();
|
this->name->Release();
|
||||||
this->info->Release();
|
this->info->Release();
|
||||||
this->url->Release();
|
this->url->Release();
|
||||||
@@ -658,7 +659,7 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
|
|||||||
f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, nullptr, c->version);
|
f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, nullptr, c->version);
|
||||||
if (f != nullptr) {
|
if (f != nullptr) {
|
||||||
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
||||||
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->filename, buf);
|
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->GetDisplayPath(), buf);
|
||||||
if (!HasBit(c->flags, GCF_COMPATIBLE)) {
|
if (!HasBit(c->flags, GCF_COMPATIBLE)) {
|
||||||
/* Preserve original_md5sum after it has been assigned */
|
/* Preserve original_md5sum after it has been assigned */
|
||||||
SetBit(c->flags, GCF_COMPATIBLE);
|
SetBit(c->flags, GCF_COMPATIBLE);
|
||||||
@@ -672,13 +673,13 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
|
|||||||
|
|
||||||
/* No compatible grf was found, mark it as disabled */
|
/* No compatible grf was found, mark it as disabled */
|
||||||
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
||||||
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->ident.grfid), c->filename, buf);
|
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->ident.grfid), c->GetDisplayPath(), buf);
|
||||||
|
|
||||||
c->status = GCS_NOT_FOUND;
|
c->status = GCS_NOT_FOUND;
|
||||||
res = GLC_NOT_FOUND;
|
res = GLC_NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
compatible_grf:
|
compatible_grf:
|
||||||
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->ident.grfid), f->filename);
|
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->ident.grfid), f->GetDisplayPath());
|
||||||
/* The filename could be the filename as in the savegame. As we need
|
/* The filename could be the filename as in the savegame. As we need
|
||||||
* to load the GRF here, we need the correct filename, so overwrite that
|
* to load the GRF here, we need the correct filename, so overwrite that
|
||||||
* in any case and set the name and info when it is not set already.
|
* in any case and set the name and info when it is not set already.
|
||||||
|
@@ -156,6 +156,7 @@ struct GRFConfig : ZeroedMemoryAllocator {
|
|||||||
GRFIdentifier ident; ///< grfid and md5sum to uniquely identify newgrfs
|
GRFIdentifier ident; ///< grfid and md5sum to uniquely identify newgrfs
|
||||||
uint8 original_md5sum[16]; ///< MD5 checksum of original file if only a 'compatible' file was loaded
|
uint8 original_md5sum[16]; ///< MD5 checksum of original file if only a 'compatible' file was loaded
|
||||||
char *filename; ///< Filename - either with or without full path
|
char *filename; ///< Filename - either with or without full path
|
||||||
|
char *full_filename; ///< NOSAVE: Full filename
|
||||||
GRFTextWrapper *name; ///< NOSAVE: GRF name (Action 0x08)
|
GRFTextWrapper *name; ///< NOSAVE: GRF name (Action 0x08)
|
||||||
GRFTextWrapper *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
|
GRFTextWrapper *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
|
||||||
GRFTextWrapper *url; ///< NOSAVE: URL belonging to this GRF.
|
GRFTextWrapper *url; ///< NOSAVE: URL belonging to this GRF.
|
||||||
@@ -182,6 +183,11 @@ struct GRFConfig : ZeroedMemoryAllocator {
|
|||||||
const char *GetDescription() const;
|
const char *GetDescription() const;
|
||||||
const char *GetURL() const;
|
const char *GetURL() const;
|
||||||
|
|
||||||
|
const char *GetDisplayPath() const
|
||||||
|
{
|
||||||
|
return this->full_filename ? this->full_filename : this->filename;
|
||||||
|
}
|
||||||
|
|
||||||
void SetParameterDefaults();
|
void SetParameterDefaults();
|
||||||
void SetSuitablePalette();
|
void SetSuitablePalette();
|
||||||
void FinalizeParameterInfo();
|
void FinalizeParameterInfo();
|
||||||
|
Reference in New Issue
Block a user