mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 11:49:26 +08:00
add: network interface for updating resource files
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -271,4 +271,5 @@ blcrack/vcpkgs/
|
||||
blcrack/out/
|
||||
blcrack/tolua/
|
||||
bin/hook/
|
||||
blcrack/patchelf/build/
|
||||
blcrack/patchelf/build/
|
||||
blcrack/test/
|
||||
@@ -17,4 +17,9 @@ POST http://127.0.0.1:7541/get_hash
|
||||
###
|
||||
POST http://127.0.0.1:7541/reload
|
||||
|
||||
BlCrackUpdater
|
||||
BlCrackUpdater
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:7541/update?key=BlCrackUpdater&arch=arm64-v8a&file=libcracker.so
|
||||
|
||||
< ../bin/Release-Android-arm64-v8a/libcracker.so
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
UpdateServer::UpdateServer() {
|
||||
UpdateServer::UpdateServer() : m_assets_dir("assets") {
|
||||
update_files();
|
||||
|
||||
Post("/files", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
@@ -85,6 +85,38 @@ UpdateServer::UpdateServer() {
|
||||
SPDLOG_WARN("Invalid key: {}", req.body);
|
||||
res.status = 400;
|
||||
});
|
||||
|
||||
Post("/update", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
SPDLOG_INFO("{} requested update", req.remote_addr);
|
||||
const auto& key = req.params.equal_range("key").first->second;
|
||||
const auto& arch = req.params.equal_range("arch").first->second;
|
||||
const auto& file = req.params.equal_range("file").first->second;
|
||||
|
||||
if (key == m_admin_key) {
|
||||
FileData data(req.body.begin(), req.body.end());
|
||||
auto md5 = hash_file(data);
|
||||
SPDLOG_INFO("Update {}/{} hash: {}", arch, file, md5);
|
||||
|
||||
m_files[arch][file] = {
|
||||
.data = std::move(data),
|
||||
.hash = std::move(md5)
|
||||
};
|
||||
|
||||
auto arch_path = m_assets_dir / arch;
|
||||
if (!exists(arch_path)) {
|
||||
create_directories(arch_path);
|
||||
}
|
||||
|
||||
std::ofstream out(arch_path / file, std::ios::binary);
|
||||
out.write(data.data(), data.size());
|
||||
out.close();
|
||||
|
||||
res.status = 200;
|
||||
return;
|
||||
}
|
||||
|
||||
res.status = 400;
|
||||
});
|
||||
}
|
||||
|
||||
UpdateServer& UpdateServer::start(int port, const std::string& admin_key) {
|
||||
@@ -107,11 +139,10 @@ UpdateServer& UpdateServer::Instance() {
|
||||
|
||||
void UpdateServer::update_files() {
|
||||
m_files.clear();
|
||||
fs::path assets_path = fs::current_path() / "assets";
|
||||
if (!exists(assets_path)) {
|
||||
if (!exists(m_assets_dir)) {
|
||||
return;
|
||||
}
|
||||
for (auto& arch : fs::directory_iterator(assets_path)) {
|
||||
for (auto& arch : fs::directory_iterator(m_assets_dir)) {
|
||||
if (!fs::is_directory(arch)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include <httplib.h>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
class UpdateServer : protected httplib::Server {
|
||||
using ArchName = std::string;
|
||||
@@ -32,6 +35,7 @@ private:
|
||||
|
||||
std::string m_admin_key;
|
||||
std::thread m_server_thread;
|
||||
fs::path m_assets_dir;
|
||||
std::map<ArchName, std::map<FileName, FileInfo>> m_files;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user