mirror of https://github.com/WerWolv/ImHex.git
build: Restructured entire custom plugin system (#1469)
This commit is contained in:
parent
538e79183c
commit
84bfd10416
|
@ -67,3 +67,4 @@ add_subdirectory(tests EXCLUDE_FROM_ALL)
|
|||
# Configure packaging
|
||||
createPackage()
|
||||
generatePDBs()
|
||||
generateSDKDirectory()
|
|
@ -256,8 +256,8 @@ macro(createPackage)
|
|||
# Enforce DragNDrop packaging.
|
||||
set(CPACK_GENERATOR "DragNDrop")
|
||||
|
||||
set (CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/resources/dist/macos/AppIcon.icns" )
|
||||
set (CPACK_BUNDLE_PLIST "${CMAKE_BINARY_DIR}/imhex.app/Contents/Info.plist")
|
||||
set(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/resources/dist/macos/AppIcon.icns" )
|
||||
set(CPACK_BUNDLE_PLIST "${CMAKE_BINARY_DIR}/imhex.app/Contents/Info.plist")
|
||||
else()
|
||||
install(TARGETS main RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
if(WIN32) # Forwarder is only needed on Windows
|
||||
|
@ -679,10 +679,9 @@ function(generatePDBs)
|
|||
WORKING_DIRECTORY ${cv2pdb_SOURCE_DIR}
|
||||
COMMAND
|
||||
(
|
||||
${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${PDB}> ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.bak &&
|
||||
${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.pdb &&
|
||||
${cv2pdb_SOURCE_DIR}/cv2pdb64.exe ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.bak &&
|
||||
${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.bak
|
||||
${cv2pdb_SOURCE_DIR}/cv2pdb64.exe
|
||||
$<TARGET_FILE:${PDB}>
|
||||
) || (exit 0)
|
||||
DEPENDS $<TARGET_FILE:${PDB}>
|
||||
COMMAND_EXPAND_LISTS)
|
||||
|
@ -694,10 +693,33 @@ function(generatePDBs)
|
|||
endfunction()
|
||||
|
||||
function(generateSDKDirectory)
|
||||
set(SDK_PATH "./sdk")
|
||||
if (WIN32)
|
||||
set(SDK_PATH "./sdk")
|
||||
elseif (APPLE)
|
||||
set(SDK_PATH "imhex.app/Contents/Resources/sdk")
|
||||
else()
|
||||
set(SDK_PATH "share/imhex/sdk")
|
||||
endif()
|
||||
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lib/libimhex DESTINATION "${SDK_PATH}/lib")
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lib/external DESTINATION "${SDK_PATH}/lib")
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lib/third_party/imgui DESTINATION "${SDK_PATH}/lib/third_party")
|
||||
if (NOT USE_SYSTEM_FMT)
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lib/third_party/fmt DESTINATION "${SDK_PATH}/lib/third_party")
|
||||
endif()
|
||||
if (NOT USE_SYSTEM_NLOHMANN_JSON)
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lib/third_party/nlohmann_json DESTINATION "${SDK_PATH}/lib/third_party")
|
||||
endif()
|
||||
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/lib/libimhex/include DESTINATION "${SDK_PATH}")
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/cmake/modules/ImHexPlugin.cmake DESTINATION "${SDK_PATH}/cmake/modules")
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/cmake/build_helpers.cmake DESTINATION "${SDK_PATH}/cmake")
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/cmake/sdk/CMakeLists.txt DESTINATION "${SDK_PATH}")
|
||||
install(TARGETS libimhex ARCHIVE DESTINATION "${SDK_PATH}/lib")
|
||||
install(TARGETS libimhex RUNTIME DESTINATION "${SDK_PATH}/lib")
|
||||
install(TARGETS libimhex LIBRARY DESTINATION "${SDK_PATH}/lib")
|
||||
endfunction()
|
||||
|
||||
function(addIncludesFromLibrary target library)
|
||||
get_target_property(library_include_dirs ${library} INTERFACE_INCLUDE_DIRECTORIES)
|
||||
target_include_directories(${target} PRIVATE ${library_include_dirs})
|
||||
endfunction()
|
|
@ -24,7 +24,8 @@ macro(add_imhex_plugin)
|
|||
|
||||
# Add include directories and link libraries
|
||||
target_include_directories(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_INCLUDES})
|
||||
target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${FMT_LIBRARIES} ${IMHEX_PLUGIN_LIBRARIES})
|
||||
target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${IMHEX_PLUGIN_LIBRARIES} fmt::fmt imgui_all_includes libwolv)
|
||||
addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl)
|
||||
|
||||
# Add IMHEX_PROJECT_NAME and IMHEX_VERSION define
|
||||
target_compile_definitions(${IMHEX_PLUGIN_NAME} PRIVATE IMHEX_PROJECT_NAME="${IMHEX_PLUGIN_NAME}")
|
||||
|
@ -53,7 +54,9 @@ macro(add_imhex_plugin)
|
|||
target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE ${LIBROMFS_LIBRARY})
|
||||
|
||||
# Add the new plugin to the main dependency list so it gets built by default
|
||||
add_dependencies(imhex_all ${IMHEX_PLUGIN_NAME})
|
||||
if (TARGET imhex_all)
|
||||
add_dependencies(imhex_all ${IMHEX_PLUGIN_NAME})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(add_romfs_resource input output)
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
cmake_minimum_required(VERSION 3.20)
|
||||
project(ImHexSDK)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/build_helpers.cmake")
|
||||
|
||||
set(IMHEX_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
|
||||
include(ImHexPlugin)
|
||||
|
||||
function(add_subdirectory_if_exists folder)
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${folder}/CMakeLists.txt")
|
||||
add_subdirectory("${folder}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set(IMHEX_EXTERNAL_PLUGIN_BUILD ON)
|
||||
add_custom_target(imhex_all)
|
||||
|
||||
add_subdirectory(lib/third_party/imgui)
|
||||
add_subdirectory_if_exists(lib/third_party/fmt)
|
||||
add_subdirectory_if_exists(lib/third_party/nlohmann_json)
|
||||
|
||||
add_subdirectory(lib/external/libwolv)
|
||||
|
||||
set(LIBPL_BUILD_CLI_AS_EXECUTABLE OFF)
|
||||
add_subdirectory(lib/external/pattern_language)
|
||||
|
||||
add_subdirectory(lib/libimhex)
|
||||
|
||||
if (WIN32)
|
||||
set_target_properties(libimhex PROPERTIES
|
||||
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/libimhex.dll"
|
||||
IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/lib/liblibimhex.dll.a"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libimhex/include")
|
||||
elseif (APPLE)
|
||||
set_target_properties(libimhex PROPERTIES
|
||||
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/libimhex.dylib"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libimhex/include")
|
||||
else()
|
||||
set_target_properties(libimhex PROPERTIES
|
||||
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/libimhex.so"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libimhex/include")
|
||||
endif()
|
|
@ -125,6 +125,7 @@ cp -a lib/third_party/xdgpp/LICENSE %{buildroot
|
|||
%{_libdir}/libimhex.so*
|
||||
%{_libdir}/%{name}/
|
||||
%{_metainfodir}/net.werwolv.%{name}.metainfo.xml
|
||||
%{_datadir}/%{name}/sdk/
|
||||
|
||||
|
||||
%changelog
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
|
@ -9,4 +9,6 @@ add_library(imgui_fonts INTERFACE)
|
|||
|
||||
target_include_directories(imgui_fonts INTERFACE
|
||||
include
|
||||
)
|
||||
)
|
||||
|
||||
target_include_directories(imgui_all_includes INTERFACE include)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -52,7 +52,7 @@ set_target_properties(main PROPERTIES
|
|||
|
||||
add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}")
|
||||
|
||||
target_link_libraries(main PRIVATE libromfs-imhex libimhex ${FMT_LIBRARIES})
|
||||
target_link_libraries(main PRIVATE libromfs-imhex libimhex ${GLFW_LIBRARIES} libwolv libpl plcli libpl-gen ${FMT_LIBRARIES})
|
||||
if (WIN32)
|
||||
target_link_libraries(main PRIVATE usp10 wsock32 ws2_32 Dwmapi.lib)
|
||||
else ()
|
||||
|
|
|
@ -125,7 +125,6 @@ namespace hex::init {
|
|||
ContentRegistry::HexEditor::impl::getVisualizers().clear();
|
||||
|
||||
ContentRegistry::BackgroundServices::impl::stopServices();
|
||||
ContentRegistry::BackgroundServices::impl::getServices().clear();
|
||||
|
||||
ContentRegistry::CommunicationInterface::impl::getNetworkEndpoints().clear();
|
||||
|
||||
|
|
|
@ -129,6 +129,17 @@ add_imhex_plugin(
|
|||
|
||||
INCLUDES
|
||||
include
|
||||
${CAPSTONE_INCLUDE_DIRS}
|
||||
${YARA_INCLUDE_DIRS}
|
||||
${MINIAUDIO_INCLUDE_DIRS}
|
||||
|
||||
LIBRARIES
|
||||
${CAPSTONE_LIBRARIES}
|
||||
${YARA_LIBRARIES}
|
||||
${MINIAUDIO_LIBRARIES}
|
||||
${JTHREAD_LIBRARIES}
|
||||
${GLFW_LIBRARIES}
|
||||
plcli libpl-gen
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <hex/ui/view.hpp>
|
||||
#include <ui/widgets.hpp>
|
||||
|
||||
#include <hex/helpers/disassembler.hpp>
|
||||
#include <content/helpers/disassembler.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
|
|
@ -15,6 +15,8 @@ if (WIN32)
|
|||
source/content/settings_entries.cpp
|
||||
INCLUDES
|
||||
include
|
||||
LIBRARIES
|
||||
${JTHREAD_LIBRARIES}
|
||||
)
|
||||
|
||||
endif ()
|
||||
|
|
|
@ -6,4 +6,4 @@ add_library(tests_common STATIC
|
|||
source/main.cpp
|
||||
)
|
||||
target_include_directories(tests_common PUBLIC include)
|
||||
target_link_libraries(tests_common PUBLIC libimhex ${FMT_LIBRARIES})
|
||||
target_link_libraries(tests_common PUBLIC libimhex ${FMT_LIBRARIES} libwolv)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include <hex/providers/provider.hpp>
|
||||
#pragma once
|
||||
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <stdexcept>
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace hex::test {
|
||||
using namespace hex::prv;
|
||||
|
||||
class TestProvider : public prv::Provider {
|
||||
public:
|
||||
explicit TestProvider(std::vector<u8> *data) : Provider() {
|
||||
explicit TestProvider(std::vector<u8> *data) {
|
||||
this->setData(data);
|
||||
}
|
||||
~TestProvider() override = default;
|
||||
|
@ -47,11 +47,14 @@ namespace hex::test {
|
|||
return m_data->size();
|
||||
}
|
||||
|
||||
[[nodiscard]] virtual std::string getTypeName() const override { return "hex.test.provider.test"; }
|
||||
[[nodiscard]] std::string getTypeName() const override { return "hex.test.provider.test"; }
|
||||
|
||||
bool open() override { return true; }
|
||||
void close() override { }
|
||||
|
||||
nlohmann::json storeSettings(nlohmann::json) const override { return {}; }
|
||||
void loadSettings(const nlohmann::json &) override {};
|
||||
|
||||
private:
|
||||
std::vector<u8> *m_data = nullptr;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue