mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-03-03 17:15:26 +03:00
Add additional place to check for finding the config.ini or plugins.ini.
Refactoring.
This commit is contained in:
parent
1dcc52fcc0
commit
bcb6bd1af5
@ -195,7 +195,7 @@ void MConfig::set_directory()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
normalize_pathname(m_directory);
|
NormalizePath(m_directory);
|
||||||
|
|
||||||
// get directory
|
// get directory
|
||||||
char *dir = Q_strrchr(m_directory, '/');
|
char *dir = Q_strrchr(m_directory, '/');
|
||||||
|
@ -116,7 +116,7 @@ bool setup_gamedll(gamedll_t *gamedll)
|
|||||||
|
|
||||||
// If the path is relative, the gamedll file will be missing and
|
// If the path is relative, the gamedll file will be missing and
|
||||||
// it might be found in the cache file.
|
// it might be found in the cache file.
|
||||||
if (!is_absolute_path(gamedll->pathname))
|
if (!IsAbsolutePath(gamedll->pathname))
|
||||||
{
|
{
|
||||||
char szInstallPath[MAX_PATH];
|
char szInstallPath[MAX_PATH];
|
||||||
Q_snprintf(szInstallPath, sizeof(szInstallPath), "%s/%s", gamedll->gamedir, gamedll->pathname);
|
Q_snprintf(szInstallPath, sizeof(szInstallPath), "%s/%s", gamedll->gamedir, gamedll->pathname);
|
||||||
|
@ -82,7 +82,7 @@ void metamod_startup()
|
|||||||
{
|
{
|
||||||
META_LOG("Configfile specified via localinfo: %s", cp);
|
META_LOG("Configfile specified via localinfo: %s", cp);
|
||||||
|
|
||||||
if (valid_gamedir_file(cp))
|
if (FileExistsInGameDir(cp))
|
||||||
{
|
{
|
||||||
Q_strncpy(configFile, cp, sizeof configFile - 1);
|
Q_strncpy(configFile, cp, sizeof configFile - 1);
|
||||||
configFile[sizeof configFile - 1] = '\0';
|
configFile[sizeof configFile - 1] = '\0';
|
||||||
@ -91,11 +91,27 @@ void metamod_startup()
|
|||||||
META_ERROR("Empty/missing config.ini file: %s; falling back to %s", cp, configFile);
|
META_ERROR("Empty/missing config.ini file: %s; falling back to %s", cp, configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!FileExistsInGameDir(configFile))
|
||||||
|
{
|
||||||
|
Q_strncpy(configFile, g_config->directory(), sizeof configFile - 1);
|
||||||
|
configFile[sizeof configFile - 1] = '\0';
|
||||||
|
|
||||||
|
// Get out of sub directory and check
|
||||||
|
char *dir = Q_strrchr(configFile, '/');
|
||||||
|
if (dir) {
|
||||||
|
*dir = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_strcat(configFile, "/" CONFIG_INI);
|
||||||
|
if (!FileExistsInGameDir(configFile))
|
||||||
|
{
|
||||||
|
META_DEBUG(2, "No config.ini file found: %s", CONFIG_INI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load config file
|
// Load config file
|
||||||
if (valid_gamedir_file(configFile))
|
if (FileExistsInGameDir(configFile))
|
||||||
g_config->load(configFile);
|
g_config->load(configFile);
|
||||||
else
|
|
||||||
META_DEBUG(2, "No config.ini file found: %s", CONFIG_INI);
|
|
||||||
|
|
||||||
// Now, override config options with localinfo commandline options.
|
// Now, override config options with localinfo commandline options.
|
||||||
if ((cp = LOCALINFO("mm_debug")) && *cp != '\0')
|
if ((cp = LOCALINFO("mm_debug")) && *cp != '\0')
|
||||||
@ -164,13 +180,30 @@ void metamod_startup()
|
|||||||
// gamedll calls engine functions during GiveFnptrsToDll (like hpb_bot
|
// gamedll calls engine functions during GiveFnptrsToDll (like hpb_bot
|
||||||
// does) then it needs to be non-null so META_ENGINE_HANDLE won't crash.
|
// does) then it needs to be non-null so META_ENGINE_HANDLE won't crash.
|
||||||
//
|
//
|
||||||
// However, having replaced valid_file with valid_gamedir_file, we need
|
// However, having replaced valid_file with FileExistsInGameDir, we need
|
||||||
// to at least initialize the gameDLL to include the gamedir, before
|
// to at least initialize the gameDLL to include the gamedir, before
|
||||||
// looking for plugins.ini.
|
// looking for plugins.ini.
|
||||||
//
|
//
|
||||||
// In fact, we need gamedir even earlier, so moved up above.
|
// In fact, we need gamedir even earlier, so moved up above.
|
||||||
|
|
||||||
// Fall back to old plugins filename, if configured one isn't found.
|
// Load plugins file
|
||||||
|
if (!FileExistsInGameDir(pluginFile))
|
||||||
|
{
|
||||||
|
Q_strncpy(pluginFile, g_config->directory(), sizeof pluginFile - 1);
|
||||||
|
pluginFile[sizeof pluginFile - 1] = '\0';
|
||||||
|
|
||||||
|
// Get out of sub directory and check
|
||||||
|
char *dir = Q_strrchr(pluginFile, '/');
|
||||||
|
if (dir) {
|
||||||
|
*dir = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_strcat(pluginFile, "/" PLUGINS_INI);
|
||||||
|
if (!FileExistsInGameDir(pluginFile))
|
||||||
|
{
|
||||||
|
META_DEBUG(2, "No plugins.ini file found: %s", PLUGINS_INI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_plugins = new MPluginList(pluginFile);
|
g_plugins = new MPluginList(pluginFile);
|
||||||
|
|
||||||
@ -200,7 +233,7 @@ void metamod_startup()
|
|||||||
execFile[sizeof execFile - 1] = '\0';
|
execFile[sizeof execFile - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid_gamedir_file(execFile))
|
if (FileExistsInGameDir(execFile))
|
||||||
{
|
{
|
||||||
if (execFile[0] == '/')
|
if (execFile[0] == '/')
|
||||||
META_ERROR("Cannot exec absolute pathnames: %s", execFile);
|
META_ERROR("Cannot exec absolute pathnames: %s", execFile);
|
||||||
@ -225,8 +258,8 @@ bool meta_init_gamedll(void)
|
|||||||
Q_memset(&g_GameDLL, 0, sizeof g_GameDLL);
|
Q_memset(&g_GameDLL, 0, sizeof g_GameDLL);
|
||||||
|
|
||||||
GET_GAME_DIR(gamedir);
|
GET_GAME_DIR(gamedir);
|
||||||
normalize_pathname(gamedir);
|
NormalizePath(gamedir);
|
||||||
//
|
|
||||||
// As of 1.1.1.1, the engine routine GET_GAME_DIR no longer returns a
|
// As of 1.1.1.1, the engine routine GET_GAME_DIR no longer returns a
|
||||||
// full-pathname, but rather just the path specified as the argument to
|
// full-pathname, but rather just the path specified as the argument to
|
||||||
// "-game".
|
// "-game".
|
||||||
@ -237,7 +270,7 @@ bool meta_init_gamedll(void)
|
|||||||
// Note: the code has always assumed the server op wouldn't do:
|
// Note: the code has always assumed the server op wouldn't do:
|
||||||
// hlds -game other/firearms
|
// hlds -game other/firearms
|
||||||
//
|
//
|
||||||
if (is_absolute_path(gamedir))
|
if (IsAbsolutePath(gamedir))
|
||||||
{
|
{
|
||||||
// Old style; GET_GAME_DIR returned full pathname. Copy this into
|
// Old style; GET_GAME_DIR returned full pathname. Copy this into
|
||||||
// our gamedir, and truncate to get the game name.
|
// our gamedir, and truncate to get the game name.
|
||||||
|
@ -45,7 +45,6 @@ bool rehlds_api_try_init(CSysModule* engineModule, char* failureReason)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool meta_init_rehlds_api() {
|
bool meta_init_rehlds_api() {
|
||||||
char failReason[2048];
|
char failReason[2048];
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ MPlugin* MPluginList::add(MPlugin* padd)
|
|||||||
// copy pathname
|
// copy pathname
|
||||||
Q_strncpy(iplug->m_pathname, padd->m_pathname, sizeof iplug->m_pathname - 1);
|
Q_strncpy(iplug->m_pathname, padd->m_pathname, sizeof iplug->m_pathname - 1);
|
||||||
iplug->m_pathname[sizeof iplug->m_pathname - 1] = '\0';
|
iplug->m_pathname[sizeof iplug->m_pathname - 1] = '\0';
|
||||||
normalize_pathname(iplug->m_pathname);
|
NormalizePath(iplug->m_pathname);
|
||||||
|
|
||||||
iplug->m_source = padd->m_source;
|
iplug->m_source = padd->m_source;
|
||||||
iplug->m_status = padd->m_status;
|
iplug->m_status = padd->m_status;
|
||||||
@ -280,7 +280,7 @@ bool MPluginList::ini_startup()
|
|||||||
int n, ln;
|
int n, ln;
|
||||||
MPlugin *pmatch;
|
MPlugin *pmatch;
|
||||||
|
|
||||||
if (!valid_gamedir_file(m_inifile))
|
if (!FileExistsInGameDir(m_inifile))
|
||||||
{
|
{
|
||||||
META_ERROR("ini: Metamod plugins file empty or missing: %s", m_inifile);
|
META_ERROR("ini: Metamod plugins file empty or missing: %s", m_inifile);
|
||||||
return false;
|
return false;
|
||||||
|
@ -53,7 +53,7 @@ bool MPlugin::ini_parseline(char *_line)
|
|||||||
|
|
||||||
Q_strncpy(m_filename, token, sizeof m_filename - 1);
|
Q_strncpy(m_filename, token, sizeof m_filename - 1);
|
||||||
m_filename[sizeof m_filename - 1] = '\0';
|
m_filename[sizeof m_filename - 1] = '\0';
|
||||||
normalize_pathname(m_filename);
|
NormalizePath(m_filename);
|
||||||
|
|
||||||
// Store name of just the actual _file_, without dir components.
|
// Store name of just the actual _file_, without dir components.
|
||||||
char* cp = Q_strrchr(m_filename, '/');
|
char* cp = Q_strrchr(m_filename, '/');
|
||||||
@ -135,8 +135,7 @@ bool MPlugin::plugin_parseline(const char *fname, int loader_index)
|
|||||||
|
|
||||||
Q_strncpy(m_filename, fname, sizeof m_filename - 1);
|
Q_strncpy(m_filename, fname, sizeof m_filename - 1);
|
||||||
m_filename[sizeof m_filename - 1] = '\0';
|
m_filename[sizeof m_filename - 1] = '\0';
|
||||||
|
NormalizePath(m_filename);
|
||||||
normalize_pathname(m_filename);
|
|
||||||
|
|
||||||
//store just name of the actual _file, without path
|
//store just name of the actual _file, without path
|
||||||
cp = Q_strrchr(m_filename, '/');
|
cp = Q_strrchr(m_filename, '/');
|
||||||
@ -181,7 +180,7 @@ bool MPlugin::cmd_parseline(const char *line)
|
|||||||
|
|
||||||
Q_strncpy(m_filename, token, sizeof m_filename - 1);
|
Q_strncpy(m_filename, token, sizeof m_filename - 1);
|
||||||
m_filename[sizeof m_filename - 1] = '\0';
|
m_filename[sizeof m_filename - 1] = '\0';
|
||||||
normalize_pathname(m_filename);
|
NormalizePath(m_filename);
|
||||||
|
|
||||||
// store name of just the actual _file_, without dir components
|
// store name of just the actual _file_, without dir components
|
||||||
cp = Q_strrchr(m_filename, '/');
|
cp = Q_strrchr(m_filename, '/');
|
||||||
@ -263,7 +262,7 @@ bool MPlugin::resolve(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_absolute_path(m_filename))
|
if (IsAbsolutePath(m_filename))
|
||||||
found = resolve_prefix(m_filename);
|
found = resolve_prefix(m_filename);
|
||||||
else
|
else
|
||||||
found = resolve_dirs(m_filename);
|
found = resolve_dirs(m_filename);
|
||||||
|
@ -13,18 +13,18 @@ void __declspec(noreturn) do_exit(int exitval)
|
|||||||
// Also, formerly named just "valid_file".
|
// Also, formerly named just "valid_file".
|
||||||
//
|
//
|
||||||
// Special-case-recognize "/dev/null" as a valid file.
|
// Special-case-recognize "/dev/null" as a valid file.
|
||||||
int valid_gamedir_file(const char* path)
|
bool FileExistsInGameDir(const char *path)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
if (!Q_strcmp(path, "/dev/null"))
|
if (!Q_strcmp(path, "/dev/null"))
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
if (is_absolute_path(path))
|
if (IsAbsolutePath(path))
|
||||||
{
|
{
|
||||||
Q_strncpy(buf, path, sizeof buf);
|
Q_strncpy(buf, path, sizeof buf);
|
||||||
buf[sizeof buf - 1] = '\0';
|
buf[sizeof buf - 1] = '\0';
|
||||||
@ -36,32 +36,32 @@ int valid_gamedir_file(const char* path)
|
|||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
META_DEBUG(5, "Unable to stat '%s': %s", buf, strerror(errno));
|
META_DEBUG(5, "Unable to stat '%s': %s", buf, strerror(errno));
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int reg = S_ISREG(st.st_mode);
|
int reg = S_ISREG(st.st_mode);
|
||||||
if (!reg)
|
if (!reg)
|
||||||
{
|
{
|
||||||
META_DEBUG(5, "Not a regular file: %s", buf);
|
META_DEBUG(5, "Not a regular file: %s", buf);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!st.st_size)
|
if (!st.st_size)
|
||||||
{
|
{
|
||||||
META_DEBUG(5, "Empty file: %s", buf);
|
META_DEBUG(5, "Empty file: %s", buf);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0 && reg)
|
if (ret == 0 && reg)
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turns path into a full path:
|
// Turns path into a full path:
|
||||||
// - if not absolute, prepends gamedir
|
// - if not absolute, prepends gamedir
|
||||||
// - calls realpath() to collapse ".." and such
|
// - calls realpath() to collapse ".." and such
|
||||||
// - calls normalize_pathname() to fix backslashes, etc
|
// - calls NormalizePath() to fix backslashes, etc
|
||||||
//
|
//
|
||||||
// Much like realpath, buffer pointed to by fullpath is assumed to be
|
// Much like realpath, buffer pointed to by fullpath is assumed to be
|
||||||
// able to store a string of PATH_MAX length.
|
// able to store a string of PATH_MAX length.
|
||||||
@ -70,7 +70,7 @@ char* full_gamedir_path(const char* path, char* fullpath)
|
|||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
// Build pathname from filename, plus gamedir if relative path.
|
// Build pathname from filename, plus gamedir if relative path.
|
||||||
if (is_absolute_path(path))
|
if (IsAbsolutePath(path))
|
||||||
{
|
{
|
||||||
Q_strncpy(buf, path, sizeof buf - 1);
|
Q_strncpy(buf, path, sizeof buf - 1);
|
||||||
buf[sizeof buf - 1] = '\0';
|
buf[sizeof buf - 1] = '\0';
|
||||||
@ -86,6 +86,6 @@ char* full_gamedir_path(const char* path, char* fullpath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replace backslashes, etc.
|
// Replace backslashes, etc.
|
||||||
normalize_pathname(fullpath);
|
NormalizePath(fullpath);
|
||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
void __declspec(noreturn) do_exit(int exitval);
|
void __declspec(noreturn) do_exit(int exitval);
|
||||||
|
|
||||||
int valid_gamedir_file(const char *path);
|
bool FileExistsInGameDir(const char *path);
|
||||||
char *full_gamedir_path(const char *path, char *fullpath);
|
char *full_gamedir_path(const char *path, char *fullpath);
|
||||||
|
|
||||||
// Turn a variable/function name into the corresponding string, optionally
|
// Turn a variable/function name into the corresponding string, optionally
|
||||||
|
@ -99,7 +99,7 @@ char *mm_strtok_r(char *s, const char *delim, char **ptrptr)
|
|||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
char* trimbuf(char *str)
|
char *trimbuf(char *str)
|
||||||
{
|
{
|
||||||
char *ibuf;
|
char *ibuf;
|
||||||
|
|
||||||
@ -119,19 +119,22 @@ char* trimbuf(char *str)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void normalize_pathname(char *path)
|
void NormalizePath(char *path)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
char *cp;
|
char *cp;
|
||||||
|
for (cp = path; *cp; cp++)
|
||||||
|
{
|
||||||
|
if (isupper(*cp))
|
||||||
|
*cp = tolower(*cp);
|
||||||
|
|
||||||
for (cp = path; *cp; cp++) {
|
if (*cp == '\\')
|
||||||
if (isupper(*cp)) *cp = tolower(*cp);
|
*cp = '/';
|
||||||
if (*cp == '\\') *cp = '/';
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_absolute_path(const char *path)
|
bool IsAbsolutePath(const char *path)
|
||||||
{
|
{
|
||||||
if (path[0] == '/') return true;
|
if (path[0] == '/') return true;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -161,7 +164,7 @@ char *realpath(const char *file_name, char *resolved_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FindClose(handle);
|
FindClose(handle);
|
||||||
normalize_pathname(resolved_name);
|
NormalizePath(resolved_name);
|
||||||
return resolved_name;
|
return resolved_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,5 +54,5 @@ char *realpath(const char *file_name, char *resolved_name);
|
|||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
char* trimbuf(char *str);
|
char* trimbuf(char *str);
|
||||||
void normalize_pathname(char *path);
|
void NormalizePath(char *path);
|
||||||
bool is_absolute_path(const char *path);
|
bool IsAbsolutePath(const char *path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user