From abf1fbf1675c73923c9e5ab09799bd760ba04683 Mon Sep 17 00:00:00 2001
From: Cj <161484149+CJ-SPT@users.noreply.github.com>
Date: Mon, 17 Jun 2024 01:22:11 -0400
Subject: [PATCH] Start work on WPF project
---
ReCodeItGUI_WPF/App.xaml | 10 ++
ReCodeItGUI_WPF/App.xaml.cs | 14 ++
ReCodeItGUI_WPF/AssemblyInfo.cs | 10 ++
ReCodeItGUI_WPF/Helpers/GUIExtentions.cs | 156 ++++++++++++++++++
ReCodeItGUI_WPF/MainWindow.xaml | 197 +++++++++++++++++++++++
ReCodeItGUI_WPF/MainWindow.xaml.cs | 94 +++++++++++
ReCodeItGUI_WPF/ReCodeItGUI_WPF.csproj | 23 +++
RecodeIt.sln | 6 +
RecodeItLib/Models/TypeDatabase.cs | 50 ++++++
9 files changed, 560 insertions(+)
create mode 100644 ReCodeItGUI_WPF/App.xaml
create mode 100644 ReCodeItGUI_WPF/App.xaml.cs
create mode 100644 ReCodeItGUI_WPF/AssemblyInfo.cs
create mode 100644 ReCodeItGUI_WPF/Helpers/GUIExtentions.cs
create mode 100644 ReCodeItGUI_WPF/MainWindow.xaml
create mode 100644 ReCodeItGUI_WPF/MainWindow.xaml.cs
create mode 100644 ReCodeItGUI_WPF/ReCodeItGUI_WPF.csproj
create mode 100644 RecodeItLib/Models/TypeDatabase.cs
diff --git a/ReCodeItGUI_WPF/App.xaml b/ReCodeItGUI_WPF/App.xaml
new file mode 100644
index 0000000..d33d2b8
--- /dev/null
+++ b/ReCodeItGUI_WPF/App.xaml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/ReCodeItGUI_WPF/App.xaml.cs b/ReCodeItGUI_WPF/App.xaml.cs
new file mode 100644
index 0000000..828021e
--- /dev/null
+++ b/ReCodeItGUI_WPF/App.xaml.cs
@@ -0,0 +1,14 @@
+using System.Configuration;
+using System.Data;
+using System.Windows;
+
+namespace ReCodeItGUI_WPF
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+
+}
diff --git a/ReCodeItGUI_WPF/AssemblyInfo.cs b/ReCodeItGUI_WPF/AssemblyInfo.cs
new file mode 100644
index 0000000..b0ec827
--- /dev/null
+++ b/ReCodeItGUI_WPF/AssemblyInfo.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs b/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs
new file mode 100644
index 0000000..143c74f
--- /dev/null
+++ b/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs
@@ -0,0 +1,156 @@
+using Microsoft.Win32;
+using ReCodeIt.Models;
+using System.Windows.Controls;
+using Xceed.Wpf.Toolkit;
+
+namespace ReCodeItGUI_WPF.Helpers
+{
+ internal static class GUIExtentions
+ {
+ #region EXT_METHODS
+
+ public static void AddToListView(this ListView listView, TextBox textBox)
+ {
+ if (!string.IsNullOrWhiteSpace(textBox.Text) && !listView.Items.Contains(textBox.Text))
+ {
+ listView.Items.Add(textBox.Text);
+ textBox.Clear();
+ }
+ }
+
+ public static void RemoveSelectedItem(this ListView listView)
+ {
+ if (listView.SelectedItem != null)
+ {
+ listView.Items.RemoveAt(listView.SelectedIndex);
+ }
+ }
+
+ #endregion EXT_METHODS
+
+ ///
+ /// Returns the string result of the dialog
+ ///
+ /// Path if valid, or empty string
+ public static string OpenFileDialog(bool dll = false)
+ {
+ var title = dll ? "Select a DLL File" : "Select a Json File";
+
+ var defaultExt = dll ? ".dll" : ".jsonc";
+
+ var dllFilter = "DLL files (*.dll)|*.dll|All files (*.*)|*.*";
+ var jsonFilter = "JSON/JSONC files (*.json;*.jsonc)|*.json;*.jsonc|All files (*.*)|*.*";
+
+ var openFileDialog = new OpenFileDialog();
+ openFileDialog.Title = title;
+ openFileDialog.Filter = dll ? dllFilter : jsonFilter;
+ openFileDialog.DefaultExt = defaultExt;
+
+ bool? result = openFileDialog.ShowDialog();
+
+ if (result == true)
+ {
+ return openFileDialog.FileName;
+ }
+
+ return string.Empty;
+ }
+
+ public static RemapModel CreateRemapFromGui(this MainWindow window)
+ {
+ var model = new RemapModel
+ {
+ NewTypeName = window.NewTypeNameTextBox.Text,
+ OriginalTypeName = window.OriginalTypeNameTextBox.Text ?? string.Empty,
+ UseForceRename = (bool)window.UseForceRenameCheckbox.IsChecked,
+ SearchParams = new SearchParams
+ {
+ IsPublic = window.IsPublicComboBox.IsComboEnabled(),
+ IsAbstract = window.IsAbstractComboBox.IsComboEnabled(),
+ IsInterface = window.IsInterfaceComboBox.IsComboEnabled(),
+ IsEnum = window.IsEnumComboBox.IsComboEnabled(),
+ IsNested = window.IsNestedComboBox.IsComboEnabled(),
+ IsSealed = window.IsSealedComboBox.IsComboEnabled(),
+ HasAttribute = window.HasAttributeComboBox.IsComboEnabled(),
+ IsDerived = window.IsDerivedComboBox.IsComboEnabled(),
+ HasGenericParameters = window.HasAttributeComboBox.IsComboEnabled(),
+ ParentName = window.ParentNameTextBox.GetText(),
+ MatchBaseClass = window.IncludeBaseClassTextBox.GetText(),
+ IgnoreBaseClass = window.IgnoreBaseClassTextBox.GetText(),
+ ConstructorParameterCount = window.CtorParamCountUpDown.GetValIfEnabled(window.CtorCheckbox),
+ MethodCount = window.MethodCountUpDown.GetValIfEnabled(window.MethodCheckbox),
+ FieldCount = window.FieldCountUpDown.GetValIfEnabled(window.FieldCountCheckbox),
+ PropertyCount = window.PropertyCountUpDown.GetValIfEnabled(window.PropertyCountCheckBox),
+ NestedTypeCount = window.NestedTypeCountUpDown.GetValIfEnabled(window.NestedTypeCountCheckBox),
+ IncludeMethods = window.MethodIncludeListView.GetItems(),
+ ExcludeMethods = window.MethodExcludeListView.GetItems(),
+ IncludeFields = window.FieldIncludeListView.GetItems(),
+ ExcludeFields = window.FieldExcludeListView.GetItems(),
+ IncludeProperties = window.PropertyIncludeListBox.GetItems(),
+ ExcludeProperties = window.PropertyExcludeListBox.GetItems(),
+ IncludeNestedTypes = window.NestedTypeIncludeListView.GetItems(),
+ ExcludeNestedTypes = window.NestedTypeExcludeListView.GetItems(),
+ }
+ };
+
+ return model;
+ }
+
+ ///
+ /// True or false if selected, otherwise null
+ ///
+ ///
+ ///
+ public static bool? IsComboEnabled(this ComboBox comboBox)
+ {
+ if (bool.TryParse(comboBox.Text, out var result))
+ {
+ return result;
+ }
+
+ return null;
+ }
+
+ ///
+ /// returns the text in the box if exists, or null
+ ///
+ ///
+ ///
+ public static string? GetText(this TextBox textBox)
+ {
+ if (textBox.Text != string.Empty)
+ {
+ return textBox.Text;
+ }
+
+ return null;
+ }
+
+ public static int? GetValIfEnabled(this IntegerUpDown intUpDown, CheckBox cBox)
+ {
+ if ((bool)cBox.IsChecked)
+ {
+ return intUpDown.Value;
+ }
+
+ return null;
+ }
+
+ ///
+ /// Converts list view objects to string list
+ ///
+ ///
+ ///
+ public static List GetItems(this ListView listView)
+ {
+ var tmp = new List();
+
+ foreach (var item in listView.Items)
+ {
+ tmp.Add(item.ToString());
+ }
+
+ return tmp;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ReCodeItGUI_WPF/MainWindow.xaml b/ReCodeItGUI_WPF/MainWindow.xaml
new file mode 100644
index 0000000..6e80674
--- /dev/null
+++ b/ReCodeItGUI_WPF/MainWindow.xaml
@@ -0,0 +1,197 @@
+
+
+
\ No newline at end of file
diff --git a/ReCodeItGUI_WPF/MainWindow.xaml.cs b/ReCodeItGUI_WPF/MainWindow.xaml.cs
new file mode 100644
index 0000000..c6f24cd
--- /dev/null
+++ b/ReCodeItGUI_WPF/MainWindow.xaml.cs
@@ -0,0 +1,94 @@
+using ReCodeIt.Utils;
+using ReCodeItGUI_WPF.Helpers;
+using System.Windows;
+using System.Windows.Input;
+
+namespace ReCodeItGUI_WPF;
+
+///
+/// Interaction logic for MainWindow.xaml
+///
+public partial class MainWindow : Window
+{
+ private ICommand deleteCommand;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ DataProvider.LoadAppSettings();
+ DataProvider.LoadMappingFile();
+ }
+
+ #region MANUAL_REMAPPER
+
+ private void SaveRemapButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.CreateRemapFromGui();
+ }
+
+ private void MethodIncludeButton_Click(object sender, RoutedEventArgs e)
+ {
+ MethodIncludeListView.AddToListView(MethodTextBox);
+ }
+
+ private void MethodExcludeButton_Click(object sender, RoutedEventArgs e)
+ {
+ MethodExcludeListView.AddToListView(MethodTextBox);
+ }
+
+ private void MethodRemoveButton_Click(object sender, RoutedEventArgs e)
+ {
+ MethodIncludeListView.RemoveSelectedItem();
+ MethodExcludeListView.RemoveSelectedItem();
+ }
+
+ private void FieldIncludeButton_Click(object sender, RoutedEventArgs e)
+ {
+ FieldIncludeListView.AddToListView(FieldTextBox);
+ }
+
+ private void FieldExcludeButton_Click(object sender, RoutedEventArgs e)
+ {
+ FieldExcludeListView.AddToListView(FieldTextBox);
+ }
+
+ private void FieldRemoveButton_Click(object sender, RoutedEventArgs e)
+ {
+ FieldIncludeListView.RemoveSelectedItem();
+ FieldExcludeListView.RemoveSelectedItem();
+ }
+
+ private void PropertyIncludeButton_Click(object sender, RoutedEventArgs e)
+ {
+ PropertyIncludeListBox.AddToListView(PropertyTextBox);
+ }
+
+ private void PropertyExcludeButton_Click(object sender, RoutedEventArgs e)
+ {
+ PropertyExcludeListBox.AddToListView(PropertyTextBox);
+ }
+
+ private void PropertyRemoveButton_Click(object sender, RoutedEventArgs e)
+ {
+ PropertyIncludeListBox.RemoveSelectedItem();
+ PropertyExcludeListBox.RemoveSelectedItem();
+ }
+
+ private void NestedTypeIncludeAddButton_Click(object sender, RoutedEventArgs e)
+ {
+ NestedTypeIncludeListView.AddToListView(NestTypeTextBox);
+ }
+
+ private void NestedTypeExcludeButton_Click(object sender, RoutedEventArgs e)
+ {
+ NestedTypeExcludeListView.AddToListView(NestTypeTextBox);
+ }
+
+ private void NestedTypeRemoveButton_Click(object sender, RoutedEventArgs e)
+ {
+ NestedTypeIncludeListView.RemoveSelectedItem();
+ NestedTypeExcludeListView.RemoveSelectedItem();
+ }
+
+ #endregion MANUAL_REMAPPER
+}
\ No newline at end of file
diff --git a/ReCodeItGUI_WPF/ReCodeItGUI_WPF.csproj b/ReCodeItGUI_WPF/ReCodeItGUI_WPF.csproj
new file mode 100644
index 0000000..9af97c5
--- /dev/null
+++ b/ReCodeItGUI_WPF/ReCodeItGUI_WPF.csproj
@@ -0,0 +1,23 @@
+
+
+
+ WinExe
+ net8.0-windows
+ disable
+ enable
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/RecodeIt.sln b/RecodeIt.sln
index 1753da4..b86f273 100644
--- a/RecodeIt.sln
+++ b/RecodeIt.sln
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCodeItGUI", "RecodeItGUI\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCodeItLib", "RecodeItLib\ReCodeItLib.csproj", "{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReCodeItGUI_WPF", "ReCodeItGUI_WPF\ReCodeItGUI_WPF.csproj", "{86142D6E-DE7E-48A7-9905-55D3ECE377AD}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|Any CPU.Build.0 = Release|Any CPU
+ {86142D6E-DE7E-48A7-9905-55D3ECE377AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86142D6E-DE7E-48A7-9905-55D3ECE377AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86142D6E-DE7E-48A7-9905-55D3ECE377AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86142D6E-DE7E-48A7-9905-55D3ECE377AD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/RecodeItLib/Models/TypeDatabase.cs b/RecodeItLib/Models/TypeDatabase.cs
new file mode 100644
index 0000000..f363432
--- /dev/null
+++ b/RecodeItLib/Models/TypeDatabase.cs
@@ -0,0 +1,50 @@
+using Mono.Cecil;
+using Mono.Collections.Generic;
+
+namespace ReCodeItLib.Models;
+
+///
+/// This is a database of type, field, property etc info collected into one place for an assembly.
+///
+///
+internal class TypeDatabaseModel
+{
+ public TypeDatabaseModel(ModuleDefinition moduleDefinition)
+ {
+ ModuleDefinition = moduleDefinition;
+
+ GetAllTypes(ModuleDefinition.Types);
+ }
+
+ public ModuleDefinition ModuleDefinition { get; private set; }
+
+ public List Types { get; private set; } = [];
+
+ ///
+ /// Key, the type definition the property belongs too
+ ///
+ public Dictionary Properties { get; private set; }
+
+ ///
+ /// Key, the type definition the method belongs too
+ ///
+ public Dictionary Methods { get; private set; }
+
+ ///
+ /// Key, the type definition the field belongs too
+ ///
+ public Dictionary Fields { get; private set; }
+
+ private void GetAllTypes(Collection types)
+ {
+ foreach (var type in types)
+ {
+ if (type.HasNestedTypes)
+ {
+ GetAllTypes(type.NestedTypes);
+ }
+
+ Types.Add(type);
+ }
+ }
+}
\ No newline at end of file