impr: Move script library to its own library
This commit is contained in:
parent
0a6815da8f
commit
d7238a5f80
@ -16,7 +16,7 @@ namespace ImHex
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.Message);
|
Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.ToString());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,10 +24,22 @@ namespace ImHex
|
|||||||
|
|
||||||
private static bool ExecuteScript(string path)
|
private static bool ExecuteScript(string path)
|
||||||
{
|
{
|
||||||
AssemblyLoadContext? context = new("ScriptDomain_" + Path.GetFileNameWithoutExtension(path), true);
|
string? basePath = Path.GetDirectoryName(path);
|
||||||
|
if (basePath == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("[.NET Script] Failed to get base path");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssemblyLoadContext? context = new("ScriptDomain_" + basePath, true);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
foreach (var file in Directory.GetFiles(basePath, "*.dll"))
|
||||||
|
{
|
||||||
|
context.LoadFromStream(new MemoryStream(File.ReadAllBytes(file)));
|
||||||
|
}
|
||||||
|
|
||||||
var assembly = context.LoadFromStream(new MemoryStream(File.ReadAllBytes(path)));
|
var assembly = context.LoadFromStream(new MemoryStream(File.ReadAllBytes(path)));
|
||||||
|
|
||||||
var entryPointType = assembly.GetType("Script");
|
var entryPointType = assembly.GetType("Script");
|
||||||
@ -48,7 +60,7 @@ namespace ImHex
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.Message);
|
Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.ToString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -4,14 +4,14 @@ function(add_dotnet_assembly name)
|
|||||||
set(OUTPUT_DLL ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.dll)
|
set(OUTPUT_DLL ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.dll)
|
||||||
set(OUTPUT_RUNTIMECONFIG ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.runtimeconfig.json)
|
set(OUTPUT_RUNTIMECONFIG ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.runtimeconfig.json)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.cs)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.dll
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.dll
|
||||||
COMMAND ${DOTNET_EXECUTABLE} build ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.csproj --nologo -c Release -o ${CMAKE_CURRENT_BINARY_DIR}/../.. && ${CMAKE_COMMAND} -DOUTPUT_RUNTIMECONFIG="${OUTPUT_RUNTIMECONFIG}" -P ${CMAKE_CURRENT_SOURCE_DIR}/post_process_runtimeconfig.cmake
|
COMMAND ${DOTNET_EXECUTABLE} build ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.csproj --nologo -c Release -o ${CMAKE_CURRENT_BINARY_DIR}/../.. && ${CMAKE_COMMAND} -DOUTPUT_RUNTIMECONFIG="${OUTPUT_RUNTIMECONFIG}" -P ${CMAKE_CURRENT_SOURCE_DIR}/post_process_runtimeconfig.cmake
|
||||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.csproj
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.csproj ${sources}
|
||||||
COMMENT "Building ${name}.dll"
|
COMMENT "Building ${name}.dll"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
add_custom_target(${name} ALL DEPENDS ${OUTPUT_DLL})
|
add_custom_target(${name} ALL DEPENDS ${OUTPUT_DLL})
|
||||||
|
|
||||||
install(FILES
|
install(FILES
|
||||||
@ -20,9 +20,6 @@ function(add_dotnet_assembly name)
|
|||||||
DESTINATION
|
DESTINATION
|
||||||
${PLUGINS_INSTALL_LOCATION}
|
${PLUGINS_INSTALL_LOCATION}
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.cs)
|
|
||||||
target_sources(${name} PRIVATE ${sources})
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
add_dotnet_assembly(AssemblyLoader)
|
add_dotnet_assembly(AssemblyLoader)
|
@ -1,3 +1,3 @@
|
|||||||
.vs/
|
.vs/
|
||||||
ImHexScript/bin/
|
*/bin/
|
||||||
ImHexScript/obj/
|
*/obj/
|
@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.6.33801.468
|
VisualStudioVersion = 17.6.33801.468
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImHexScript", "ImHexScript\ImHexScript.csproj", "{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImHexScript", "ImHexScript\ImHexScript.csproj", "{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImHexLibrary", "ImHexLibrary\ImHexLibrary.csproj", "{B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -15,6 +17,10 @@ Global
|
|||||||
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AssemblyName>Main</AssemblyName>
|
<AssemblyName>Main</AssemblyName>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||||
<SelfContained>true</SelfContained>
|
<SelfContained>true</SelfContained>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@ -14,4 +14,12 @@
|
|||||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ImGui.NET" Version="1.89.7.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ImHexLibrary\ImHexLibrary.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -5,6 +5,6 @@ class Script
|
|||||||
{
|
{
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
|
UI.ShowMessageBox("Hello World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user