Add CLI and build command

This commit is contained in:
Cj 2024-06-19 21:11:42 -04:00
parent 1d5558935b
commit d5c8796fb3
10 changed files with 170 additions and 25 deletions

View File

@ -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<string>("LastLoadedProject"));
if (RegistryHelper.GetRegistryValue<string>("LastLoadedProject") != null)
{
CrossCompiler = new();
ProjectManager.LoadProject(RegistryHelper.GetRegistryValue<string>("LastLoadedProject"), true);
CrossCompiler.StartCrossCompile();
return default;
}
return default;
}
}

11
ReCodeIt_CLI/Program.cs Normal file
View File

@ -0,0 +1,11 @@
// See https://aka.ms/new-console-template for more information
using CliFx;
public static class Program
{
public static async Task<int> Main() =>
await new CliApplicationBuilder()
.AddCommandsFromThisAssembly()
.Build()
.RunAsync();
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RecodeItLib\ReCodeItLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CliFx" Version="2.3.5" />
</ItemGroup>
</Project>

View File

@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCodeItGUI", "RecodeItGUI\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCodeItLib", "RecodeItLib\ReCodeItLib.csproj", "{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCodeItLib", "RecodeItLib\ReCodeItLib.csproj", "{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReCodeIt", "ReCodeIt_CLI\ReCodeIt.csproj", "{7DC1B062-C286-421B-B918-A56D5D7F2AE7}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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|x64.Build.0 = Release|Any CPU
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|x86.ActiveCfg = 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 {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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -142,7 +142,6 @@ partial class ReCodeItForm
tabPage5 = new TabPage(); tabPage5 = new TabPage();
groupBox4 = new GroupBox(); groupBox4 = new GroupBox();
groupBox5 = new GroupBox(); groupBox5 = new GroupBox();
CCBuildConfiguration = new TextBox();
CrossPatchRemapButton = new Button(); CrossPatchRemapButton = new Button();
CrossPatchRunButton = new Button(); CrossPatchRunButton = new Button();
label4 = new Label(); label4 = new Label();
@ -1442,28 +1441,18 @@ partial class ReCodeItForm
// //
// groupBox5 // groupBox5
// //
groupBox5.Controls.Add(CCBuildConfiguration);
groupBox5.Controls.Add(CrossPatchRemapButton); groupBox5.Controls.Add(CrossPatchRemapButton);
groupBox5.Controls.Add(CrossPatchRunButton); groupBox5.Controls.Add(CrossPatchRunButton);
groupBox5.Location = new Point(6, 304); groupBox5.Location = new Point(6, 304);
groupBox5.Name = "groupBox5"; groupBox5.Name = "groupBox5";
groupBox5.Size = new Size(631, 215); groupBox5.Size = new Size(631, 85);
groupBox5.TabIndex = 27; groupBox5.TabIndex = 27;
groupBox5.TabStop = false; groupBox5.TabStop = false;
groupBox5.Text = "Generation"; 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
// //
CrossPatchRemapButton.Location = new Point(6, 175); CrossPatchRemapButton.Location = new Point(6, 30);
CrossPatchRemapButton.Name = "CrossPatchRemapButton"; CrossPatchRemapButton.Name = "CrossPatchRemapButton";
CrossPatchRemapButton.Size = new Size(316, 34); CrossPatchRemapButton.Size = new Size(316, 34);
CrossPatchRemapButton.TabIndex = 21; CrossPatchRemapButton.TabIndex = 21;
@ -1473,7 +1462,7 @@ partial class ReCodeItForm
// //
// CrossPatchRunButton // CrossPatchRunButton
// //
CrossPatchRunButton.Location = new Point(328, 175); CrossPatchRunButton.Location = new Point(328, 30);
CrossPatchRunButton.Name = "CrossPatchRunButton"; CrossPatchRunButton.Name = "CrossPatchRunButton";
CrossPatchRunButton.Size = new Size(150, 34); CrossPatchRunButton.Size = new Size(150, 34);
CrossPatchRunButton.TabIndex = 24; CrossPatchRunButton.TabIndex = 24;
@ -1704,7 +1693,7 @@ partial class ReCodeItForm
Controls.Add(TabControlMain); Controls.Add(TabControlMain);
FormBorderStyle = FormBorderStyle.FixedSingle; FormBorderStyle = FormBorderStyle.FixedSingle;
Name = "ReCodeItForm"; Name = "ReCodeItForm";
Text = "ReCodeIt V0.1.0 - PRC0"; Text = "ReCodeIt V0.1.0 - RC0";
TabPageRemapper.ResumeLayout(false); TabPageRemapper.ResumeLayout(false);
groupBox1.ResumeLayout(false); groupBox1.ResumeLayout(false);
groupBox1.PerformLayout(); groupBox1.PerformLayout();
@ -1731,7 +1720,6 @@ partial class ReCodeItForm
groupBox4.ResumeLayout(false); groupBox4.ResumeLayout(false);
groupBox4.PerformLayout(); groupBox4.PerformLayout();
groupBox5.ResumeLayout(false); groupBox5.ResumeLayout(false);
groupBox5.PerformLayout();
groupBox3.ResumeLayout(false); groupBox3.ResumeLayout(false);
groupBox3.PerformLayout(); groupBox3.PerformLayout();
SettingsTab.ResumeLayout(false); SettingsTab.ResumeLayout(false);
@ -1884,7 +1872,6 @@ partial class ReCodeItForm
private Button CCLoadProjButton; private Button CCLoadProjButton;
private CheckBox CCAutoLoadLastProj; private CheckBox CCAutoLoadLastProj;
private GroupBox groupBox5; private GroupBox groupBox5;
private TextBox CCBuildConfiguration;
private LinkLabel GithubLinkLabel; private LinkLabel GithubLinkLabel;
private Button CCImportMappings; private Button CCImportMappings;
} }

View File

@ -1,5 +1,7 @@
using Microsoft.Win32;
using ReCodeIt.GUI; using ReCodeIt.GUI;
using ReCodeIt.Utils; using ReCodeIt.Utils;
using ReCodeItLib.Utils;
namespace ReCodeIt; namespace ReCodeIt;
@ -11,6 +13,21 @@ internal static class Program
[STAThread] [STAThread]
private static void Main() 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(); DataProvider.LoadAppSettings();
// To customize application configuration such as set high DPI settings or default font, see https://aka.ms/applicationconfiguration. // To customize application configuration such as set high DPI settings or default font, see https://aka.ms/applicationconfiguration.

View File

@ -1,7 +1,9 @@
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.Win32;
using Newtonsoft.Json; using Newtonsoft.Json;
using ReCodeIt.Models; using ReCodeIt.Models;
using ReCodeIt.Utils; using ReCodeIt.Utils;
using ReCodeItLib.Utils;
namespace ReCodeIt.CrossCompiler; namespace ReCodeIt.CrossCompiler;
@ -50,9 +52,9 @@ public static class ProjectManager
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow); 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); CopyVisualStudioProject(ActiveProject);
LoadVSProjectFromClone(); LoadVSProjectFromClone();
Logger.Log($"Found and Loaded ReCodeIt Project at {path}"); Logger.Log($"Found and Loaded ReCodeIt Project at {path}");
@ -141,12 +143,14 @@ public static class ProjectManager
File.WriteAllText(path, jsonText); File.WriteAllText(path, jsonText);
DataProvider.Settings.CrossCompiler.LastLoadedProject = path; DataProvider.Settings.CrossCompiler.LastLoadedProject = path;
RegistryHelper.SetRegistryValue("LastLoadedProject", path, RegistryValueKind.String);
DataProvider.SaveAppSettings(); DataProvider.SaveAppSettings();
Logger.Log($"Cross Compiler project json saved to {path}", ConsoleColor.Green); 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)) if (!File.Exists(path))
{ {
@ -157,7 +161,12 @@ public static class ProjectManager
var model = JsonConvert.DeserializeObject<CrossCompilerProjectModel>(jsonText); var model = JsonConvert.DeserializeObject<CrossCompilerProjectModel>(jsonText);
DataProvider.Settings.CrossCompiler.LastLoadedProject = path; if (!cli)
{
DataProvider.Settings.CrossCompiler.LastLoadedProject = path;
}
RegistryHelper.SetRegistryValue("LastLoadedProject", path, RegistryValueKind.String);
DataProvider.SaveAppSettings(); DataProvider.SaveAppSettings();
Logger.Log($"Loaded Cross Compiler Project: {model?.RemappedAssemblyPath}"); Logger.Log($"Loaded Cross Compiler Project: {model?.RemappedAssemblyPath}");

View File

@ -1,6 +1,7 @@
using Mono.Cecil; using Mono.Cecil;
using Newtonsoft.Json; using Newtonsoft.Json;
using ReCodeIt.Models; using ReCodeIt.Models;
using ReCodeItLib.Utils;
namespace ReCodeIt.Utils; namespace ReCodeIt.Utils;
@ -14,7 +15,12 @@ public static class DataProvider
} }
} }
public static readonly string DataPath = Path.Combine(AppContext.BaseDirectory, "Data"); /// <summary>
/// Is this running in the CLI?
/// </summary>
public static bool IsCli { get; set; } = false;
public static string DataPath => RegistryHelper.GetRegistryValue<string>("DataPath");
public static readonly string ReCodeItProjectsPath = Path.Combine(AppContext.BaseDirectory, "Projects"); public static readonly string ReCodeItProjectsPath = Path.Combine(AppContext.BaseDirectory, "Projects");
@ -55,7 +61,7 @@ public static class DataProvider
public static void SaveAppSettings() public static void SaveAppSettings()
{ {
var settingsPath = Path.Combine(AppContext.BaseDirectory, "Data", "Settings.jsonc"); var settingsPath = RegistryHelper.GetRegistryValue<string>("SettingsPath");
if (!File.Exists(settingsPath)) if (!File.Exists(settingsPath))
{ {

View File

@ -1,4 +1,6 @@
namespace ReCodeIt.Utils; using ReCodeItLib.Utils;
namespace ReCodeIt.Utils;
public static class Logger 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<string>("LogPath");
public static void ClearLog() public static void ClearLog()
{ {

View File

@ -0,0 +1,32 @@
using Microsoft.Win32;
namespace ReCodeItLib.Utils;
public static class RegistryHelper
{
/// <summary>
/// Sets a key in the registry, given its key, value, and kind
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="kind"></param>
public static void SetRegistryValue(string key, string value, RegistryValueKind kind)
{
var regKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\ReCodeIt");
regKey.SetValue(key, value, kind);
}
/// <summary>
/// Gets a key from the registry, given its key and type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public static T? GetRegistryValue<T>(string key)
{
var regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\ReCodeIt");
return (T)regKey.GetValue(key);
}
}