impr: Added nicer console warning when .NET runtime isn't installed
This commit is contained in:
parent
b3b7a19df4
commit
4020ac9843
@ -89,4 +89,5 @@ if (CoreClrEmbed_INCLUDE_DIR AND CoreClrEmbed_LIBRARY)
|
||||
set(CoreClrEmbed_LIBRARIES "${CoreClrEmbed_LIBRARY}" CACHE STRING "CoreClrEmbed libraries" FORCE)
|
||||
set(CoreClrEmbed_SHARED_LIBRARIES "${CoreClrEmbed_SHARED_LIBRARY}" CACHE STRING "CoreClrEmbed shared libraries" FORCE)
|
||||
set(CoreClrEmbed_INCLUDE_DIRS "${CoreClrEmbed_INCLUDE_DIR}" CACHE STRING "CoreClrEmbed include directories" FORCE)
|
||||
set(CoreClrEmbed_VERSION "${CORECLR_RUNTIME_VERSION_FULL}" CACHE STRING "CoreClrEmbed version" FORCE)
|
||||
endif()
|
@ -3,9 +3,12 @@ cmake_minimum_required(VERSION 3.16)
|
||||
include(ImHexPlugin)
|
||||
|
||||
find_package(CoreClrEmbed)
|
||||
add_library(dotnet INTERFACE)
|
||||
if (CoreClrEmbed_FOUND)
|
||||
set(IMHEX_DOTNET_SCRIPT_SUPPORT ON)
|
||||
|
||||
target_compile_definitions(dotnet INTERFACE IMHEX_DOTNET_RUNTIME_VERSION="${CoreClrEmbed_VERSION}")
|
||||
|
||||
add_library(nethost SHARED IMPORTED)
|
||||
target_include_directories(nethost INTERFACE "${CoreClrEmbed_INCLUDE_DIRS}")
|
||||
get_filename_component(CoreClrEmbed_FOLDER ${CoreClrEmbed_SHARED_LIBRARIES} DIRECTORY)
|
||||
@ -40,6 +43,7 @@ add_imhex_plugin(
|
||||
c_api
|
||||
fonts
|
||||
ui
|
||||
dotnet
|
||||
)
|
||||
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <nethost.h>
|
||||
#include <coreclr_delegates.h>
|
||||
#include <hostfxr.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <hex/api/plugin_manager.hpp>
|
||||
|
||||
@ -110,13 +111,7 @@ namespace hex::script::loader {
|
||||
= getExport<hostfxr_set_error_writer_fn>(hostfxrLibrary, "hostfxr_set_error_writer");
|
||||
}
|
||||
|
||||
hostfxr_set_error_writer([] HOSTFXR_CALLTYPE (const char_t *message) {
|
||||
#if defined(OS_WINDOWS)
|
||||
log::error("{}", utf16ToUtf8(message));
|
||||
#else
|
||||
log::error("{}", message);
|
||||
#endif
|
||||
});
|
||||
hostfxr_set_error_writer([] HOSTFXR_CALLTYPE (const char_t *) { });
|
||||
|
||||
return
|
||||
hostfxr_initialize_for_runtime_config != nullptr &&
|
||||
@ -137,7 +132,12 @@ namespace hex::script::loader {
|
||||
};
|
||||
|
||||
if (result > 2 || ctx == nullptr) {
|
||||
throw std::runtime_error(hex::format("Failed to initialize command line 0x{:X}", result));
|
||||
if (result == /* FrameworkMissingFailure */ 0x80008096) {
|
||||
log::warn("ImHex has built-in support for .NET scripts and extensions. However, these can only be used when the .NET runtime is installed.");
|
||||
log::warn("Please install version {} or later of the .NET runtime if you plan to use them. Otherwise this error can be safely ignored.", IMHEX_DOTNET_RUNTIME_VERSION);
|
||||
}
|
||||
|
||||
throw std::runtime_error(hex::format("Command line init failed 0x{:X}", result));
|
||||
}
|
||||
|
||||
#if defined (OS_WINDOWS)
|
||||
@ -146,6 +146,14 @@ namespace hex::script::loader {
|
||||
hostfxr_set_runtime_property_value(ctx, STRING("PINVOKE_OVERRIDE"), hex::format("{}", (void*)pInvokeOverride).c_str());
|
||||
#endif
|
||||
|
||||
hostfxr_set_error_writer([] HOSTFXR_CALLTYPE (const char_t *message) {
|
||||
#if defined(OS_WINDOWS)
|
||||
log::error("{}", utf16ToUtf8(message));
|
||||
#else
|
||||
log::error("{}", message);
|
||||
#endif
|
||||
});
|
||||
|
||||
result = hostfxr_get_runtime_delegate(
|
||||
ctx,
|
||||
hostfxr_delegate_type::hdt_load_assembly_and_get_function_pointer,
|
||||
|
Loading…
Reference in New Issue
Block a user