Fix Nested renaming

This commit is contained in:
Cj 2024-06-22 02:28:36 -04:00
parent c10e9a6d3e
commit fe6145cb08
3 changed files with 26 additions and 8 deletions

View File

@ -135,15 +135,17 @@ public class ReCodeItRemapper
var tokens = DataProvider.Settings.AutoMapper.TokensToMatch; var tokens = DataProvider.Settings.AutoMapper.TokensToMatch;
if (tokens.Where(token => !tokens.Any(token => type.Name.StartsWith(token))).Any()) bool ignore = tokens
.Where(token => !tokens
.Any(token => type.Name.StartsWith(token))).Any();
if (ignore && remap.SearchParams.IsNested is null)
{ {
return; return;
} }
foreach (var nestedType in type.NestedTypes) foreach (var nestedType in type.NestedTypes)
{ {
if (remap.SearchParams.IsNested is false) { return; }
FindMatch(nestedType, remap); FindMatch(nestedType, remap);
} }
@ -188,8 +190,8 @@ public class ReCodeItRemapper
if (match) if (match)
{ {
// Set the original type name to be used later // Set the original type name to be used later
score.ReMap.OriginalTypeName = type.Name; score.ReMap.OriginalTypeName = type.FullName;
remap.OriginalTypeName = type.Name; remap.OriginalTypeName = type.FullName;
remap.Succeeded = true; remap.Succeeded = true;
remap.FailureReason = EFailureReason.None; remap.FailureReason = EFailureReason.None;
score.AddScoreToResult(); score.AddScoreToResult();
@ -271,7 +273,7 @@ public class ReCodeItRemapper
if (highestScore is null) { return; } if (highestScore is null) { return; }
Logger.Log("-----------------------------------------------", ConsoleColor.Green); Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log($"Renaming {highestScore.Definition.Name} to {highestScore.ProposedNewName}", ConsoleColor.Green); Logger.Log($"Renaming {highestScore.Definition.FullName} to {highestScore.ProposedNewName}", ConsoleColor.Green);
Logger.Log($"Scored: {highestScore.Score} points", ConsoleColor.Green); Logger.Log($"Scored: {highestScore.Score} points", ConsoleColor.Green);
if (filteredScores.Count() > 1 && filteredScores.Skip(1).Any(score => score.Score == highestScore.Score)) if (filteredScores.Count() > 1 && filteredScores.Skip(1).Any(score => score.Score == highestScore.Score))
@ -284,7 +286,7 @@ public class ReCodeItRemapper
} }
} }
// highestScore.ReMap.OriginalTypeName = highestScore.Definition.Name; highestScore.ReMap.OriginalTypeName = highestScore.Definition.Name;
if (CrossMapMode) if (CrossMapMode)
{// Store the original types for caching {// Store the original types for caching

View File

@ -166,7 +166,13 @@ internal static class RenameHelper
RenameType(type.NestedTypes, score); RenameType(type.NestedTypes, score);
} }
if (score.Definition.Name == null) { continue; } if (score.Definition.Name is null) { continue; }
if (score.ReMap.SearchParams.IsNested is true &&
type.IsNested && type.Name == score.Definition.Name)
{
type.Name = score.ProposedNewName;
}
if (type.FullName == score.Definition.Name) if (type.FullName == score.Definition.Name)
{ {

View File

@ -55,6 +55,16 @@ internal static class TypeDefExtensions
return EMatchResult.Disabled; return EMatchResult.Disabled;
} }
if (parms.ParentName is not null)
{
if (type.Name == parms.ParentName)
{
Logger.Log($"Match! {type.Name} : {score.ProposedNewName}");
score.Score++;
return EMatchResult.Match;
}
}
if (type.IsNested == parms.IsNested) if (type.IsNested == parms.IsNested)
{ {
score.Score++; score.Score++;