Skip to content

Commit

Permalink
refactor: replace string() with u8string()
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed May 9, 2024
1 parent 744a0ae commit d8d82e6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/legacy/main/PythonHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ bool processConsolePipCmd(const std::string& cmd) {
// (./plugins/legacy-script-engine/lib/python-env/Lib/site-packages)
int executePipCommand(std::string cmd) {
if (cmd.find("--disable-pip-version-check") == std::string::npos) cmd += " --disable-pip-version-check";
cmd = (lse::getSelfPluginInstance().getPluginDir() / "python.exe").string() + " -m" + cmd;
cmd = ll::string_utils::u8str2str((lse::getSelfPluginInstance().getPluginDir() / "python.exe").u8string()) + " -m"
+ cmd;

SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
Expand Down
27 changes: 19 additions & 8 deletions src/lse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ PluginManager::PluginManager() : ll::plugin::PluginManager(PluginManagerName) {}
ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) {
auto& logger = getSelfPluginInstance().getLogger();
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
std::filesystem::path dirPath = ll::plugin::getPluginsRoot() / manifest.name; // Plugin path
std::string entryPath = PythonHelper::findEntryScript(dirPath.string()); // Plugin entry
std::filesystem::path dirPath = ll::plugin::getPluginsRoot() / manifest.name; // Plugin path
std::string entryPath =
PythonHelper::findEntryScript(ll::string_utils::u8str2str(dirPath.u8string())); // Plugin entry
// if (entryPath.empty()) return false;
// std::string pluginName = PythonHelper::getPluginPackageName(dirPath.string()); // Plugin name

// Run "pip install" if needed
auto realPackageInstallDir = (std::filesystem::path(dirPath) / "site-packages").make_preferred();
if (!std::filesystem::exists(realPackageInstallDir)) {
std::string dependTmpFilePath = PythonHelper::getPluginPackDependencyFilePath(dirPath.string());
std::string dependTmpFilePath =
PythonHelper::getPluginPackDependencyFilePath(ll::string_utils::u8str2str(dirPath.u8string()));
if (!dependTmpFilePath.empty()) {
int exitCode = 0;
lse::getSelfPluginInstance().getLogger().info("llse.loader.python.executePipInstall.start"_tr(
Expand Down Expand Up @@ -103,13 +105,14 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) {
// std::string pluginName = NodeJsHelper::getPluginPackageName(dirPath.string()); // Plugin name

// Run "npm install" if needed
if (NodeJsHelper::doesPluginPackHasDependency(dirPath.string())
if (NodeJsHelper::doesPluginPackHasDependency(ll::string_utils::u8str2str(dirPath.u8string()))
&& !std::filesystem::exists(std::filesystem::path(dirPath) / "node_modules")) {
int exitCode = 0;
lse::getSelfPluginInstance().getLogger().info("llse.loader.nodejs.executeNpmInstall.start"_tr(
fmt::arg("name", ll::string_utils::u8str2str(dirPath.filename().u8string()))
));
if ((exitCode = NodeJsHelper::executeNpmCommand("npm install", dirPath.string())) == 0)
if ((exitCode = NodeJsHelper::executeNpmCommand("npm install", ll::string_utils::u8str2str(dirPath.u8string())))
== 0)
lse::getSelfPluginInstance().getLogger().info("llse.loader.nodejs.executeNpmInstall.success"_tr());
else
lse::getSelfPluginInstance().getLogger().error(
Expand Down Expand Up @@ -173,14 +176,22 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) {
// Load the plugin entry.
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
auto entryPath = pluginDir / manifest.entry;
ENGINE_OWN_DATA()->pluginFileOrDirPath = entryPath.string();
ENGINE_OWN_DATA()->pluginFileOrDirPath = ll::string_utils::u8str2str(entryPath.u8string());
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
if (!PythonHelper::loadPluginCode(&scriptEngine, entryPath.string(), dirPath.string())) {
if (!PythonHelper::loadPluginCode(
&scriptEngine,
ll::string_utils::u8str2str(entryPath.u8string()),
ll::string_utils::u8str2str(dirPath.u8string())
)) {
return ll::makeStringError(fmt::format("failed to load plugin code"));
}
#endif
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
if (!NodeJsHelper::loadPluginCode(&scriptEngine, entryPath.string(), dirPath.string())) {
if (!NodeJsHelper::loadPluginCode(
&scriptEngine,
ll::string_utils::u8str2str(entryPath.u8string()),
ll::string_utils::u8str2str(dirPath.u8string())
)) {
return ll::makeStringError(fmt::format("failed to load plugin code"));
}
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/lse/PluginMigration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::pa
};
#endif
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
lse::legacy::UncompressFile(path.string(), pluginDir.string(), 30000);
lse::legacy::UncompressFile(
ll::string_utils::u8str2str(path.u8string()),
ll::string_utils::u8str2str(pluginDir.u8string()),
30000
);
ll::plugin::Manifest manifest{
.entry = NodeJsHelper::findEntryScript(path.string()),
.entry = NodeJsHelper::findEntryScript(ll::string_utils::u8str2str(path.u8string())),
.name = ll::string_utils::u8str2str(pluginFileBaseName.u8string()),
.type = pluginType,
.dependencies =
Expand Down

0 comments on commit d8d82e6

Please sign in to comment.