From 799971ca7a739d566c62a4822330d557cd1266ce Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 11 Aug 2024 14:06:02 -0600 Subject: [PATCH] Fixed renaming (creating new web) projects to include a few more files. fixes #1441 --- .../Managers/ProjectCreationHelper.cs | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/FRBDK/Glue/NpcWpfLib/Managers/ProjectCreationHelper.cs b/FRBDK/Glue/NpcWpfLib/Managers/ProjectCreationHelper.cs index 35c6019d4..5afa4f021 100644 --- a/FRBDK/Glue/NpcWpfLib/Managers/ProjectCreationHelper.cs +++ b/FRBDK/Glue/NpcWpfLib/Managers/ProjectCreationHelper.cs @@ -200,8 +200,7 @@ public static void RenameProject(string newProjectName, string oldProjectName, s newNamespace = newNamespace ?? newProjectName; if(oldProjectName != newNamespace) { - UpdateNamespaces(projectRootDirectory, oldProjectName, - newNamespace); + UpdateNamespaces(projectRootDirectory, oldProjectName, newNamespace); } } @@ -431,6 +430,9 @@ private static void RenameFiles(string unpackDirectory, string stringToReplace, filesToReplace.AddRange(FileManager.GetAllFilesInDirectory( unpackDirectory, "pfx")); + filesToReplace.AddRange(FileManager.GetAllFilesInDirectory( + unpackDirectory, "mgcb")); + foreach (string fileName in filesToReplace) { @@ -619,6 +621,10 @@ private static void UpdateNamespaces(string unpackDirectory, string stringToRepl string newProjectReference = $@""; contents = contents.Replace(originalProjectReference, newProjectReference); + string originalMgcb = $@""; + string newMgcb = $@""; + contents = contents.Replace(originalMgcb, newMgcb); + System.IO.File.WriteAllText(fileName, contents, Encoding.UTF8); } @@ -700,8 +706,38 @@ private static void UpdateNamespaces(string unpackDirectory, string stringToRepl contents = contents.Replace(whatToSearchFor, replacement); + if(contents.Contains($"{stringToReplace}")) + { + whatToSearchFor = $"{stringToReplace}"; + replacement = $"{stringToReplaceWith}"; + + contents = contents.Replace(whatToSearchFor, replacement); + } + + FileManager.SaveText(contents, fileName); + } + #endregion + + #region launchSettings.json + + filesToFix.Clear(); + filesToFix.AddRange(FileManager.GetAllFilesInDirectory(unpackDirectory, "json")); + foreach(var fileName in filesToFix) + { + if (fileName.ToLowerInvariant().EndsWith("launchsettings.json") == false) + { + continue; + } + + string contents = FileManager.FromFileText(fileName); + string whatToSearchFor = "\"" + stringToReplace + "\": {"; + string replacement = "\"" + stringToReplaceWith + "\": {"; + + contents = contents.Replace(whatToSearchFor, replacement); + FileManager.SaveText(contents, fileName); } + #endregion }