From d8d82e69d6bf91ed8ae3feeb7ea38ca8874dd919 Mon Sep 17 00:00:00 2001 From: ShrBox Date: Thu, 9 May 2024 13:19:51 +0800 Subject: [PATCH] refactor: replace string() with u8string() --- src/legacy/main/PythonHelper.cpp | 3 ++- src/lse/PluginManager.cpp | 27 +++++++++++++++++++-------- src/lse/PluginMigration.cpp | 8 ++++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/legacy/main/PythonHelper.cpp b/src/legacy/main/PythonHelper.cpp index e9fa1f3..66581be 100644 --- a/src/legacy/main/PythonHelper.cpp +++ b/src/legacy/main/PythonHelper.cpp @@ -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); diff --git a/src/lse/PluginManager.cpp b/src/lse/PluginManager.cpp index 2479120..0a7b89b 100644 --- a/src/lse/PluginManager.cpp +++ b/src/lse/PluginManager.cpp @@ -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( @@ -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( @@ -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 diff --git a/src/lse/PluginMigration.cpp b/src/lse/PluginMigration.cpp index f3218a0..5727edc 100644 --- a/src/lse/PluginMigration.cpp +++ b/src/lse/PluginMigration.cpp @@ -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 =