From 5084db4179adbed89fde4dffc5cdbfd411f97262 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:48:41 -0400 Subject: [PATCH] Remove obsolete code --- RecodeItLib/CrossCompiler/ProjectManager.cs | 104 ------------------ .../CrossCompiler/ReCodeItCrossCompiler.cs | 89 --------------- 2 files changed, 193 deletions(-) diff --git a/RecodeItLib/CrossCompiler/ProjectManager.cs b/RecodeItLib/CrossCompiler/ProjectManager.cs index 0259de1..0881c03 100644 --- a/RecodeItLib/CrossCompiler/ProjectManager.cs +++ b/RecodeItLib/CrossCompiler/ProjectManager.cs @@ -40,9 +40,6 @@ public static class ProjectManager RemapModels = [] }; - // Now copy over the visual studio project - CopyVisualStudioProject(ActiveProject); - // Now save the project json inside the original solution directory SaveCrossCompilerProjectModel(ActiveProject); @@ -88,107 +85,6 @@ public static class ProjectManager Logger.Log($"Found and Loaded ReCodeIt Project at {path}"); } - /// - /// The "LoadProjectCC" method loads all the project data and loads source files - /// - /// - public static void LoadProjectCC(CrossCompilerProjectModel proj) - { - CopyVisualStudioProject(ActiveProject); - MoveOriginalReference(); - LoadProjectSourceFiles(); - } - - /// - /// Replaces the original reference back into the cloned build directory - /// - private static void MoveOriginalReference() - { - var outPath = Path.Combine( - ActiveProject.VisualStudioClonedDependencyPath, - ActiveProject.OriginalAssemblyDllName); - - Logger.Log($"Placing original reference `{ActiveProject.OriginalAssemblyPath}` into cloned build directory `{outPath}`", ConsoleColor.Green); - File.Copy(ActiveProject.OriginalAssemblyPath, outPath, true); - } - - /// - /// Copies the visual studio project to a temporary location for changes - /// - /// - private static void CopyVisualStudioProject(CrossCompilerProjectModel proj) - { - var solutionDirPath = proj.VisualStudioSolutionDirectoryPath; - var solutionFiles = Directory.GetFiles(solutionDirPath, "*.sln", SearchOption.AllDirectories); - var solutionFile = string.Empty; - - if (solutionFiles.Length > 1) - { - Logger.Log("ERROR More than one solution in a directory is not supported, Why tho?", ConsoleColor.Red); - return; - } - - var solutionName = Path.GetFileNameWithoutExtension(solutionFiles.First()); - var destination = Path.Combine(DataProvider.ReCodeItProjectsPath, solutionName); - - proj.SolutionName = solutionName; - - Logger.Log($"Copying solution: {solutionName} to {destination}", ConsoleColor.Yellow); - - CopyProjectRecursive(solutionDirPath, destination); - } - - /// - /// Recursively copies all children directories in the project - /// - /// - /// - /// - private static void CopyProjectRecursive(string sourceDirPath, string destinationDirPath) - { - DirectoryInfo sourceDir = new DirectoryInfo(sourceDirPath); - - if (!sourceDir.Exists) - { - throw new DirectoryNotFoundException( - "Solution directory does not exist or could not be found: " - + sourceDirPath); - } - - DirectoryInfo[] dirs = sourceDir.GetDirectories(); - - // If the destination directory doesn't exist, create it. - Directory.CreateDirectory(destinationDirPath); - - // Get the files in the directory and copy them to the new location. - FileInfo[] files = sourceDir.GetFiles(); - - foreach (FileInfo file in files) - { - string tempPath = Path.Combine(destinationDirPath, file.Name); - - if (File.Exists(tempPath)) { File.Delete(tempPath); } - - file.CopyTo(tempPath, true); - } - - // We dont want git and vs directories they are often locked leading to problems, we also - // dont want the RecodeIt build project if it exists - List copyIgnoreDirectories = - [ - ".vs", - ".git", - ]; - - foreach (DirectoryInfo subdir in dirs) - { - if (copyIgnoreDirectories.Contains(subdir.Name)) { continue; } - - string tempPath = Path.Combine(destinationDirPath, subdir.Name); - CopyProjectRecursive(subdir.FullName, tempPath); - } - } - /// /// Loads the project model from disk /// diff --git a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs index 5c4aae5..1739f9e 100644 --- a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs +++ b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs @@ -59,8 +59,6 @@ public class ReCodeItCrossCompiler public async Task StartCrossCompile() { - ProjectManager.LoadProjectCC(ActiveProject); - SW.Reset(); SW.Start(); @@ -169,91 +167,4 @@ public class ReCodeItCrossCompiler return newSyntax; } - - /// - /// Starts the build process for the active project. - /// - private void StartBuild() - { - var arguements = $"build {ActiveProject.VisualStudioClonedSolutionPath} " + - $"/p:Configuration=Debug " + - $"/p:Platform=\"Any CPU\""; - - var path = ActiveProject.VisualStudioClonedSolutionDirectory; - - // clean the project first - ExecuteDotnetCommand("clean", path); - - // Restore packages - ExecuteDotnetCommand("restore", path); - - // Then build the project - ExecuteDotnetCommand(arguements, path); - } - - private static void ExecuteDotnetCommand(string arguments, string workingDirectory) - { - ProcessStartInfo startInfo = new ProcessStartInfo - { - FileName = "dotnet", - Arguments = arguments, - WorkingDirectory = workingDirectory, - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true - }; - - using (Process process = new Process()) - { - process.StartInfo = startInfo; - - process.OutputDataReceived += (sender, e) => Logger.Log(e.Data); - - process.Start(); - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); - process.WaitForExit(); - - int exitCode = process.ExitCode; - Logger.Log($"dotnet {arguments} exited with code {exitCode}"); - } - } - - private void MoveResult() - { - 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); - //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