Fix renamer
This commit is contained in:
parent
50c2f2fcc5
commit
fce2869dac
@ -10,21 +10,7 @@ internal class Remapper
|
|||||||
public void InitializeRemap()
|
public void InitializeRemap()
|
||||||
{
|
{
|
||||||
DisplayBasicModuleInformation();
|
DisplayBasicModuleInformation();
|
||||||
StartRemap();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DisplayBasicModuleInformation()
|
|
||||||
{
|
|
||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
|
||||||
Logger.Log($"Starting remap...", ConsoleColor.Yellow);
|
|
||||||
Logger.Log($"Module contains {DataProvider.ModuleDefinition.Types.Count} Types", ConsoleColor.Yellow);
|
|
||||||
Logger.Log($"Publicize: {DataProvider.AppSettings.Publicize}", ConsoleColor.Yellow);
|
|
||||||
Logger.Log($"Unseal: {DataProvider.AppSettings.Unseal}", ConsoleColor.Yellow);
|
|
||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartRemap()
|
|
||||||
{
|
|
||||||
foreach (var remap in DataProvider.Remaps)
|
foreach (var remap in DataProvider.Remaps)
|
||||||
{
|
{
|
||||||
Logger.Log($"Trying to remap {remap.NewTypeName}...", ConsoleColor.Gray);
|
Logger.Log($"Trying to remap {remap.NewTypeName}...", ConsoleColor.Gray);
|
||||||
@ -44,6 +30,16 @@ internal class Remapper
|
|||||||
WriteAssembly();
|
WriteAssembly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DisplayBasicModuleInformation()
|
||||||
|
{
|
||||||
|
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
||||||
|
Logger.Log($"Starting remap...", ConsoleColor.Yellow);
|
||||||
|
Logger.Log($"Module contains {DataProvider.ModuleDefinition.Types.Count} Types", ConsoleColor.Yellow);
|
||||||
|
Logger.Log($"Publicize: {DataProvider.AppSettings.Publicize}", ConsoleColor.Yellow);
|
||||||
|
Logger.Log($"Unseal: {DataProvider.AppSettings.Unseal}", ConsoleColor.Yellow);
|
||||||
|
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
||||||
|
}
|
||||||
|
|
||||||
private void HandleMapping(RemapModel mapping)
|
private void HandleMapping(RemapModel mapping)
|
||||||
{
|
{
|
||||||
foreach (var type in DataProvider.ModuleDefinition.Types)
|
foreach (var type in DataProvider.ModuleDefinition.Types)
|
||||||
@ -123,6 +119,9 @@ internal class Remapper
|
|||||||
Definition = type,
|
Definition = type,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set the original type name to be used later
|
||||||
|
score.RemapModel.OriginalTypeName = type.Name;
|
||||||
|
|
||||||
if (type.MatchIsAbstract(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsAbstract(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
LogDiscard("IsAbstract", type.Name, score.ProposedNewName);
|
LogDiscard("IsAbstract", type.Name, score.ProposedNewName);
|
||||||
@ -210,10 +209,12 @@ internal class Remapper
|
|||||||
var oldName = type.Name;
|
var oldName = type.Name;
|
||||||
type.Name = remap.NewTypeName;
|
type.Name = remap.NewTypeName;
|
||||||
|
|
||||||
RenameService.RenameAllFields(remap, DataProvider.ModuleDefinition.Types);
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
RenameService.RenameAllProperties(remap, DataProvider.ModuleDefinition.Types);
|
|
||||||
|
|
||||||
Logger.Log($"Renamed {oldName} to {type.Name} directly", ConsoleColor.Green);
|
Logger.Log($"Renamed {oldName} to {type.Name} directly", ConsoleColor.Green);
|
||||||
|
|
||||||
|
RenameService.RenameAllDirect(remap, type);
|
||||||
|
|
||||||
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogDiscard(string action, string type, string search)
|
private void LogDiscard(string action, string type, string search)
|
||||||
@ -251,9 +252,8 @@ internal class Remapper
|
|||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
Logger.Log($"Renaming {highestScore.Definition.Name} to {highestScore.ProposedNewName}", ConsoleColor.Green);
|
Logger.Log($"Renaming {highestScore.Definition.Name} to {highestScore.ProposedNewName}", ConsoleColor.Green);
|
||||||
|
|
||||||
RenameService.RenameAllFields(highestScore.RemapModel, DataProvider.ModuleDefinition.Types);
|
// Rename type and all associated type members
|
||||||
RenameService.RenameAllProperties(highestScore.RemapModel, DataProvider.ModuleDefinition.Types);
|
RenameService.RenameAll(highestScore);
|
||||||
highestScore.Definition.Name = highestScore.ProposedNewName;
|
|
||||||
|
|
||||||
if (DataProvider.AppSettings.ScoringMode)
|
if (DataProvider.AppSettings.ScoringMode)
|
||||||
{
|
{
|
||||||
|
@ -7,21 +7,44 @@ namespace AssemblyRemapper.Reflection;
|
|||||||
|
|
||||||
internal static class RenameService
|
internal static class RenameService
|
||||||
{
|
{
|
||||||
public static void RenameAllFields(
|
public static void RenameAll(ScoringModel score)
|
||||||
RemapModel remap,
|
{
|
||||||
|
var types = DataProvider.ModuleDefinition.Types;
|
||||||
|
|
||||||
|
// Rename all fields and properties first
|
||||||
|
RenameAllFields(score, types);
|
||||||
|
RenameAllProperties(score, types);
|
||||||
|
|
||||||
|
score.Definition.Name = score.ProposedNewName;
|
||||||
|
|
||||||
|
types.FirstOrDefault(t => t.Name == score.ProposedNewName).Name = score.ProposedNewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RenameAllDirect(RemapModel remap, TypeDefinition type)
|
||||||
|
{
|
||||||
|
var directRename = new ScoringModel();
|
||||||
|
directRename.Definition = type;
|
||||||
|
directRename.RemapModel = remap;
|
||||||
|
|
||||||
|
RenameAll(directRename);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RenameAllFields(
|
||||||
|
ScoringModel score,
|
||||||
Collection<TypeDefinition> typesToCheck)
|
Collection<TypeDefinition> typesToCheck)
|
||||||
{
|
{
|
||||||
foreach (var type in typesToCheck)
|
foreach (var type in typesToCheck)
|
||||||
{
|
{
|
||||||
int fieldCount = 0;
|
int fieldCount = 0;
|
||||||
|
|
||||||
foreach (var field in type.Fields)
|
foreach (var field in type.Fields)
|
||||||
{
|
{
|
||||||
if (field.FieldType.ToString() == remap.NewTypeName)
|
if (field.FieldType.Name == score.Definition.Name)
|
||||||
{
|
{
|
||||||
var newFieldName = GetNewFieldName(remap.NewTypeName, field.IsPrivate, fieldCount);
|
var newFieldName = GetNewFieldName(score.RemapModel.NewTypeName, field.IsPrivate, fieldCount);
|
||||||
|
|
||||||
Logger.Log($"Renaming: `{field.Name}` on Type `{type}` to {remap.NewTypeName}");
|
if (field.Name == newFieldName) { continue; }
|
||||||
|
|
||||||
|
Logger.Log($"Renaming field: `{field.Name}` on Type `{type.Name}` to {newFieldName}");
|
||||||
|
|
||||||
field.Name = newFieldName;
|
field.Name = newFieldName;
|
||||||
|
|
||||||
@ -33,14 +56,14 @@ internal static class RenameService
|
|||||||
{
|
{
|
||||||
foreach (var _ in type.NestedTypes)
|
foreach (var _ in type.NestedTypes)
|
||||||
{
|
{
|
||||||
RenameAllFields(remap, type.NestedTypes);
|
RenameAllFields(score, type.NestedTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RenameAllProperties(
|
private static void RenameAllProperties(
|
||||||
RemapModel remap,
|
ScoringModel score,
|
||||||
Collection<TypeDefinition> typesToCheck)
|
Collection<TypeDefinition> typesToCheck)
|
||||||
{
|
{
|
||||||
foreach (var type in typesToCheck)
|
foreach (var type in typesToCheck)
|
||||||
@ -49,10 +72,12 @@ internal static class RenameService
|
|||||||
|
|
||||||
foreach (var property in type.Properties)
|
foreach (var property in type.Properties)
|
||||||
{
|
{
|
||||||
if (property.PropertyType.ToString() == remap.NewTypeName)
|
if (property.PropertyType.Name == score.Definition.Name)
|
||||||
{
|
{
|
||||||
Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}`");
|
var newName = propertyCount > 0 ? $"{score.RemapModel.NewTypeName}_{propertyCount}" : score.RemapModel.NewTypeName;
|
||||||
property.Name = propertyCount > 0 ? $"{remap.NewTypeName}_{propertyCount}" : remap.NewTypeName;
|
|
||||||
|
Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}` to {newName}");
|
||||||
|
property.Name = newName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +85,7 @@ internal static class RenameService
|
|||||||
{
|
{
|
||||||
foreach (var _ in type.NestedTypes)
|
foreach (var _ in type.NestedTypes)
|
||||||
{
|
{
|
||||||
RenameAllProperties(remap, type.NestedTypes);
|
RenameAllProperties(score, type.NestedTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ namespace AssemblyRemapper.Reflection;
|
|||||||
|
|
||||||
internal static class SearchProvider
|
internal static class SearchProvider
|
||||||
{
|
{
|
||||||
public static int MatchCount { get; private set; }
|
|
||||||
|
|
||||||
public static EMatchResult MatchIsAbstract(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchIsAbstract(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.IsAbstract is null)
|
if (parms.IsAbstract is null)
|
||||||
@ -17,7 +15,7 @@ internal static class SearchProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Interfaces cannot be abstract, and abstract cannot be static
|
// Interfaces cannot be abstract, and abstract cannot be static
|
||||||
if (type.IsInterface || type.GetStaticConstructor() != null)
|
if (type.IsInterface || type.GetStaticConstructor() is not null)
|
||||||
{
|
{
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user