Skip to content

Commit 0f0130e

Browse files
committed
Fix relative parent ResourceDirectory loading.
1 parent 3c9c29d commit 0f0130e

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

Confuser.Renamer/Analyzers/WPFAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef meth
177177
if (match.Success)
178178
operand = match.Groups[1].Value;
179179
else if (operand.Contains("/"))
180-
context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", instr.Operand);
180+
context.Logger.WarnFormat("[WPF] Fail to extract XAML name from '{0}'.", instr.Operand);
181181

182182
var reference = new BAMLStringReference(instr);
183183
operand = operand.TrimStart('/');

Confuser.Renamer/BAML/BAMLAnalyzer.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,27 @@ void ProcessConverter(PropertyWithConverterRecord rec, TypeDef type) {
503503
if (declType == "System.Windows.ResourceDictionary") {
504504
var src = rec.Value.ToUpperInvariant();
505505
if (src.EndsWith(".BAML") || src.EndsWith(".XAML")) {
506-
var match = WPFAnalyzer.UriPattern.Match(src);
507-
if (match.Success)
508-
src = match.Groups[1].Value;
509-
else if (rec.Value.Contains("/"))
510-
context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", rec.Value);
511-
512-
if (!src.Contains("//")) {
513-
var rel = new Uri(new Uri(packScheme + "application:,,,/" + CurrentBAMLName), src);
514-
src = rel.LocalPath;
506+
// Relative address
507+
if (src.StartsWith("../")) {
508+
var oldSrc = src;
509+
var fake_domain = "http://Confuser.Ex/";
510+
var uri = new Uri(fake_domain + CurrentBAMLName + "/../" + src);
511+
src = uri.ToString().Substring(fake_domain.Length);
512+
513+
context.Logger.InfoFormat("Convert [{0}] at [{1}] to [{2}].", oldSrc, CurrentBAMLName, src);
514+
} else {
515+
var match = WPFAnalyzer.UriPattern.Match(src);
516+
if (match.Success)
517+
src = match.Groups[1].Value;
518+
else if (rec.Value.Contains("/"))
519+
context.Logger.WarnFormat("[BAML] Fail to extract XAML name from '{0}'.", rec.Value);
520+
521+
if (!src.Contains("//")) {
522+
var rel = new Uri(new Uri(packScheme + "application:,,,/" + CurrentBAMLName), src);
523+
src = rel.LocalPath;
524+
}
515525
}
526+
516527
var reference = new BAMLPropertyReference(rec);
517528
src = src.TrimStart('/');
518529
var baml = src.Substring(0, src.Length - 5) + ".BAML";

0 commit comments

Comments
 (0)