mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Don't crash when loading fonts from CLR DLLs
This commit is contained in:
@@ -210,14 +210,23 @@ namespace Microsoft.Iris.Markup.UIX
|
|||||||
|
|
||||||
private static object CallLoadFontResourceStringString(object instanceObj, object[] parameters)
|
private static object CallLoadFontResourceStringString(object instanceObj, object[] parameters)
|
||||||
{
|
{
|
||||||
string parameter1 = (string)parameters[0];
|
string moduleName = (string)parameters[0];
|
||||||
string parameter2 = (string)parameters[1];
|
string resourceName = (string)parameters[1];
|
||||||
if (string.IsNullOrEmpty(parameter1))
|
if (string.IsNullOrEmpty(moduleName))
|
||||||
ErrorManager.ReportError("Script runtime failure: Invalid 'null' value for '{0}'", "moduleName");
|
ErrorManager.ReportError("Script runtime failure: Invalid 'null' value for '{0}'", "moduleName");
|
||||||
if (string.IsNullOrEmpty(parameter2))
|
if (string.IsNullOrEmpty(resourceName))
|
||||||
ErrorManager.ReportError("Script runtime failure: Invalid 'null' value for '{0}'", "resourceName");
|
ErrorManager.ReportError("Script runtime failure: Invalid 'null' value for '{0}'", "resourceName");
|
||||||
if (!NativeApi.SpLoadFontResource(parameter1, parameter2))
|
|
||||||
ErrorManager.ReportError("Font Resource {1} not found in module {0}", parameter1, parameter2);
|
// Check if DLL is a .NET assembly
|
||||||
|
var assemblyName = System.IO.Path.GetFileNameWithoutExtension(moduleName);
|
||||||
|
if (ClrDllResources.Instance.TryGetResource($"{assemblyName}!{resourceName}", $"clr-res://{assemblyName}", true, out var resource))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NativeApi.SpLoadFontResource(moduleName, resourceName))
|
||||||
|
ErrorManager.ReportError("Font Resource {1} not found in module {0}", moduleName, resourceName);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,17 +23,26 @@ namespace Microsoft.Iris.OS
|
|||||||
|
|
||||||
public Resource GetResource(string hierarchicalPart, string uri, bool forceSynchronous)
|
public Resource GetResource(string hierarchicalPart, string uri, bool forceSynchronous)
|
||||||
{
|
{
|
||||||
Resource resource = null;
|
if (!TryGetResource(hierarchicalPart, uri, forceSynchronous, out var resource))
|
||||||
|
ErrorManager.ReportError($"Invalid resource uri: '{uri}'");
|
||||||
|
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetResource(string hierarchicalPart, string uri, bool forceSynchronous, out Resource resource)
|
||||||
|
{
|
||||||
|
resource = null;
|
||||||
|
|
||||||
DllResources.ParseResource(hierarchicalPart, out string host, out string identifier);
|
DllResources.ParseResource(hierarchicalPart, out string host, out string identifier);
|
||||||
|
|
||||||
if (host != null)
|
if (host != null)
|
||||||
{
|
{
|
||||||
Assembly assembly = GetAssembly(host);
|
Assembly assembly = GetAssembly(host);
|
||||||
if (assembly != null)
|
if (assembly != null)
|
||||||
resource = new ClrDllResource(uri, assembly, identifier);
|
resource = new ClrDllResource(uri, assembly, identifier);
|
||||||
}
|
}
|
||||||
if (resource == null)
|
|
||||||
ErrorManager.ReportError($"Invalid resource uri: '{uri}'");
|
return resource is not null;
|
||||||
return resource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Assembly GetAssembly(string moduleName)
|
public Assembly GetAssembly(string moduleName)
|
||||||
|
|||||||
Reference in New Issue
Block a user