diff --git a/lib/libimhex/include/hex/api/event_manager.hpp b/lib/libimhex/include/hex/api/event_manager.hpp index 340590253..e6092aab9 100644 --- a/lib/libimhex/include/hex/api/event_manager.hpp +++ b/lib/libimhex/include/hex/api/event_manager.hpp @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -90,9 +89,9 @@ EXPORT_MODULE namespace hex { explicit Event(Callback func) noexcept : m_func(std::move(func)) { } template - void call(Params... params) const { + void call(auto&& ... params) const { try { - m_func(params...); + m_func(std::forward(params)...); } catch (const std::exception &e) { log::error("An exception occurred while handling event {}: {}", wolv::type::getTypeName(), e.what()); throw; @@ -125,8 +124,8 @@ EXPORT_MODULE namespace hex { * @return Token to unsubscribe from the event */ template - static EventList::iterator subscribe(typename E::Callback function) { - std::scoped_lock lock(getEventMutex()); + static EventList::iterator subscribe(E::Callback function) { + std::lock_guard lock(getEventMutex()); auto &events = getEvents(); return events.insert({ E::Id, std::make_unique(function) }); @@ -139,15 +138,15 @@ EXPORT_MODULE namespace hex { * @param function Function to call when the event is posted */ template - static void subscribe(void *token, typename E::Callback function) { - std::scoped_lock lock(getEventMutex()); + static void subscribe(void *token, E::Callback function) { + std::lock_guard lock(getEventMutex()); if (isAlreadyRegistered(token, E::Id)) { log::fatal("The token '{}' has already registered the same event ('{}')", token, wolv::type::getTypeName()); return; } - getTokenStore().insert({ token, subscribe(function) }); + getTokenStore().insert({ token, subscribe(std::move(function)) }); } /** @@ -155,7 +154,7 @@ EXPORT_MODULE namespace hex { * @param token Token returned by subscribe */ static void unsubscribe(const EventList::iterator &token) noexcept { - std::scoped_lock lock(getEventMutex()); + std::lock_guard lock(getEventMutex()); getEvents().erase(token); } @@ -167,7 +166,7 @@ EXPORT_MODULE namespace hex { */ template static void unsubscribe(void *token) noexcept { - std::scoped_lock lock(getEventMutex()); + std::lock_guard lock(getEventMutex()); unsubscribe(token, E::Id); } @@ -179,9 +178,9 @@ EXPORT_MODULE namespace hex { */ template static void post(auto && ...args) { - std::scoped_lock lock(getEventMutex()); + std::lock_guard lock(getEventMutex()); - auto [begin, end] = getEvents().equal_range(E::Id); + const auto &[begin, end] = getEvents().equal_range(E::Id); for (auto it = begin; it != end; ++it) { const auto &[id, event] = *it; (*static_cast(event.get())).template call(std::forward(args)...); @@ -197,7 +196,7 @@ EXPORT_MODULE namespace hex { * @brief Unsubscribe all subscribers from all events */ static void clear() noexcept { - std::scoped_lock lock(getEventMutex()); + std::lock_guard lock(getEventMutex()); getEvents().clear(); getTokenStore().clear(); diff --git a/lib/libimhex/include/hex/api/events/events_gui.hpp b/lib/libimhex/include/hex/api/events/events_gui.hpp index e14e6e4b6..d8c7b328d 100644 --- a/lib/libimhex/include/hex/api/events/events_gui.hpp +++ b/lib/libimhex/include/hex/api/events/events_gui.hpp @@ -4,6 +4,7 @@ /* Forward declarations */ struct GLFWwindow; +using ImGuiID = unsigned int; namespace hex { class View; } /* GUI events definitions */ diff --git a/lib/libimhex/include/hex/api/events/events_interaction.hpp b/lib/libimhex/include/hex/api/events/events_interaction.hpp index 59941dbad..a7433cc4b 100644 --- a/lib/libimhex/include/hex/api/events/events_interaction.hpp +++ b/lib/libimhex/include/hex/api/events/events_interaction.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/lib/libimhex/include/hex/api/events/events_lifecycle.hpp b/lib/libimhex/include/hex/api/events/events_lifecycle.hpp index 52a1540a3..684c4b6fd 100644 --- a/lib/libimhex/include/hex/api/events/events_lifecycle.hpp +++ b/lib/libimhex/include/hex/api/events/events_lifecycle.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include struct ImGuiTestEngine; diff --git a/lib/libimhex/include/hex/api/events/events_provider.hpp b/lib/libimhex/include/hex/api/events/events_provider.hpp index eb94468cf..11a64e57b 100644 --- a/lib/libimhex/include/hex/api/events/events_provider.hpp +++ b/lib/libimhex/include/hex/api/events/events_provider.hpp @@ -5,6 +5,11 @@ /* Provider events definitions */ namespace hex { + + namespace prv { + class Provider; + } + /** * @brief Called when the provider is created. * This event is responsible for (optionally) initializing the provider and calling EventProviderOpened diff --git a/lib/libimhex/include/hex/api/events/requests_interaction.hpp b/lib/libimhex/include/hex/api/events/requests_interaction.hpp index a214e4e68..f68bff5c6 100644 --- a/lib/libimhex/include/hex/api/events/requests_interaction.hpp +++ b/lib/libimhex/include/hex/api/events/requests_interaction.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include /* Forward declarations */ diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index b83c9a334..42dbc5595 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -873,16 +873,16 @@ namespace hex { LocalizationManager::impl::setFallbackLanguage(code.get()); } - impl::s_languages->insert({ code.get(), hex::format("{} ({})", language.get(), country.get()) }); + impl::s_languages->emplace(code.get(), hex::format("{} ({})", language.get(), country.get())); std::map translationDefinitions; for (auto &[key, value] : translations.items()) { - if (!value.is_string()) { + if (!value.is_string()) [[unlikely]] { log::error("Localization data has invalid fields!"); continue; } - translationDefinitions[key] = value.get(); + translationDefinitions.emplace(key, value.get()); } (*impl::s_definitions)[code.get()].emplace_back(std::move(translationDefinitions)); diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index fdf9719ef..6ad2f2fc9 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -1086,21 +1086,21 @@ namespace hex { return; } - impl::s_fonts->emplace_back(MergeFont { + impl::s_fonts->emplace_back( wolv::util::toUTF8String(path.filename()), fontFile.readVector(), offset, fontSizeMultiplier - }); + ); } void registerMergeFont(const std::string &name, const std::span &data, Offset offset, std::optional fontSizeMultiplier) { - impl::s_fonts->emplace_back(MergeFont { + impl::s_fonts->emplace_back( name, - { data.begin(), data.end() }, + std::vector { data.begin(), data.end() }, offset, fontSizeMultiplier - }); + ); } void registerFont(const Font& font) { diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index 9bf88170e..e3fd35cc6 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -658,7 +658,7 @@ namespace hex { static std::map s_fonts; extern "C" void registerFont(const char *fontName, const char *fontPath) { - s_fonts[fontPath] = fontName; + s_fonts.emplace(fontPath, fontName); } const std::map& getFonts() { diff --git a/lib/libimhex/source/helpers/utils_macos.m b/lib/libimhex/source/helpers/utils_macos.m index df26e5cc4..95bff3473 100644 --- a/lib/libimhex/source/helpers/utils_macos.m +++ b/lib/libimhex/source/helpers/utils_macos.m @@ -91,16 +91,23 @@ for (CFIndex i = 0; i < count; i++) { CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(fontDescriptors, i); - // Get font path - CFDictionaryRef attributes = (__bridge CFDictionaryRef)@{ (__bridge NSString *)kCTFontNameAttribute : (__bridge NSString *)fontName }; + // Get font path - skip fonts without valid URLs + CFDictionaryRef attributes = (__bridge CFDictionaryRef)@{ (__bridge NSString *)kCTFontFamilyNameAttribute : (__bridge NSString *)fontName }; CTFontDescriptorRef descriptor = CTFontDescriptorCreateWithAttributes(attributes); CFURLRef fontURL = CTFontDescriptorCopyAttribute(descriptor, kCTFontURLAttribute); - CFStringRef fontPath = CFURLCopyFileSystemPath(fontURL, kCFURLPOSIXPathStyle); - registerFont([(__bridge NSString *)fontName UTF8String], [(__bridge NSString *)fontPath UTF8String]); + if (fontURL != NULL) { + CFStringRef fontPath = CFURLCopyFileSystemPath(fontURL, kCFURLPOSIXPathStyle); + + if (fontPath != NULL) { + registerFont([(__bridge NSString *)fontName UTF8String], [(__bridge NSString *)fontPath UTF8String]); + CFRelease(fontPath); + } + + CFRelease(fontURL); + } CFRelease(descriptor); - CFRelease(fontURL); } CFRelease(fontDescriptors); diff --git a/plugins/builtin/include/content/providers/null_provider.hpp b/plugins/builtin/include/content/providers/null_provider.hpp index 4c84acaa8..2d69d9d10 100644 --- a/plugins/builtin/include/content/providers/null_provider.hpp +++ b/plugins/builtin/include/content/providers/null_provider.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/plugins/builtin/source/content/background_services.cpp b/plugins/builtin/source/content/background_services.cpp index 3d01f8532..0e1733581 100644 --- a/plugins/builtin/source/content/background_services.cpp +++ b/plugins/builtin/source/content/background_services.cpp @@ -1,3 +1,4 @@ +#include #include #include #include