342 lines
12 KiB
C#
Raw Normal View History

2024-06-13 21:20:48 -04:00
using AssemblyRemapper.Enums;
using AssemblyRemapper.Models;
using AssemblyRemapper.Remapper;
2024-06-14 13:47:30 -04:00
using AssemblyRemapper.Utils;
2024-06-13 22:58:26 -04:00
using RemapperGUI.Utils;
2024-06-13 20:25:11 -04:00
2024-06-13 18:09:31 -04:00
namespace AssemblyRemapperGUI
{
2024-06-13 20:25:11 -04:00
public partial class AssemblyToolGUI : Form
2024-06-13 18:09:31 -04:00
{
2024-06-14 13:47:30 -04:00
public static Remapper Remapper { get; private set; } = new();
2024-06-13 21:20:48 -04:00
2024-06-13 20:25:11 -04:00
public AssemblyToolGUI()
2024-06-13 18:09:31 -04:00
{
InitializeComponent();
2024-06-14 13:47:30 -04:00
PopulateDomainUpDowns();
foreach (var remap in DataProvider.Remaps)
{
RemapTreeView.Nodes.Add(GUI.GenerateTreeNode(remap));
}
2024-06-13 18:09:31 -04:00
}
2024-06-13 20:25:11 -04:00
#region BUTTONS
2024-06-14 13:47:30 -04:00
#region MAIN_BUTTONS
2024-06-13 21:20:48 -04:00
/// <summary>
/// Construct a new remap when the button is pressed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2024-06-13 20:25:11 -04:00
private void AddRemapButton_Click(object sender, EventArgs e)
{
2024-06-14 11:01:21 -04:00
if (NewTypeName.Text == string.Empty)
{
2024-06-14 13:47:30 -04:00
MessageBox.Show("Please enter a new type name", "Invalid data");
2024-06-14 11:01:21 -04:00
return;
}
2024-06-13 21:20:48 -04:00
var remap = new RemapModel
{
Succeeded = false,
FailureReason = EFailureReason.None,
NewTypeName = NewTypeName.Text,
2024-06-14 11:01:21 -04:00
OriginalTypeName = OriginalTypeName.Text == string.Empty ? null : OriginalTypeName.Text,
2024-06-13 21:20:48 -04:00
UseForceRename = ForceRenameCheckbox.Checked,
SearchParams = new SearchParams
{
2024-06-13 22:58:26 -04:00
IsPublic = IsPublicUpDown.GetEnabled(),
IsAbstract = IsAbstractUpDown.GetEnabled(),
IsInterface = IsInterfaceUpDown.GetEnabled(),
IsEnum = IsEnumUpDown.GetEnabled(),
IsNested = IsNestedUpDown.GetEnabled(),
IsSealed = IsSealedUpDown.GetEnabled(),
HasAttribute = HasAttributeUpDown.GetEnabled(),
IsDerived = IsDerivedUpDown.GetEnabled(),
HasGenericParameters = HasGenericParametersUpDown.GetEnabled(),
ParentName = NestedTypeParentName.Text == string.Empty
? null
: NestedTypeParentName.Text,
MatchBaseClass = BaseClassIncludeTextFIeld.Text == string.Empty
? null
: BaseClassIncludeTextFIeld.Text,
IgnoreBaseClass = BaseClassExcludeTextField.Text == string.Empty
? null
: BaseClassExcludeTextField.Text,
2024-06-14 11:01:21 -04:00
// Constructor - TODO
2024-06-14 14:18:17 -04:00
ConstructorParameterCount = ConstructorCountEnabled.GetCount(ConstuctorCountUpDown),
2024-06-13 22:58:26 -04:00
MethodCount = MethodCountEnabled.GetCount(MethodCountUpDown),
FieldCount = FieldCountEnabled.GetCount(FieldCountUpDown),
PropertyCount = PropertyCountEnabled.GetCount(PropertyCountUpDown),
NestedTypeCount = NestedTypeCountEnabled.GetCount(NestedTypeCountUpDown),
IncludeMethods = GUI.GetAllEntriesFromListBox(MethodIncludeBox),
ExcludeMethods = GUI.GetAllEntriesFromListBox(MethodExcludeBox),
IncludeFields = GUI.GetAllEntriesFromListBox(FieldIncludeBox),
ExcludeFields = GUI.GetAllEntriesFromListBox(FieldExcludeBox),
IncludeProperties = GUI.GetAllEntriesFromListBox(PropertiesIncludeBox),
ExcludeProperties = GUI.GetAllEntriesFromListBox(PropertiesExcludeBox),
IncludeNestedTypes = GUI.GetAllEntriesFromListBox(NestedTypesIncludeBox),
ExcludeNestedTypes = GUI.GetAllEntriesFromListBox(NestedTypesExcludeBox),
2024-06-13 21:20:48 -04:00
}
};
2024-06-14 11:01:21 -04:00
RemapTreeView.Nodes.Add(GUI.GenerateTreeNode(remap));
2024-06-14 13:47:30 -04:00
DataProvider.Remaps.Add(remap);
ResetAll();
2024-06-13 20:25:11 -04:00
}
private void RemoveRemapButton_Click(object sender, EventArgs e)
{
2024-06-14 13:47:30 -04:00
DataProvider.Remaps?.RemoveAt(RemapTreeView.SelectedNode.Index);
2024-06-14 11:01:21 -04:00
RemapTreeView.SelectedNode?.Remove();
2024-06-13 20:25:11 -04:00
}
2024-06-14 13:47:30 -04:00
private void RunRemapButton_Click(object sender, EventArgs e)
{
2024-06-14 14:18:17 -04:00
if (Remapper.IsRunning) { return; }
Task.Run(() => Remapper.InitializeRemap());
2024-06-14 13:47:30 -04:00
}
private void SaveMappingFileButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show(
"Are you sure?",
"Confirmation",
MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
DataProvider.SaveMapping();
}
}
private void LoadMappingFileButton_Click(object sender, EventArgs e)
{
var fDialog = new OpenFileDialog
{
Title = "Select a mapping file",
Filter = "JSON Files (*.json)|*.json|JSONC Files (*.jsonc)|*.jsonc|All Files (*.*)|*.*",
Multiselect = false
};
if (fDialog.ShowDialog() == DialogResult.OK)
{
var fileName = fDialog.FileName;
DataProvider.LoadMappingFile(fileName);
}
RemapTreeView.Nodes.Clear();
foreach (var remap in DataProvider.Remaps)
{
RemapTreeView.Nodes.Add(GUI.GenerateTreeNode(remap));
}
}
#endregion MAIN_BUTTONS
#region LISTBOX_BUTTONS
2024-06-13 20:25:11 -04:00
private void MethodIncludeAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!MethodIncludeBox.Items.Contains(IncludeMethodTextBox.Text))
{
MethodIncludeBox.Items.Add(IncludeMethodTextBox.Text);
}
2024-06-13 20:25:11 -04:00
}
private void MethodIncludeRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (MethodIncludeBox.SelectedItem != null)
{
MethodIncludeBox.Items.Remove(MethodIncludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
private void MethodExcludeAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!MethodExcludeBox.Items.Contains(ExcludeMethodTextBox.Text))
{
MethodExcludeBox.Items.Add(ExcludeMethodTextBox.Text);
}
2024-06-13 20:25:11 -04:00
}
private void MethodExcludeRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (MethodExcludeBox.SelectedItem != null)
{
MethodExcludeBox.Items.Remove(MethodExcludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
private void FIeldIncludeAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!FieldIncludeBox.Items.Contains(FieldsIncludeTextInput.Text))
{
FieldIncludeBox.Items.Add(FieldsIncludeTextInput.Text);
}
2024-06-13 20:25:11 -04:00
}
private void FieldIncludeRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (FieldIncludeBox.SelectedItem != null)
{
FieldIncludeBox.Items.Remove(FieldIncludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
private void FieldExcludeAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!FieldExcludeBox.Items.Contains(FieldsExcludeTextInput.Text))
{
FieldExcludeBox.Items.Add(FieldsExcludeTextInput.Text);
}
2024-06-13 20:25:11 -04:00
}
private void FieldExcludeRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (FieldExcludeBox.SelectedItem != null)
{
FieldExcludeBox.Items.Remove(FieldExcludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
private void PropertiesIncludeAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!PropertiesIncludeBox.Items.Contains(PropertiesIncludeTextField.Text))
{
PropertiesIncludeBox.Items.Add(PropertiesIncludeTextField.Text);
}
2024-06-13 20:25:11 -04:00
}
private void PropertiesIncludeRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (PropertiesIncludeBox.SelectedItem != null)
{
PropertiesIncludeBox.Items.Remove(PropertiesIncludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
private void PropertiesExcludeAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!PropertiesExcludeBox.Items.Contains(PropertiesExcludeTextField.Text))
{
PropertiesExcludeBox.Items.Add(PropertiesExcludeTextField.Text);
}
2024-06-13 20:25:11 -04:00
}
private void PropertiesExcludeRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (PropertiesExcludeBox.SelectedItem != null)
{
PropertiesExcludeBox.Items.Remove(PropertiesExcludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
private void NestedTypesAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!NestedTypesIncludeBox.Items.Contains(NestedTypesIncludeTextField.Text))
{
NestedTypesIncludeBox.Items.Add(NestedTypesIncludeTextField.Text);
}
2024-06-13 20:25:11 -04:00
}
private void NestedTypesRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (NestedTypesIncludeBox.SelectedItem != null)
{
NestedTypesIncludeBox.Items.Remove(NestedTypesIncludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
private void NestedTypesExlcudeAddButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (!NestedTypesExcludeBox.Items.Contains(NestedTypesExcludeTextField.Text))
{
NestedTypesExcludeBox.Items.Add(NestedTypesExcludeTextField.Text);
}
2024-06-13 20:25:11 -04:00
}
private void NestedTypesExcludeRemoveButton_Click(object sender, EventArgs e)
{
2024-06-13 21:20:48 -04:00
if (NestedTypesExcludeBox.SelectedItem != null)
{
NestedTypesExcludeBox.Items.Remove(NestedTypesExcludeBox.SelectedItem);
}
2024-06-13 20:25:11 -04:00
}
2024-06-14 13:47:30 -04:00
#endregion LISTBOX_BUTTONS
2024-06-13 20:25:11 -04:00
#endregion BUTTONS
2024-06-14 13:47:30 -04:00
// Reset All UI elements to default
private void ResetAll()
{
PopulateDomainUpDowns();
// Text fields
NewTypeName.Clear();
BaseClassIncludeTextFIeld.Clear();
BaseClassExcludeTextField.Clear();
NestedTypeParentName.Clear();
BaseClassExcludeTextField.Clear();
IncludeMethodTextBox.Clear();
ExcludeMethodTextBox.Clear();
FieldsIncludeTextInput.Clear();
FieldsExcludeTextInput.Clear();
PropertiesIncludeTextField.Clear();
PropertiesExcludeTextField.Clear();
NestedTypesIncludeTextField.Clear();
NestedTypesExcludeTextField.Clear();
// Numeric UpDowns
MethodCountUpDown.Value = 0;
FieldCountUpDown.Value = 0;
PropertyCountUpDown.Value = 0;
NestedTypeCountUpDown.Value = 0;
// Check boxes
ForceRenameCheckbox.Checked = false;
MethodCountEnabled.Checked = false;
FieldCountEnabled.Checked = false;
PropertyCountEnabled.Checked = false;
NestedTypeCountEnabled.Checked = false;
// List boxes
MethodIncludeBox.Items.Clear();
MethodExcludeBox.Items.Clear();
FieldIncludeBox.Items.Clear();
FieldExcludeBox.Items.Clear();
PropertiesIncludeBox.Items.Clear();
PropertiesExcludeBox.Items.Clear();
NestedTypesIncludeBox.Items.Clear();
NestedTypesExcludeBox.Items.Clear();
}
private void PopulateDomainUpDowns()
{
// Clear them all first just incase
IsPublicUpDown.BuildStringList("IsPublic");
IsAbstractUpDown.BuildStringList("IsAbstract");
IsInterfaceUpDown.BuildStringList("IsInterface");
IsEnumUpDown.BuildStringList("IsEnum");
IsNestedUpDown.BuildStringList("IsNested");
IsSealedUpDown.BuildStringList("IsSealed");
HasAttributeUpDown.BuildStringList("HasAttribute");
IsDerivedUpDown.BuildStringList("IsDerived");
HasGenericParametersUpDown.BuildStringList("HasGenericParams");
}
2024-06-13 18:09:31 -04:00
}
2024-06-13 20:25:11 -04:00
}