mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
build: Restructured entire custom plugin system (#1469)
This commit is contained in:
@@ -65,10 +65,17 @@ endif ()
|
||||
|
||||
add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}")
|
||||
|
||||
if (IMHEX_STATIC_LINK_PLUGINS)
|
||||
add_library(libimhex STATIC ${LIBIMHEX_SOURCES})
|
||||
if (IMHEX_EXTERNAL_PLUGIN_BUILD)
|
||||
add_library(libimhex IMPORTED SHARED GLOBAL)
|
||||
set(LIBIMHEX_LIBRARY_TYPE INTERFACE)
|
||||
else()
|
||||
add_library(libimhex SHARED ${LIBIMHEX_SOURCES})
|
||||
if (IMHEX_STATIC_LINK_PLUGINS)
|
||||
add_library(libimhex STATIC ${LIBIMHEX_SOURCES})
|
||||
else()
|
||||
add_library(libimhex SHARED ${LIBIMHEX_SOURCES})
|
||||
endif()
|
||||
|
||||
set(LIBIMHEX_LIBRARY_TYPE PUBLIC)
|
||||
endif()
|
||||
|
||||
set_target_properties(libimhex PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
@@ -78,26 +85,29 @@ setupCompilerFlags(libimhex)
|
||||
include(GenerateExportHeader)
|
||||
generate_export_header(libimhex)
|
||||
|
||||
target_include_directories(libimhex PUBLIC include ${XDGPP_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIR} ${CAPSTONE_INCLUDE_DIRS} ${MAGIC_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${FMT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ${YARA_INCLUDE_DIRS} ${LIBBACKTRACE_INCLUDE_DIRS})
|
||||
target_link_directories(libimhex PUBLIC ${MBEDTLS_LIBRARY_DIR} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS})
|
||||
target_include_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} include ${XDGPP_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIR} ${MAGIC_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${FMT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ${LIBBACKTRACE_INCLUDE_DIRS})
|
||||
target_link_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${MBEDTLS_LIBRARY_DIR} ${MAGIC_LIBRARY_DIRS})
|
||||
|
||||
if (NOT EMSCRIPTEN)
|
||||
# curl is only used in non-emscripten builds
|
||||
target_include_directories(libimhex PUBLIC ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(libimhex PUBLIC ${LIBCURL_LIBRARIES})
|
||||
target_include_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${LIBCURL_LIBRARIES})
|
||||
endif()
|
||||
|
||||
|
||||
if (WIN32)
|
||||
set_target_properties(libimhex PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
|
||||
target_link_options(libimhex PRIVATE -Wl,--export-all-symbols)
|
||||
elseif (APPLE)
|
||||
find_library(FOUNDATION NAMES Foundation)
|
||||
target_link_libraries(libimhex PUBLIC ${FOUNDATION})
|
||||
endif ()
|
||||
if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD)
|
||||
if (WIN32)
|
||||
set_target_properties(libimhex PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
|
||||
target_link_options(libimhex PRIVATE -Wl,--export-all-symbols)
|
||||
elseif (APPLE)
|
||||
find_library(FOUNDATION NAMES Foundation)
|
||||
target_link_libraries(libimhex PUBLIC ${FOUNDATION})
|
||||
endif ()
|
||||
|
||||
target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES})
|
||||
target_link_libraries(libimhex PUBLIC dl ${IMGUI_LIBRARIES} ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} plcli libpl libpl-gen ${MINIAUDIO_LIBRARIES} ${JTHREAD_LIBRARIES} wolv::utils wolv::io wolv::hash wolv::net wolv::containers wolv::math_eval)
|
||||
target_link_libraries(libimhex PRIVATE microtar libpl plcli libpl-gen libwolv ${FMT_LIBRARIES} ${NFD_LIBRARIES} magic dl ${IMGUI_LIBRARIES} ${NLOHMANN_JSON_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} ${JTHREAD_LIBRARIES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${NLOHMANN_JSON_LIBRARIES} ${IMGUI_LIBRARIES} LLVMDemangle)
|
||||
|
||||
set_property(TARGET libimhex PROPERTY INTERPROCEDURAL_OPTIMIZATION FALSE)
|
||||
|
||||
|
||||
@@ -4,19 +4,16 @@
|
||||
#include <hex/api/localization_manager.hpp>
|
||||
#include <hex/helpers/concepts.hpp>
|
||||
|
||||
#include <pl/pattern_language.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <jthread.hpp>
|
||||
|
||||
#include <pl/pattern_language.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <wolv/io/fs.hpp>
|
||||
|
||||
using ImGuiDataType = int;
|
||||
using ImGuiInputTextFlags = int;
|
||||
@@ -972,12 +969,6 @@ namespace hex {
|
||||
namespace impl {
|
||||
using Callback = std::function<void()>;
|
||||
|
||||
struct Service {
|
||||
std::string name;
|
||||
std::jthread thread;
|
||||
};
|
||||
|
||||
std::vector<Service> &getServices();
|
||||
void stopServices();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,12 @@
|
||||
#include <hex/api/localization_manager.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <jthread.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
class TaskHolder;
|
||||
@@ -166,8 +163,6 @@ namespace hex {
|
||||
static void runDeferredCalls();
|
||||
|
||||
private:
|
||||
static void runner(const std::stop_token &stopToken);
|
||||
|
||||
static TaskHolder createTask(std::string name, u64 maxValue, bool background, std::function<void(Task &)> function);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <capstone/capstone.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
enum class Architecture : i32
|
||||
{
|
||||
ARM = CS_ARCH_ARM,
|
||||
ARM64 = CS_ARCH_ARM64,
|
||||
MIPS = CS_ARCH_MIPS,
|
||||
X86 = CS_ARCH_X86,
|
||||
PPC = CS_ARCH_PPC,
|
||||
SPARC = CS_ARCH_SPARC,
|
||||
SYSZ = CS_ARCH_SYSZ,
|
||||
XCORE = CS_ARCH_XCORE,
|
||||
M68K = CS_ARCH_M68K,
|
||||
TMS320C64X = CS_ARCH_TMS320C64X,
|
||||
M680X = CS_ARCH_M680X,
|
||||
EVM = CS_ARCH_EVM,
|
||||
|
||||
#if CS_API_MAJOR >= 5
|
||||
WASM = CS_ARCH_WASM,
|
||||
RISCV = CS_ARCH_RISCV,
|
||||
MOS65XX = CS_ARCH_MOS65XX,
|
||||
BPF = CS_ARCH_BPF,
|
||||
SH = CS_ARCH_SH,
|
||||
TRICORE = CS_ARCH_TRICORE,
|
||||
MAX = TRICORE,
|
||||
# else
|
||||
MAX = EVM,
|
||||
#endif
|
||||
|
||||
MIN = ARM
|
||||
};
|
||||
|
||||
class Disassembler {
|
||||
public:
|
||||
constexpr static cs_arch toCapstoneArchitecture(Architecture architecture) {
|
||||
return static_cast<cs_arch>(architecture);
|
||||
}
|
||||
|
||||
static bool isSupported(Architecture architecture) {
|
||||
return cs_support(toCapstoneArchitecture(architecture));
|
||||
}
|
||||
|
||||
constexpr static auto ArchitectureNames = []{
|
||||
std::array<const char *, static_cast<u32>(Architecture::MAX) + 1> names = { };
|
||||
|
||||
names[CS_ARCH_ARM] = "ARM";
|
||||
names[CS_ARCH_ARM64] = "AArch64";
|
||||
names[CS_ARCH_MIPS] = "MIPS";
|
||||
names[CS_ARCH_X86] = "Intel x86";
|
||||
names[CS_ARCH_PPC] = "PowerPC";
|
||||
names[CS_ARCH_SPARC] = "SPARC";
|
||||
names[CS_ARCH_SYSZ] = "SystemZ";
|
||||
names[CS_ARCH_XCORE] = "XCore";
|
||||
names[CS_ARCH_M68K] = "Motorola 68K";
|
||||
names[CS_ARCH_TMS320C64X] = "TMS320C64x";
|
||||
names[CS_ARCH_M680X] = "M680X";
|
||||
names[CS_ARCH_EVM] = "Ethereum Virtual Machine";
|
||||
|
||||
#if CS_API_MAJOR >= 5
|
||||
names[CS_ARCH_WASM] = "WebAssembly";
|
||||
names[CS_ARCH_RISCV] = "RISC-V";
|
||||
names[CS_ARCH_MOS65XX] = "MOS Technology 65xx";
|
||||
names[CS_ARCH_BPF] = "Berkeley Packet Filter";
|
||||
names[CS_ARCH_SH] = "SuperH";
|
||||
names[CS_ARCH_TRICORE] = "Tricore";
|
||||
#endif
|
||||
|
||||
return names;
|
||||
}();
|
||||
|
||||
static i32 getArchitectureSupportedCount() {
|
||||
static i32 supportedCount = -1;
|
||||
|
||||
if (supportedCount != -1) {
|
||||
return supportedCount;
|
||||
}
|
||||
|
||||
for (supportedCount = static_cast<i32>(Architecture::MIN); supportedCount < static_cast<i32>(Architecture::MAX) + 1; supportedCount++) {
|
||||
if (!cs_support(supportedCount)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return supportedCount;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
#include <hex/helpers/fs.hpp>
|
||||
|
||||
#include <microtar.h>
|
||||
#include <memory>
|
||||
|
||||
struct mtar_t;
|
||||
|
||||
namespace hex {
|
||||
|
||||
@@ -32,28 +34,28 @@ namespace hex {
|
||||
*/
|
||||
std::string getOpenErrorString() const;
|
||||
|
||||
[[nodiscard]] std::vector<u8> readVector(const std::fs::path &path);
|
||||
[[nodiscard]] std::string readString(const std::fs::path &path);
|
||||
[[nodiscard]] std::vector<u8> readVector(const std::fs::path &path) const;
|
||||
[[nodiscard]] std::string readString(const std::fs::path &path) const;
|
||||
|
||||
void writeVector(const std::fs::path &path, const std::vector<u8> &data);
|
||||
void writeString(const std::fs::path &path, const std::string &data);
|
||||
void writeVector(const std::fs::path &path, const std::vector<u8> &data) const;
|
||||
void writeString(const std::fs::path &path, const std::string &data) const;
|
||||
|
||||
[[nodiscard]] std::vector<std::fs::path> listEntries(const std::fs::path &basePath = "/");
|
||||
[[nodiscard]] bool contains(const std::fs::path &path);
|
||||
[[nodiscard]] std::vector<std::fs::path> listEntries(const std::fs::path &basePath = "/") const;
|
||||
[[nodiscard]] bool contains(const std::fs::path &path) const;
|
||||
|
||||
void extract(const std::fs::path &path, const std::fs::path &outputPath);
|
||||
void extractAll(const std::fs::path &outputPath);
|
||||
void extract(const std::fs::path &path, const std::fs::path &outputPath) const;
|
||||
void extractAll(const std::fs::path &outputPath) const;
|
||||
|
||||
[[nodiscard]] bool isValid() const { return m_valid; }
|
||||
|
||||
private:
|
||||
mtar_t m_ctx = { };
|
||||
std::unique_ptr<mtar_t> m_ctx;
|
||||
std::fs::path m_path;
|
||||
|
||||
bool m_valid = false;
|
||||
|
||||
// These will be updated when the constructor is called
|
||||
int m_tarOpenErrno = MTAR_ESUCCESS;
|
||||
int m_tarOpenErrno = 0;
|
||||
int m_fileOpenErrno = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <hex/data_processor/node.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
#include <jthread.hpp>
|
||||
|
||||
#if defined(OS_WEB)
|
||||
@@ -1000,6 +999,11 @@ namespace hex {
|
||||
|
||||
namespace impl {
|
||||
|
||||
struct Service {
|
||||
std::string name;
|
||||
std::jthread thread;
|
||||
};
|
||||
|
||||
std::vector<Service> &getServices() {
|
||||
static std::vector<Service> services;
|
||||
|
||||
@@ -1007,14 +1011,18 @@ namespace hex {
|
||||
}
|
||||
|
||||
void stopServices() {
|
||||
for (auto &service : getServices()) {
|
||||
auto &services = getServices();
|
||||
|
||||
for (auto &service : services) {
|
||||
service.thread.request_stop();
|
||||
}
|
||||
|
||||
for (auto &service : getServices()) {
|
||||
for (auto &service : services) {
|
||||
if (service.thread.joinable())
|
||||
service.thread.join();
|
||||
}
|
||||
|
||||
services.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <jthread.hpp>
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#include <windows.h>
|
||||
#include <processthreadsapi.h>
|
||||
@@ -227,8 +229,57 @@ namespace hex {
|
||||
log::debug("Initializing task manager thread pool with {} workers.", threadCount);
|
||||
|
||||
// Create worker threads
|
||||
for (u32 i = 0; i < threadCount; i++)
|
||||
s_workers.emplace_back(TaskManager::runner);
|
||||
for (u32 i = 0; i < threadCount; i++) {
|
||||
s_workers.emplace_back([](const std::stop_token &stopToken) {
|
||||
while (true) {
|
||||
std::shared_ptr<Task> task;
|
||||
|
||||
// Set the thread name to "Idle Task" while waiting for a task
|
||||
setThreadName("Idle Task");
|
||||
|
||||
{
|
||||
// Wait for a task to be added to the queue
|
||||
std::unique_lock lock(s_queueMutex);
|
||||
s_jobCondVar.wait(lock, [&] {
|
||||
return !s_taskQueue.empty() || stopToken.stop_requested();
|
||||
});
|
||||
|
||||
// Check if the thread should exit
|
||||
if (stopToken.stop_requested())
|
||||
break;
|
||||
|
||||
// Grab the next task from the queue
|
||||
task = std::move(s_taskQueue.front());
|
||||
s_taskQueue.pop_front();
|
||||
}
|
||||
|
||||
try {
|
||||
// Set the thread name to the name of the task
|
||||
setThreadName(Lang(task->m_unlocalizedName));
|
||||
|
||||
// Execute the task
|
||||
task->m_function(*task);
|
||||
|
||||
log::debug("Task '{}' finished", task->m_unlocalizedName.get());
|
||||
} catch (const Task::TaskInterruptor &) {
|
||||
// Handle the task being interrupted by user request
|
||||
task->interruption();
|
||||
} catch (const std::exception &e) {
|
||||
log::error("Exception in task '{}': {}", task->m_unlocalizedName.get(), e.what());
|
||||
|
||||
// Handle the task throwing an uncaught exception
|
||||
task->exception(e.what());
|
||||
} catch (...) {
|
||||
log::error("Exception in task '{}'", task->m_unlocalizedName.get());
|
||||
|
||||
// Handle the task throwing an uncaught exception of unknown type
|
||||
task->exception("Unknown Exception");
|
||||
}
|
||||
|
||||
task->finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void TaskManager::exit() {
|
||||
@@ -251,56 +302,6 @@ namespace hex {
|
||||
s_taskQueue.clear();
|
||||
}
|
||||
|
||||
void TaskManager::runner(const std::stop_token &stopToken) {
|
||||
while (true) {
|
||||
std::shared_ptr<Task> task;
|
||||
|
||||
// Set the thread name to "Idle Task" while waiting for a task
|
||||
setThreadName("Idle Task");
|
||||
|
||||
{
|
||||
// Wait for a task to be added to the queue
|
||||
std::unique_lock lock(s_queueMutex);
|
||||
s_jobCondVar.wait(lock, [&] {
|
||||
return !s_taskQueue.empty() || stopToken.stop_requested();
|
||||
});
|
||||
|
||||
// Check if the thread should exit
|
||||
if (stopToken.stop_requested())
|
||||
break;
|
||||
|
||||
// Grab the next task from the queue
|
||||
task = std::move(s_taskQueue.front());
|
||||
s_taskQueue.pop_front();
|
||||
}
|
||||
|
||||
try {
|
||||
// Set the thread name to the name of the task
|
||||
setThreadName(Lang(task->m_unlocalizedName));
|
||||
|
||||
// Execute the task
|
||||
task->m_function(*task);
|
||||
|
||||
log::debug("Task '{}' finished", task->m_unlocalizedName.get());
|
||||
} catch (const Task::TaskInterruptor &) {
|
||||
// Handle the task being interrupted by user request
|
||||
task->interruption();
|
||||
} catch (const std::exception &e) {
|
||||
log::error("Exception in task '{}': {}", task->m_unlocalizedName.get(), e.what());
|
||||
|
||||
// Handle the task throwing an uncaught exception
|
||||
task->exception(e.what());
|
||||
} catch (...) {
|
||||
log::error("Exception in task '{}'", task->m_unlocalizedName.get());
|
||||
|
||||
// Handle the task throwing an uncaught exception of unknown type
|
||||
task->exception("Unknown Exception");
|
||||
}
|
||||
|
||||
task->finish();
|
||||
}
|
||||
}
|
||||
|
||||
TaskHolder TaskManager::createTask(std::string name, u64 maxValue, bool background, std::function<void(Task&)> function) {
|
||||
std::scoped_lock lock(s_queueMutex);
|
||||
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
#include <microtar.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
using namespace hex::literals;
|
||||
|
||||
Tar::Tar(const std::fs::path &path, Mode mode) {
|
||||
int tar_error = MTAR_ESUCCESS;
|
||||
int tarError = MTAR_ESUCCESS;
|
||||
|
||||
// Explicitly create file so a short path gets generated
|
||||
if (mode == Mode::Create) {
|
||||
@@ -18,21 +20,23 @@ namespace hex {
|
||||
file.flush();
|
||||
}
|
||||
|
||||
m_ctx = std::make_unique<mtar_t>();
|
||||
|
||||
auto shortPath = wolv::io::fs::toShortPath(path);
|
||||
if (mode == Tar::Mode::Read)
|
||||
tar_error = mtar_open(&m_ctx, shortPath.string().c_str(), "r");
|
||||
tarError = mtar_open(m_ctx.get(), shortPath.string().c_str(), "r");
|
||||
else if (mode == Tar::Mode::Write)
|
||||
tar_error = mtar_open(&m_ctx, shortPath.string().c_str(), "a");
|
||||
tarError = mtar_open(m_ctx.get(), shortPath.string().c_str(), "a");
|
||||
else if (mode == Tar::Mode::Create)
|
||||
tar_error = mtar_open(&m_ctx, shortPath.string().c_str(), "w");
|
||||
tarError = mtar_open(m_ctx.get(), shortPath.string().c_str(), "w");
|
||||
else
|
||||
tar_error = MTAR_EFAILURE;
|
||||
tarError = MTAR_EFAILURE;
|
||||
|
||||
m_path = path;
|
||||
m_valid = (tar_error == MTAR_ESUCCESS);
|
||||
m_valid = (tarError == MTAR_ESUCCESS);
|
||||
|
||||
if (!m_valid) {
|
||||
m_tarOpenErrno = tar_error;
|
||||
m_tarOpenErrno = tarError;
|
||||
|
||||
// Hopefully this errno corresponds to the file open call in mtar_open
|
||||
m_fileOpenErrno = errno;
|
||||
@@ -44,7 +48,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
Tar::Tar(hex::Tar &&other) noexcept {
|
||||
m_ctx = other.m_ctx;
|
||||
m_ctx = std::move(other.m_ctx);
|
||||
m_path = other.m_path;
|
||||
m_valid = other.m_valid;
|
||||
m_tarOpenErrno = other.m_tarOpenErrno;
|
||||
@@ -55,10 +59,8 @@ namespace hex {
|
||||
}
|
||||
|
||||
Tar &Tar::operator=(Tar &&other) noexcept {
|
||||
m_ctx = other.m_ctx;
|
||||
other.m_ctx = { };
|
||||
|
||||
m_path = other.m_path;
|
||||
m_ctx = std::move(other.m_ctx);
|
||||
m_path = std::move(other.m_path);
|
||||
|
||||
m_valid = other.m_valid;
|
||||
other.m_valid = false;
|
||||
@@ -68,24 +70,24 @@ namespace hex {
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<std::fs::path> Tar::listEntries(const std::fs::path &basePath) {
|
||||
std::vector<std::fs::path> Tar::listEntries(const std::fs::path &basePath) const {
|
||||
std::vector<std::fs::path> result;
|
||||
|
||||
const std::string PaxHeaderName = "@PaxHeader";
|
||||
mtar_header_t header;
|
||||
while (mtar_read_header(&m_ctx, &header) != MTAR_ENULLRECORD) {
|
||||
while (mtar_read_header(m_ctx.get(), &header) != MTAR_ENULLRECORD) {
|
||||
std::fs::path path = header.name;
|
||||
if (header.name != PaxHeaderName && wolv::io::fs::isSubPath(basePath, path)) {
|
||||
result.emplace_back(header.name);
|
||||
}
|
||||
|
||||
mtar_next(&m_ctx);
|
||||
mtar_next(m_ctx.get());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Tar::contains(const std::fs::path &path) {
|
||||
bool Tar::contains(const std::fs::path &path) const {
|
||||
mtar_header_t header;
|
||||
|
||||
auto fixedPath = path.string();
|
||||
@@ -93,7 +95,7 @@ namespace hex {
|
||||
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
|
||||
#endif
|
||||
|
||||
return mtar_find(&m_ctx, fixedPath.c_str(), &header) == MTAR_ESUCCESS;
|
||||
return mtar_find(m_ctx.get(), fixedPath.c_str(), &header) == MTAR_ESUCCESS;
|
||||
}
|
||||
|
||||
std::string Tar::getOpenErrorString() const {
|
||||
@@ -102,22 +104,22 @@ namespace hex {
|
||||
|
||||
void Tar::close() {
|
||||
if (m_valid) {
|
||||
mtar_finalize(&m_ctx);
|
||||
mtar_close(&m_ctx);
|
||||
mtar_finalize(m_ctx.get());
|
||||
mtar_close(m_ctx.get());
|
||||
}
|
||||
|
||||
m_ctx = { };
|
||||
m_ctx.reset();
|
||||
m_valid = false;
|
||||
}
|
||||
|
||||
std::vector<u8> Tar::readVector(const std::fs::path &path) {
|
||||
std::vector<u8> Tar::readVector(const std::fs::path &path) const {
|
||||
mtar_header_t header;
|
||||
|
||||
auto fixedPath = path.string();
|
||||
#if defined(OS_WINDOWS)
|
||||
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
|
||||
#endif
|
||||
int ret = mtar_find(&m_ctx, fixedPath.c_str(), &header);
|
||||
int ret = mtar_find(m_ctx.get(), fixedPath.c_str(), &header);
|
||||
if (ret != MTAR_ESUCCESS){
|
||||
log::debug("Failed to read vector from path {} in tarred file {}: {}",
|
||||
path.string(), m_path.string(), mtar_strerror(ret));
|
||||
@@ -125,17 +127,17 @@ namespace hex {
|
||||
}
|
||||
|
||||
std::vector<u8> result(header.size, 0x00);
|
||||
mtar_read_data(&m_ctx, result.data(), result.size());
|
||||
mtar_read_data(m_ctx.get(), result.data(), result.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Tar::readString(const std::fs::path &path) {
|
||||
std::string Tar::readString(const std::fs::path &path) const {
|
||||
auto result = this->readVector(path);
|
||||
return { result.begin(), result.end() };
|
||||
}
|
||||
|
||||
void Tar::writeVector(const std::fs::path &path, const std::vector<u8> &data) {
|
||||
void Tar::writeVector(const std::fs::path &path, const std::vector<u8> &data) const {
|
||||
if (path.has_parent_path()) {
|
||||
std::fs::path pathPart;
|
||||
for (const auto &part : path.parent_path()) {
|
||||
@@ -145,7 +147,7 @@ namespace hex {
|
||||
#if defined(OS_WINDOWS)
|
||||
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
|
||||
#endif
|
||||
mtar_write_dir_header(&m_ctx, fixedPath.c_str());
|
||||
mtar_write_dir_header(m_ctx.get(), fixedPath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,11 +155,11 @@ namespace hex {
|
||||
#if defined(OS_WINDOWS)
|
||||
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
|
||||
#endif
|
||||
mtar_write_file_header(&m_ctx, fixedPath.c_str(), data.size());
|
||||
mtar_write_data(&m_ctx, data.data(), data.size());
|
||||
mtar_write_file_header(m_ctx.get(), fixedPath.c_str(), data.size());
|
||||
mtar_write_data(m_ctx.get(), data.data(), data.size());
|
||||
}
|
||||
|
||||
void Tar::writeString(const std::fs::path &path, const std::string &data) {
|
||||
void Tar::writeString(const std::fs::path &path, const std::string &data) const {
|
||||
this->writeVector(path, { data.begin(), data.end() });
|
||||
}
|
||||
|
||||
@@ -175,26 +177,26 @@ namespace hex {
|
||||
}
|
||||
}
|
||||
|
||||
void Tar::extract(const std::fs::path &path, const std::fs::path &outputPath) {
|
||||
void Tar::extract(const std::fs::path &path, const std::fs::path &outputPath) const {
|
||||
mtar_header_t header;
|
||||
mtar_find(&m_ctx, path.string().c_str(), &header);
|
||||
mtar_find(m_ctx.get(), path.string().c_str(), &header);
|
||||
|
||||
writeFile(&m_ctx, &header, outputPath);
|
||||
writeFile(m_ctx.get(), &header, outputPath);
|
||||
}
|
||||
|
||||
void Tar::extractAll(const std::fs::path &outputPath) {
|
||||
void Tar::extractAll(const std::fs::path &outputPath) const {
|
||||
mtar_header_t header;
|
||||
while (mtar_read_header(&m_ctx, &header) != MTAR_ENULLRECORD) {
|
||||
while (mtar_read_header(m_ctx.get(), &header) != MTAR_ENULLRECORD) {
|
||||
const auto filePath = std::fs::absolute(outputPath / std::fs::path(header.name));
|
||||
|
||||
if (filePath.filename() != "@PaxHeader") {
|
||||
|
||||
std::fs::create_directories(filePath.parent_path());
|
||||
|
||||
writeFile(&m_ctx, &header, filePath);
|
||||
writeFile(m_ctx.get(), &header, filePath);
|
||||
}
|
||||
|
||||
mtar_next(&m_ctx);
|
||||
mtar_next(m_ctx.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
lib/third_party/imgui/CMakeLists.txt
vendored
2
lib/third_party/imgui/CMakeLists.txt
vendored
@@ -3,6 +3,8 @@ project(imgui)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_library(imgui_all_includes INTERFACE)
|
||||
|
||||
add_subdirectory(imgui)
|
||||
add_subdirectory(implot)
|
||||
add_subdirectory(imnodes)
|
||||
|
||||
@@ -12,5 +12,7 @@ target_include_directories(imgui_color_text_editor PUBLIC
|
||||
include
|
||||
)
|
||||
|
||||
target_include_directories(imgui_all_includes INTERFACE include)
|
||||
|
||||
target_link_libraries(imgui_color_text_editor PRIVATE imgui_includes)
|
||||
set_property(TARGET imgui_color_text_editor PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
1
lib/third_party/imgui/custom/CMakeLists.txt
vendored
1
lib/third_party/imgui/custom/CMakeLists.txt
vendored
@@ -15,6 +15,7 @@ target_include_directories(imgui_custom PUBLIC
|
||||
|
||||
target_link_libraries(imgui_custom PRIVATE imgui_includes)
|
||||
set_property(TARGET imgui_custom PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
target_include_directories(imgui_all_includes INTERFACE include)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
4
lib/third_party/imgui/fonts/CMakeLists.txt
vendored
4
lib/third_party/imgui/fonts/CMakeLists.txt
vendored
@@ -9,4 +9,6 @@ add_library(imgui_fonts INTERFACE)
|
||||
|
||||
target_include_directories(imgui_fonts INTERFACE
|
||||
include
|
||||
)
|
||||
)
|
||||
|
||||
target_include_directories(imgui_all_includes INTERFACE include)
|
||||
|
||||
1
lib/third_party/imgui/imgui/CMakeLists.txt
vendored
1
lib/third_party/imgui/imgui/CMakeLists.txt
vendored
@@ -21,6 +21,7 @@ target_include_directories(imgui_imgui PUBLIC
|
||||
|
||||
add_library(imgui_includes INTERFACE)
|
||||
target_include_directories(imgui_includes INTERFACE include)
|
||||
target_include_directories(imgui_all_includes INTERFACE include include/misc/freetype)
|
||||
|
||||
target_compile_options(imgui_imgui PRIVATE -Wno-unknown-warning-option)
|
||||
set_property(TARGET imgui_imgui PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
1
lib/third_party/imgui/imnodes/CMakeLists.txt
vendored
1
lib/third_party/imgui/imnodes/CMakeLists.txt
vendored
@@ -13,4 +13,5 @@ target_include_directories(imgui_imnodes PUBLIC
|
||||
)
|
||||
|
||||
target_link_libraries(imgui_imnodes PRIVATE imgui_includes)
|
||||
target_include_directories(imgui_all_includes INTERFACE include)
|
||||
set_property(TARGET imgui_imnodes PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
2
lib/third_party/imgui/implot/CMakeLists.txt
vendored
2
lib/third_party/imgui/implot/CMakeLists.txt
vendored
@@ -15,4 +15,6 @@ target_include_directories(imgui_implot PUBLIC
|
||||
)
|
||||
|
||||
target_link_libraries(imgui_implot PRIVATE imgui_includes)
|
||||
target_include_directories(imgui_all_includes INTERFACE include)
|
||||
|
||||
set_property(TARGET imgui_implot PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
Reference in New Issue
Block a user