diff --git a/FRBDK/Glue/Glue/VSHelpers/VSSolution.cs b/FRBDK/Glue/Glue/VSHelpers/VSSolution.cs index 7d9de07dc..38e83a978 100644 --- a/FRBDK/Glue/Glue/VSHelpers/VSSolution.cs +++ b/FRBDK/Glue/Glue/VSHelpers/VSSolution.cs @@ -23,6 +23,38 @@ public string FullFileName set; } + public static bool RemoveProjectReference(FilePath solution, string project, out string output, out string error) + { + output = string.Empty; + error = string.Empty; + + if(solution.Exists()) + { + var contents = System.IO.File.ReadAllText(solution.FullPath); + + if(contents?.Contains(project) == true) + { + var indexOfProjectReference = contents.IndexOf(project); + const string startOfTextToRemove = "Project(\""; + const string endOfTextToRemove = "EndProject"; + + var indexOfStart = contents.LastIndexOf(startOfTextToRemove, indexOfProjectReference); + var indexOfEnd = contents.IndexOf(endOfTextToRemove, indexOfProjectReference + project.Length); + + if(indexOfStart > -1 && indexOfEnd > -1) + { + var endWithLenth = indexOfEnd + endOfTextToRemove.Length; + // Remove between indexOfStart and indexOfEnd + contents = contents.Remove(indexOfStart, endWithLenth - indexOfStart); + + System.IO.File.WriteAllText(solution.FullPath, contents); + return true; + } + } + } + return false; + } + public static bool AddExistingProjectWithDotNet(FilePath solution, FilePath project, out string output, out string error) { output = null; diff --git a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/AssetTypeInfoManager.cs b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/AssetTypeInfoManager.cs index 3f8fac7b7..48cea804e 100644 --- a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/AssetTypeInfoManager.cs +++ b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/AssetTypeInfoManager.cs @@ -14,6 +14,7 @@ using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; using static FlatRedBall.Glue.SaveClasses.GlueProjectSave; using FlatRedBall.Glue.Parsing; +using Gum.DataTypes.Variables; namespace GumPlugin.Managers { @@ -770,14 +771,19 @@ public void UpdateAtiForElement(AssetTypeInfo newAti, ElementSave element) variableName = "Current" + variableName; } - var hasAlreadyBeenAdded = newAti.VariableDefinitions.Any(item => item.Name == variableName); + var existing = newAti.VariableDefinitions.FirstOrDefault(item => item.Name == variableName); + var hasAlreadyBeenAdded = existing != null; if (!hasAlreadyBeenAdded) { var variableDefinition = new VariableDefinition(); variableDefinition.Category = variable.Category; - variableDefinition.DefaultValue = variable.Value?.ToString(); + + // We should bubble up the recursive value so that it can show here: + //variableDefinition.DefaultValue = variable.Value?.ToString(); + variableDefinition.DefaultValue = state.GetValueRecursive(variableName)?.ToString(); + variableDefinition.Name = variableName; // gum variables can have spaces, but Glue variables can't variableDefinition.Type = QualifyGumVariableType(variable, element); @@ -787,6 +793,11 @@ public void UpdateAtiForElement(AssetTypeInfo newAti, ElementSave element) newAti.VariableDefinitions.Add(variableDefinition); } + else + { + // This could be different per type so let's do this: + existing.DefaultValue = state.GetValueRecursive(variableName)?.ToString(); + } } } } diff --git a/FRBDK/Glue/OfficialPlugins/FrbSourcePlugin/Managers/AddSourceManager.cs b/FRBDK/Glue/OfficialPlugins/FrbSourcePlugin/Managers/AddSourceManager.cs index 2ab991ad9..92373f0a4 100644 --- a/FRBDK/Glue/OfficialPlugins/FrbSourcePlugin/Managers/AddSourceManager.cs +++ b/FRBDK/Glue/OfficialPlugins/FrbSourcePlugin/Managers/AddSourceManager.cs @@ -175,7 +175,8 @@ private static async Task LinkToSourceInternal(string frbRootFolder, string gumR { await TaskManager.Self.AddAsync(() => { - var projectReferences = GetProjectReferencesForCurrentProject(); + var projectReferences = GetNecessaryProjectReferencesForCurrentProject(); + var necessaryReferencesStripped = projectReferences.Select(item => FileManager.RemovePath(item.RelativeProjectFilePath)).ToArray(); string outerError = null; string innerError; @@ -211,12 +212,34 @@ await TaskManager.Self.AddAsync(() => if (!string.IsNullOrEmpty(frbRootFolder) && !string.IsNullOrEmpty(gumRootFolder)) { + //Update project references + var slnFilePath = GlueState.Self.CurrentSlnFileName; + var sln = VSSolution.FromFile(slnFilePath); + var referencedProjects = sln.ReferencedProjects; - //Update project references - var sln = VSSolution.FromFile(GlueState.Self.CurrentSlnFileName); + List slnProjectReferencesToRemove = new List(); + // remove any old references: + foreach(var existingReference in referencedProjects) + { + var strippedExisting = FileManager.RemovePath(existingReference); + + var willBeReplaced = necessaryReferencesStripped.Contains(strippedExisting); + + if(willBeReplaced) + { + slnProjectReferencesToRemove.Add(existingReference); + } + } + + foreach(var referenceToRemove in slnProjectReferencesToRemove) + { + VSSolution.RemoveProjectReference(slnFilePath, referenceToRemove, out string _, out string _); + } - var referencedProject = sln.ReferencedProjects; + // references may have been removed so re-load it: + sln = VSSolution.FromFile(slnFilePath); + referencedProjects = sln.ReferencedProjects; var proj = GlueState.Self.CurrentMainProject; @@ -224,18 +247,18 @@ await TaskManager.Self.AddAsync(() => foreach (var projectReference in projectReferences) { - AddProjectReference(sln, referencedProject, proj, addGeneralResponse, projectReference, frbRootFolder, gumRootFolder); + AddProjectReference(sln, referencedProjects, proj, addGeneralResponse, projectReference, frbRootFolder, gumRootFolder); } var isFNA = GlueState.Self.CurrentMainProject is FnaDesktopProject; if (includeGumSkia) { - AddProjectReference(sln, referencedProject, proj, addGeneralResponse, isFNA ? GumSkiaFNA : GumSkia, frbRootFolder, gumRootFolder); + AddProjectReference(sln, referencedProjects, proj, addGeneralResponse, isFNA ? GumSkiaFNA : GumSkia, frbRootFolder, gumRootFolder); } if (isFNA) { - AddProjectReference(sln, referencedProject, proj, addGeneralResponse, FNA, frbRootFolder, gumRootFolder); + AddProjectReference(sln, referencedProjects, proj, addGeneralResponse, FNA, frbRootFolder, gumRootFolder); } if (addGeneralResponse.Succeeded) @@ -270,7 +293,7 @@ await TaskManager.Self.AddAsync(() => }, "Linking game to FRB Source"); } - private static List GetProjectReferencesForCurrentProject() + private static List GetNecessaryProjectReferencesForCurrentProject() { if (GlueState.Self.CurrentMainProject.DotNetVersion.Major >= 6) { // When we support Android/iOS .NET 6, we need to handle those here: @@ -345,7 +368,7 @@ private static bool ValidateSourceGum(string path, List projec return true; } - private static void AddProjectReference(VSSolution sln, List referencedProject, VisualStudioProject proj, + private static void AddProjectReference(VSSolution sln, List existingProjectReferences, VisualStudioProject proj, GeneralResponse addGeneralResponse, ProjectReference reference, string frbRootFolder, string gumRootFolder ) @@ -360,7 +383,7 @@ private static void AddProjectReference(VSSolution sln, List referencedP if (extension == "csproj") { - if (!AddProject(referencedProject, sln.FullFileName, fullPath)) + if (!AddProject(existingProjectReferences, sln.FullFileName, fullPath)) { addGeneralResponse.Succeeded = false; addGeneralResponse.Message = $"Failed to add {fullPath}"; @@ -370,7 +393,7 @@ private static void AddProjectReference(VSSolution sln, List referencedP } else if (extension == "shproj") { - if (!AddSharedProject(referencedProject, sln.FullFileName, fullPath, reference.ProjectTypeId, reference.ProjectId, fullPath.NoPathNoExtension)) + if (!AddSharedProject(existingProjectReferences, sln.FullFileName, fullPath, reference.ProjectTypeId, reference.ProjectId, fullPath.NoPathNoExtension)) { addGeneralResponse.Succeeded = false; addGeneralResponse.Message = $"Failed to add {fullPath}";