Skip to content

Commit

Permalink
refactor: remove lse::legacy::GetFileNameList
Browse files Browse the repository at this point in the history
refactor: remove legacyapi/Base64.h
fix: fix mysql support
  • Loading branch information
ShrBox committed Jan 22, 2025
1 parent d957e80 commit 991acad
Show file tree
Hide file tree
Showing 12 changed files with 988 additions and 1,053 deletions.
8 changes: 3 additions & 5 deletions src/legacy/api/DataAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
#include <string>
#include <vector>

#include "legacyapi/Base64.h"
#include "legacyapi/utils/FileHelper.h"
#include "ll/api/utils/Base64Utils.h"
#include "ll/api/io/FileUtils.h"
#include "ll/api/service/Bedrock.h"
#include "ll/api/service/PlayerInfo.h"
#include "ll/api/utils/StringUtils.h"
#include "main/EconomicSystem.h"
#include "mc/deps/crypto/hash/Hash.h"
#include "mc/world/actor/player/Player.h"
#include "utils/JsonHelper.h"

//////////////////// Class Definition ////////////////////
Expand Down Expand Up @@ -924,7 +922,7 @@ Local<Value> DataClass::toBase64(const Arguments& args) {
LOG_WRONG_ARG_TYPE(__FUNCTION__);
return Local<Value>();
}
return String::newString(Base64::Encode(data));
return String::newString(ll::base64_utils::encode(data));
}
CATCH("Fail in ToBase64!");
}
Expand All @@ -939,7 +937,7 @@ Local<Value> DataClass::fromBase64(const Arguments& args) {
CHECK_ARG_TYPE(args[1], ValueKind::kBoolean);
isBinary = args[1].asBoolean().value();
}
auto data = Base64::Decode(args[0].asString().toString());
auto data = ll::base64_utils::decode(args[0].asString().toString());
if (isBinary) {
return ByteBuffer::newByteBuffer((void*)data.c_str(), data.size());
} else {
Expand Down
13 changes: 10 additions & 3 deletions src/legacy/api/FileSystemAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ Local<Value> CheckIsDir(const Arguments& args) {
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, "Fail to Get Type of " + args[0].asString().toString() + "!\n");
return {};
}
CATCH("Fail in GetFilesList!");
CATCH("Fail in CheckIsDir!");
}

Local<Value> GetFileSize(const Arguments& args) {
Expand All @@ -630,15 +630,22 @@ Local<Value> GetFileSize(const Arguments& args) {
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, "Fail to Get Size of " + args[0].asString().toString() + "!\n");
return {};
}
CATCH("Fail in GetFilesList!");
CATCH("Fail in GetFileSize!");
}

Local<Value> GetFilesList(const Arguments& args) {
CHECK_ARGS_COUNT(args, 1);
CHECK_ARG_TYPE(args[0], ValueKind::kString);

try {
auto fileList = lse::legacy::GetFileNameList(args[0].asString().toString());
std::filesystem::directory_entry directory(args[0].asString().toU8string());
if (!directory.is_directory()) return {};

std::vector<std::string> fileList;
std::filesystem::directory_iterator deps(directory);
for (auto& i : deps) {
fileList.push_back(ll::string_utils::u8str2str(i.path().filename().u8string()));
}

Local<Array> arr = Array::newArray();
for (auto& file : fileList) arr.add(String::newString(file));
Expand Down
9 changes: 4 additions & 5 deletions src/legacy/api/NbtAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "api/NbtAPI.h"

#include "api/APIHelp.h"
#include "legacyapi/Base64.h"
#include "ll/api/utils/Base64Utils.h"
#include "mc/nbt/ByteArrayTag.h"
#include "mc/nbt/ByteTag.h"
#include "mc/nbt/CompoundTag.h"
Expand All @@ -16,7 +16,6 @@
#include "mc/nbt/StringTag.h"

#include <magic_enum.hpp>
#include <mc/nbt/CompoundTag.h>
#include <memory>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -193,7 +192,7 @@ void TagToJson_List_Helper(ordered_json& res, ListTag* nbt) {
for (unsigned int i = 0; i < bytes.size(); ++i) {
tmpData[i] = bytes[i];
}
res.push_back(Base64::Encode(tmpData));
res.push_back(ll::base64_utils::encode(tmpData));
break;
}
case Tag::Type::List: {
Expand Down Expand Up @@ -248,7 +247,7 @@ void TagToJson_Compound_Helper(ordered_json& res, CompoundTag* nbt) {
for (unsigned int i = 0; i < bytes.size(); ++i) {
tmpData[i] = bytes[i];
}
res.push_back(Base64::Encode(tmpData));
res.push_back(ll::base64_utils::encode(tmpData));
break;
}
case Tag::Type::List: {
Expand Down Expand Up @@ -304,7 +303,7 @@ std::string TagToJson(Tag* nbt, int formatIndent) {
for (uchar data : bytes) {
tmpData.push_back(data);
}
result = Base64::Encode(tmpData);
result = ll::base64_utils::encode(tmpData);
break;
}
case Tag::Type::List: {
Expand Down
108 changes: 0 additions & 108 deletions src/legacy/legacyapi/Base64.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/legacy/legacyapi/db/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ SharedPointer<Session> Session::_Create(DBType type, const ConnParams& params) {
case DBType::SQLite:
session = params.empty() ? new SQLiteSession() : new SQLiteSession(params);
break;
// case DBType::MySQL:
// session = params.empty() ? new MySQLSession() : new MySQLSession(params);
// break;
case DBType::MySQL:
session = params.empty() ? new MySQLSession() : new MySQLSession(params);
break;
default:
throw std::runtime_error("Session::_Create: Unknown/Unsupported database type");
}
Expand Down
Loading

0 comments on commit 991acad

Please sign in to comment.