core-legacy/CSmmAPI.cpp
changeset 714 966f819588a2
parent 689 4065ba5e9155
child 747 9563de0165f7
     1.1 --- a/core-legacy/CSmmAPI.cpp	Sun May 16 23:21:08 2010 -0400
     1.2 +++ b/core-legacy/CSmmAPI.cpp	Wed May 19 01:28:55 2010 -0500
     1.3 @@ -1,5 +1,5 @@
     1.4  /* ======== SourceMM ========
     1.5 - * Copyright (C) 2004-2009 Metamod:Source Development Team
     1.6 + * Copyright (C) 2004-2010 Metamod:Source Development Team
     1.7   * No warranties of any kind
     1.8   *
     1.9   * License: zlib/libpng
    1.10 @@ -16,6 +16,9 @@
    1.11  #include "util.h"
    1.12  #include "sh_memory.h"
    1.13  #include <setjmp.h>
    1.14 +#if defined __linux__
    1.15 +#include <sys/stat.h>
    1.16 +#endif
    1.17  
    1.18  /**
    1.19   * @brief Implementation of main API interface
    1.20 @@ -607,3 +610,44 @@
    1.21  {
    1.22  	return g_Engine.original ? SOURCE_ENGINE_ORIGINAL : SOURCE_ENGINE_EPISODEONE;
    1.23  }
    1.24 +
    1.25 +void CSmmAPI::GetFullPluginPath(const char *plugin, char *buffer, size_t len)
    1.26 +{
    1.27 +	const char *pext, *ext;
    1.28 +
    1.29 +	/* First find if it's an absolute path or not... */
    1.30 +	if (plugin[0] == '/' || strncmp(&(plugin[1]), ":\\", 2) == 0)
    1.31 +	{
    1.32 +		UTIL_Format(buffer, len, plugin);
    1.33 +		return;
    1.34 +	}
    1.35 +
    1.36 +	/* Attempt to find a file extension */
    1.37 +	pext = UTIL_GetExtension(plugin);
    1.38 +	/* Add an extension if there's none there */
    1.39 +	if (!pext)
    1.40 +	{
    1.41 +#if defined WIN32 || defined _WIN32
    1.42 +		ext = ".dll";
    1.43 +#else
    1.44 +		ext = "_i486.so";
    1.45 +#endif
    1.46 +	}
    1.47 +	else
    1.48 +	{
    1.49 +		ext = "";
    1.50 +	}
    1.51 +
    1.52 +	/* Format the new path */
    1.53 +	PathFormat(buffer, len, "%s/%s%s", g_ModPath.c_str(), plugin, ext);
    1.54 +
    1.55 +#if defined __linux__
    1.56 +	/* If path was passed without extension and it doesn't exist with "_i486.so" try ".so" */
    1.57 +	struct stat s;
    1.58 +	if (!pext && stat(buffer, &s) != 0)
    1.59 +	{
    1.60 +		PathFormat(buffer, len, "%s/%s.so", g_ModPath.c_str(), plugin);
    1.61 +	}
    1.62 +#endif
    1.63 +}
    1.64 +