Skip to content

Commit 424b054

Browse files
committed
Revert "fix: fixed chinese path related problems(issues#24)"
This reverts commit 9ff739d.
1 parent a10bec2 commit 424b054

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

src/legacy/api/FileSystemAPI.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ FileClass* FileClass::constructor(const Arguments& args) {
121121
FileOpenMode fMode = (FileOpenMode)(args[1].toInt());
122122
// Auto Create
123123
if (fMode == FileOpenMode::ReadMode || fMode == FileOpenMode::WriteMode) {
124-
std::fstream tmp(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP), std::ios_base::app);
124+
std::fstream tmp(ll::string_utils::str2wstr(path), std::ios_base::app);
125125
tmp.flush();
126126
tmp.close();
127127
}
@@ -141,7 +141,7 @@ FileClass* FileClass::constructor(const Arguments& args) {
141141
mode |= std::ios_base::binary;
142142
}
143143

144-
std::fstream fs(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP), mode);
144+
std::fstream fs(ll::string_utils::str2wstr(path), mode);
145145
if (!fs.is_open()) {
146146
LOG_ERROR_WITH_SCRIPT_INFO("Fail to Open File " + path + "!\n");
147147
return nullptr;
@@ -164,7 +164,7 @@ Local<Value> FileClass::getPath() {
164164

165165
Local<Value> FileClass::getAbsolutePath() {
166166
try {
167-
return String::newString(canonical(std::filesystem::path(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP))).u8string());
167+
return String::newString(canonical(std::filesystem::path(ll::string_utils::str2wstr(path))).u8string());
168168
}
169169
CATCH("Fail in getAbsolutePath!");
170170
}
@@ -533,7 +533,7 @@ Local<Value> PathDelete(const Arguments& args) {
533533
CHECK_ARG_TYPE(args[0], ValueKind::kString);
534534

535535
try {
536-
return Boolean::newBoolean(remove_all(ll::string_utils::str2wstr(args[0].asString().toString(), ll::string_utils::CodePage::DefaultACP)) > 0);
536+
return Boolean::newBoolean(remove_all(ll::string_utils::str2wstr(args[0].asString().toString())) > 0);
537537
} catch (const filesystem_error& e) {
538538
LOG_ERROR_WITH_SCRIPT_INFO("Fail to Delete " + args[0].asString().toString() + "!\n");
539539
return Boolean::newBoolean(false);
@@ -546,7 +546,7 @@ Local<Value> PathExists(const Arguments& args) {
546546
CHECK_ARG_TYPE(args[0], ValueKind::kString);
547547

548548
try {
549-
return Boolean::newBoolean(std::filesystem::exists(ll::string_utils::str2wstr(args[0].asString().toString(), ll::string_utils::CodePage::DefaultACP)));
549+
return Boolean::newBoolean(std::filesystem::exists(ll::string_utils::str2wstr(args[0].asString().toString())));
550550
} catch (const filesystem_error& e) {
551551
LOG_ERROR_WITH_SCRIPT_INFO("Fail to Check " + args[0].asString().toString() + "!\n");
552552
return Boolean::newBoolean(false);
@@ -561,8 +561,8 @@ Local<Value> PathCopy(const Arguments& args) {
561561

562562
try {
563563
copy(
564-
ll::string_utils::str2wstr(args[0].asString().toString(), ll::string_utils::CodePage::DefaultACP),
565-
ll::string_utils::str2wstr(args[1].asString().toString(), ll::string_utils::CodePage::DefaultACP)
564+
ll::string_utils::str2wstr(args[0].asString().toString()),
565+
ll::string_utils::str2wstr(args[1].asString().toString())
566566
);
567567
return Boolean::newBoolean(true);
568568
} catch (const filesystem_error& e) {
@@ -579,8 +579,8 @@ Local<Value> PathRename(const Arguments& args) {
579579

580580
try {
581581
rename(
582-
ll::string_utils::str2wstr(args[0].asString().toString(), ll::string_utils::CodePage::DefaultACP),
583-
ll::string_utils::str2wstr(args[1].asString().toString(), ll::string_utils::CodePage::DefaultACP)
582+
ll::string_utils::str2wstr(args[0].asString().toString()),
583+
ll::string_utils::str2wstr(args[1].asString().toString())
584584
);
585585
return Boolean::newBoolean(true);
586586
} catch (const filesystem_error& e) {
@@ -597,10 +597,10 @@ Local<Value> PathMove(const Arguments& args) {
597597

598598
try {
599599
copy(
600-
ll::string_utils::str2wstr(args[0].asString().toString(), ll::string_utils::CodePage::DefaultACP),
601-
ll::string_utils::str2wstr(args[1].asString().toString(), ll::string_utils::CodePage::DefaultACP)
600+
ll::string_utils::str2wstr(args[0].asString().toString()),
601+
ll::string_utils::str2wstr(args[1].asString().toString())
602602
);
603-
remove_all(ll::string_utils::str2wstr(args[0].asString().toString(), ll::string_utils::CodePage::DefaultACP));
603+
remove_all(ll::string_utils::str2wstr(args[0].asString().toString()));
604604
return Boolean::newBoolean(true);
605605
} catch (const filesystem_error& e) {
606606
LOG_ERROR_WITH_SCRIPT_INFO("Fail to Move " + args[0].asString().toString() + "!\n");
@@ -614,7 +614,7 @@ Local<Value> CheckIsDir(const Arguments& args) {
614614
CHECK_ARG_TYPE(args[0], ValueKind::kString);
615615

616616
try {
617-
path p(ll::string_utils::str2wstr(args[0].toStr(), ll::string_utils::CodePage::DefaultACP));
617+
path p(ll::string_utils::str2wstr(args[0].toStr()));
618618
if (!exists(p)) return Boolean::newBoolean(false);
619619

620620
return Boolean::newBoolean(directory_entry(p).is_directory());
@@ -630,7 +630,7 @@ Local<Value> GetFileSize(const Arguments& args) {
630630
CHECK_ARG_TYPE(args[0], ValueKind::kString);
631631

632632
try {
633-
path p(ll::string_utils::str2wstr(args[0].toStr(), ll::string_utils::CodePage::DefaultACP));
633+
path p(ll::string_utils::str2wstr(args[0].toStr()));
634634
if (!exists(p)) return Number::newNumber(0);
635635
if (directory_entry(p).is_directory()) return Number::newNumber(0);
636636

@@ -732,7 +732,7 @@ Local<Value> OpenFile(const Arguments& args) {
732732
FileOpenMode fMode = (FileOpenMode)(args[1].toInt());
733733
std::ios_base::openmode mode = std::ios_base::in;
734734
if (fMode == FileOpenMode::WriteMode) {
735-
std::fstream tmp(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP), std::ios_base::app);
735+
std::fstream tmp(ll::string_utils::str2wstr(path), std::ios_base::app);
736736
tmp.flush();
737737
tmp.close();
738738
mode |= std::ios_base::out;
@@ -744,7 +744,7 @@ Local<Value> OpenFile(const Arguments& args) {
744744
mode |= std::ios_base::binary;
745745
}
746746

747-
std::fstream fs(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP), mode);
747+
std::fstream fs(ll::string_utils::str2wstr(path), mode);
748748
if (!fs.is_open()) {
749749
LOG_ERROR_WITH_SCRIPT_INFO("Fail to Open File " + path + "!\n");
750750
return {};

src/legacy/engine/EngineManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ScriptEngine* EngineManager::getEngine(std::string name, bool onlyLocalEngine) {
8585
if (onlyLocalEngine && getEngineType(engine) != LLSE_BACKEND_TYPE) continue;
8686
auto ownerData = ENGINE_GET_DATA(engine);
8787
auto filename = ll::string_utils::u8str2str(
88-
std::filesystem::path(ll::string_utils::str2wstr(ownerData->pluginFileOrDirPath, ll::string_utils::CodePage::DefaultACP)).filename().u8string()
88+
std::filesystem::path(ll::string_utils::str2wstr(ownerData->pluginFileOrDirPath)).filename().u8string()
8989
);
9090
if (ownerData->pluginName == name || filename == name) return engine;
9191
}

src/legacy/legacyapi/utils/FileHelper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ std::optional<std::string> ReadAllFile(const std::string& filePath, bool isBinar
1313
std::ios_base::openmode mode = std::ios_base::in;
1414
if (isBinary) mode |= std::ios_base::binary;
1515

16-
fRead.open(ll::string_utils::str2wstr(filePath, ll::string_utils::CodePage::DefaultACP), mode);
16+
fRead.open(ll::string_utils::str2wstr(filePath), mode);
1717
if (!fRead.is_open()) {
1818
return std::nullopt;
1919
}
@@ -28,7 +28,7 @@ bool WriteAllFile(const std::string& filePath, const std::string& content, bool
2828
std::ios_base::openmode mode = std::ios_base::out;
2929
if (isBinary) mode |= std::ios_base::binary;
3030

31-
fWrite.open(ll::string_utils::str2wstr(filePath, ll::string_utils::CodePage::DefaultACP), mode);
31+
fWrite.open(ll::string_utils::str2wstr(filePath), mode);
3232
if (!fWrite.is_open()) {
3333
return false;
3434
}
@@ -51,7 +51,7 @@ std::vector<std::string> GetFileNameList(const std::string& dir) {
5151

5252
bool CreateDirs(const std::string path) {
5353
std::error_code ec;
54-
auto ret = std::filesystem::create_directories(std::filesystem::path(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP)), ec);
54+
auto ret = std::filesystem::create_directories(std::filesystem::path(ll::string_utils::str2wstr(path)), ec);
5555
if (ec.value() != 0) {
5656
lse::getSelfPluginInstance().getLogger().error("Fail to create dir, err code: {}", ec.value());
5757
lse::getSelfPluginInstance().getLogger().error(ec.message());

src/legacy/main/PluginManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ using ll::string_utils::str2wstr;
4848
bool PluginManager::loadPlugin(const std::string& fileOrDirPath, bool isHotLoad, bool mustBeCurrentModule) {
4949
if (fileOrDirPath == LLSE_DEBUG_ENGINE_NAME) return true;
5050

51-
if (!std::filesystem::exists(ll::string_utils::str2wstr(fileOrDirPath, ll::string_utils::CodePage::DefaultACP))) {
51+
if (!std::filesystem::exists(ll::string_utils::str2u8str(fileOrDirPath))) {
5252
lse::getSelfPluginInstance().getLogger().error("Plugin not found! Check the path you input again.");
5353
return false;
5454
}
@@ -60,7 +60,7 @@ bool PluginManager::loadPlugin(const std::string& fileOrDirPath, bool isHotLoad,
6060
lse::getSelfPluginInstance().getLogger().error(fileOrDirPath + " is not a valid plugin path!");
6161
return false;
6262
}
63-
std::filesystem::path p(ll::string_utils::str2wstr(fileOrDirPath, ll::string_utils::CodePage::DefaultACP));
63+
std::filesystem::path p(ll::string_utils::str2wstr(fileOrDirPath));
6464
string pluginFileName = RemoveRealAllExtension(ll::string_utils::u8str2str(p.filename().stem().u8string()));
6565

6666
// Uncompress plugin package if needed
@@ -351,7 +351,7 @@ bool PluginManager::unRegisterPlugin(std::string name) {
351351
// Get plugin backend type from its file path (single file plugin)
352352
// or its unpressed dir path (plugin package)
353353
std::string PluginManager::getPluginBackendType(const std::string& path) {
354-
std::filesystem::path filePath(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP));
354+
std::filesystem::path filePath(ll::string_utils::str2wstr(path));
355355
if (!std::filesystem::exists(filePath)) return "";
356356

357357
if (std::filesystem::is_directory(filePath)) {

src/legacy/utils/IniHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#include <filesystem>
88

99
SimpleIni* SimpleIni::create(const std::string& path, const std::string& defContent) {
10-
if (!std::filesystem::exists(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP))) {
10+
if (!std::filesystem::exists(ll::string_utils::str2wstr(path))) {
1111
// 创建新的
1212
std::filesystem::create_directories(
13-
std::filesystem::path(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP)).remove_filename().u8string()
13+
std::filesystem::path(ll::string_utils::str2wstr(path)).remove_filename().u8string()
1414
);
1515

1616
std::ofstream iniFile(path);

src/legacy/utils/JsonHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace nlohmann;
1313

1414
inline ordered_json CreateJson(const std::string& path, const std::string& defContent, bool allowComment = true) {
1515
ordered_json jsonConf;
16-
if (!std::filesystem::exists(ll::string_utils::str2wstr(path, ll::string_utils::CodePage::DefaultACP))) {
16+
if (!std::filesystem::exists(ll::string_utils::str2wstr(path))) {
1717
if (path.find('/') != std::string::npos) { // e.g. plugins/LeviLamina/LeviLamina.json
1818
std::size_t pos = path.find_last_of('/');
1919
if (pos != std::string::npos) {

0 commit comments

Comments
 (0)