6
6
#include " legacy/engine/EngineOwnData.h"
7
7
#include " ll/api/chrono/GameChrono.h"
8
8
#include " ll/api/coro/CoroTask.h"
9
- #include " ll/api/io/FileUtils.h"
9
+ #include " ll/api/io/FileUtils.h" // IWYU pragma: keep
10
10
#include " ll/api/mod/Mod.h"
11
11
#include " ll/api/mod/ModManager.h"
12
12
#include " ll/api/service/GamingStatus.h"
@@ -56,14 +56,15 @@ bool LLSERemoveCmdRegister(script::ScriptEngine* engine);
56
56
bool LLSERemoveCmdCallback (script::ScriptEngine* engine);
57
57
bool LLSERemoveAllExportedFuncs (script::ScriptEngine* engine);
58
58
bool LLSECallEventsOnHotLoad (ScriptEngine* engine);
59
- bool LLSECallEventsOnHotUnload (ScriptEngine* engine);
59
+ bool LLSECallEventsOnUnload (ScriptEngine* engine);
60
60
61
61
namespace lse {
62
62
63
63
PluginManager::PluginManager () : ll::mod::ModManager(PluginManagerName) {}
64
64
PluginManager::~PluginManager () = default ;
65
65
66
66
ll::Expected<> PluginManager::load (ll::mod::Manifest manifest) {
67
+ auto & logger = lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ();
67
68
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
68
69
std::filesystem::path dirPath = ll::mod::getModsRoot () / manifest.name ; // Plugin path
69
70
std::string entryPath =
@@ -78,22 +79,17 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
78
79
PythonHelper::getPluginPackDependencyFilePath (ll::string_utils::u8str2str (dirPath.u8string ()));
79
80
if (!dependTmpFilePath.empty ()) {
80
81
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
+ ));
86
85
87
86
if ((exitCode = PythonHelper::executePipCommand (
88
87
" pip install -r \" " + dependTmpFilePath + " \" -t \" "
89
88
+ ll::string_utils::u8str2str (realPackageInstallDir.u8string ()) + " \" --disable-pip-version-check "
90
89
))
91
90
== 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)));
97
93
98
94
// remove temp dependency file after installation
99
95
std::error_code ec;
@@ -111,19 +107,15 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
111
107
if (NodeJsHelper::doesPluginPackHasDependency (ll::string_utils::u8str2str (dirPath.u8string ()))
112
108
&& !std::filesystem::exists (std::filesystem::path (dirPath) / " node_modules" )) {
113
109
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
+ ));
119
113
if ((exitCode = NodeJsHelper::executeNpmCommand (
120
114
{" install" , " --omit=dev" , " --no-fund" },
121
115
ll::string_utils::u8str2str (dirPath.u8string ())
122
116
))
123
117
!= 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)));
127
119
}
128
120
}
129
121
#endif
@@ -260,9 +252,7 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
260
252
#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
261
253
LLSERemoveTimeTaskData (scriptEngine);
262
254
#endif
263
- if (ll::getGamingStatus () == ll::GamingStatus::Running) {
264
- LLSECallEventsOnHotUnload (scriptEngine);
265
- }
255
+ LLSECallEventsOnUnload (scriptEngine);
266
256
LLSERemoveAllEventListeners (scriptEngine);
267
257
LLSERemoveCmdRegister (scriptEngine);
268
258
LLSERemoveCmdCallback (scriptEngine);
@@ -296,6 +286,8 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
296
286
}
297
287
298
288
return {};
289
+ } catch (const script::Exception& e) {
290
+ return ll::makeStringError (" Failed to unload plugin {0}: {1}" _tr (name, " Unknown script exception" ));
299
291
} catch (const std::exception& e) {
300
292
return ll::makeStringError (" Failed to unload plugin {0}: {1}" _tr (name, e.what ()));
301
293
}
0 commit comments