mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-12 16:50:44 -05:00
cleanup renamer
This commit is contained in:
parent
371bda961c
commit
af8afeab78
@ -8,28 +8,23 @@ internal class Renamer
|
||||
{
|
||||
private static List<string> TokensToMatch => DataProvider.Settings!.TypeNamesToMatch;
|
||||
|
||||
/// <summary>
|
||||
/// Only used by the manual remapper, should probably be removed
|
||||
/// </summary>
|
||||
/// <param name="module"></param>
|
||||
/// <param name="remap"></param>
|
||||
/// <param name="direct"></param>
|
||||
public void RenameAll(IEnumerable<TypeDef> types, RemapModel remap)
|
||||
{
|
||||
if (remap.TypePrimeCandidate is null) return;
|
||||
|
||||
// Rename all fields and properties first
|
||||
var typesToCheck = types as TypeDef[] ?? types.ToArray();
|
||||
RenameAllFields(
|
||||
remap.TypePrimeCandidate.Name.String,
|
||||
remap.NewTypeName,
|
||||
types);
|
||||
typesToCheck);
|
||||
|
||||
RenameAllProperties(
|
||||
remap.TypePrimeCandidate!.Name.String,
|
||||
remap.NewTypeName,
|
||||
types);
|
||||
typesToCheck);
|
||||
|
||||
FixMethods(types, remap);
|
||||
FixMethods(typesToCheck, remap);
|
||||
|
||||
remap.TypePrimeCandidate.Name = remap.NewTypeName;
|
||||
}
|
||||
@ -58,12 +53,6 @@ internal class Renamer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rename all fields recursively, returns number of fields changed
|
||||
/// </summary>
|
||||
/// <param name="oldTypeName"></param>
|
||||
/// <param name="newTypeName"></param>
|
||||
/// <param name="typesToCheck"></param>
|
||||
private static void RenameAllFields(
|
||||
|
||||
string oldTypeName,
|
||||
@ -74,28 +63,25 @@ internal class Renamer
|
||||
foreach (var type in typeDefs)
|
||||
{
|
||||
var fields = type.Fields
|
||||
.Where(field => field.Name.IsFieldOrPropNameInList(TokensToMatch!));
|
||||
.Where(field => field.Name.IsFieldOrPropNameInList(TokensToMatch));
|
||||
|
||||
if (!fields.Any()) { continue; }
|
||||
|
||||
int fieldCount = 0;
|
||||
var fieldCount = 0;
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (field.FieldType.TypeName == oldTypeName)
|
||||
{
|
||||
var newFieldName = GetNewFieldName(newTypeName, fieldCount);
|
||||
if (field.FieldType.TypeName != oldTypeName) continue;
|
||||
|
||||
// Dont need to do extra work
|
||||
if (field.Name == newFieldName) { continue; }
|
||||
var newFieldName = GetNewFieldName(newTypeName, fieldCount);
|
||||
|
||||
var oldName = field.Name.ToString();
|
||||
// Dont need to do extra work
|
||||
if (field.Name == newFieldName) { continue; }
|
||||
|
||||
field.Name = newFieldName;
|
||||
var oldName = field.Name.ToString();
|
||||
|
||||
UpdateAllTypeFieldMemberRefs(typeDefs, field, oldName);
|
||||
field.Name = newFieldName;
|
||||
|
||||
fieldCount++;
|
||||
}
|
||||
UpdateAllTypeFieldMemberRefs(typeDefs, field, oldName);
|
||||
|
||||
fieldCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,12 +110,6 @@ internal class Renamer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rename all properties recursively, returns number of fields changed
|
||||
/// </summary>
|
||||
/// <param name="oldTypeName"></param>
|
||||
/// <param name="newTypeName"></param>
|
||||
/// <param name="typesToCheck"></param>
|
||||
private static void RenameAllProperties(
|
||||
string oldTypeName,
|
||||
string newTypeName,
|
||||
@ -138,33 +118,30 @@ internal class Renamer
|
||||
foreach (var type in typesToCheck)
|
||||
{
|
||||
var properties = type.Properties
|
||||
.Where(prop => prop.Name.IsFieldOrPropNameInList(TokensToMatch!));
|
||||
.Where(prop => prop.Name.IsFieldOrPropNameInList(TokensToMatch));
|
||||
|
||||
if (!properties.Any()) { continue; }
|
||||
|
||||
int propertyCount = 0;
|
||||
var propertyCount = 0;
|
||||
foreach (var property in properties)
|
||||
{
|
||||
if (property.PropertySig.RetType.TypeName == oldTypeName)
|
||||
{
|
||||
var newPropertyName = GetNewPropertyName(newTypeName, propertyCount);
|
||||
if (property.PropertySig.RetType.TypeName != oldTypeName) continue;
|
||||
|
||||
// Dont need to do extra work
|
||||
if (property.Name == newPropertyName) { continue; }
|
||||
var newPropertyName = GetNewPropertyName(newTypeName, propertyCount);
|
||||
|
||||
property.Name = new UTF8String(newPropertyName);
|
||||
// Dont need to do extra work
|
||||
if (property.Name == newPropertyName) continue;
|
||||
|
||||
propertyCount++;
|
||||
}
|
||||
property.Name = newPropertyName;
|
||||
|
||||
propertyCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetNewFieldName(string NewName, int fieldCount = 0)
|
||||
private static string GetNewFieldName(string newName, int fieldCount = 0)
|
||||
{
|
||||
string newFieldCount = fieldCount > 0 ? $"_{fieldCount}" : string.Empty;
|
||||
var newFieldCount = fieldCount > 0 ? $"_{fieldCount}" : string.Empty;
|
||||
|
||||
return $"{char.ToLower(NewName[0])}{NewName[1..]}{newFieldCount}";
|
||||
return $"{char.ToLower(newName[0])}{newName[1..]}{newFieldCount}";
|
||||
}
|
||||
|
||||
private static string GetNewPropertyName(string newName, int propertyCount = 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user