Current progress
This commit is contained in:
parent
f76ba2f091
commit
dfd50b3b75
@ -27,7 +27,7 @@ internal class Remap
|
|||||||
|
|
||||||
public string OldTypeName { get; set; } = string.Empty;
|
public string OldTypeName { get; set; } = string.Empty;
|
||||||
|
|
||||||
public bool UseDirectRename { get; set; }
|
public bool UseForceRename { get; set; }
|
||||||
|
|
||||||
public RemapSearchParams SearchParams { get; set; } = new();
|
public RemapSearchParams SearchParams { get; set; } = new();
|
||||||
}
|
}
|
||||||
@ -46,8 +46,7 @@ internal class RemapSearchParams
|
|||||||
public bool? IsSealed { get; set; } = null;
|
public bool? IsSealed { get; set; } = null;
|
||||||
public bool? HasAttribute { get; set; } = null;
|
public bool? HasAttribute { get; set; } = null;
|
||||||
public bool? IsDerived { get; set; } = null;
|
public bool? IsDerived { get; set; } = null;
|
||||||
public string? BaseClassName { get; set; } = null;
|
public bool? HasGenericParameters { get; set; } = null;
|
||||||
public bool? IsGeneric { get; set; } = null;
|
|
||||||
public HashSet<string> MethodNamesToMatch { get; set; } = [];
|
public HashSet<string> MethodNamesToMatch { get; set; } = [];
|
||||||
public HashSet<string> MethodNamesToIgnore { get; set; } = [];
|
public HashSet<string> MethodNamesToIgnore { get; set; } = [];
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using AssemblyRemapper.Reflection;
|
using AssemblyRemapper.Utils;
|
||||||
using Mono.Cecil;
|
using Mono.Cecil;
|
||||||
|
|
||||||
namespace AssemblyRemapper.Models;
|
namespace AssemblyRemapper.Models;
|
||||||
@ -22,8 +22,17 @@ internal static class ScoringModelExtensions
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Remapper.ScoringModels.TryGetValue(model.ProposedNewName, out HashSet<ScoringModel> modelHashset))
|
if (DataProvider.ScoringModels.TryGetValue(model.ProposedNewName, out HashSet<ScoringModel> modelHashset))
|
||||||
{
|
{
|
||||||
|
foreach (var outVal in modelHashset)
|
||||||
|
{
|
||||||
|
if (outVal.Definition.FullName == model.Definition.FullName)
|
||||||
|
{
|
||||||
|
Logger.Log("Skipping adding duplicate type match to list", ConsoleColor.Yellow);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modelHashset.Add(model);
|
modelHashset.Add(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -33,7 +42,7 @@ internal static class ScoringModelExtensions
|
|||||||
model
|
model
|
||||||
};
|
};
|
||||||
|
|
||||||
Remapper.ScoringModels.Add(model.ProposedNewName, newHash);
|
DataProvider.ScoringModels.Add(model.ProposedNewName, newHash);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -6,31 +6,27 @@ namespace AssemblyRemapper.Reflection;
|
|||||||
|
|
||||||
internal class Remapper
|
internal class Remapper
|
||||||
{
|
{
|
||||||
public static Dictionary<string, HashSet<ScoringModel>> ScoringModels { get; set; } = [];
|
|
||||||
|
|
||||||
public void InitializeRemap()
|
public void InitializeRemap()
|
||||||
{
|
{
|
||||||
// Make sure any previous results are cleared just incase
|
|
||||||
ScoringModels.Clear();
|
|
||||||
|
|
||||||
DisplayBasicModuleInformation();
|
DisplayBasicModuleInformation();
|
||||||
StartRemap();
|
StartRemap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisplayBasicModuleInformation()
|
private void DisplayBasicModuleInformation()
|
||||||
{
|
{
|
||||||
Logger.Log($"Module contains {DataProvider.ModuleDefinition.Types.Count} Types");
|
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Starting remap...");
|
Logger.Log($"Starting remap...", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Publicize: {DataProvider.AppSettings.Publicize}");
|
Logger.Log($"Module contains {DataProvider.ModuleDefinition.Types.Count} Types", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Unseal: {DataProvider.AppSettings.Unseal}");
|
Logger.Log($"Publicize: {DataProvider.AppSettings.Publicize}", ConsoleColor.Yellow);
|
||||||
|
Logger.Log($"Unseal: {DataProvider.AppSettings.Unseal}", ConsoleColor.Yellow);
|
||||||
|
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartRemap()
|
private void StartRemap()
|
||||||
{
|
{
|
||||||
foreach (var remap in DataProvider.AppSettings.Remaps)
|
foreach (var remap in DataProvider.AppSettings.Remaps)
|
||||||
{
|
{
|
||||||
Logger.Log("-----------------------------------------------");
|
Logger.Log($"Trying to remap {remap.NewTypeName}...", ConsoleColor.Gray);
|
||||||
Logger.Log($"Trying to remap {remap.NewTypeName}...");
|
|
||||||
|
|
||||||
HandleMapping(remap);
|
HandleMapping(remap);
|
||||||
}
|
}
|
||||||
@ -49,20 +45,8 @@ internal class Remapper
|
|||||||
|
|
||||||
private void HandleMapping(Remap mapping)
|
private void HandleMapping(Remap mapping)
|
||||||
{
|
{
|
||||||
string newName = mapping.NewTypeName;
|
|
||||||
string oldName = mapping?.OldTypeName ?? string.Empty;
|
|
||||||
|
|
||||||
bool useDirectRename = mapping.UseDirectRename;
|
|
||||||
|
|
||||||
foreach (var type in DataProvider.ModuleDefinition.Types)
|
foreach (var type in DataProvider.ModuleDefinition.Types)
|
||||||
{
|
{
|
||||||
// Handle Direct Remaps by strict naming first bypasses everything else
|
|
||||||
if (useDirectRename)
|
|
||||||
{
|
|
||||||
HandleByDirectName(oldName, newName, type);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScoreType(type, mapping);
|
ScoreType(type, mapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +55,7 @@ internal class Remapper
|
|||||||
{
|
{
|
||||||
if (!DataProvider.AppSettings.Publicize) { return; }
|
if (!DataProvider.AppSettings.Publicize) { return; }
|
||||||
|
|
||||||
Logger.Log("Starting publicization...");
|
Logger.Log("Starting publicization...", ConsoleColor.Green);
|
||||||
|
|
||||||
foreach (var type in DataProvider.ModuleDefinition.Types)
|
foreach (var type in DataProvider.ModuleDefinition.Types)
|
||||||
{
|
{
|
||||||
@ -109,7 +93,7 @@ internal class Remapper
|
|||||||
{
|
{
|
||||||
if (!DataProvider.AppSettings.Unseal) { return; }
|
if (!DataProvider.AppSettings.Unseal) { return; }
|
||||||
|
|
||||||
Logger.Log("Starting unseal...");
|
Logger.Log("Starting unseal...", ConsoleColor.Green);
|
||||||
|
|
||||||
foreach (var type in DataProvider.ModuleDefinition.Types)
|
foreach (var type in DataProvider.ModuleDefinition.Types)
|
||||||
{
|
{
|
||||||
@ -117,23 +101,15 @@ internal class Remapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleByDirectName(string oldName, string newName, TypeDefinition type)
|
|
||||||
{
|
|
||||||
if (type.Name != oldName) { return; }
|
|
||||||
|
|
||||||
Logger.Log($"Renaming directly...");
|
|
||||||
|
|
||||||
type.Name = newName;
|
|
||||||
|
|
||||||
RenameService.RenameAllFields(oldName, newName, DataProvider.ModuleDefinition.Types);
|
|
||||||
RenameService.RenameAllProperties(oldName, newName, DataProvider.ModuleDefinition.Types);
|
|
||||||
|
|
||||||
Logger.Log($"Renamed {oldName} to {newName}");
|
|
||||||
Logger.Log("-----------------------------------------------");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ScoreType(TypeDefinition type, Remap remap, string parentTypeName = "")
|
private void ScoreType(TypeDefinition type, Remap remap, string parentTypeName = "")
|
||||||
{
|
{
|
||||||
|
// Handle Direct Remaps by strict naming first bypasses everything else
|
||||||
|
if (remap.UseForceRename)
|
||||||
|
{
|
||||||
|
HandleByDirectName(type, remap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var nestedType in type.NestedTypes)
|
foreach (var nestedType in type.NestedTypes)
|
||||||
{
|
{
|
||||||
ScoreType(nestedType, remap, type.Name);
|
ScoreType(nestedType, remap, type.Name);
|
||||||
@ -147,33 +123,38 @@ internal class Remapper
|
|||||||
|
|
||||||
if (type.MatchIsAbstract(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsAbstract(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("IsAbstract", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (type.MatchIsEnum(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsEnum(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("IsEnum", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.MatchIsNested(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsNested(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("IsNested", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
type.MatchIsSealed(remap.SearchParams, score);
|
|
||||||
|
|
||||||
if (type.MatchIsSealed(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsSealed(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("IsSealed", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
if (type.MatchIsDerived(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsDerived(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("IsDerived", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.MatchIsInterface(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsInterface(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("IsInterface", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,105 +165,107 @@ internal class Remapper
|
|||||||
|
|
||||||
if (type.MatchIsPublic(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchIsPublic(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("IsPublic", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.MatchHasAttribute(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchHasAttribute(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("HasAttribute", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.MatchMethods(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchMethods(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("Methods", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.MatchFields(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchFields(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("Fields", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.MatchProperties(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchProperties(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("Properties", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.MatchNestedTypes(remap.SearchParams, score) == EMatchResult.NoMatch)
|
if (type.MatchNestedTypes(remap.SearchParams, score) == EMatchResult.NoMatch)
|
||||||
{
|
{
|
||||||
|
LogDiscard("NestedTypes", type.Name, score.ProposedNewName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
ScoringModelExtensions.AddModelToResult(score);
|
ScoringModelExtensions.AddModelToResult(score);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleByDirectName(TypeDefinition type, Remap remap)
|
||||||
|
{
|
||||||
|
if (type.Name != remap.OldTypeName) { return; }
|
||||||
|
|
||||||
|
var oldName = type.Name;
|
||||||
|
type.Name = remap.NewTypeName;
|
||||||
|
|
||||||
|
RenameService.RenameAllFields(remap, DataProvider.ModuleDefinition.Types);
|
||||||
|
RenameService.RenameAllProperties(remap, DataProvider.ModuleDefinition.Types);
|
||||||
|
|
||||||
|
Logger.Log($"Renamed {oldName} to {type.Name} directly", ConsoleColor.Green);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogDiscard(string action, string type, string search)
|
||||||
|
{
|
||||||
|
if (DataProvider.AppSettings.Debug)
|
||||||
|
{
|
||||||
|
Logger.Log($"[{action}] Discarding type [{type}] for search [{search}]", ConsoleColor.Red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ChooseBestMatches()
|
private void ChooseBestMatches()
|
||||||
{
|
{
|
||||||
foreach (var remap in ScoringModels)
|
foreach (var score in DataProvider.ScoringModels)
|
||||||
{
|
{
|
||||||
ChooseBestMatch(remap.Value, true);
|
ChooseBestMatch(score.Value, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChooseBestMatch(HashSet<ScoringModel> scores, bool isBest = false)
|
private void ChooseBestMatch(HashSet<ScoringModel> scores, bool isBest = false)
|
||||||
{
|
{
|
||||||
if (ScoringModels.Count == 0)
|
if (DataProvider.ScoringModels.Count == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var highestScore = scores.OrderByDescending(model => model.Score).FirstOrDefault();
|
var highestScore = scores.OrderByDescending(model => model.Score).FirstOrDefault();
|
||||||
var secondScore = scores.OrderByDescending(model => model.Score).Skip(1).FirstOrDefault();
|
var nextHighestScores = scores.OrderByDescending(model => model.Score).Skip(1);
|
||||||
|
|
||||||
if (highestScore is null || secondScore is null) { return; }
|
if (highestScore is null) { return; }
|
||||||
|
|
||||||
var potentialText = isBest
|
var potentialText = isBest
|
||||||
? "Best potential"
|
? "Best potential"
|
||||||
: "Next potential";
|
: "Next potential";
|
||||||
|
|
||||||
if (highestScore.Score <= 0) { return; }
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
|
Logger.Log($"Found {scores.Count} results from search", ConsoleColor.Green);
|
||||||
|
Logger.Log($"{potentialText} match is `{highestScore.Definition.Name}` for `{highestScore.ProposedNewName}`", ConsoleColor.Green);
|
||||||
|
|
||||||
Logger.Log("-----------------------------------------------");
|
foreach (var score in nextHighestScores)
|
||||||
Logger.Log($"Found {scores.Count} possible matches");
|
{
|
||||||
Logger.Log($"Scored: {highestScore.Score} points");
|
Logger.Log($"Next potential match is `{score.Definition.Name}` for `{highestScore.ProposedNewName}`", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Next Best: {secondScore.Score} points");
|
}
|
||||||
Logger.Log($"{potentialText} match is `{highestScore.Definition.Name}` for `{highestScore.ProposedNewName}`");
|
|
||||||
|
|
||||||
if (DataProvider.AppSettings.ScoringMode)
|
if (DataProvider.AppSettings.ScoringMode)
|
||||||
{
|
{
|
||||||
Logger.Log("Show next result? (y/n)");
|
scores.Remove(highestScore);
|
||||||
var answer = Console.ReadLine();
|
ChooseBestMatch(scores);
|
||||||
|
|
||||||
if (answer == "yes" || answer == "y")
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
{
|
|
||||||
scores.Remove(highestScore);
|
|
||||||
ChooseBestMatch(scores);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log("-----------------------------------------------");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var anwser = "";
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
|
|
||||||
if (!DataProvider.AppSettings.SilentMode)
|
|
||||||
{
|
|
||||||
Logger.Log($"Should we continue? (y/n)");
|
|
||||||
anwser = Console.ReadLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (anwser == "yes" || anwser == "y" || DataProvider.AppSettings.SilentMode)
|
|
||||||
{
|
|
||||||
var oldName = highestScore.Definition.Name;
|
|
||||||
|
|
||||||
highestScore.Definition.Name = highestScore.ProposedNewName;
|
|
||||||
|
|
||||||
RenameService.RenameAllFields(oldName, highestScore.Definition.Name, DataProvider.ModuleDefinition.Types);
|
|
||||||
RenameService.RenameAllProperties(oldName, highestScore.Definition.Name, DataProvider.ModuleDefinition.Types);
|
|
||||||
|
|
||||||
Logger.Log($"Remapped {oldName} to `{highestScore.Definition.Name}`");
|
|
||||||
Logger.Log("-----------------------------------------------");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
scores.Remove(highestScore);
|
scores.Remove(highestScore);
|
||||||
ChooseBestMatch(scores);
|
ChooseBestMatch(scores);
|
||||||
@ -299,8 +282,8 @@ internal class Remapper
|
|||||||
|
|
||||||
DataProvider.AssemblyDefinition.Write(remappedPath);
|
DataProvider.AssemblyDefinition.Write(remappedPath);
|
||||||
|
|
||||||
Logger.Log("-----------------------------------------------");
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
Logger.Log($"Complete: Assembly written to `{remappedPath}`");
|
Logger.Log($"Complete: Assembly written to `{remappedPath}`", ConsoleColor.Green);
|
||||||
Logger.Log("-----------------------------------------------");
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
using AssemblyRemapper.Utils;
|
using AssemblyRemapper.Models;
|
||||||
|
using AssemblyRemapper.Utils;
|
||||||
|
using Mono.Cecil;
|
||||||
using Mono.Collections.Generic;
|
using Mono.Collections.Generic;
|
||||||
|
|
||||||
namespace AssemblyRemapper.Reflection;
|
namespace AssemblyRemapper.Reflection;
|
||||||
@ -6,20 +8,19 @@ namespace AssemblyRemapper.Reflection;
|
|||||||
internal static class RenameService
|
internal static class RenameService
|
||||||
{
|
{
|
||||||
public static void RenameAllFields(
|
public static void RenameAllFields(
|
||||||
string oldName,
|
Remap remap,
|
||||||
string newName,
|
Collection<TypeDefinition> typesToCheck)
|
||||||
Collection<Mono.Cecil.TypeDefinition> types)
|
|
||||||
{
|
{
|
||||||
foreach (var type in types)
|
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() == newName)
|
if (field.FieldType.ToString() == remap.NewTypeName)
|
||||||
{
|
{
|
||||||
Logger.Log($"Renaming Field: `{field.Name}` on Type `{type}`");
|
Logger.Log($"Renaming Field: `{field.Name}` on Type `{type}`");
|
||||||
field.Name = GetNewFieldName(newName, field.IsPrivate, fieldCount);
|
field.Name = GetNewFieldName(remap.NewTypeName, field.IsPrivate, fieldCount);
|
||||||
fieldCount++;
|
fieldCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,27 +29,26 @@ internal static class RenameService
|
|||||||
{
|
{
|
||||||
foreach (var _ in type.NestedTypes)
|
foreach (var _ in type.NestedTypes)
|
||||||
{
|
{
|
||||||
RenameAllFields(oldName, newName, type.NestedTypes);
|
RenameAllFields(remap, type.NestedTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RenameAllProperties(
|
public static void RenameAllProperties(
|
||||||
string oldName,
|
Remap remap,
|
||||||
string newName,
|
Collection<TypeDefinition> typesToCheck)
|
||||||
Collection<Mono.Cecil.TypeDefinition> types)
|
|
||||||
{
|
{
|
||||||
foreach (var type in types)
|
foreach (var type in typesToCheck)
|
||||||
{
|
{
|
||||||
int propertyCount = 0;
|
int propertyCount = 0;
|
||||||
|
|
||||||
foreach (var property in type.Properties)
|
foreach (var property in type.Properties)
|
||||||
{
|
{
|
||||||
if (property.PropertyType.ToString() == newName)
|
if (property.PropertyType.ToString() == remap.NewTypeName)
|
||||||
{
|
{
|
||||||
Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}`");
|
Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}`");
|
||||||
property.Name = propertyCount > 0 ? $"{newName}_{propertyCount}" : newName;
|
property.Name = propertyCount > 0 ? $"{remap.NewTypeName}_{propertyCount}" : remap.NewTypeName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ internal static class RenameService
|
|||||||
{
|
{
|
||||||
foreach (var _ in type.NestedTypes)
|
foreach (var _ in type.NestedTypes)
|
||||||
{
|
{
|
||||||
RenameAllProperties(oldName, newName, type.NestedTypes);
|
RenameAllProperties(remap, type.NestedTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using AssemblyRemapper.Models;
|
using AssemblyRemapper.Models;
|
||||||
using AssemblyRemapper.Utils;
|
|
||||||
using Mono.Cecil;
|
using Mono.Cecil;
|
||||||
using Mono.Cecil.Rocks;
|
using Mono.Cecil.Rocks;
|
||||||
|
|
||||||
@ -19,18 +18,15 @@ 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() != null)
|
||||||
{
|
{
|
||||||
Logger.Log($"Searching for an abstract type, skipping interface or static");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.IsAbstract != parms.IsAbstract)
|
if (type.IsAbstract == parms.IsAbstract)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsAbstract");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsAbstract does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,11 +40,9 @@ internal static class SearchProvider
|
|||||||
if (type.IsEnum == parms.IsEnum)
|
if (type.IsEnum == parms.IsEnum)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsEnum");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsEnum does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,11 +56,9 @@ internal static class SearchProvider
|
|||||||
if (type.IsNested == parms.IsNested)
|
if (type.IsNested == parms.IsNested)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsNested");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsNested does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,11 +72,9 @@ internal static class SearchProvider
|
|||||||
if (type.IsSealed == parms.IsSealed)
|
if (type.IsSealed == parms.IsSealed)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsSealed");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsSealed does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,11 +88,9 @@ internal static class SearchProvider
|
|||||||
if (type.BaseType != null && (bool)parms.IsDerived)
|
if (type.BaseType != null && (bool)parms.IsDerived)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsDerived");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsDerived does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,38 +101,28 @@ internal static class SearchProvider
|
|||||||
return EMatchResult.Disabled;
|
return EMatchResult.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interfaces cannot be a class
|
if (type.IsInterface == parms.IsInterface)
|
||||||
if (type.IsClass)
|
|
||||||
{
|
|
||||||
return EMatchResult.NoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.IsInterface != parms.IsInterface)
|
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsInterface");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsInterface does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EMatchResult MatchIsGeneric(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
public static EMatchResult MatchIsGeneric(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.IsGeneric is null)
|
if (parms.HasGenericParameters is null)
|
||||||
{
|
{
|
||||||
return EMatchResult.Disabled;
|
return EMatchResult.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.HasGenericParameters == parms.IsGeneric)
|
if (type.HasGenericParameters == parms.HasGenericParameters)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsGeneric");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsGeneric does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,14 +133,14 @@ internal static class SearchProvider
|
|||||||
return EMatchResult.Disabled;
|
return EMatchResult.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.IsPublic == parms.IsPublic)
|
var boolToCheck = parms.IsPublic == true ? type.IsPublic : type.IsNotPublic;
|
||||||
|
|
||||||
|
if (boolToCheck == !parms.IsPublic)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : IsPublic");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` IsPublic does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,30 +154,26 @@ internal static class SearchProvider
|
|||||||
if (type.HasCustomAttributes == parms.HasAttribute)
|
if (type.HasCustomAttributes == parms.HasAttribute)
|
||||||
{
|
{
|
||||||
score.Score += 1;
|
score.Score += 1;
|
||||||
Logger.Log($"Matched `{type.Name}` on search `{score.ProposedNewName}` : HasAttribute");
|
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Skipping `{type.Name}` on search `{score.ProposedNewName}` HasAttribute does not match.");
|
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EMatchResult MatchMethods(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
public static EMatchResult MatchMethods(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
// Ignore types that dont have methods when we are looking for them, and ignore types that
|
if (parms.MethodNamesToMatch.Count == 0) { return EMatchResult.Disabled; }
|
||||||
// have methods while we're not looking for them
|
|
||||||
if ((type.HasMethods is true && parms.MethodNamesToMatch.Count == 0) || (type.HasMethods is false && parms.MethodNamesToMatch.Count > 0))
|
if (type.HasMethods)
|
||||||
{
|
{
|
||||||
return EMatchResult.NoMatch;
|
// `*` is the wildcard to ignore all methods that exist on types
|
||||||
|
if (parms.MethodNamesToIgnore.Contains("*"))
|
||||||
|
{
|
||||||
|
return EMatchResult.NoMatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `*` is the wildcard to ignore all methods that exist on types
|
var matchCount = 0;
|
||||||
if (parms.MethodNamesToIgnore.Contains("*"))
|
|
||||||
{
|
|
||||||
return EMatchResult.NoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
int matchCount = 0;
|
|
||||||
|
|
||||||
foreach (var method in type.Methods)
|
foreach (var method in type.Methods)
|
||||||
{
|
{
|
||||||
@ -209,10 +183,14 @@ internal static class SearchProvider
|
|||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parms.MethodNamesToMatch.Contains(method.Name))
|
foreach (var name in parms.MethodNamesToMatch)
|
||||||
{
|
{
|
||||||
matchCount++;
|
if (method.Name == name)
|
||||||
score.Score += 2;
|
{
|
||||||
|
matchCount += 1;
|
||||||
|
score.Score += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,17 +199,15 @@ internal static class SearchProvider
|
|||||||
|
|
||||||
public static EMatchResult MatchFields(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
public static EMatchResult MatchFields(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
// Ignore types that dont have fields when we are looking for them, and ignore types that
|
if (parms.FieldNamesToMatch.Count == 0) { return EMatchResult.Disabled; }
|
||||||
// have fields while we're not looking for them
|
|
||||||
if ((type.HasFields is true && parms.FieldNamesToMatch.Count == 0) || (type.HasFields is false && parms.FieldNamesToMatch.Count > 0))
|
|
||||||
{
|
|
||||||
return EMatchResult.NoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// `*` is the wildcard to ignore all fields that exist on types
|
if (type.HasFields)
|
||||||
if (parms.FieldNamesToIgnore.Contains("*"))
|
|
||||||
{
|
{
|
||||||
return EMatchResult.NoMatch;
|
// `*` is the wildcard to ignore all fields that exist on types
|
||||||
|
if (parms.FieldNamesToIgnore.Contains("*"))
|
||||||
|
{
|
||||||
|
return EMatchResult.NoMatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int matchCount = 0;
|
int matchCount = 0;
|
||||||
@ -256,17 +232,15 @@ internal static class SearchProvider
|
|||||||
|
|
||||||
public static EMatchResult MatchProperties(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
public static EMatchResult MatchProperties(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
// Ignore types that dont have properties when we are looking for them, and ignore types
|
if (parms.PropertyNamesToMatch.Count == 0) { return EMatchResult.Disabled; }
|
||||||
// that have properties while we're not looking for them
|
|
||||||
if ((type.HasProperties is true && parms.PropertyNamesToMatch.Count == 0) || (type.HasProperties is false && parms.PropertyNamesToMatch.Count > 0))
|
|
||||||
{
|
|
||||||
return EMatchResult.NoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// `*` is the wildcard to ignore all properties that exist on types
|
if (type.HasProperties)
|
||||||
if (parms.PropertyNamesToIgnore.Contains("*"))
|
|
||||||
{
|
{
|
||||||
return EMatchResult.NoMatch;
|
// `*` is the wildcard to ignore all fields that exist on types
|
||||||
|
if (parms.PropertyNamesToIgnore.Contains("*"))
|
||||||
|
{
|
||||||
|
return EMatchResult.NoMatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int matchCount = 0;
|
int matchCount = 0;
|
||||||
@ -291,17 +265,15 @@ internal static class SearchProvider
|
|||||||
|
|
||||||
public static EMatchResult MatchNestedTypes(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
public static EMatchResult MatchNestedTypes(this TypeDefinition type, RemapSearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
// Ignore types that dont have nested types when we are looking for them, and ignore types
|
if (parms.NestedTypesToMatch.Count == 0) { return EMatchResult.Disabled; }
|
||||||
// that have nested types while we're not looking for them
|
|
||||||
if ((type.HasNestedTypes is true && parms.NestedTypesToMatch.Count == 0) || (type.HasNestedTypes is false && parms.NestedTypesToMatch.Count > 0))
|
|
||||||
{
|
|
||||||
return EMatchResult.NoMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// `*` is the wildcard to ignore all nested types that exist on types
|
if (type.HasNestedTypes)
|
||||||
if (parms.PropertyNamesToIgnore.Contains("*"))
|
|
||||||
{
|
{
|
||||||
return EMatchResult.NoMatch;
|
// `*` is the wildcard to ignore all fields that exist on types
|
||||||
|
if (parms.NestedTypesToIgnore.Contains("*"))
|
||||||
|
{
|
||||||
|
return EMatchResult.NoMatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int matchCount = 0;
|
int matchCount = 0;
|
||||||
|
@ -12,6 +12,8 @@ internal static class DataProvider
|
|||||||
LoadAssemblyDefinition();
|
LoadAssemblyDefinition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, HashSet<ScoringModel>> ScoringModels { get; set; } = [];
|
||||||
|
|
||||||
public static AppSettings AppSettings { get; private set; }
|
public static AppSettings AppSettings { get; private set; }
|
||||||
|
|
||||||
public static AssemblyDefinition AssemblyDefinition { get; private set; }
|
public static AssemblyDefinition AssemblyDefinition { get; private set; }
|
||||||
@ -57,6 +59,7 @@ internal static class DataProvider
|
|||||||
if (module.Name == fileName)
|
if (module.Name == fileName)
|
||||||
{
|
{
|
||||||
ModuleDefinition = module;
|
ModuleDefinition = module;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user