Feature: Adding Include/Exclude for events. (#13)
Added checking events for the remapping, can include/exclude any events, tested. Added New GUI option for events. also fixed ExcludeNestedTypes wrongly displayed if no IncludeNestedTypes exists. Co-authored-by: SlejmUr <slejmur@protonmail.com> Reviewed-on: SPT/AssemblyTool#13 Co-authored-by: SlejmUr <slejmur@noreply.dev.sp-tarkov.com> Co-committed-by: SlejmUr <slejmur@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
1d44e1cac2
commit
8a350c6818
869
RecodeItGUI/GUI/Main.Designer.cs
generated
869
RecodeItGUI/GUI/Main.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -113,6 +113,22 @@ public partial class ReCodeItForm : Form
|
||||
}
|
||||
};
|
||||
|
||||
EventsIncludeTextField.KeyDown += (sender, e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
EventsAddButton_Click(sender, e);
|
||||
}
|
||||
};
|
||||
|
||||
EventsExcludeTextField.KeyDown += (sender, e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
EventsExcludeAddButton_Click(sender, e);
|
||||
}
|
||||
};
|
||||
|
||||
#endregion MANUAL_REMAPPER
|
||||
|
||||
#region AUTOMAPPER
|
||||
@ -287,6 +303,8 @@ public partial class ReCodeItForm : Form
|
||||
ExcludeProperties = GUIHelpers.GetAllEntriesFromListBox(PropertiesExcludeBox),
|
||||
IncludeNestedTypes = GUIHelpers.GetAllEntriesFromListBox(NestedTypesIncludeBox),
|
||||
ExcludeNestedTypes = GUIHelpers.GetAllEntriesFromListBox(NestedTypesExcludeBox),
|
||||
IncludeEvents = GUIHelpers.GetAllEntriesFromListBox(EventsIncludeBox),
|
||||
ExcludeEvents = GUIHelpers.GetAllEntriesFromListBox(EventsExcludeBox)
|
||||
}
|
||||
};
|
||||
|
||||
@ -631,6 +649,45 @@ public partial class ReCodeItForm : Form
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void EventsAddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (EventsIncludeTextField.Text == string.Empty) return;
|
||||
|
||||
if (!EventsIncludeBox.Items.Contains(EventsIncludeTextField.Text))
|
||||
{
|
||||
EventsIncludeBox.Items.Add(EventsIncludeTextField.Text);
|
||||
EventsIncludeTextField.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void EventsRemoveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (EventsIncludeBox.SelectedItem != null)
|
||||
{
|
||||
EventsIncludeBox.Items.Remove(EventsIncludeBox.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void EventsExcludeAddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (EventsExcludeTextField.Text == string.Empty) return;
|
||||
|
||||
if (!EventsExcludeBox.Items.Contains(EventsExcludeTextField.Text))
|
||||
{
|
||||
EventsExcludeBox.Items.Add(EventsExcludeTextField.Text);
|
||||
EventsExcludeTextField.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void EventsExcludeRemoveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (EventsExcludeBox.SelectedItem != null)
|
||||
{
|
||||
EventsExcludeBox.Items.Remove(EventsExcludeBox.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoMapperExcludeAddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (AutoMapperTypesToIgnoreTextField.Text == string.Empty) return;
|
||||
@ -932,6 +989,8 @@ public partial class ReCodeItForm : Form
|
||||
PropertiesExcludeTextField.Clear();
|
||||
NestedTypesIncludeTextField.Clear();
|
||||
NestedTypesExcludeTextField.Clear();
|
||||
EventsIncludeTextField.Clear();
|
||||
EventsExcludeTextField.Clear();
|
||||
|
||||
// Numeric UpDowns
|
||||
|
||||
@ -960,6 +1019,8 @@ public partial class ReCodeItForm : Form
|
||||
PropertiesExcludeBox.Items.Clear();
|
||||
NestedTypesIncludeBox.Items.Clear();
|
||||
NestedTypesExcludeBox.Items.Clear();
|
||||
EventsIncludeBox.Items.Clear();
|
||||
EventsExcludeBox.Items.Clear();
|
||||
}
|
||||
|
||||
private void ManualEditSelectedRemap(object? sender, TreeNodeMouseClickEventArgs e)
|
||||
@ -1122,6 +1183,16 @@ public partial class ReCodeItForm : Form
|
||||
{
|
||||
NestedTypesExcludeBox.Items.Add(method);
|
||||
}
|
||||
|
||||
foreach (var method in remap.SearchParams.IncludeEvents)
|
||||
{
|
||||
EventsIncludeBox.Items.Add(method);
|
||||
}
|
||||
|
||||
foreach (var method in remap.SearchParams.ExcludeEvents)
|
||||
{
|
||||
EventsExcludeBox.Items.Add(method);
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateDomainUpDowns()
|
||||
@ -1183,4 +1254,5 @@ public partial class ReCodeItForm : Form
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -126,4 +126,7 @@
|
||||
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>47</value>
|
||||
</metadata>
|
||||
</root>
|
@ -251,7 +251,7 @@ internal static class GUIHelpers
|
||||
remapTreeItem.Nodes.Add(includeNestedTypes);
|
||||
}
|
||||
|
||||
if (model.SearchParams.IncludeNestedTypes?.Count > 0)
|
||||
if (model.SearchParams.ExcludeNestedTypes?.Count > 0)
|
||||
{
|
||||
var excludeNestedTypes =
|
||||
GenerateNodeFromList(model.SearchParams.ExcludeNestedTypes, "Exclude Nested Types");
|
||||
@ -259,6 +259,22 @@ internal static class GUIHelpers
|
||||
remapTreeItem.Nodes.Add(excludeNestedTypes);
|
||||
}
|
||||
|
||||
if (model.SearchParams.IncludeEvents?.Count > 0)
|
||||
{
|
||||
var includeEvents =
|
||||
GenerateNodeFromList(model.SearchParams.IncludeEvents, "Include Events");
|
||||
|
||||
remapTreeItem.Nodes.Add(includeEvents);
|
||||
}
|
||||
|
||||
if (model.SearchParams.ExcludeEvents?.Count > 0)
|
||||
{
|
||||
var excludeEvents =
|
||||
GenerateNodeFromList(model.SearchParams.ExcludeEvents, "Exclude Events");
|
||||
|
||||
remapTreeItem.Nodes.Add(excludeEvents);
|
||||
}
|
||||
|
||||
ReCodeItForm.RemapNodes.Add(remapTreeItem, model);
|
||||
|
||||
return remapTreeItem;
|
||||
|
@ -101,6 +101,8 @@ public class SearchParams
|
||||
public List<string> ExcludeProperties { get; set; }
|
||||
public List<string> IncludeNestedTypes { get; set; }
|
||||
public List<string> ExcludeNestedTypes { get; set; }
|
||||
public List<string> IncludeEvents { get; set; } = [];
|
||||
public List<string> ExcludeEvents { get; set; } = [];
|
||||
|
||||
#endregion LISTS
|
||||
|
||||
|
@ -158,6 +158,7 @@ public class ReCodeItRemapper
|
||||
if (!FilterTypesByMethods(mapping, ref types)) return;
|
||||
if (!FilterTypesByFields(mapping, ref types)) return;
|
||||
if (!FilterTypesByProps(mapping, ref types)) return;
|
||||
if (!FilterTypesByEvents(mapping, ref types)) return;
|
||||
if (!FilterTypesByNested(mapping, ref types)) return;
|
||||
|
||||
types = CtorTypeFilters.FilterByParameterCount(types, mapping.SearchParams);
|
||||
@ -386,6 +387,29 @@ public class ReCodeItRemapper
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool FilterTypesByEvents(RemapModel mapping, ref IEnumerable<TypeDef> types)
|
||||
{
|
||||
types = EventTypeFilters.FilterByInclude(types, mapping.SearchParams);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesInclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = EventTypeFilters.FilterByExclude(types, mapping.SearchParams);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesExclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void HandleDirectRename(RemapModel mapping, ref IEnumerable<TypeDef> types)
|
||||
{
|
||||
foreach (var type in types)
|
||||
|
58
RecodeItLib/Remapper/Search/EventTypeFilters.cs
Normal file
58
RecodeItLib/Remapper/Search/EventTypeFilters.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using dnlib.DotNet;
|
||||
using ReCodeIt.Models;
|
||||
|
||||
namespace ReCodeItLib.Remapper.Search;
|
||||
|
||||
internal static class EventTypeFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Filters based on events name
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterByInclude(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
if (parms.IncludeEvents.Count == 0) return types;
|
||||
|
||||
List<TypeDef> filteredTypes = [];
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (parms.IncludeEvents
|
||||
.All(includeName => type.Events
|
||||
.Any(ev => ev.Name.String == includeName)))
|
||||
{
|
||||
filteredTypes.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return filteredTypes.Any() ? filteredTypes : types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on events name
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterByExclude(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
if (parms.ExcludeEvents.Count == 0) return types;
|
||||
|
||||
List<TypeDef> filteredTypes = [];
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
var match = type.Events
|
||||
.Where(prop => parms.ExcludeEvents.Contains(prop.Name.String));
|
||||
|
||||
if (!match.Any())
|
||||
{
|
||||
filteredTypes.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return filteredTypes.Any() ? filteredTypes : types;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user