CJ-SPT d33f1f3c9b
Dnlib refactor
* First compiling build

* fix out path

* fix hollow

* Traditional loops in favor of linq for clarity

* Start refactor

* Refactor part 2

* Rename variable

* Better error reason handling

* Clean up enum

* Refactor part 3

* Use combo boxes in favor of updowns

* Update tooltips

* fix is nested tree view display

* Capitialization

* Refactor part ??

* remove unused methods

* Expanded IsNested Check

* TypeFilter class + Fix CLI bug

* Remove reflection, change IsDerived and IsNested checks

* Remove optional out for IsPublic

* Remove nullable from IsPublic

* fix logger not resetting color

* actually fix it...

* remove redundant if else on IsPublic check

* Add logging to indicate all types have been filtered out

* Default IsPublic to true

* remove duplicate method call

* Refactor logger to be on its own thread

* Multithread remapping and grouped logging for threads

* 5 more filters

* Finish migrating to the new system

* bug fixes

* Add empty string validation to text fields

* re-enable renamer

* restore renamer

* Multi threaded renaming, still broken

* Basis for method renaming

* More renamer work, might get a passing build now?

* Re-enable publicizer

* Rework logging

* re-enable mapping updates

* fix hollow

* Iterate over all types instead of just one to re-link fields

* Add reference list command

---------

Co-authored-by: clodan <clodan@clodan.com>
2024-06-26 14:45:54 -04:00

131 lines
4.0 KiB
C#

using CliFx;
using CliFx.Attributes;
using CliFx.Infrastructure;
using ReCodeIt.CrossCompiler;
using ReCodeIt.Utils;
using ReCodeItLib.Utils;
namespace ReCodeIt.Commands;
[Command("Build", Description = "(Compile Time Reflection) Build your project and get a dll output for the original assembly.")]
public class Build : ICommand
{
private ReCodeItCrossCompiler CrossCompiler { get; set; }
[CommandParameter(0, IsRequired = false, Description = "the location of your project file (ReCodeItProj.json). You don't need to provide a path if the last project you built is the one you want to target, or you are running this command from inside a directory where a project file exists.")]
public string ProjectJsonPath { get; init; }
public async ValueTask ExecuteAsync(IConsole console)
{
var isLocal = await UseLocalProject(console);
if (isLocal) { return; }
var isRemote = await UseRemoteProject(console);
if (isRemote) { return; }
await UseLastLoadedProject(console);
// Wait for log termination
Logger.Terminate();
while(Logger.IsRunning()) {}
}
private async Task<bool> UseLocalProject(IConsole console)
{
var jsonPath = Path.Combine(Directory.GetCurrentDirectory(), "ReCodeItProj.json");
if (File.Exists(jsonPath))
{
Logger.Log("Found a project file in the current directory, loading it", ConsoleColor.Yellow);
CrossCompiler = new();
DataProvider.LoadAppSettings();
DataProvider.IsCli = true;
ProjectManager.LoadProject(jsonPath);
await CrossCompiler.StartCrossCompile();
return true;
}
return false;
}
private async Task<bool> UseRemoteProject(IConsole console)
{
if (ProjectJsonPath is not null && ProjectJsonPath != string.Empty)
{
if (!File.Exists(ProjectJsonPath))
{
console.Output.WriteLine("The project file you provided does not exist");
return false;
}
CrossCompiler = new();
DataProvider.LoadAppSettings();
DataProvider.IsCli = true;
ProjectManager.LoadProject(ProjectJsonPath);
await CrossCompiler.StartCrossCompile();
return true;
}
return false;
}
private async Task<bool> UseLastLoadedProject(IConsole console)
{
if (RegistryHelper.GetRegistryValue<string>("LastLoadedProject") != null)
{
string currentDirectory = Directory.GetCurrentDirectory();
console.Output.WriteLine($"Project: {RegistryHelper.GetRegistryValue<string>("LastLoadedProject")}");
console.Output.WriteLine($"Working Dir: {currentDirectory}");
CrossCompiler = new();
DataProvider.LoadAppSettings();
DataProvider.IsCli = true;
ProjectManager.LoadProject(RegistryHelper.GetRegistryValue<string>("LastLoadedProject"), true);
if (!Validate(console)) { return false; }
await CrossCompiler.StartCrossCompile();
DataProvider.SaveAppSettings();
return true;
}
return false;
}
private bool Validate(IConsole console)
{
if (ProjectManager.ActiveProject == null)
{
console.Output.WriteLine("No project loaded, go create or load a project in the gui first");
return false;
}
if (ProjectManager.ActiveProject.RemapModels.Count == 0)
{
console.Output.WriteLine("No Remaps present, go to the gui and create some first");
return false;
}
if (ProjectManager.ActiveProject.ChangedTypes.Count == 0)
{
console.Output.WriteLine("There are no changed types, have you created and used a remapped reference? \nRun the command `buildRef` to generate a project reference");
return false;
}
return true;
}
}