Fixed analysis of XAML references
The pack strings were not properly analyzed and handled, causing illegal values to be placed in the embedded baml files.
This commit is contained in:
Родитель
2bce5bb210
Коммит
0709c71811
|
@ -17,7 +17,7 @@ namespace Confuser.Renamer.Analyzers {
|
|||
static readonly object BAMLKey = new object();
|
||||
|
||||
static readonly Regex ResourceNamePattern = new Regex("^.*\\.g\\.resources$");
|
||||
internal static readonly Regex UriPattern = new Regex("(?:;COMPONENT|APPLICATION\\:,,,)(/.+\\.[BX]AML)$");
|
||||
internal static readonly Regex UriPattern = new Regex("^(?:PACK\\://(?:COMPONENT|APPLICATION)\\:,,,)*(?:/(.+);COMPONENT)*(/.+\\.[BX]AML)$");
|
||||
BAMLAnalyzer analyzer;
|
||||
|
||||
internal Dictionary<string, List<IBAMLReference>> bamlRefs = new Dictionary<string, List<IBAMLReference>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
@ -180,8 +180,15 @@ namespace Confuser.Renamer.Analyzers {
|
|||
var operand = ((string)instr.Operand).ToUpperInvariant();
|
||||
if (operand.EndsWith(".BAML") || operand.EndsWith(".XAML")) {
|
||||
var match = UriPattern.Match(operand);
|
||||
if (match.Success)
|
||||
operand = match.Groups[1].Value;
|
||||
if (match.Success) {
|
||||
var resourceAssemblyName = match.Groups[1].Value;
|
||||
if (resourceAssemblyName != null && !resourceAssemblyName.Equals(method.Module.Assembly.Name.String, StringComparison.OrdinalIgnoreCase)) {
|
||||
// This resource points to another assembly.
|
||||
// Leave it alone!
|
||||
return;
|
||||
}
|
||||
operand = match.Groups[2].Value;
|
||||
}
|
||||
else if (operand.Contains("/"))
|
||||
context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", instr.Operand);
|
||||
|
||||
|
|
|
@ -504,12 +504,19 @@ namespace Confuser.Renamer.BAML {
|
|||
var src = rec.Value.ToUpperInvariant();
|
||||
if (src.EndsWith(".BAML") || src.EndsWith(".XAML")) {
|
||||
var match = WPFAnalyzer.UriPattern.Match(src);
|
||||
if (match.Success)
|
||||
src = match.Groups[1].Value;
|
||||
if (match.Success) {
|
||||
var resourceAssemblyName = match.Groups[1].Value;
|
||||
if (resourceAssemblyName != null && !resourceAssemblyName.Equals(Module.Assembly.Name.String, StringComparison.OrdinalIgnoreCase)) {
|
||||
// This resource points to another assembly.
|
||||
// Leave it alone!
|
||||
return;
|
||||
}
|
||||
src = match.Groups[2].Value;
|
||||
}
|
||||
else if (rec.Value.Contains("/"))
|
||||
context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", rec.Value);
|
||||
|
||||
if (!src.Contains("//")) {
|
||||
if (!src.StartsWith(packScheme, StringComparison.OrdinalIgnoreCase)) {
|
||||
var rel = new Uri(new Uri(packScheme + "application:,,,/" + CurrentBAMLName), src);
|
||||
src = rel.LocalPath;
|
||||
}
|
||||
|
@ -652,4 +659,4 @@ namespace Confuser.Renamer.BAML {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,19 @@ namespace Confuser.Renamer.BAML {
|
|||
|
||||
public void Rename(string oldName, string newName) {
|
||||
var value = rec.Value;
|
||||
if (value.IndexOf(oldName, StringComparison.OrdinalIgnoreCase) != -1)
|
||||
value = newName;
|
||||
else if (oldName.EndsWith(".baml")) {
|
||||
Debug.Assert(newName.EndsWith(".baml"));
|
||||
value = newName.Substring(0, newName.Length - 5) + ".xaml";
|
||||
if (value.IndexOf(oldName, StringComparison.OrdinalIgnoreCase) != -1) {
|
||||
rec.Value = value.Substring(0, value.Length - oldName.Length) + newName;
|
||||
}
|
||||
else
|
||||
throw new UnreachableException();
|
||||
rec.Value = "pack://application:,,,/" + value;
|
||||
else if (oldName.EndsWith(".baml", StringComparison.OrdinalIgnoreCase)) {
|
||||
// Lets try this again with .xaml at the end.
|
||||
Rename(ToXaml(oldName), ToXaml(newName));
|
||||
}
|
||||
// Reaching this point means that the record was already properly replaced.
|
||||
}
|
||||
|
||||
private static string ToXaml(string refName) {
|
||||
Debug.Assert(refName.EndsWith(".baml"));
|
||||
return refName.Substring(0, refName.Length - 5) + ".xaml";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче