diff --git a/src/wildmidi/file_io.cpp b/src/wildmidi/file_io.cpp index c2ef557157..50a2a6b6cf 100644 --- a/src/wildmidi/file_io.cpp +++ b/src/wildmidi/file_io.cpp @@ -38,18 +38,56 @@ #include "../files.h" #include "wm_error.h" #include "file_io.h" +#include "pathexpander.h" +#include "cmdlib.h" -unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size) +static PathExpander wmPathExpander; + +unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size, bool ismain) { - FileReader file; + FileReader *fp; + int lumpnum; - if (!file.Open(filename)) + if (ismain) + { + wmPathExpander.openmode = PathExpander::OM_FILEORLUMP; + wmPathExpander.clearPathlist(); +#ifdef _WIN32 + wmPathExpander.addToPathlist("C:\\TIMIDITY"); + wmPathExpander.addToPathlist("\\TIMIDITY"); + wmPathExpander.addToPathlist(progdir); +#else + wmPathExpander.addToPathlist("/usr/local/lib/timidity"); + wmPathExpander.addToPathlist("/etc/timidity"); + wmPathExpander.addToPathlist("/etc"); +#endif + } + + if (!(fp = wmPathExpander.openFileReader(filename, &lumpnum))) + return NULL; + + if (ismain) + { + if (lumpnum > 0) + { + wmPathExpander.openmode = PathExpander::OM_LUMP; + wmPathExpander.clearPathlist(); // when reading from a PK3 we don't want to use any external path + } + else + { + wmPathExpander.openmode = PathExpander::OM_FILE; + } + } + + + + if (fp == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno); return NULL; } - long fsize = file.GetLength(); + long fsize = fp->GetLength(); if (fsize > WM_MAXFILESIZE) { @@ -66,7 +104,8 @@ unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size) return NULL; } - file.Read(data, fsize); + fp->Read(data, fsize); + delete fp; data[fsize] = 0; *size = fsize; return data; diff --git a/src/wildmidi/file_io.h b/src/wildmidi/file_io.h index d38caffbb4..550a8a4b25 100644 --- a/src/wildmidi/file_io.h +++ b/src/wildmidi/file_io.h @@ -28,6 +28,6 @@ #define __FILE_IO_H #define WM_MAXFILESIZE 0x1fffffff -extern unsigned char *_WM_BufferFile (const char *filename, unsigned long int *size); +extern unsigned char *_WM_BufferFile (const char *filename, unsigned long int *size, bool mainfile = false); #endif /* __FILE_IO_H */ diff --git a/src/wildmidi/wildmidi_lib.cpp b/src/wildmidi/wildmidi_lib.cpp index 19e290f6bd..eebd428301 100644 --- a/src/wildmidi/wildmidi_lib.cpp +++ b/src/wildmidi/wildmidi_lib.cpp @@ -645,7 +645,7 @@ static int WM_LoadConfig(const char *config_file) { char **line_tokens = NULL; int token_count = 0; - config_buffer = (char *) _WM_BufferFile(config_file, &config_size); + config_buffer = (char *) _WM_BufferFile(config_file, &config_size, true); if (!config_buffer) { WM_FreePatches(); return -1;