diff --git a/Engines/FlatRedBallXNA/FlatRedBall/IO/FilePath.cs b/Engines/FlatRedBallXNA/FlatRedBall/IO/FilePath.cs index be9d37fc0..3de5ee224 100644 --- a/Engines/FlatRedBallXNA/FlatRedBall/IO/FilePath.cs +++ b/Engines/FlatRedBallXNA/FlatRedBall/IO/FilePath.cs @@ -87,6 +87,10 @@ public string FullPath } string standardizedCache; + /// + /// Returns the file with all slashes as forward slashes, and with the relative directory prepended if the file is relative, and lower-case. Use + /// StandardizedCaseSensitive to preserve case. + /// public string Standardized { get diff --git a/Engines/FlatRedBallXNA/FlatRedBall/Utilities/StringFunctions.cs b/Engines/FlatRedBallXNA/FlatRedBall/Utilities/StringFunctions.cs index bf905ac6b..3c1c20aaf 100644 --- a/Engines/FlatRedBallXNA/FlatRedBall/Utilities/StringFunctions.cs +++ b/Engines/FlatRedBallXNA/FlatRedBall/Utilities/StringFunctions.cs @@ -896,20 +896,20 @@ public static void RemoveDuplicates(List strings) public static void RemoveDuplicates(List strings, bool ignoreCase) { - Dictionary uniqueStore = new Dictionary(); + Dictionary uniqueStore; + if(ignoreCase) + { + uniqueStore = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + } + else + { + uniqueStore = new Dictionary(); + } List finalList = new List(); foreach (string currValueUncasted in strings) { - string currValue; - if (ignoreCase) - { - currValue = currValueUncasted.ToLowerInvariant(); - } - else - { - currValue = currValueUncasted; - } + string currValue=currValueUncasted; if (!uniqueStore.ContainsKey(currValue)) { diff --git a/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ProjectCommands.cs b/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ProjectCommands.cs index 9e319ed60..878edd65d 100644 --- a/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ProjectCommands.cs +++ b/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ProjectCommands.cs @@ -164,7 +164,8 @@ public bool UpdateFileMembershipInProject(ReferencedFileSave referencedFileSave) var isExcludedFromProject = referencedFileSave.ProjectsToExcludeFrom.Contains(projectName); if(!isExcludedFromProject) { - wasAnythingAdded = UpdateFileMembershipInProject(GlueState.Self.CurrentMainProject, GlueCommands.Self.GetAbsoluteFilePath(referencedFileSave), useContentPipeline, false, fileRfs: referencedFileSave); + var absoluteFilePath = GlueCommands.Self.GetAbsoluteFilePath(referencedFileSave); + wasAnythingAdded = UpdateFileMembershipInProject(GlueState.Self.CurrentMainProject, absoluteFilePath, useContentPipeline, false, fileRfs: referencedFileSave); } foreach (ProjectSpecificFile projectSpecificFile in referencedFileSave.ProjectSpecificFiles) @@ -297,7 +298,7 @@ project.ContentProject is VisualStudioProject && { var inner = new List(); FileReferenceManager.Self.GetFilesReferencedBy(fileToAddAbsolute, TopLevelOrRecursive.TopLevel, inner); - listOfReferencedFiles.AddRange(inner.Select(item => item.Standardized)); + listOfReferencedFiles.AddRange(inner.Select(item => item.StandardizedCaseSensitive)); if (alreadyReferencedFiles != null) { listOfReferencedFiles = listOfReferencedFiles.Except(alreadyReferencedFiles).ToList(); diff --git a/FRBDK/Glue/Glue/Plugins/PluginManager.cs b/FRBDK/Glue/Glue/Plugins/PluginManager.cs index bf2028c1a..d3fee4947 100644 --- a/FRBDK/Glue/Glue/Plugins/PluginManager.cs +++ b/FRBDK/Glue/Glue/Plugins/PluginManager.cs @@ -718,7 +718,7 @@ internal static bool CanFileReferenceContent(string absoluteName) CallMethodOnPluginNotUiThread( - delegate(PluginBase plugin) + plugin => { if (plugin.CanFileReferenceContent != null) { @@ -740,7 +740,7 @@ internal static GeneralResponse GetFilesReferencedBy(string absoluteName, Editor SaveRelativeDirectory(); CallMethodOnPluginNotUiThread( - delegate(PluginBase plugin) + plugin => { if(plugin.FillWithReferencedFiles != null) { @@ -763,7 +763,7 @@ internal static void GetFilesNeededOnDiskBy(string absoluteName, EditorObjects.P { SaveRelativeDirectory(); CallMethodOnPluginNotUiThread( - delegate (PluginBase plugin) + plugin => { if (plugin.GetFilesNeededOnDiskBy != null) { diff --git a/FRBDK/Glue/Glue/VSHelpers/Projects/AndroidMonoGameNet8Project.cs b/FRBDK/Glue/Glue/VSHelpers/Projects/AndroidMonoGameNet8Project.cs index 5986bf457..bf47cbbe9 100644 --- a/FRBDK/Glue/Glue/VSHelpers/Projects/AndroidMonoGameNet8Project.cs +++ b/FRBDK/Glue/Glue/VSHelpers/Projects/AndroidMonoGameNet8Project.cs @@ -50,9 +50,6 @@ public override string ProcessLink(string path) return returnValue; } - - public override string ContentDirectory => "content/"; - public override List GetErrors() { List toReturn = new List(); diff --git a/FRBDK/Glue/Glue/VSHelpers/Projects/CombinedEmbeddedContentProject.cs b/FRBDK/Glue/Glue/VSHelpers/Projects/CombinedEmbeddedContentProject.cs index 478e29037..7708822fc 100644 --- a/FRBDK/Glue/Glue/VSHelpers/Projects/CombinedEmbeddedContentProject.cs +++ b/FRBDK/Glue/Glue/VSHelpers/Projects/CombinedEmbeddedContentProject.cs @@ -14,24 +14,13 @@ namespace FlatRedBall.Glue.VSHelpers.Projects /// public abstract class CombinedEmbeddedContentProject : VisualStudioProject { - public CombinedEmbeddedContentProject(Project project) - : base(project) + public CombinedEmbeddedContentProject(Project project) : base(project) { - - } - protected override bool NeedToSaveContentProject { get { return false; } } - public override bool ContentCopiedToOutput { get { return false; } } - - public override string ContentDirectory - { - get { return "Content/"; } - } - - - public override string DefaultContentAction { get { return "Content"; } } - - + protected override bool NeedToSaveContentProject => false; + public override bool ContentCopiedToOutput => false; + public override string ContentDirectory => "Content/"; + public override string DefaultContentAction => "Content"; } } diff --git a/FRBDK/Glue/Glue/VSHelpers/Projects/VisualStudioProject.cs b/FRBDK/Glue/Glue/VSHelpers/Projects/VisualStudioProject.cs index 73e5661c9..189ef1dfc 100644 --- a/FRBDK/Glue/Glue/VSHelpers/Projects/VisualStudioProject.cs +++ b/FRBDK/Glue/Glue/VSHelpers/Projects/VisualStudioProject.cs @@ -186,6 +186,8 @@ private void GetDotNetVersion() #endregion + #region Add Items + /// /// Adds the argument absoluteFile to the project. This method will not first check /// if the file is already part of the project or not. See IsFilePartOfProject for @@ -380,6 +382,119 @@ public void AddProjectReference(string projectPath) metadata); } + public virtual ProjectItem AddCodeBuildItem(string fileName) + { + return AddCodeBuildItem(fileName, false, ""); + } + + protected virtual void AddCodeBuildItems(ProjectBase sourceProjectBase) + { + + var sourceCodeFiles = ((VisualStudioProject)sourceProjectBase).EvaluatedItems + .Where(item => item.UnevaluatedInclude.EndsWith(".cs") && !ShouldIgnoreFile(item.UnevaluatedInclude)) + .ToList(); + + foreach (var bi in sourceCodeFiles) + { + string fileName; + + if (SaveAsAbsoluteSyncedProject) + { + fileName = sourceProjectBase.FullFileName.GetDirectoryContainingThis().FullPath + bi.UnevaluatedInclude; + } + else if (SaveAsRelativeSyncedProject) + { + fileName = FileManager.MakeRelative( + sourceProjectBase.FullFileName.GetDirectoryContainingThis().FullPath, + FullFileName.GetDirectoryContainingThis().FullPath) + bi.UnevaluatedInclude; + } + else + { + fileName = bi.UnevaluatedInclude; + } + + + if (!IsFilePartOfProject(fileName, BuildItemMembershipType.CompileOrContentPipeline) && + !IsFilePartOfProject(bi.UnevaluatedInclude, BuildItemMembershipType.CompileOrContentPipeline)) + { + if (SaveAsAbsoluteSyncedProject) + { + AddCodeBuildItem(fileName, true, bi.UnevaluatedInclude); + } + else if (SaveAsRelativeSyncedProject) + { + AddCodeBuildItem(fileName, true, bi.UnevaluatedInclude); + } + else + { + AddCodeBuildItem(bi.UnevaluatedInclude); + } + } + } + + } + + public void AddNugetPackage(string packageName, string versionNumber) + { + lock (this) + { + ProjectItem projectItem = this.Project.AddItem("PackageReference", packageName).First(); + projectItem.SetMetadataValue("Version", versionNumber); + mBuildItemDictionaries.Add(packageName, projectItem); + Project.ReevaluateIfNecessary(); + } + } + + protected ProjectItem AddCodeBuildItem(string fileName, bool isSyncedProject, string nameRelativeToThisProject) + { + lock (this) + { + if (!FileManager.IsRelative(fileName)) + { + fileName = FileManager.MakeRelative(fileName, this.Directory); + } + + string fleNameFixedSlashes = fileName.Replace('/', '\\'); + + + + if (mBuildItemDictionaries.ContainsKey(fleNameFixedSlashes)) + { + return mBuildItemDictionaries[fleNameFixedSlashes]; + } + + + if (!FileManager.IsRelative(fileName) && !isSyncedProject) + { + fileName = FileManager.MakeRelative(fileName, + FileManager.GetDirectory(this.FullFileName.FullPath)); + } + + fileName = fileName.Replace('/', '\\'); + ProjectItem item; + item = this.Project.AddItem("Compile", fileName).First(); + Project.ReevaluateIfNecessary(); + item.UnevaluatedInclude = fileName; + if (isSyncedProject) + { + item.SetMetadataValue("Link", nameRelativeToThisProject); + + if (nameRelativeToThisProject.Contains("Generated")) + { + var parent = FileManager.RemovePath(fileName).Replace(".Generated", ""); + MakeBuildItemNested(item, parent); + } + } + + + mBuildItemDictionaries.Add(fleNameFixedSlashes, item); + + return item; + } + } + + #endregion + public bool IsCodeItem(ProjectItem buildItem) { if (buildItem.ItemType == "Compile") @@ -777,10 +892,6 @@ public void RenameItem(string oldName, string newName) } - public virtual ProjectItem AddCodeBuildItem(string fileName) - { - return AddCodeBuildItem(fileName, false, ""); - } public override void UpdateContentFile(string sourceFileName) { @@ -848,54 +959,6 @@ public void MakeBuildItemNested(ProjectItem item, string parent) } } - protected virtual void AddCodeBuildItems(ProjectBase sourceProjectBase) - { - - var sourceCodeFiles = ((VisualStudioProject)sourceProjectBase).EvaluatedItems - .Where(item => item.UnevaluatedInclude.EndsWith(".cs") && !ShouldIgnoreFile(item.UnevaluatedInclude)) - .ToList(); - - foreach (var bi in sourceCodeFiles) - { - string fileName; - - if (SaveAsAbsoluteSyncedProject) - { - fileName = sourceProjectBase.FullFileName.GetDirectoryContainingThis().FullPath + bi.UnevaluatedInclude; - } - else if (SaveAsRelativeSyncedProject) - { - fileName = FileManager.MakeRelative( - sourceProjectBase.FullFileName.GetDirectoryContainingThis().FullPath, - FullFileName.GetDirectoryContainingThis().FullPath) + bi.UnevaluatedInclude; - } - else - { - fileName = bi.UnevaluatedInclude; - } - - - if (!IsFilePartOfProject(fileName, BuildItemMembershipType.CompileOrContentPipeline) && - !IsFilePartOfProject(bi.UnevaluatedInclude, BuildItemMembershipType.CompileOrContentPipeline)) - { - if (SaveAsAbsoluteSyncedProject) - { - AddCodeBuildItem(fileName, true, bi.UnevaluatedInclude); - } - else if (SaveAsRelativeSyncedProject) - { - AddCodeBuildItem(fileName, true, bi.UnevaluatedInclude); - } - else - { - AddCodeBuildItem(bi.UnevaluatedInclude); - } - } - } - - } - - public override void Save(string fileName) { // this used to save a backup, but doing so @@ -948,7 +1011,6 @@ public override string ToString() return mName; } - protected virtual bool NeedToSaveContentProject { get { return true; } } public override void SyncTo(ProjectBase projectBase, bool performTranslation) @@ -968,53 +1030,6 @@ public override void SyncTo(ProjectBase projectBase, bool performTranslation) Save(FullFileName.FullPath); } - protected ProjectItem AddCodeBuildItem(string fileName, bool isSyncedProject, string nameRelativeToThisProject) - { - lock (this) - { - if (!FileManager.IsRelative(fileName)) - { - fileName = FileManager.MakeRelative(fileName, this.Directory); - } - - string fleNameFixedSlashes = fileName.Replace('/', '\\'); - - - - if (mBuildItemDictionaries.ContainsKey(fleNameFixedSlashes)) - { - return mBuildItemDictionaries[fleNameFixedSlashes]; - } - - - if (!FileManager.IsRelative(fileName) && !isSyncedProject) - { - fileName = FileManager.MakeRelative(fileName, - FileManager.GetDirectory(this.FullFileName.FullPath)); - } - - fileName = fileName.Replace('/', '\\'); - ProjectItem item; - item = this.Project.AddItem("Compile", fileName).First(); - Project.ReevaluateIfNecessary(); - item.UnevaluatedInclude = fileName; - if (isSyncedProject) - { - item.SetMetadataValue("Link", nameRelativeToThisProject); - - if (nameRelativeToThisProject.Contains("Generated")) - { - var parent = FileManager.RemovePath(fileName).Replace(".Generated", ""); - MakeBuildItemNested(item, parent); - } - } - - - mBuildItemDictionaries.Add(fleNameFixedSlashes, item); - - return item; - } - } public bool HasPackage(string packageName) { @@ -1079,16 +1094,6 @@ public bool HasProjectReference(string csprojName) .Any(); } - public void AddNugetPackage(string packageName, string versionNumber) - { - lock (this) - { - ProjectItem projectItem = this.Project.AddItem("PackageReference", packageName).First(); - projectItem.SetMetadataValue("Version", versionNumber); - mBuildItemDictionaries.Add(packageName, projectItem); - Project.ReevaluateIfNecessary(); - } - } public bool RemoveItem(ProjectItem buildItem) { diff --git a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs index a9c96656f..138049bf2 100644 --- a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs +++ b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs @@ -564,7 +564,7 @@ internal GeneralResponse HandleFillWithReferencedFiles(FilePath filePath, List stringListToFill = new List(); - var respnse = GetReferencesInProjectOrDisk(filePath.Standardized, + var respnse = GetReferencesInProjectOrDisk(filePath, stringListToFill, projectOrDisk); listToFill.AddRange(stringListToFill @@ -573,13 +573,15 @@ internal GeneralResponse HandleFillWithReferencedFiles(FilePath filePath, List listToFill, ProjectOrDisk projectOrDisk) + private GeneralResponse GetReferencesInProjectOrDisk(FilePath filePath, List listToFill, ProjectOrDisk projectOrDisk) { GeneralResponse generalResponse = GeneralResponse.SuccessfulResponse; + var fileName = filePath.StandardizedCaseSensitive; + if (CanTrackDependenciesOn(fileName)) { - string extension = FileManager.GetExtension(fileName); + string extension = filePath.Extension; string oldRelative = FileManager.RelativeDirectory; @@ -737,7 +739,7 @@ public void LoadGumxIfNecessaryFromDirectory(string gumxDirectory, bool force = private static string GetGumProjectFile(string gumxDirectory) { var files = System.IO.Directory.GetFiles(gumxDirectory) - .Where(item => item.ToLowerInvariant().EndsWith(".gumx")) + .Where(item => item.EndsWith(".gumx", StringComparison.InvariantCultureIgnoreCase)) .ToArray(); bool multipleGumxFilesExist = files.Length > 1; @@ -747,11 +749,11 @@ private static string GetGumProjectFile(string gumxDirectory) if(files.Length > 1) { // Let's limit it to any files in the project. - var gumxInProject = GlueState.Self.CurrentGlueProject.GetAllReferencedFiles().Where(item => item.Name.ToLowerInvariant().EndsWith("gumx")); + var gumxInProject = GlueState.Self.CurrentGlueProject.GetAllReferencedFiles().Where(item => item.Name.EndsWith("gumx", StringComparison.InvariantCultureIgnoreCase)); - var absoluteFiles = gumxInProject.Select(item => GlueCommands.Self.GetAbsoluteFileName(item).ToLowerInvariant()); + var absoluteFiles = gumxInProject.Select(item => GlueCommands.Self.GetAbsoluteFileName(item)); - toReturn = files.FirstOrDefault(item => absoluteFiles.Contains(item.ToLowerInvariant())); + toReturn = files.FirstOrDefault(item => absoluteFiles.Contains(item, StringComparer.InvariantCultureIgnoreCase)); } else { @@ -946,7 +948,7 @@ private static void FillWithContentBuildItemsToRemove(GumProjectSave gumProject, try { referencedGumFiles = GlueCommands.Self.FileCommands.GetFilesReferencedBy(gumProject.FullFileName, TopLevelOrRecursive.Recursive) - .Select(item=>FileManager.Standardize(item.FullPath).ToLowerInvariant()) + .Select(item=>FileManager.Standardize(item.FullPath)) .Distinct() .ToArray(); } @@ -1000,7 +1002,7 @@ private static void FillWithContentBuildItemsToRemove(GumProjectSave gumProject, private static bool GetIfShouldRemoveGumRelativeFile(GumProjectSave gumProject, ProjectItem buildItem, string glueContentFolder, string[] referencedGumFiles) { - string contentFullFileName = FileManager.Standardize(glueContentFolder + buildItem.UnevaluatedInclude).ToLowerInvariant(); + string contentFullFileName = FileManager.Standardize(glueContentFolder + buildItem.UnevaluatedInclude); string gumFolder = FileManager.GetDirectory(gumProject.FullFileName); @@ -1028,7 +1030,7 @@ private static bool GetIfShouldRemoveFontFile(List toRemove, Projec if(isFontCacheFile) { - var invariant = FileManager.Standardize(contentFullFileName).ToLowerInvariant(); + var invariant = FileManager.Standardize(contentFullFileName); bool isReferenced = fileReferencedByGumx.Contains(invariant); @@ -1052,7 +1054,7 @@ private static bool GetIfShouldRemoveStandardElement(GumProjectSave gumProject, string elementName = FileManager.RemoveExtension(FileManager.MakeRelative(buildItem.UnevaluatedInclude, standardFolder)) .Replace("/", "\\"); - bool exists = gumProject.StandardElements.Any(item => item.Name.Replace("/", "\\").ToLowerInvariant() == elementName.ToLowerInvariant()); + bool exists = gumProject.StandardElements.Any(item => item.Name.Replace("/", "\\").Equals(elementName, StringComparison.InvariantCultureIgnoreCase)); if (!exists) { @@ -1076,7 +1078,7 @@ private static bool GetIfShouldRemoveComponent(GumProjectSave gumProject, Projec string elementName = FileManager.RemoveExtension(FileManager.MakeRelative(buildItem.UnevaluatedInclude, componentFolder)) .Replace("/", "\\"); - bool exists = gumProject.Components.Any(item => item.Name.Replace("/", "\\").ToLowerInvariant() == elementName.ToLowerInvariant()); + bool exists = gumProject.Components.Any(item => item.Name.Replace("/", "\\").Equals(elementName, StringComparison.InvariantCultureIgnoreCase)); if (!exists) { @@ -1100,7 +1102,7 @@ private static bool GetIfShouldRemoveScreen(GumProjectSave gumProject, ProjectIt string elementName = FileManager.RemoveExtension(FileManager.MakeRelative(buildItem.UnevaluatedInclude, screenFolder)) .Replace("/", "\\"); - bool exists = gumProject.Screens.Any(item => item.Name.ToLowerInvariant() == elementName.ToLowerInvariant()); + bool exists = gumProject.Screens.Any(item => item.Name.Equals(elementName, StringComparison.InvariantCultureIgnoreCase)); shouldRemove = !exists;