1
0
mirror of synced 2025-01-29 19:17:28 +01:00

resources: Start using libromfs to embed resources

This commit is contained in:
WerWolv 2021-12-22 15:06:16 +01:00
parent 28cba0602c
commit 85f276c259
10 changed files with 42 additions and 128 deletions

3
.gitmodules vendored
View File

@ -21,3 +21,6 @@
[submodule "external/capstone"]
path = external/capstone
url = https://github.com/capstone-engine/capstone
[submodule "external/libromfs"]
path = external/libromfs
url = https://github.com/WerWolv/libromfs

View File

@ -71,7 +71,7 @@ namespace ImGui {
}
Texture LoadImageFromPath(const char *path);
Texture LoadImageFromMemory(ImU8 *buffer, int size);
Texture LoadImageFromMemory(const ImU8 *buffer, int size);
void UnloadImage(Texture &texture);
void OpenPopupInWindow(const char *window_name, const char *popup_name);

View File

@ -329,7 +329,7 @@ namespace ImGui {
return { reinterpret_cast<ImTextureID>(static_cast<intptr_t>(texture)), imageWidth, imageHeight };
}
Texture LoadImageFromMemory(ImU8 *buffer, int size) {
Texture LoadImageFromMemory(const ImU8 *buffer, int size) {
int imageWidth = 0;
int imageHeight = 0;

1
external/libromfs vendored Submodule

@ -0,0 +1 @@
Subproject commit 7f134647d92898ad33022ed7dda48d7a4c490f56

View File

@ -13,6 +13,10 @@ set_target_properties(microtar PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/nativefiledialog ${CMAKE_CURRENT_BINARY_DIR}/external/nativefiledialog EXCLUDE_FROM_ALL)
set_target_properties(nfd PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(LIBROMFS_RESOURCE_LOCATION ${CMAKE_SOURCE_DIR}/res/resources)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/external/libromfs EXCLUDE_FROM_ALL)
set_target_properties(libromfs PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(XDGPP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../external/xdgpp")
set(CMAKE_USE_MBEDTLS ON)
set(BUILD_CURL_EXE OFF)
@ -131,8 +135,7 @@ set(LIBIMHEX_SOURCES
source/views/view.cpp
source/resources.cpp
)
)
if (APPLE)
set(OSX_11_0_SDK_PATH /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk)
@ -158,4 +161,4 @@ if (APPLE)
target_link_libraries(libimhex PUBLIC ${FOUNDATION})
endif ()
target_link_libraries(libimhex PUBLIC imgui nfd magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${FMT_LIBRARIES} ${Python_LIBRARIES})
target_link_libraries(libimhex PUBLIC imgui nfd magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${FMT_LIBRARIES} ${Python_LIBRARIES} libromfs)

View File

@ -1,18 +0,0 @@
#pragma once
#define RESOURCE_EXPORT(name) \
extern "C" unsigned char name[]; \
extern "C" int name##_size;
RESOURCE_EXPORT(splash);
RESOURCE_EXPORT(banner_light);
RESOURCE_EXPORT(banner_dark);
RESOURCE_EXPORT(imhex_logo);
RESOURCE_EXPORT(cacert);
#undef RESOURCE_EXPORT

View File

@ -11,7 +11,7 @@
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include <hex/resources.hpp>
#include <romfs/romfs.hpp>
namespace hex {
@ -54,7 +54,9 @@ namespace hex {
static mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
mbedtls_x509_crt_parse(&crt, cacert, cacert_size);
auto cacert = romfs::get("cacert.pem");
mbedtls_x509_crt_parse(&crt, reinterpret_cast<const u8*>(cacert.data()), cacert.size());
mbedtls_ssl_conf_ca_chain(cfg, &crt, nullptr);

View File

@ -1,96 +0,0 @@
#if defined(OS_WINDOWS)
#define RESOURCE(name, path) \
__asm__ ( \
".section .rodata\n" \
".global " #name "\n" \
".global " #name "_size\n" \
#name ":\n" \
".incbin \"" path "\"\n" \
#name "_size:\n" \
".int " #name "_size - " #name "\n" \
".align 8\n" \
)
#define RESOURCE_NULL_TERMINATED(name, path) \
__asm__ ( \
".section .rodata\n" \
".global " #name "\n" \
".global " #name "_size\n" \
#name ":\n" \
".incbin \"" path "\"\n" \
".byte 0\n" \
#name "_size:\n" \
".int " #name "_size - " #name "\n" \
".align 8\n" \
)
#elif defined(OS_MACOS)
#define RESOURCE(name, path) \
__asm__ ( \
".global _" #name ";\n" \
".global _" #name "_size;\n" \
"_" #name ":\n" \
".incbin \"" path "\";\n" \
".align 8;\n" \
"_" #name "_size:\n" \
".int _" #name "_size - _" #name ";\n" \
".align 8;\n" \
)
#define RESOURCE_NULL_TERMINATED(name, path) \
__asm__ ( \
".global _" #name ";\n" \
".global _" #name "_size;\n" \
"_" #name ":\n" \
".incbin \"" path "\";\n" \
".byte 0\n" \
".align 8;\n" \
"_" #name "_size:\n" \
".int _" #name "_size - _" #name ";\n" \
".align 8;\n" \
)
#elif defined(OS_LINUX)
#define RESOURCE(name, path) \
__asm__ ( \
".section .rodata\n" \
".global " #name "\n" \
".global " #name "_size\n" \
#name ":\n" \
".incbin \"" path "\"\n" \
".byte 0\n" \
".type " #name ", @object\n" \
".size " #name "_size, 1\n" \
#name "_size:\n" \
".int " #name "_size - " #name "\n" \
".align 8\n" \
)
#define RESOURCE_NULL_TERMINATED(name, path) \
__asm__ ( \
".section .rodata\n" \
".global " #name "\n" \
".global " #name "_size\n" \
#name ":\n" \
".incbin \"" path "\"\n" \
".byte 0\n" \
".type " #name ", @object\n" \
".size " #name "_size, 1\n" \
#name "_size:\n" \
".int " #name "_size - " #name "\n" \
".align 8\n" \
)
#endif
RESOURCE(banner_light, "../../../res/resources/banner_light.png");
RESOURCE(banner_dark, "../../../res/resources/banner_dark.png");
RESOURCE(splash, "../../../res/resources/splash.png");
RESOURCE(imhex_logo, "../../../res/resources/logo.png");
RESOURCE_NULL_TERMINATED(cacert, "../../../res/resources/cacert.pem");

View File

@ -4,7 +4,8 @@
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/shared_data.hpp>
#include <hex/resources.hpp>
#include <romfs/romfs.hpp>
#include <imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
@ -70,7 +71,8 @@ namespace hex::init {
}
bool WindowSplash::loop() {
ImGui::Texture splashTexture = ImGui::LoadImageFromMemory(splash, splash_size);
auto splash = romfs::get("splash.png");
ImGui::Texture splashTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8*>(splash.data()), splash.size());
if (splashTexture == nullptr) {
log::fatal("Could not load splash screen image!");

View File

@ -2,7 +2,6 @@
#include <hex.hpp>
#include <hex/resources.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/paths.hpp>
#include <hex/helpers/logger.hpp>
@ -14,6 +13,8 @@
#include <numeric>
#include <thread>
#include <romfs/romfs.hpp>
#include <imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>
@ -127,23 +128,38 @@ namespace hex {
switch (theme) {
default:
case 1: /* Dark theme */
{
ImGui::StyleColorsDark();
ImGui::StyleCustomColorsDark();
ImPlot::StyleColorsDark();
this->m_bannerTexture = ImGui::LoadImageFromMemory(banner_dark, banner_dark_size);
auto banner = romfs::get("banner_dark.png");
this->m_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8*>(banner.data()), banner.size());
break;
}
case 2: /* Light theme */
{
ImGui::StyleColorsLight();
ImGui::StyleCustomColorsLight();
ImPlot::StyleColorsLight();
this->m_bannerTexture = ImGui::LoadImageFromMemory(banner_light, banner_light_size);
auto banner = romfs::get("banner_light.png");
this->m_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8*>(banner.data()), banner.size());
break;
}
case 3: /* Classic theme */
{
ImGui::StyleColorsClassic();
ImGui::StyleCustomColorsClassic();
ImPlot::StyleColorsClassic();
this->m_bannerTexture = ImGui::LoadImageFromMemory(banner_dark, banner_dark_size);
auto banner = romfs::get("banner_dark.png");
this->m_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8*>(banner.data()), banner.size());
break;
}
}
ImGui::GetStyle().Colors[ImGuiCol_DockingEmptyBg] = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
@ -255,7 +271,8 @@ namespace hex {
std::signal(SIGABRT, signalHandler);
std::signal(SIGFPE, signalHandler);
this->m_logoTexture = ImGui::LoadImageFromMemory(imhex_logo, imhex_logo_size);
auto imhexLogo = romfs::get("logo.png");
this->m_logoTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8*>(imhexLogo.data()), imhexLogo.size());
ContentRegistry::Settings::store();
EventManager::post<EventSettingsChanged>();