66#include " legacy/engine/EngineOwnData.h"
77#include " ll/api/chrono/GameChrono.h"
88#include " ll/api/coro/CoroTask.h"
9- #include " ll/api/io/FileUtils.h"
9+ #include " ll/api/io/FileUtils.h" // IWYU pragma: keep
1010#include " ll/api/mod/Mod.h"
1111#include " ll/api/mod/ModManager.h"
1212#include " ll/api/service/GamingStatus.h"
@@ -56,14 +56,15 @@ bool LLSERemoveCmdRegister(script::ScriptEngine* engine);
5656bool LLSERemoveCmdCallback (script::ScriptEngine* engine);
5757bool LLSERemoveAllExportedFuncs (script::ScriptEngine* engine);
5858bool LLSECallEventsOnHotLoad (ScriptEngine* engine);
59- bool LLSECallEventsOnHotUnload (ScriptEngine* engine);
59+ bool LLSECallEventsOnUnload (ScriptEngine* engine);
6060
6161namespace lse {
6262
6363PluginManager::PluginManager () : ll::mod::ModManager(PluginManagerName) {}
6464PluginManager::~PluginManager () = default ;
6565
6666ll::Expected<> PluginManager::load (ll::mod::Manifest manifest) {
67+ auto & logger = lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ();
6768#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
6869 std::filesystem::path dirPath = ll::mod::getModsRoot () / manifest.name ; // Plugin path
6970 std::string entryPath =
@@ -78,22 +79,17 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
7879 PythonHelper::getPluginPackDependencyFilePath (ll::string_utils::u8str2str (dirPath.u8string ()));
7980 if (!dependTmpFilePath.empty ()) {
8081 int exitCode = 0 ;
81- lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ().info (
82- " Executing \" pip install\" for plugin {name}..." _tr (
83- fmt::arg (" name" , ll::string_utils::u8str2str (dirPath.filename ().u8string ()))
84- )
85- );
82+ logger.info (" Executing \" pip install\" for plugin {name}..." _tr (
83+ fmt::arg (" name" , ll::string_utils::u8str2str (dirPath.filename ().u8string ()))
84+ ));
8685
8786 if ((exitCode = PythonHelper::executePipCommand (
8887 " pip install -r \" " + dependTmpFilePath + " \" -t \" "
8988 + ll::string_utils::u8str2str (realPackageInstallDir.u8string ()) + " \" --disable-pip-version-check "
9089 ))
9190 == 0 ) {
92- lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ().info (" Pip finished successfully." _tr ());
93- } else
94- lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ().error (
95- " Error occurred. Exit code: {code}" _tr (fmt::arg (" code" , exitCode))
96- );
91+ logger.info (" Pip finished successfully." _tr ());
92+ } else logger.error (" Error occurred. Exit code: {code}" _tr (fmt::arg (" code" , exitCode)));
9793
9894 // remove temp dependency file after installation
9995 std::error_code ec;
@@ -111,19 +107,15 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
111107 if (NodeJsHelper::doesPluginPackHasDependency (ll::string_utils::u8str2str (dirPath.u8string ()))
112108 && !std::filesystem::exists (std::filesystem::path (dirPath) / " node_modules" )) {
113109 int exitCode = 0 ;
114- lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ().info (
115- " Executing \" npm install\" for plugin {name}..." _tr (
116- fmt::arg (" name" , ll::string_utils::u8str2str (dirPath.filename ().u8string ()))
117- )
118- );
110+ logger.info (" Executing \" npm install\" for plugin {name}..." _tr (
111+ fmt::arg (" name" , ll::string_utils::u8str2str (dirPath.filename ().u8string ()))
112+ ));
119113 if ((exitCode = NodeJsHelper::executeNpmCommand (
120114 {" install" , " --omit=dev" , " --no-fund" },
121115 ll::string_utils::u8str2str (dirPath.u8string ())
122116 ))
123117 != 0 ) {
124- lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ().error (
125- " Error occurred. Exit code: {code}" _tr (fmt::arg (" code" , exitCode))
126- );
118+ logger.error (" Error occurred. Exit code: {code}" _tr (fmt::arg (" code" , exitCode)));
127119 }
128120 }
129121#endif
@@ -260,9 +252,7 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
260252#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
261253 LLSERemoveTimeTaskData (scriptEngine);
262254#endif
263- if (ll::getGamingStatus () == ll::GamingStatus::Running) {
264- LLSECallEventsOnHotUnload (scriptEngine);
265- }
255+ LLSECallEventsOnUnload (scriptEngine);
266256 LLSERemoveAllEventListeners (scriptEngine);
267257 LLSERemoveCmdRegister (scriptEngine);
268258 LLSERemoveCmdCallback (scriptEngine);
@@ -296,6 +286,8 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
296286 }
297287
298288 return {};
289+ } catch (const script::Exception& e) {
290+ return ll::makeStringError (" Failed to unload plugin {0}: {1}" _tr (name, " Unknown script exception" ));
299291 } catch (const std::exception& e) {
300292 return ll::makeStringError (" Failed to unload plugin {0}: {1}" _tr (name, e.what ()));
301293 }
0 commit comments