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(); 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(); UIDispatcher.VerifyOnApplicationThread();
if (fromPrefix == null) if (fromPrefix == null)
throw new ArgumentNullException(nameof(fromPrefix)); throw new ArgumentNullException(nameof(fromPrefix));
if (toPrefix == null) if (toPrefix == null)
throw new ArgumentNullException(nameof(toPrefix)); throw new ArgumentNullException(nameof(toPrefix));
ResourceManager.Instance.AddUriRedirect(fromPrefix, toPrefix); ResourceManager.Instance.AddUriRedirect(fromPrefix, toPrefix, bank);
} }
public static void AddImportRedirect(string fromPrefix, string toPrefix) [Obsolete("Only for backward compatibility. Use AddResourceRedirect")]
{ 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);
}
public static void RegisterDataProvider(string name, DataProviderQueryFactory factory) public static void RegisterDataProvider(string name, DataProviderQueryFactory factory)
{ {
+22 -41
View File
@@ -28,8 +28,6 @@ namespace Microsoft.Iris.Markup
public static bool MarkupSystemActive; public static bool MarkupSystemActive;
private static Vector s_factoriesByProtocol; private static Vector s_factoriesByProtocol;
private static Vector s_factoriesByExtension; 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_rootIslandId;
private static uint s_activeIslands; private static uint s_activeIslands;
@@ -102,37 +100,41 @@ namespace Microsoft.Iris.Markup
public static LoadResult ResolveLoadResult(string uri, uint islandId) public static LoadResult ResolveLoadResult(string uri, uint islandId)
{ {
ErrorManager.EnterContext(uri); ErrorManager.EnterContext(uri);
uri = ApplyImportRedirects(uri); var loadResult = LoadResultCache.Read(uri);
LoadResult loadResult = LoadResultCache.Read(uri);
if (loadResult == null) if (loadResult == null)
{ {
bool flag = false; var handled = false;
bool cacheResult = true; var cacheResult = true;
foreach (MarkupSystem.Factory factory in s_factoriesByProtocol)
foreach (Factory factory in s_factoriesByProtocol)
{ {
if (uri.StartsWith(factory.key, StringComparison.Ordinal)) if (uri.StartsWith(factory.key, StringComparison.Ordinal))
{ {
loadResult = factory.handler(uri); loadResult = factory.handler(uri);
flag = true; handled = true;
break; 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)) if (uri.EndsWith(factory.key, StringComparison.Ordinal))
{ {
loadResult = factory.handler(uri); loadResult = factory.handler(uri);
flag = true; handled = true;
break; break;
} }
} }
} }
if (!flag)
if (!handled)
loadResult = CreateMarkupLoadResult(uri, ref cacheResult); loadResult = CreateMarkupLoadResult(uri, ref cacheResult);
if (loadResult == null)
loadResult = new ErrorLoadResult(uri); loadResult ??= new ErrorLoadResult(uri);
if (cacheResult && loadResult.Cachable) if (cacheResult && loadResult.Cachable)
{ {
LoadResultCache.Write(uri, loadResult); LoadResultCache.Write(uri, loadResult);
@@ -140,8 +142,10 @@ namespace Microsoft.Iris.Markup
LoadResultCache.Write(loadResult.UnderlyingUri, loadResult); LoadResultCache.Write(loadResult.UnderlyingUri, loadResult);
} }
} }
loadResult?.AddReference(islandId); loadResult?.AddReference(islandId);
ErrorManager.ExitContext(); ErrorManager.ExitContext();
return loadResult; return loadResult;
} }
@@ -226,34 +230,11 @@ namespace Microsoft.Iris.Markup
return flag; return flag;
} }
public static void AddImportRedirect(string fromPrefix, string toPrefix) [Obsolete]
{ 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);
}
private static string ApplyImportRedirects(string uri) [Obsolete]
{ private static string ApplyImportRedirects(string uri) => 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;
}
public static bool IsDebuggingEnabled(byte level) => !CompileMode && Trace.IsCategoryEnabled(TraceCategory.MarkupDebug, level); public static bool IsDebuggingEnabled(byte level) => !CompileMode && Trace.IsCategoryEnabled(TraceCategory.MarkupDebug, level);
+14 -5
View File
@@ -31,20 +31,29 @@ namespace Microsoft.Iris.OS
string errorDetails = null; string errorDetails = null;
if (_buffer == IntPtr.Zero) if (_buffer == IntPtr.Zero)
{ {
var error = true;
try try
{ {
var rm = new ResourceManagerCore(_specifier, _assembly); var rm = new ResourceManagerCore(_specifier, _assembly);
var data = (byte[])rm.GetObject(_identifier); var data = rm.GetObject(_identifier) as byte[];
_handle = GCHandle.Alloc(data, GCHandleType.Pinned); if (data is not null)
_buffer = _handle.AddrOfPinnedObject(); {
_length = (uint)data.LongLength; _handle = GCHandle.Alloc(data, GCHandleType.Pinned);
_buffer = _handle.AddrOfPinnedObject();
_length = (uint)data.LongLength;
error = false;
}
} }
catch 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); 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="System.Security.Permissions" Version="6.0.0" />
<PackageReference Include="Vanara.PInvoke.Accessibility" Version="3.4.2" /> <PackageReference Include="Vanara.PInvoke.Accessibility" Version="3.4.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Update="RCDATA.resx">
<Generator></Generator>
<LogicalName>RCDATA.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project> </Project>
+1 -8
View File
@@ -5,7 +5,6 @@
// Assembly location: C:\Program Files\Zune\UIXcontrols.dll // Assembly location: C:\Program Files\Zune\UIXcontrols.dll
using Microsoft.Iris; using Microsoft.Iris;
using Microsoft.Iris.Data;
#nullable disable #nullable disable
namespace UIXControls namespace UIXControls
@@ -14,12 +13,6 @@ namespace UIXControls
{ {
public static bool IsModelItemDisposed(ModelItem item) => item.IsDisposed; public static bool IsModelItemDisposed(ModelItem item) => item.IsDisposed;
public static void AddUIXControlsClrRedirect() => AddResourceRedirect("res://UIXControls!", "clr-res://UIXControls!"); public static void AddUIXControlsClrRedirect() => Application.AddResourceRedirect("res://UIXControls!", "clr-res://UIXControls!");
public static void AddResourceRedirect(string fromPrefix, string toPrefix)
{
Application.AddImportRedirect(fromPrefix, toPrefix);
ResourceManager.Instance.AddUriRedirect(fromPrefix, toPrefix);
}
} }
} }
File diff suppressed because one or more lines are too long
+8 -3
View File
@@ -7,10 +7,15 @@
<RootNamespace>UIXControls</RootNamespace> <RootNamespace>UIXControls</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\**\*.*" />
<ProjectReference Include="..\UIX\UIX.csproj" /> <ProjectReference Include="..\UIX\UIX.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\RCDATA.resx">
<Generator></Generator>
<LogicalName>RCDATA.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project> </Project>