diff --git a/AssemblyRemapper/Remapper/Remapper.cs b/AssemblyRemapper/Remapper/Remapper.cs index 7e0b3ff..f7e6733 100644 --- a/AssemblyRemapper/Remapper/Remapper.cs +++ b/AssemblyRemapper/Remapper/Remapper.cs @@ -11,6 +11,10 @@ public class Remapper { public static bool IsRunning { get; private set; } = false; + public delegate void OnCompleteHandler(object sender, EventArgs e); + + public event OnCompleteHandler OnComplete; + private static Stopwatch Stopwatch = new(); /// @@ -260,6 +264,7 @@ public class Remapper Reset(); IsRunning = false; + OnComplete.Invoke(this, EventArgs.Empty); } private void Reset() diff --git a/AssemblyRemapperGUI/Form1.cs b/AssemblyRemapperGUI/Form1.cs index 26402dd..23c7103 100644 --- a/AssemblyRemapperGUI/Form1.cs +++ b/AssemblyRemapperGUI/Form1.cs @@ -15,10 +15,8 @@ namespace AssemblyRemapperGUI InitializeComponent(); PopulateDomainUpDowns(); - foreach (var remap in DataProvider.Remaps) - { - RemapTreeView.Nodes.Add(GUI.GenerateTreeNode(remap)); - } + Remapper.OnComplete += ReloadTreeView; + ReloadTreeView(this, EventArgs.Empty); } #region BUTTONS @@ -101,7 +99,7 @@ namespace AssemblyRemapperGUI { if (Remapper.IsRunning) { return; } - Task.Run(() => Remapper.InitializeRemap()); + Remapper.InitializeRemap(); } private void SaveMappingFileButton_Click(object sender, EventArgs e) @@ -338,5 +336,20 @@ namespace AssemblyRemapperGUI IsDerivedUpDown.BuildStringList("IsDerived"); HasGenericParametersUpDown.BuildStringList("HasGenericParams"); } + + /// + /// Subscribes the the remappers OnComplete event + /// + /// + /// + private void ReloadTreeView(object sender, EventArgs e) + { + RemapTreeView.Nodes.Clear(); + + foreach (var remap in DataProvider.Remaps) + { + RemapTreeView.Nodes.Add(GUI.GenerateTreeNode(remap)); + } + } } } \ No newline at end of file diff --git a/AssemblyRemapperGUI/Utils/GUI.cs b/AssemblyRemapperGUI/Utils/GUI.cs index 53c8082..5465be7 100644 --- a/AssemblyRemapperGUI/Utils/GUI.cs +++ b/AssemblyRemapperGUI/Utils/GUI.cs @@ -132,7 +132,7 @@ internal static class GUI remapTreeItem.Nodes.Add(IsDerivedNode); remapTreeItem.Nodes.Add(HasGenericsNode); - if (model.SearchParams.IncludeMethods.Count > 0) + if (model.SearchParams.IncludeMethods?.Count > 0) { var includeMethodsNode = GenerateNodeFromList(model.SearchParams.IncludeMethods, "Include Methods"); @@ -140,7 +140,7 @@ internal static class GUI remapTreeItem.Nodes.Add(includeMethodsNode); } - if (model.SearchParams.ExcludeMethods.Count > 0) + if (model.SearchParams.ExcludeMethods?.Count > 0) { var excludeMethodsNode = GenerateNodeFromList(model.SearchParams.ExcludeMethods, "Exclude Methods"); @@ -148,7 +148,7 @@ internal static class GUI remapTreeItem.Nodes.Add(excludeMethodsNode); } - if (model.SearchParams.IncludeFields.Count > 0) + if (model.SearchParams.IncludeFields?.Count > 0) { var includeFieldsNode = GenerateNodeFromList(model.SearchParams.IncludeFields, "Include Fields"); @@ -156,7 +156,7 @@ internal static class GUI remapTreeItem.Nodes.Add(includeFieldsNode); } - if (model.SearchParams.ExcludeFields.Count > 0) + if (model.SearchParams.ExcludeFields?.Count > 0) { var excludeFieldsNode = GenerateNodeFromList(model.SearchParams.ExcludeFields, "Exclude Fields"); @@ -164,7 +164,7 @@ internal static class GUI remapTreeItem.Nodes.Add(excludeFieldsNode); } - if (model.SearchParams.IncludeProperties.Count > 0) + if (model.SearchParams.IncludeProperties?.Count > 0) { var includeProperties = GenerateNodeFromList(model.SearchParams.IncludeProperties, "Include Properties"); @@ -172,7 +172,7 @@ internal static class GUI remapTreeItem.Nodes.Add(includeProperties); } - if (model.SearchParams.ExcludeProperties.Count > 0) + if (model.SearchParams.ExcludeProperties?.Count > 0) { var excludeProperties = GenerateNodeFromList(model.SearchParams.ExcludeProperties, "Exclude Properties"); @@ -180,7 +180,7 @@ internal static class GUI remapTreeItem.Nodes.Add(excludeProperties); } - if (model.SearchParams.IncludeNestedTypes.Count > 0) + if (model.SearchParams.IncludeNestedTypes?.Count > 0) { var includeNestedTypes = GenerateNodeFromList(model.SearchParams.IncludeNestedTypes, "Include Nested Types"); @@ -188,7 +188,7 @@ internal static class GUI remapTreeItem.Nodes.Add(includeNestedTypes); } - if (model.SearchParams.IncludeNestedTypes.Count > 0) + if (model.SearchParams.IncludeNestedTypes?.Count > 0) { var excludeNestedTypes = GenerateNodeFromList(model.SearchParams.ExcludeNestedTypes, "Exclude Nested Types");