Use RESX files for resources and unify import and resource redirects

This commit is contained in:
Yoshi Askharoun
2025-08-09 00:06:09 -05:00
parent 7cf79e87f9
commit 3307b6ea3c
8 changed files with 61 additions and 68 deletions
+7 -11
View File
@@ -250,25 +250,21 @@ namespace Microsoft.Iris
MarkupSystem.UnloadAll();
}
public static void AddMarkupRedirect(string fromPrefix, string toPrefix)
[Obsolete("Only for backward compatibility. Use AddResourceRedirect")]
public static void AddMarkupRedirect(string fromPrefix, string toPrefix) => AddResourceRedirect(fromPrefix, toPrefix, -1);
public static void AddResourceRedirect(string fromPrefix, string toPrefix, int bank = -1)
{
UIDispatcher.VerifyOnApplicationThread();
if (fromPrefix == null)
throw new ArgumentNullException(nameof(fromPrefix));
if (toPrefix == null)
throw new ArgumentNullException(nameof(toPrefix));
ResourceManager.Instance.AddUriRedirect(fromPrefix, toPrefix);
ResourceManager.Instance.AddUriRedirect(fromPrefix, toPrefix, bank);
}
public static void AddImportRedirect(string fromPrefix, string toPrefix)
{
UIDispatcher.VerifyOnApplicationThread();
if (fromPrefix == null)
throw new ArgumentNullException(nameof(fromPrefix));
if (toPrefix == null)
throw new ArgumentNullException(nameof(toPrefix));
MarkupSystem.AddImportRedirect(fromPrefix, toPrefix);
}
[Obsolete("Only for backward compatibility. Use AddResourceRedirect")]
public static void AddImportRedirect(string fromPrefix, string toPrefix) { }
public static void RegisterDataProvider(string name, DataProviderQueryFactory factory)
{
+22 -41
View File
@@ -28,8 +28,6 @@ namespace Microsoft.Iris.Markup
public static bool MarkupSystemActive;
private static Vector s_factoriesByProtocol;
private static Vector s_factoriesByExtension;
private static Vector<string> s_importRedirectsFrom;
private static Vector<string> s_importRedirectsTo;
private static uint s_rootIslandId;
private static uint s_activeIslands;
@@ -102,37 +100,41 @@ namespace Microsoft.Iris.Markup
public static LoadResult ResolveLoadResult(string uri, uint islandId)
{
ErrorManager.EnterContext(uri);
uri = ApplyImportRedirects(uri);
LoadResult loadResult = LoadResultCache.Read(uri);
var loadResult = LoadResultCache.Read(uri);
if (loadResult == null)
{
bool flag = false;
bool cacheResult = true;
foreach (MarkupSystem.Factory factory in s_factoriesByProtocol)
var handled = false;
var cacheResult = true;
foreach (Factory factory in s_factoriesByProtocol)
{
if (uri.StartsWith(factory.key, StringComparison.Ordinal))
{
loadResult = factory.handler(uri);
flag = true;
handled = true;
break;
}
}
if (!flag)
if (!handled)
{
foreach (MarkupSystem.Factory factory in s_factoriesByExtension)
foreach (Factory factory in s_factoriesByExtension)
{
if (uri.EndsWith(factory.key, StringComparison.Ordinal))
{
loadResult = factory.handler(uri);
flag = true;
handled = true;
break;
}
}
}
if (!flag)
if (!handled)
loadResult = CreateMarkupLoadResult(uri, ref cacheResult);
if (loadResult == null)
loadResult = new ErrorLoadResult(uri);
loadResult ??= new ErrorLoadResult(uri);
if (cacheResult && loadResult.Cachable)
{
LoadResultCache.Write(uri, loadResult);
@@ -140,8 +142,10 @@ namespace Microsoft.Iris.Markup
LoadResultCache.Write(loadResult.UnderlyingUri, loadResult);
}
}
loadResult?.AddReference(islandId);
ErrorManager.ExitContext();
return loadResult;
}
@@ -226,34 +230,11 @@ namespace Microsoft.Iris.Markup
return flag;
}
public static void AddImportRedirect(string fromPrefix, string toPrefix)
{
if (s_importRedirectsFrom == null)
{
s_importRedirectsFrom = new Vector<string>();
s_importRedirectsTo = new Vector<string>();
}
s_importRedirectsFrom.Add(fromPrefix);
s_importRedirectsTo.Add(toPrefix);
}
[Obsolete]
public static void AddImportRedirect(string fromPrefix, string toPrefix) { }
private static string ApplyImportRedirects(string uri)
{
if (s_importRedirectsFrom != null)
{
for (int index = 0; index < s_importRedirectsFrom.Count; ++index)
{
string str = s_importRedirectsFrom[index];
if (uri.StartsWith(str, StringComparison.Ordinal))
{
uri = uri.Substring(str.Length);
uri = s_importRedirectsTo[index] + uri;
break;
}
}
}
return uri;
}
[Obsolete]
private static string ApplyImportRedirects(string uri) => uri;
public static bool IsDebuggingEnabled(byte level) => !CompileMode && Trace.IsCategoryEnabled(TraceCategory.MarkupDebug, level);
+11 -2
View File
@@ -31,20 +31,29 @@ namespace Microsoft.Iris.OS
string errorDetails = null;
if (_buffer == IntPtr.Zero)
{
var error = true;
try
{
var rm = new ResourceManagerCore(_specifier, _assembly);
var data = (byte[])rm.GetObject(_identifier);
var data = rm.GetObject(_identifier) as byte[];
if (data is not null)
{
_handle = GCHandle.Alloc(data, GCHandleType.Pinned);
_buffer = _handle.AddrOfPinnedObject();
_length = (uint)data.LongLength;
error = false;
}
}
catch
{
errorDetails = $"Resource '{_identifier}' not found in {_assembly}, resource '{_specifier}'";
error = true;
}
if (error)
errorDetails = $"Resource '{_identifier}' not found in {_assembly}, resource '{_specifier}'";
}
NotifyAcquisitionComplete(_buffer, _length, false, errorDetails);
}
+1
View File
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><root><resheader name="resmimetype"><value>text/microsoft-resx</value></resheader><resheader name="version"><value>2.0</value></resheader><resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader><resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader><assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /><data name="ACQUIRINGIMAGE.PNG" type="System.Resources.ResXFileRef, System.Windows.Forms"><value>Resources\ACQUIRINGIMAGE.PNG;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></data><data name="ERRORIMAGE.PNG" type="System.Resources.ResXFileRef, System.Windows.Forms"><value>Resources\ERRORIMAGE.PNG;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></data></root>
+7
View File
@@ -29,4 +29,11 @@
<PackageReference Include="System.Security.Permissions" Version="6.0.0" />
<PackageReference Include="Vanara.PInvoke.Accessibility" Version="3.4.2" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="RCDATA.resx">
<Generator></Generator>
<LogicalName>RCDATA.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>
+1 -8
View File
@@ -5,7 +5,6 @@
// Assembly location: C:\Program Files\Zune\UIXcontrols.dll
using Microsoft.Iris;
using Microsoft.Iris.Data;
#nullable disable
namespace UIXControls
@@ -14,12 +13,6 @@ namespace UIXControls
{
public static bool IsModelItemDisposed(ModelItem item) => item.IsDisposed;
public static void AddUIXControlsClrRedirect() => AddResourceRedirect("res://UIXControls!", "clr-res://UIXControls!");
public static void AddResourceRedirect(string fromPrefix, string toPrefix)
{
Application.AddImportRedirect(fromPrefix, toPrefix);
ResourceManager.Instance.AddUriRedirect(fromPrefix, toPrefix);
}
public static void AddUIXControlsClrRedirect() => Application.AddResourceRedirect("res://UIXControls!", "clr-res://UIXControls!");
}
}
File diff suppressed because one or more lines are too long
+7 -2
View File
@@ -9,8 +9,13 @@
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\**\*.*" />
<ProjectReference Include="..\UIX\UIX.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\RCDATA.resx">
<Generator></Generator>
<LogicalName>RCDATA.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>