core/systems/PluginSys.cpp
changeset 333 b668cbd49c35
parent 327 e244337a9b38
child 336 3f4073018d76
     1.1 --- a/core/systems/PluginSys.cpp	Fri Jan 19 23:30:22 2007 +0000
     1.2 +++ b/core/systems/PluginSys.cpp	Sat Jan 20 02:12:53 2007 +0000
     1.3 @@ -449,6 +449,35 @@
     1.4  	return (m_status <= Plugin_Paused) ? true : false;
     1.5  }
     1.6  
     1.7 +time_t CPlugin::GetFileTimeStamp()
     1.8 +{
     1.9 +	char path[PLATFORM_MAX_PATH+1];
    1.10 +	g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "plugins/%s", m_filename);
    1.11 +#ifdef PLATFORM_WINDOWS
    1.12 +	struct _stat s;
    1.13 +	if (_stat(path, &s) != 0)
    1.14 +#else if defined PLATFORM_POSIX
    1.15 +	struct stat s;
    1.16 +	if (stat(path, &s) != 0)
    1.17 +#endif
    1.18 +	{
    1.19 +		g_Logger.LogError("Could not obtain plugin time stamp, error: %d", errno);
    1.20 +		return 0;
    1.21 +	} else {
    1.22 +		return s.st_mtime;
    1.23 +	}
    1.24 +}
    1.25 +
    1.26 +time_t CPlugin::GetTimeStamp() const
    1.27 +{
    1.28 +	return m_LastAccess;
    1.29 +}
    1.30 +
    1.31 +void CPlugin::SetTimeStamp(time_t t)
    1.32 +{
    1.33 +	m_LastAccess = t;
    1.34 +}
    1.35 +
    1.36  /*******************
    1.37   * PLUGIN ITERATOR *
    1.38   *******************/
    1.39 @@ -681,6 +710,10 @@
    1.40  		}
    1.41  	}
    1.42  
    1.43 +	/* Save the time stamp */
    1.44 +	time_t t = pPlugin->GetFileTimeStamp();
    1.45 +	pPlugin->SetTimeStamp(t);
    1.46 +
    1.47  	if (_plugin)
    1.48  	{
    1.49  		*_plugin = pPlugin;
    1.50 @@ -1522,3 +1555,31 @@
    1.51  	g_RootMenu.DrawGenericOption("info", "Information about a plugin");
    1.52  	g_RootMenu.DrawGenericOption("debug", "Toggle debug mode on a plugin");
    1.53  }
    1.54 +
    1.55 +void CPluginManager::ReloadOrUnloadPlugins()
    1.56 +{
    1.57 +	List<CPlugin *>::iterator iter;
    1.58 +	List<CPlugin *> tmp_list = m_plugins;
    1.59 +	CPlugin *pl;
    1.60 +	time_t t;
    1.61 +
    1.62 +	for (iter=tmp_list.begin(); iter!=tmp_list.end(); iter++)
    1.63 +	{
    1.64 +		pl = (*iter);
    1.65 +		if (pl->GetType() ==  PluginType_MapOnly)
    1.66 +		{
    1.67 +			UnloadPlugin((IPlugin *)pl);
    1.68 +		} else if (pl->GetType() == PluginType_MapUpdated) {
    1.69 +			t=pl->GetFileTimeStamp();
    1.70 +			if (!t)
    1.71 +			{
    1.72 +				continue;
    1.73 +			}
    1.74 +			if (t > pl->GetTimeStamp())
    1.75 +			{
    1.76 +				pl->SetTimeStamp(t);
    1.77 +				UnloadPlugin((IPlugin *)pl);
    1.78 +			}
    1.79 +		}
    1.80 +	}
    1.81 +}