diff --git a/ReCodeIt_CLI/Commands/BuildCommand.cs b/ReCodeIt_CLI/Commands/BuildCommand.cs new file mode 100644 index 0000000..b6063ab --- /dev/null +++ b/ReCodeIt_CLI/Commands/BuildCommand.cs @@ -0,0 +1,41 @@ +using CliFx; +using CliFx.Attributes; +using CliFx.Infrastructure; +using ReCodeIt.CrossCompiler; +using ReCodeItLib.Utils; + +namespace ReCodeIt.Commands; + +[Command("Build", Description = "Build your project and get a dll output for the original assembly. You dont need to provide a path if the last project you built is the one you want to target")] +public class BuildCommand : ICommand +{ + private ReCodeItCrossCompiler CrossCompiler { get; set; } + + [CommandParameter(0, IsRequired = false, Description = "the location of your project file")] + public string ProjectJsonPath { get; init; } + + public ValueTask ExecuteAsync(IConsole console) + { + if (ProjectJsonPath is not null && ProjectJsonPath != string.Empty) + { + CrossCompiler = new(); + ProjectManager.LoadProject(ProjectJsonPath); + CrossCompiler.StartCrossCompile(); + + return default; + } + + console.Output.WriteLine(RegistryHelper.GetRegistryValue("LastLoadedProject")); + + if (RegistryHelper.GetRegistryValue("LastLoadedProject") != null) + { + CrossCompiler = new(); + ProjectManager.LoadProject(RegistryHelper.GetRegistryValue("LastLoadedProject"), true); + CrossCompiler.StartCrossCompile(); + + return default; + } + + return default; + } +} \ No newline at end of file diff --git a/ReCodeIt_CLI/Program.cs b/ReCodeIt_CLI/Program.cs new file mode 100644 index 0000000..d61197d --- /dev/null +++ b/ReCodeIt_CLI/Program.cs @@ -0,0 +1,11 @@ +// See https://aka.ms/new-console-template for more information +using CliFx; + +public static class Program +{ + public static async Task Main() => + await new CliApplicationBuilder() + .AddCommandsFromThisAssembly() + .Build() + .RunAsync(); +} \ No newline at end of file diff --git a/ReCodeIt_CLI/ReCodeIt.csproj b/ReCodeIt_CLI/ReCodeIt.csproj new file mode 100644 index 0000000..8785096 --- /dev/null +++ b/ReCodeIt_CLI/ReCodeIt.csproj @@ -0,0 +1,18 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + diff --git a/RecodeIt.sln b/RecodeIt.sln index 958e4f3..b8cd12e 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}") = "ReCodeIt", "ReCodeIt_CLI\ReCodeIt.csproj", "{7DC1B062-C286-421B-B918-A56D5D7F2AE7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,26 @@ Global {FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|x64.Build.0 = Release|Any CPU {FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|x86.ActiveCfg = Release|Any CPU {FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|x86.Build.0 = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|ARM.ActiveCfg = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|ARM.Build.0 = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|ARM64.Build.0 = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|x64.ActiveCfg = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|x64.Build.0 = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|x86.ActiveCfg = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Debug|x86.Build.0 = Debug|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|Any CPU.Build.0 = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|ARM.ActiveCfg = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|ARM.Build.0 = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|ARM64.ActiveCfg = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|ARM64.Build.0 = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|x64.ActiveCfg = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|x64.Build.0 = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|x86.ActiveCfg = Release|Any CPU + {7DC1B062-C286-421B-B918-A56D5D7F2AE7}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RecodeItGUI/GUI/Main.Designer.cs b/RecodeItGUI/GUI/Main.Designer.cs index a47f0bb..9ad3492 100644 --- a/RecodeItGUI/GUI/Main.Designer.cs +++ b/RecodeItGUI/GUI/Main.Designer.cs @@ -142,7 +142,6 @@ partial class ReCodeItForm tabPage5 = new TabPage(); groupBox4 = new GroupBox(); groupBox5 = new GroupBox(); - CCBuildConfiguration = new TextBox(); CrossPatchRemapButton = new Button(); CrossPatchRunButton = new Button(); label4 = new Label(); @@ -1442,28 +1441,18 @@ partial class ReCodeItForm // // groupBox5 // - groupBox5.Controls.Add(CCBuildConfiguration); groupBox5.Controls.Add(CrossPatchRemapButton); groupBox5.Controls.Add(CrossPatchRunButton); groupBox5.Location = new Point(6, 304); groupBox5.Name = "groupBox5"; - groupBox5.Size = new Size(631, 215); + groupBox5.Size = new Size(631, 85); groupBox5.TabIndex = 27; groupBox5.TabStop = false; groupBox5.Text = "Generation"; // - // CCBuildConfiguration - // - CCBuildConfiguration.Location = new Point(6, 30); - CCBuildConfiguration.Name = "CCBuildConfiguration"; - CCBuildConfiguration.PlaceholderText = "Build Configuration"; - CCBuildConfiguration.Size = new Size(150, 31); - CCBuildConfiguration.TabIndex = 25; - CCBuildConfiguration.Text = "Debug"; - // // CrossPatchRemapButton // - CrossPatchRemapButton.Location = new Point(6, 175); + CrossPatchRemapButton.Location = new Point(6, 30); CrossPatchRemapButton.Name = "CrossPatchRemapButton"; CrossPatchRemapButton.Size = new Size(316, 34); CrossPatchRemapButton.TabIndex = 21; @@ -1473,7 +1462,7 @@ partial class ReCodeItForm // // CrossPatchRunButton // - CrossPatchRunButton.Location = new Point(328, 175); + CrossPatchRunButton.Location = new Point(328, 30); CrossPatchRunButton.Name = "CrossPatchRunButton"; CrossPatchRunButton.Size = new Size(150, 34); CrossPatchRunButton.TabIndex = 24; @@ -1704,7 +1693,7 @@ partial class ReCodeItForm Controls.Add(TabControlMain); FormBorderStyle = FormBorderStyle.FixedSingle; Name = "ReCodeItForm"; - Text = "ReCodeIt V0.1.0 - PRC0"; + Text = "ReCodeIt V0.1.0 - RC0"; TabPageRemapper.ResumeLayout(false); groupBox1.ResumeLayout(false); groupBox1.PerformLayout(); @@ -1731,7 +1720,6 @@ partial class ReCodeItForm groupBox4.ResumeLayout(false); groupBox4.PerformLayout(); groupBox5.ResumeLayout(false); - groupBox5.PerformLayout(); groupBox3.ResumeLayout(false); groupBox3.PerformLayout(); SettingsTab.ResumeLayout(false); @@ -1884,7 +1872,6 @@ partial class ReCodeItForm private Button CCLoadProjButton; private CheckBox CCAutoLoadLastProj; private GroupBox groupBox5; - private TextBox CCBuildConfiguration; private LinkLabel GithubLinkLabel; private Button CCImportMappings; } diff --git a/RecodeItGUI/Program.cs b/RecodeItGUI/Program.cs index 855c17a..a077f3f 100644 --- a/RecodeItGUI/Program.cs +++ b/RecodeItGUI/Program.cs @@ -1,5 +1,7 @@ +using Microsoft.Win32; using ReCodeIt.GUI; using ReCodeIt.Utils; +using ReCodeItLib.Utils; namespace ReCodeIt; @@ -11,6 +13,21 @@ internal static class Program [STAThread] private static void Main() { + RegistryHelper.SetRegistryValue( + "DataPath", + DataProvider.DataPath, + RegistryValueKind.String); + + RegistryHelper.SetRegistryValue( + "SettingsPath", + Path.Combine(DataProvider.DataPath, "Settings.jsonc"), + RegistryValueKind.String); + + RegistryHelper.SetRegistryValue( + "LogPath", + Path.Combine(DataProvider.DataPath, "Log.log"), + RegistryValueKind.String); + DataProvider.LoadAppSettings(); // To customize application configuration such as set high DPI settings or default font, see https://aka.ms/applicationconfiguration. diff --git a/RecodeItLib/CrossCompiler/ProjectManager.cs b/RecodeItLib/CrossCompiler/ProjectManager.cs index c9c151c..a209192 100644 --- a/RecodeItLib/CrossCompiler/ProjectManager.cs +++ b/RecodeItLib/CrossCompiler/ProjectManager.cs @@ -1,7 +1,9 @@ using Microsoft.CodeAnalysis; +using Microsoft.Win32; using Newtonsoft.Json; using ReCodeIt.Models; using ReCodeIt.Utils; +using ReCodeItLib.Utils; namespace ReCodeIt.CrossCompiler; @@ -50,9 +52,9 @@ public static class ProjectManager Logger.Log("-----------------------------------------------", ConsoleColor.Yellow); } - public static void LoadProject(string path) + public static void LoadProject(string path, bool cli = false) { - ActiveProject = LoadCrossCompilerProjModel(path); + ActiveProject = LoadCrossCompilerProjModel(path, cli); CopyVisualStudioProject(ActiveProject); LoadVSProjectFromClone(); Logger.Log($"Found and Loaded ReCodeIt Project at {path}"); @@ -141,12 +143,14 @@ public static class ProjectManager File.WriteAllText(path, jsonText); DataProvider.Settings.CrossCompiler.LastLoadedProject = path; + + RegistryHelper.SetRegistryValue("LastLoadedProject", path, RegistryValueKind.String); DataProvider.SaveAppSettings(); Logger.Log($"Cross Compiler project json saved to {path}", ConsoleColor.Green); } - private static CrossCompilerProjectModel LoadCrossCompilerProjModel(string path) + private static CrossCompilerProjectModel LoadCrossCompilerProjModel(string path, bool cli = false) { if (!File.Exists(path)) { @@ -157,7 +161,12 @@ public static class ProjectManager var model = JsonConvert.DeserializeObject(jsonText); - DataProvider.Settings.CrossCompiler.LastLoadedProject = path; + if (!cli) + { + DataProvider.Settings.CrossCompiler.LastLoadedProject = path; + } + + RegistryHelper.SetRegistryValue("LastLoadedProject", path, RegistryValueKind.String); DataProvider.SaveAppSettings(); Logger.Log($"Loaded Cross Compiler Project: {model?.RemappedAssemblyPath}"); diff --git a/RecodeItLib/Utils/DataProvider.cs b/RecodeItLib/Utils/DataProvider.cs index ab436b2..63c452b 100644 --- a/RecodeItLib/Utils/DataProvider.cs +++ b/RecodeItLib/Utils/DataProvider.cs @@ -1,6 +1,7 @@ using Mono.Cecil; using Newtonsoft.Json; using ReCodeIt.Models; +using ReCodeItLib.Utils; namespace ReCodeIt.Utils; @@ -14,7 +15,12 @@ public static class DataProvider } } - public static readonly string DataPath = Path.Combine(AppContext.BaseDirectory, "Data"); + /// + /// Is this running in the CLI? + /// + public static bool IsCli { get; set; } = false; + + public static string DataPath => RegistryHelper.GetRegistryValue("DataPath"); public static readonly string ReCodeItProjectsPath = Path.Combine(AppContext.BaseDirectory, "Projects"); @@ -55,7 +61,7 @@ public static class DataProvider public static void SaveAppSettings() { - var settingsPath = Path.Combine(AppContext.BaseDirectory, "Data", "Settings.jsonc"); + var settingsPath = RegistryHelper.GetRegistryValue("SettingsPath"); if (!File.Exists(settingsPath)) { diff --git a/RecodeItLib/Utils/Logger.cs b/RecodeItLib/Utils/Logger.cs index c5112c5..d81c16f 100644 --- a/RecodeItLib/Utils/Logger.cs +++ b/RecodeItLib/Utils/Logger.cs @@ -1,4 +1,6 @@ -namespace ReCodeIt.Utils; +using ReCodeItLib.Utils; + +namespace ReCodeIt.Utils; public static class Logger { @@ -11,7 +13,7 @@ public static class Logger } } - private static string _logPath = Path.Combine(AppContext.BaseDirectory, "Data", "Log.log"); + private static string _logPath => RegistryHelper.GetRegistryValue("LogPath"); public static void ClearLog() { diff --git a/RecodeItLib/Utils/RegistryHelper.cs b/RecodeItLib/Utils/RegistryHelper.cs new file mode 100644 index 0000000..294a307 --- /dev/null +++ b/RecodeItLib/Utils/RegistryHelper.cs @@ -0,0 +1,32 @@ +using Microsoft.Win32; + +namespace ReCodeItLib.Utils; + +public static class RegistryHelper +{ + /// + /// Sets a key in the registry, given its key, value, and kind + /// + /// + /// + /// + public static void SetRegistryValue(string key, string value, RegistryValueKind kind) + { + var regKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\ReCodeIt"); + + regKey.SetValue(key, value, kind); + } + + /// + /// Gets a key from the registry, given its key and type + /// + /// + /// + /// + public static T? GetRegistryValue(string key) + { + var regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\ReCodeIt"); + + return (T)regKey.GetValue(key); + } +} \ No newline at end of file