From b9f8e34339bdaef64342630e6d9d5d785c945ced Mon Sep 17 00:00:00 2001
From: Cj <161484149+CJ-SPT@users.noreply.github.com>
Date: Thu, 20 Jun 2024 14:44:21 -0400
Subject: [PATCH] Refactor + comments
---
RecodeItLib/CrossCompiler/ProjectManager.cs | 102 ++++++++++++------
.../CrossCompiler/ReCodeItCrossCompiler.cs | 3 +-
2 files changed, 71 insertions(+), 34 deletions(-)
diff --git a/RecodeItLib/CrossCompiler/ProjectManager.cs b/RecodeItLib/CrossCompiler/ProjectManager.cs
index e21fab7..d3ff3ee 100644
--- a/RecodeItLib/CrossCompiler/ProjectManager.cs
+++ b/RecodeItLib/CrossCompiler/ProjectManager.cs
@@ -52,29 +52,71 @@ public static class ProjectManager
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
}
+ ///
+ /// Saves the provided project model to disk, used from the GUI
+ ///
+ ///
+ public static void SaveCrossCompilerProjectModel(CrossCompilerProjectModel model)
+ {
+ var path = Path.Combine(model.VisualStudioSolutionDirectoryPath, "ReCodeItProj.json");
+
+ JsonSerializerSettings settings = new()
+ {
+ Formatting = Formatting.Indented
+ };
+
+ var jsonText = JsonConvert.SerializeObject(model, settings);
+
+ 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);
+ }
+
+ ///
+ /// The "LoadProject" method only loads the project file from disk, used for initiating the GUI
+ ///
+ ///
+ ///
public static void LoadProject(string path, bool cli = false)
{
ActiveProject = LoadCrossCompilerProjModel(path, cli);
-
- CopyVisualStudioProject(ActiveProject);
-
- LoadProjectSourceFiles();
Logger.Log($"Found and Loaded ReCodeIt Project at {path}");
}
- public static void MoveOriginalReference()
+ ///
+ /// 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(ActiveProject.VisualStudioClonedDependencyPath, ConsoleColor.Red);
-
Logger.Log($"Placing original reference `{ActiveProject.OriginalAssemblyPath}` into cloned build directory `{outPath}`", ConsoleColor.Green);
File.Copy(ActiveProject.OriginalAssemblyPath, outPath, true);
}
- public static void CopyVisualStudioProject(CrossCompilerProjectModel proj)
+ ///
+ /// 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);
@@ -86,12 +128,14 @@ public static class ProjectManager
return;
}
- foreach (var file in solutionFiles)
+ // Make sure the project is clean
+ if (Path.Exists(proj.VisualStudioClonedSolutionPath))
{
- solutionFile = file;
+ Logger.Log("Cleaning old project files", ConsoleColor.Yellow);
+ Directory.Delete(proj.VisualStudioClonedSolutionDirectory, true);
}
- var solutionName = Path.GetFileNameWithoutExtension(solutionFile);
+ var solutionName = Path.GetFileNameWithoutExtension(solutionFiles.First());
var destination = Path.Combine(DataProvider.ReCodeItProjectsPath, solutionName);
proj.SolutionName = solutionName;
@@ -101,6 +145,12 @@ public static class ProjectManager
CopyProjectRecursive(solutionDirPath, destination);
}
+ ///
+ /// Recursively copies all children directories in the project
+ ///
+ ///
+ ///
+ ///
private static void CopyProjectRecursive(string sourceDirPath, string destinationDirPath)
{
DirectoryInfo sourceDir = new DirectoryInfo(sourceDirPath);
@@ -145,27 +195,12 @@ public static class ProjectManager
}
}
- public static void SaveCrossCompilerProjectModel(CrossCompilerProjectModel model)
- {
- var path = Path.Combine(model.VisualStudioSolutionDirectoryPath, "ReCodeItProj.json");
-
- JsonSerializerSettings settings = new()
- {
- Formatting = Formatting.Indented
- };
-
- var jsonText = JsonConvert.SerializeObject(model, settings);
-
- 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);
- }
-
+ ///
+ /// Loads the project model from disk
+ ///
+ ///
+ ///
+ ///
private static CrossCompilerProjectModel LoadCrossCompilerProjModel(string path, bool cli = false)
{
if (!File.Exists(path))
@@ -190,6 +225,9 @@ public static class ProjectManager
return model!;
}
+ ///
+ /// Gathers all the projects source files
+ ///
private static void LoadProjectSourceFiles()
{
var path = Path.Combine(
diff --git a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs
index 7d971e0..3ac2780 100644
--- a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs
+++ b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs
@@ -57,8 +57,7 @@ public class ReCodeItCrossCompiler
public void StartCrossCompile()
{
- ProjectManager.CopyVisualStudioProject(ActiveProject);
- ProjectManager.MoveOriginalReference();
+ ProjectManager.LoadProjectCC(ActiveProject);
AnalyzeSourceFiles();