481 lines
16 KiB
C#
Raw Normal View History

2024-06-14 19:06:21 -04:00
using ReCodeIt.Enums;
using ReCodeIt.Models;
using ReCodeIt.ReMapper;
using ReCodeIt.Utils;
2024-06-13 20:25:11 -04:00
2024-06-14 19:06:21 -04:00
namespace ReCodeIt.GUI;
2024-06-14 18:07:01 -04:00
2024-06-14 19:06:21 -04:00
public partial class ReCodeItForm : Form
2024-06-13 18:09:31 -04:00
{
2024-06-14 19:06:21 -04:00
public static ReCodeItRemapper Remapper { get; private set; } = new();
2024-06-14 18:07:01 -04:00
2024-06-14 19:06:21 -04:00
public ReCodeItForm()
2024-06-13 18:09:31 -04:00
{
2024-06-14 18:07:01 -04:00
InitializeComponent();
PopulateDomainUpDowns();
2024-06-13 21:20:48 -04:00
2024-06-14 18:07:01 -04:00
Remapper.OnComplete += ReloadTreeView;
ReloadTreeView(this, EventArgs.Empty);
}
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
#region BUTTONS
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
#region MAIN_BUTTONS
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
/// <summary>
/// Construct a new remap when the button is pressed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddRemapButton_Click(object sender, EventArgs e)
{
if (NewTypeName.Text == string.Empty)
{
MessageBox.Show("Please enter a new type name", "Invalid data");
return;
}
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
var remap = new RemapModel
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
Succeeded = false,
FailureReason = EFailureReason.None,
NewTypeName = NewTypeName.Text,
OriginalTypeName = OriginalTypeName.Text == string.Empty ? null : OriginalTypeName.Text,
UseForceRename = ForceRenameCheckbox.Checked,
SearchParams = new SearchParams
2024-06-14 11:01:21 -04:00
{
2024-06-14 18:07:01 -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,
// Constructor - TODO
ConstructorParameterCount = ConstructorCountEnabled.GetCount(ConstuctorCountUpDown),
MethodCount = MethodCountEnabled.GetCount(MethodCountUpDown),
FieldCount = FieldCountEnabled.GetCount(FieldCountUpDown),
PropertyCount = PropertyCountEnabled.GetCount(PropertyCountUpDown),
NestedTypeCount = NestedTypeCountEnabled.GetCount(NestedTypeCountUpDown),
2024-06-14 19:06:21 -04:00
IncludeMethods = GUIHelpers.GetAllEntriesFromListBox(MethodIncludeBox),
ExcludeMethods = GUIHelpers.GetAllEntriesFromListBox(MethodExcludeBox),
IncludeFields = GUIHelpers.GetAllEntriesFromListBox(FieldIncludeBox),
ExcludeFields = GUIHelpers.GetAllEntriesFromListBox(FieldExcludeBox),
IncludeProperties = GUIHelpers.GetAllEntriesFromListBox(PropertiesIncludeBox),
ExcludeProperties = GUIHelpers.GetAllEntriesFromListBox(PropertiesExcludeBox),
IncludeNestedTypes = GUIHelpers.GetAllEntriesFromListBox(NestedTypesIncludeBox),
ExcludeNestedTypes = GUIHelpers.GetAllEntriesFromListBox(NestedTypesExcludeBox),
2024-06-14 11:01:21 -04:00
}
2024-06-14 18:07:01 -04:00
};
2024-06-13 21:20:48 -04:00
2024-06-14 19:06:21 -04:00
RemapTreeView.Nodes.Add(GUIHelpers.GenerateTreeNode(remap, this));
2024-06-14 18:07:01 -04:00
DataProvider.Remaps.Add(remap);
ResetAll();
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void RemoveRemapButton_Click(object sender, EventArgs e)
{
DataProvider.Remaps?.RemoveAt(RemapTreeView.SelectedNode.Index);
RemapTreeView.SelectedNode?.Remove();
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void RunRemapButton_Click(object sender, EventArgs e)
{
2024-06-14 19:06:21 -04:00
if (ReCodeItRemapper.IsRunning) { return; }
2024-06-14 14:18:17 -04:00
2024-06-14 18:07:01 -04:00
Console.Clear();
2024-06-14 16:18:43 -04:00
2024-06-14 18:07:01 -04:00
Remapper.InitializeRemap();
}
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -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)
2024-06-14 13:47:30 -04:00
{
2024-06-14 18:07:01 -04:00
DataProvider.SaveMapping();
2024-06-14 13:47:30 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
private void LoadMappingFileButton_Click(object sender, EventArgs e)
{
var fDialog = new OpenFileDialog
2024-06-14 13:47:30 -04:00
{
2024-06-14 18:07:01 -04:00
Title = "Select a mapping file",
Filter = "JSON Files (*.json)|*.json|JSONC Files (*.jsonc)|*.jsonc|All Files (*.*)|*.*",
Multiselect = false
};
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
if (fDialog.ShowDialog() == DialogResult.OK)
{
DataProvider.LoadMappingFile(fDialog.FileName);
}
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
RemapTreeView.Nodes.Clear();
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
foreach (var remap in DataProvider.Remaps)
{
2024-06-14 19:06:21 -04:00
RemapTreeView.Nodes.Add(GUIHelpers.GenerateTreeNode(remap, this));
2024-06-14 13:47:30 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
#endregion MAIN_BUTTONS
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
#region LISTBOX_BUTTONS
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
private void MethodIncludeAddButton_Click(object sender, EventArgs e)
{
if (!MethodIncludeBox.Items.Contains(IncludeMethodTextBox.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
MethodIncludeBox.Items.Add(IncludeMethodTextBox.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void MethodIncludeRemoveButton_Click(object sender, EventArgs e)
{
if (MethodIncludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
MethodIncludeBox.Items.Remove(MethodIncludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void MethodExcludeAddButton_Click(object sender, EventArgs e)
{
if (!MethodExcludeBox.Items.Contains(ExcludeMethodTextBox.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
MethodExcludeBox.Items.Add(ExcludeMethodTextBox.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void MethodExcludeRemoveButton_Click(object sender, EventArgs e)
{
if (MethodExcludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
MethodExcludeBox.Items.Remove(MethodExcludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void FIeldIncludeAddButton_Click(object sender, EventArgs e)
{
if (!FieldIncludeBox.Items.Contains(FieldsIncludeTextInput.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
FieldIncludeBox.Items.Add(FieldsIncludeTextInput.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void FieldIncludeRemoveButton_Click(object sender, EventArgs e)
{
if (FieldIncludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
FieldIncludeBox.Items.Remove(FieldIncludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void FieldExcludeAddButton_Click(object sender, EventArgs e)
{
if (!FieldExcludeBox.Items.Contains(FieldsExcludeTextInput.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
FieldExcludeBox.Items.Add(FieldsExcludeTextInput.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void FieldExcludeRemoveButton_Click(object sender, EventArgs e)
{
if (FieldExcludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
FieldExcludeBox.Items.Remove(FieldExcludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void PropertiesIncludeAddButton_Click(object sender, EventArgs e)
{
if (!PropertiesIncludeBox.Items.Contains(PropertiesIncludeTextField.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
PropertiesIncludeBox.Items.Add(PropertiesIncludeTextField.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void PropertiesIncludeRemoveButton_Click(object sender, EventArgs e)
{
if (PropertiesIncludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
PropertiesIncludeBox.Items.Remove(PropertiesIncludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void PropertiesExcludeAddButton_Click(object sender, EventArgs e)
{
if (!PropertiesExcludeBox.Items.Contains(PropertiesExcludeTextField.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
PropertiesExcludeBox.Items.Add(PropertiesExcludeTextField.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void PropertiesExcludeRemoveButton_Click(object sender, EventArgs e)
{
if (PropertiesExcludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
PropertiesExcludeBox.Items.Remove(PropertiesExcludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void NestedTypesAddButton_Click(object sender, EventArgs e)
{
if (!NestedTypesIncludeBox.Items.Contains(NestedTypesIncludeTextField.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
NestedTypesIncludeBox.Items.Add(NestedTypesIncludeTextField.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void NestedTypesRemoveButton_Click(object sender, EventArgs e)
{
if (NestedTypesIncludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
NestedTypesIncludeBox.Items.Remove(NestedTypesIncludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void NestedTypesExlcudeAddButton_Click(object sender, EventArgs e)
{
if (!NestedTypesExcludeBox.Items.Contains(NestedTypesExcludeTextField.Text))
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
NestedTypesExcludeBox.Items.Add(NestedTypesExcludeTextField.Text);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
private void NestedTypesExcludeRemoveButton_Click(object sender, EventArgs e)
{
if (NestedTypesExcludeBox.SelectedItem != null)
2024-06-13 20:25:11 -04:00
{
2024-06-14 18:07:01 -04:00
NestedTypesExcludeBox.Items.Remove(NestedTypesExcludeBox.SelectedItem);
2024-06-13 20:25:11 -04:00
}
2024-06-14 18:07:01 -04:00
}
2024-06-13 20:25:11 -04:00
2024-06-14 18:07:01 -04:00
#endregion LISTBOX_BUTTONS
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
#endregion BUTTONS
2024-06-14 13:47:30 -04:00
2024-06-14 19:06:21 -04:00
#region SETTINGS_TAB
public void RefreshSettingsPage()
{
AssemblyPathTextBox.Text = DataProvider.Settings.AppSettings.AssemblyPath;
OutputPathTextBox.Text = DataProvider.Settings.AppSettings.OutputPath;
MappingPathTextBox.Text = DataProvider.Settings.AppSettings.MappingPath;
DebugLoggingCheckbox.Checked = DataProvider.Settings.AppSettings.Debug;
SilentModeCheckbox.Checked = DataProvider.Settings.AppSettings.SilentMode;
RenameFieldsCheckbox.Checked = DataProvider.Settings.AppSettings.RenameFields;
RenamePropertiesCheckbox.Checked = DataProvider.Settings.AppSettings.RenameProperties;
PublicizeCheckbox.Checked = DataProvider.Settings.AppSettings.Publicize;
UnsealCheckbox.Checked = DataProvider.Settings.AppSettings.Unseal;
MaxMatchCountUpDown.Value = DataProvider.Settings.Remapper.MaxMatchCount;
AutoMapperRequiredMatchesUpDown.Value = DataProvider.Settings.AutoMapper.RequiredMatches;
}
#region SETTINGS_BUTTONS
private void PickAssemblyPathButton_Click(object sender, EventArgs e)
{
OpenFileDialog fDialog = new()
{
Title = "Select a DLL file",
Filter = "DLL Files (*.dll)|*.dll|All Files (*.*)|*.*",
Multiselect = false
};
if (fDialog.ShowDialog() == DialogResult.OK)
{
DataProvider.Settings.AppSettings.AssemblyPath = fDialog.FileName;
DataProvider.LoadAssemblyDefinition();
AssemblyPathTextBox.Text = fDialog.FileName;
}
}
private void OutputDirectoryButton_Click(object sender, EventArgs e)
{
using FolderBrowserDialog fDialog = new();
fDialog.Description = "Select a directory";
fDialog.ShowNewFolderButton = true;
if (fDialog.ShowDialog() == DialogResult.OK)
{
DataProvider.Settings.AppSettings.OutputPath = fDialog.SelectedPath;
OutputPathTextBox.Text = fDialog.SelectedPath;
}
}
private void MappingChooseButton_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)
{
DataProvider.LoadMappingFile(fDialog.FileName);
MappingPathTextBox.Text = fDialog.FileName;
}
}
#endregion SETTINGS_BUTTONS
#region CHECKBOXES
private void DebugLoggingCheckbox_CheckedChanged(object sender, EventArgs e)
{
DataProvider.Settings.AppSettings.Debug = DebugLoggingCheckbox.Checked;
DataProvider.SaveAppSettings();
}
private void SilentModeCheckbox_CheckedChanged(object sender, EventArgs e)
{
DataProvider.Settings.AppSettings.SilentMode = SilentModeCheckbox.Checked;
DataProvider.SaveAppSettings();
}
private void RenameFieldsCheckbox_CheckedChanged(object sender, EventArgs e)
{
DataProvider.Settings.AppSettings.RenameFields = RenameFieldsCheckbox.Checked;
DataProvider.SaveAppSettings();
}
private void RenamePropertiesCheckbox_CheckedChanged(object sender, EventArgs e)
{
DataProvider.Settings.AppSettings.RenameProperties = RenamePropertiesCheckbox.Checked;
DataProvider.SaveAppSettings();
}
private void PublicizeCheckbox_CheckedChanged(object sender, EventArgs e)
{
DataProvider.Settings.AppSettings.Publicize = PublicizeCheckbox.Checked;
DataProvider.SaveAppSettings();
}
private void UnsealCheckbox_CheckedChanged(object sender, EventArgs e)
{
DataProvider.Settings.AppSettings.Unseal = UnsealCheckbox.Checked;
DataProvider.SaveAppSettings();
}
#endregion CHECKBOXES
#region UPDOWNS
private void MaxMatchCountUpDown_ValueChanged(object sender, EventArgs e)
{
DataProvider.Settings.Remapper.MaxMatchCount = (int)MaxMatchCountUpDown.Value;
DataProvider.SaveAppSettings();
}
private void AutoMapperRequiredMatchesUpDown_ValueChanged(object sender, EventArgs e)
{
DataProvider.Settings.AutoMapper.RequiredMatches = (int)AutoMapperRequiredMatchesUpDown.Value;
DataProvider.SaveAppSettings();
}
#endregion UPDOWNS
#endregion SETTINGS_TAB
2024-06-14 18:07:01 -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();
}
2024-06-14 13:47:30 -04:00
2024-06-14 18:07:01 -04:00
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-14 18:07:01 -04:00
/// <summary>
/// Subscribes the the remappers OnComplete event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ReloadTreeView(object sender, EventArgs e)
{
RemapTreeView.Nodes.Clear();
2024-06-14 18:07:01 -04:00
foreach (var remap in DataProvider.Remaps)
{
2024-06-14 19:06:21 -04:00
RemapTreeView.Nodes.Add(GUIHelpers.GenerateTreeNode(remap, this));
}
2024-06-13 18:09:31 -04:00
}
2024-06-13 20:25:11 -04:00
}