Skip to content

Commit d8d82e6

Browse files
committed
refactor: replace string() with u8string()
1 parent 744a0ae commit d8d82e6

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/legacy/main/PythonHelper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ bool processConsolePipCmd(const std::string& cmd) {
231231
// (./plugins/legacy-script-engine/lib/python-env/Lib/site-packages)
232232
int executePipCommand(std::string cmd) {
233233
if (cmd.find("--disable-pip-version-check") == std::string::npos) cmd += " --disable-pip-version-check";
234-
cmd = (lse::getSelfPluginInstance().getPluginDir() / "python.exe").string() + " -m" + cmd;
234+
cmd = ll::string_utils::u8str2str((lse::getSelfPluginInstance().getPluginDir() / "python.exe").u8string()) + " -m"
235+
+ cmd;
235236

236237
SECURITY_ATTRIBUTES sa;
237238
sa.nLength = sizeof(SECURITY_ATTRIBUTES);

src/lse/PluginManager.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,17 @@ PluginManager::PluginManager() : ll::plugin::PluginManager(PluginManagerName) {}
6464
ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) {
6565
auto& logger = getSelfPluginInstance().getLogger();
6666
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
67-
std::filesystem::path dirPath = ll::plugin::getPluginsRoot() / manifest.name; // Plugin path
68-
std::string entryPath = PythonHelper::findEntryScript(dirPath.string()); // Plugin entry
67+
std::filesystem::path dirPath = ll::plugin::getPluginsRoot() / manifest.name; // Plugin path
68+
std::string entryPath =
69+
PythonHelper::findEntryScript(ll::string_utils::u8str2str(dirPath.u8string())); // Plugin entry
6970
// if (entryPath.empty()) return false;
7071
// std::string pluginName = PythonHelper::getPluginPackageName(dirPath.string()); // Plugin name
7172

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

105107
// Run "npm install" if needed
106-
if (NodeJsHelper::doesPluginPackHasDependency(dirPath.string())
108+
if (NodeJsHelper::doesPluginPackHasDependency(ll::string_utils::u8str2str(dirPath.u8string()))
107109
&& !std::filesystem::exists(std::filesystem::path(dirPath) / "node_modules")) {
108110
int exitCode = 0;
109111
lse::getSelfPluginInstance().getLogger().info("llse.loader.nodejs.executeNpmInstall.start"_tr(
110112
fmt::arg("name", ll::string_utils::u8str2str(dirPath.filename().u8string()))
111113
));
112-
if ((exitCode = NodeJsHelper::executeNpmCommand("npm install", dirPath.string())) == 0)
114+
if ((exitCode = NodeJsHelper::executeNpmCommand("npm install", ll::string_utils::u8str2str(dirPath.u8string())))
115+
== 0)
113116
lse::getSelfPluginInstance().getLogger().info("llse.loader.nodejs.executeNpmInstall.success"_tr());
114117
else
115118
lse::getSelfPluginInstance().getLogger().error(
@@ -173,14 +176,22 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) {
173176
// Load the plugin entry.
174177
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
175178
auto entryPath = pluginDir / manifest.entry;
176-
ENGINE_OWN_DATA()->pluginFileOrDirPath = entryPath.string();
179+
ENGINE_OWN_DATA()->pluginFileOrDirPath = ll::string_utils::u8str2str(entryPath.u8string());
177180
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
178-
if (!PythonHelper::loadPluginCode(&scriptEngine, entryPath.string(), dirPath.string())) {
181+
if (!PythonHelper::loadPluginCode(
182+
&scriptEngine,
183+
ll::string_utils::u8str2str(entryPath.u8string()),
184+
ll::string_utils::u8str2str(dirPath.u8string())
185+
)) {
179186
return ll::makeStringError(fmt::format("failed to load plugin code"));
180187
}
181188
#endif
182189
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
183-
if (!NodeJsHelper::loadPluginCode(&scriptEngine, entryPath.string(), dirPath.string())) {
190+
if (!NodeJsHelper::loadPluginCode(
191+
&scriptEngine,
192+
ll::string_utils::u8str2str(entryPath.u8string()),
193+
ll::string_utils::u8str2str(dirPath.u8string())
194+
)) {
184195
return ll::makeStringError(fmt::format("failed to load plugin code"));
185196
}
186197
#endif

src/lse/PluginMigration.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::pa
8686
};
8787
#endif
8888
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
89-
lse::legacy::UncompressFile(path.string(), pluginDir.string(), 30000);
89+
lse::legacy::UncompressFile(
90+
ll::string_utils::u8str2str(path.u8string()),
91+
ll::string_utils::u8str2str(pluginDir.u8string()),
92+
30000
93+
);
9094
ll::plugin::Manifest manifest{
91-
.entry = NodeJsHelper::findEntryScript(path.string()),
95+
.entry = NodeJsHelper::findEntryScript(ll::string_utils::u8str2str(path.u8string())),
9296
.name = ll::string_utils::u8str2str(pluginFileBaseName.u8string()),
9397
.type = pluginType,
9498
.dependencies =

0 commit comments

Comments
 (0)