From 88e524c974dfbb861d1acec5091a97960d7ca5d8 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:03:17 -0400 Subject: [PATCH] Proper build directory handling --- RecodeItLib/CrossCompiler/ProjectManager.cs | 7 ---- .../CrossCompiler/ReCodeItCrossCompiler.cs | 39 +++++++++++++++---- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/RecodeItLib/CrossCompiler/ProjectManager.cs b/RecodeItLib/CrossCompiler/ProjectManager.cs index d3ff3ee..cbc5218 100644 --- a/RecodeItLib/CrossCompiler/ProjectManager.cs +++ b/RecodeItLib/CrossCompiler/ProjectManager.cs @@ -128,13 +128,6 @@ public static class ProjectManager return; } - // Make sure the project is clean - if (Path.Exists(proj.VisualStudioClonedSolutionPath)) - { - Logger.Log("Cleaning old project files", ConsoleColor.Yellow); - Directory.Delete(proj.VisualStudioClonedSolutionDirectory, true); - } - var solutionName = Path.GetFileNameWithoutExtension(solutionFiles.First()); var destination = Path.Combine(DataProvider.ReCodeItProjectsPath, solutionName); diff --git a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs index 3ac2780..f47bbf1 100644 --- a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs +++ b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs @@ -153,13 +153,38 @@ public class ReCodeItCrossCompiler private void MoveResult() { - Logger.Log("-----------------------------------------------", ConsoleColor.Green); + var builtDll = Directory + .GetFiles(ActiveProject.VisualStudioClonedSolutionDirectory, "*.dll", SearchOption.AllDirectories) + .FirstOrDefault(file => file.Contains(ActiveProject.ProjectDllName)); + + if (builtDll == null) + { + Logger.Log($"ERROR: No {ActiveProject.ProjectDllName} found at path {ActiveProject.VisualStudioClonedSolutionDirectory}, build failed.", ConsoleColor.Red); + CleanUp(); + return; + } + + var dest = Path.Combine(ActiveProject.BuildDirectory, ActiveProject.ProjectDllName); + + // Create it if it doesnt exist + if (!Directory.Exists(ActiveProject.BuildDirectory)) + { + Directory.CreateDirectory(ActiveProject.BuildDirectory); + } + + File.Copy(builtDll, dest, true); + + Logger.Log($"Copying {ActiveProject.ProjectDllName} to {dest}", ConsoleColor.Yellow); Logger.Log($"Successfully Cross Compiled Project {ActiveProject.SolutionName}", ConsoleColor.Green); - Logger.Log($"Reversed {_identifiersChanged} Remaps", ConsoleColor.Green); - Logger.Log($"Original assembly path: {ActiveProject.OriginalAssemblyPath}", ConsoleColor.Green); - Logger.Log($"Original assembly hash: {ActiveProject.OriginalAssemblyHash}", ConsoleColor.Green); - Logger.Log($"Final build directory: {ActiveProject.BuildDirectory}", ConsoleColor.Green); - //Logger.Log($"Original patched assembly hash: {ActiveProject.RemappedAssemblyHash}", ConsoleColor.Green); - Logger.Log("-----------------------------------------------", ConsoleColor.Green); + CleanUp(); + } + + private void CleanUp() + { + if (Path.Exists(ActiveProject.VisualStudioClonedSolutionDirectory)) + { + Logger.Log("Cleaning up cloned project files", ConsoleColor.Yellow); + Directory.Delete(ActiveProject.VisualStudioClonedSolutionDirectory, true); + } } } \ No newline at end of file