Skip to content

Commit d3237c6

Browse files
authored
fix: fixed chinese path related problems #24 (#30)
1 parent c6258c5 commit d3237c6

File tree

6 files changed

+38
-57
lines changed

6 files changed

+38
-57
lines changed

src/legacy/main/Loader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ void LoadDepends() {
4242
if (!content) throw("Fail to open plugin file!");
4343
depends.emplace(path, *content);
4444
lse::getSelfPluginInstance().getLogger().info(
45-
"llse.loader.loadDepends.success"_tr(i.path().filename().string())
45+
"llse.loader.loadDepends.success"_tr(ll::string_utils::u8str2str(i.path().filename().u8string()))
4646
);
4747
} catch (std::exception e) {
4848
lse::getSelfPluginInstance().getLogger().warn(
49-
"llse.loader.loadDepends.fail"_tr(i.path().filename().string())
49+
"llse.loader.loadDepends.fail"_tr(ll::string_utils::u8str2str(i.path().filename().u8string()))
5050
);
5151
lse::getSelfPluginInstance().getLogger().warn(ll::string_utils::tou8str(e.what()));
5252
} catch (...) {
5353
lse::getSelfPluginInstance().getLogger().warn(
54-
"llse.loader.loadDepends.fail"_tr(i.path().filename().string())
54+
"llse.loader.loadDepends.fail"_tr(ll::string_utils::u8str2str(i.path().filename().u8string()))
5555
);
5656
}
5757
}

src/legacy/main/PluginManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool PluginManager::loadPlugin(const std::string& fileOrDirPath, bool isHotLoad,
5454
}
5555

5656
// Get bacis information
57-
bool isPluginPackage = std::filesystem::is_directory(fileOrDirPath);
57+
bool isPluginPackage = std::filesystem::is_directory(ll::string_utils::str2wstr(fileOrDirPath));
5858
string backendType = getPluginBackendType(fileOrDirPath);
5959
if (backendType.empty()) {
6060
lse::getSelfPluginInstance().getLogger().error(fileOrDirPath + " is not a valid plugin path!");

src/lse/Entry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ auto loadBaseLib(ll::plugin::NativePlugin& self) -> bool {
150150
auto content = ll::file_utils::readFile(path);
151151

152152
if (!content) {
153-
throw std::runtime_error(fmt::format("failed to read {}", path.string()));
153+
throw std::runtime_error(fmt::format("failed to read {}", ll::string_utils::u8str2str(path.u8string())));
154154
}
155155

156-
depends.emplace(path.string(), *content);
156+
depends.emplace(ll::string_utils::u8str2str(path.u8string()), *content);
157157

158158
return true;
159159
}

src/lse/PluginManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
6767

6868
logger.info("loading plugin {}", manifest.name);
6969

70-
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
71-
auto entryPath = pluginDir / manifest.entry;
70+
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / ll::string_utils::str2wstr(manifest.name));
71+
auto entryPath = pluginDir / ll::string_utils::str2wstr(manifest.entry);
7272

73-
if (!::PluginManager::loadPlugin(entryPath.string(), false, true)) {
73+
if (!::PluginManager::loadPlugin(ll::string_utils::u8str2str(entryPath.u8string()), false, true)) {
7474
throw std::runtime_error(fmt::format("failed to load plugin {}", manifest.name));
7575
}
7676
return true;

src/lse/PluginMigration.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ auto migratePlugin(const std::filesystem::path& path) -> void {
3131

3232
auto& logger = self.getLogger();
3333

34-
logger.info("migrating legacy plugin at {}", path.string());
34+
logger.info("migrating legacy plugin at {}", ll::string_utils::u8str2str(path.u8string()));
3535

3636
auto& pluginManager = getPluginManager();
3737

@@ -43,22 +43,22 @@ auto migratePlugin(const std::filesystem::path& path) -> void {
4343

4444
if (std::filesystem::exists(pluginDir / pluginFileName)) {
4545
throw std::runtime_error(
46-
fmt::format("failed to migrate legacy plugin at {}: {} already exists", path.string(), pluginDir.string())
46+
fmt::format("failed to migrate legacy plugin at {}: {} already exists", ll::string_utils::u8str2str(path.u8string()), ll::string_utils::u8str2str(pluginDir.u8string()))
4747
);
4848
}
4949

5050
if (!std::filesystem::exists(pluginDir)) {
5151
if (!std::filesystem::create_directory(pluginDir)) {
52-
throw std::runtime_error(fmt::format("failed to create directory {}", pluginDir.string()));
52+
throw std::runtime_error(fmt::format("failed to create directory {}", ll::string_utils::u8str2str(pluginDir.u8string())));
5353
}
5454
}
5555

5656
// Move plugin file.
5757
std::filesystem::rename(path, pluginDir / pluginFileName);
5858

5959
ll::plugin::Manifest manifest{
60-
.entry = pluginFileName.string(),
61-
.name = pluginFileBaseName.string(),
60+
.entry = ll::string_utils::u8str2str(pluginFileName.u8string()),
61+
.name = ll::string_utils::u8str2str(pluginFileBaseName.u8string()),
6262
.type = pluginType,
6363
.dependencies =
6464
std::unordered_set<ll::plugin::Dependency>{

xmake.lua

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,49 @@
11
add_rules("mode.debug", "mode.release")
22

33
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
4+
45
add_requires(
56
"demangler v2.0.0",
67
"dyncall 1.4",
78
"fmt 10.1.1",
89
"legacymoney 0.2.0",
910
"legacyparticleapi 0.2.0",
11+
"legacyremotecall 0.2.0",
1012
"levilamina 0.7.2",
1113
"lightwebsocketclient 1.0.0",
1214
"magic_enum v0.9.0",
15+
"more-events develop",
1316
"nlohmann_json 3.11.2",
1417
"openssl 1.1.1-w",
1518
"simpleini v4.19",
1619
"sqlite3 3.43.0+200",
17-
"toml++ v3.4.0",
18-
"legacyremotecall 0.2.0"
20+
"toml++ v3.4.0"
1921
)
20-
add_requires("cpp-httplib v0.14.0", {configs={shared=false, ssl=true, zlib=true}})
21-
add_requires("scriptx", {configs={backend=get_config("backend")}})
22+
add_requires("cpp-httplib v0.14.0", {configs={ssl=true, zlib=true}})
23+
24+
if is_config("backend", "lua") then
25+
add_requires("scriptx 3.2.0", {configs={backend="Lua"}})
26+
27+
elseif is_config("backend", "quickjs") then
28+
add_requires("scriptx 3.2.0", {configs={backend="QuickJs"}})
2229

23-
set_runtimes("MD") -- For compatibility with the /MD build configuration of ScriptX.
30+
end
31+
32+
if not has_config("vs_runtime") then
33+
set_runtimes("MD")
34+
end
2435

2536
option("backend")
2637
set_default("lua")
2738
set_values("lua", "quickjs")
2839

29-
package("quickjs")
30-
add_urls("https://github.com/LiteLDev/ScriptX/releases/download/prebuilt/quickjs.zip")
31-
add_versions("latest", "af0c38b0cf80aa1deb58e727e408477fffcc6f5f57da537dffc335861d652ed0")
40+
package("more-events")
41+
add_urls("https://github.com/LiteLDev/MoreEvents.git")
3242

33-
on_install(function (package)
34-
os.cp("*", package:installdir())
35-
end)
36-
37-
package("scriptx")
38-
add_configs("backend", {default = "lua", values = {"lua", "quickjs"}})
39-
add_includedirs(
40-
"src/include/"
41-
)
42-
add_urls("https://github.com/LiteLDev/ScriptX/releases/download/prebuilt/scriptx.zip")
43-
add_versions("latest", "dd5fb21370a59f38e4c33f48f4a6eecb25692283e4d49bbee983453e05b128ab")
43+
add_deps("levilamina 0.7.2")
4444

4545
on_install(function (package)
46-
os.cp("*", package:installdir())
47-
end)
48-
49-
on_load(function (package)
50-
local backend = package:config("backend")
51-
52-
local deps = {
53-
lua = "lua v5.4.6",
54-
quickjs = "quickjs",
55-
}
56-
57-
local scriptx_backends = {
58-
lua = "Lua",
59-
quickjs = "QuickJs",
60-
}
61-
62-
print("Using ScriptX config: backend=" .. backend .. ", scriptx_backend=" .. scriptx_backends[backend])
63-
64-
package:add("defines", "SCRIPTX_BACKEND=" .. scriptx_backends[backend])
65-
package:add("defines", "SCRIPTX_BACKEND_TRAIT_PREFIX=../backend/" .. scriptx_backends[backend] .. "/trait/Trait")
66-
package:add("deps", deps[backend])
67-
package:add("links", "scriptx_" .. scriptx_backends[backend])
46+
import("package.tools.xmake").install(package)
6847
end)
6948

7049
target("legacy-script-engine")
@@ -92,15 +71,16 @@ target("legacy-script-engine")
9271
"fmt",
9372
"legacymoney",
9473
"legacyparticleapi",
74+
"legacyremotecall",
9575
"levilamina",
9676
"lightwebsocketclient",
9777
"magic_enum",
78+
"moreevents",
9879
"nlohmann_json",
9980
"scriptx",
10081
"simpleini",
10182
"sqlite3",
102-
"toml++",
103-
"legacyremotecall"
83+
"toml++"
10484
)
10585
add_shflags(
10686
"/DELAYLOAD:bedrock_server.dll" -- To use forged symbols of SymbolProvider.
@@ -134,3 +114,4 @@ target("legacy-script-engine")
134114

135115
plugin_packer.pack_plugin(target,plugin_define)
136116
end)
117+

0 commit comments

Comments
 (0)