Compare commits

...

2 Commits

Author SHA1 Message Date
Leilei Zhang
0d086a7ad1 update log 2025-06-24 09:52:10 +08:00
Leilei Zhang
14feac48d6 slow 2025-06-23 19:58:06 +08:00

View File

@@ -173,6 +173,25 @@ public class UWPApplication : IProgram
return false;
}
private static string TryLoadIndirectString(string source, Span<char> buffer, string errorContext)
{
try
{
PInvoke.SHLoadIndirectString(source, buffer).ThrowOnFailure();
var len = buffer.IndexOf('\0');
var loaded = len >= 0
? buffer[..len].ToString()
: buffer.ToString();
return string.IsNullOrEmpty(loaded) ? string.Empty : loaded;
}
catch (Exception ex)
{
Logger.LogError($"Unable to load resource {source} : {errorContext} : {ex.Message}");
return string.Empty;
}
}
internal unsafe string ResourceFromPri(string packageFullName, string resourceReference)
{
const string prefix = "ms-resource:";
@@ -221,28 +240,15 @@ public class UWPApplication : IProgram
Span<char> outBuffer = stackalloc char[1024];
var source = $"@{{{packageFullName}? {parsed}}}";
try
{
PInvoke.SHLoadIndirectString(source, outBuffer).ThrowOnFailure();
var loaded = TryLoadIndirectString(source, outBuffer, resourceReference);
var loaded = outBuffer.ToString();
return string.IsNullOrEmpty(loaded) ? string.Empty : loaded;
}
catch (Exception)
if (!string.IsNullOrEmpty(loaded))
{
try
{
var sourceFallback = $"@{{{packageFullName}?{parsedFallback}}}";
PInvoke.SHLoadIndirectString(sourceFallback, outBuffer).ThrowOnFailure();
var loaded = outBuffer.ToString();
return string.IsNullOrEmpty(loaded) ? string.Empty : loaded;
}
catch (Exception)
{
// ProgramLogger.Exception($"Unable to load resource {resourceReference} from {packageFullName}", new InvalidOperationException(), GetType(), packageFullName);
return string.Empty;
}
return loaded;
}
var sourceFallback = $"@{{{packageFullName}?{parsedFallback}}}";
return TryLoadIndirectString(sourceFallback, outBuffer, $"{resourceReference} (fallback)");
}
else
{