mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-25 22:17:45 +00:00
remove module cache code
This commit is contained in:
parent
75202b0782
commit
1d9c12ce1c
1 changed files with 5 additions and 19 deletions
|
@ -55,16 +55,10 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy to temp dir
|
|
||||||
boost::filesystem::path cacheDir( f.parent_path() /= g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.CachePath", "./cache/" ) );
|
|
||||||
boost::filesystem::create_directories( cacheDir );
|
|
||||||
boost::filesystem::path dest( cacheDir /= f.filename().string() );
|
|
||||||
boost::filesystem::copy_file( f, dest, boost::filesystem::copy_option::overwrite_if_exists );
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ModuleHandle handle = LoadLibrary( dest.string().c_str() );
|
ModuleHandle handle = LoadLibrary( path.c_str() );
|
||||||
#else
|
#else
|
||||||
ModuleHandle handle = dlopen( dest.string().c_str(), RTLD_LAZY );
|
ModuleHandle handle = dlopen( path.c_str(), RTLD_LAZY );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( !handle )
|
if( !handle )
|
||||||
|
@ -79,7 +73,7 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
|
||||||
auto info = new ScriptInfo;
|
auto info = new ScriptInfo;
|
||||||
info->handle = handle;
|
info->handle = handle;
|
||||||
info->library_name = f.stem().string();
|
info->library_name = f.stem().string();
|
||||||
info->library_path = dest.string();
|
info->library_path = path;
|
||||||
|
|
||||||
m_scriptMap.insert( std::make_pair( f.stem().string(), info ) );
|
m_scriptMap.insert( std::make_pair( f.stem().string(), info ) );
|
||||||
|
|
||||||
|
@ -120,18 +114,10 @@ bool Core::Scripting::ScriptLoader::unloadScript( ModuleHandle handle )
|
||||||
{
|
{
|
||||||
if( it->second->handle == handle )
|
if( it->second->handle == handle )
|
||||||
{
|
{
|
||||||
auto info = it->second;
|
delete it->second;
|
||||||
m_scriptMap.erase( it );
|
m_scriptMap.erase( it );
|
||||||
|
|
||||||
if( unloadModule( handle ) )
|
return unloadModule( handle );
|
||||||
{
|
|
||||||
// remove cached file
|
|
||||||
boost::filesystem::remove( info->library_path );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue