FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ProjectCommands.cs
/// <summary>
/// Adds the argument fileRelativeToProject to the argument project if it's not already part of the project.
/// </summary>
/// <param name="project"></param>
/// <param name="fileName"></param>
/// <param name="useContentPipeline">Whether this file must be part of the content pipeline. See internal notes on this variable.</param>
/// <param name="shouldLink"></param>
/// <param name="parentFile"></param>
/// <returns>Whether the project was modified.</returns>
Adds the argument fileRelativeToProject to the argument project if it's not already part of the project.
Adds the argument fileRelativeToProject to the argument project if it ' s not already part of the project .
public bool UpdateFileMembershipInProject(ProjectBase project, string fileName, bool useContentPipeline, bool shouldLink, string parentFile = null, bool recursive = true, List<string> alreadyReferencedFiles = null)
        {
            bool wasProjectModified = false;
            if (project == null || GlueState.Self.CurrentMainProject == null) return wasProjectModified;
            string fileToAddAbsolute = GlueCommands.Self.GetAbsoluteFileName(fileName, isContent:true);
            fileToAddAbsolute = fileToAddAbsolute.Replace("/", "\\");
            bool isFileAlreadyPartOfProject = false;
            bool needsToBeInContentProject = ShouldFileBeInContentProject(fileToAddAbsolute);
            BuildItemMembershipType bimt = BuildItemMembershipType.CopyIfNewer;
            if (!useContentPipeline)
            {
                useContentPipeline = GetIfShouldUseContentPipeline(fileToAddAbsolute);
            }
            if (useContentPipeline)
            {
                bimt = BuildItemMembershipType.CompileOrContentPipeline;
            }
            else if (!project.ContentProject.ContentCopiedToOutput)
            {
                bimt = BuildItemMembershipType.Content;
            }
            if (!needsToBeInContentProject)
            {
                isFileAlreadyPartOfProject = project.IsFilePartOfProject(fileName, BuildItemMembershipType.CompileOrContentPipeline);
            }
            string fileRelativeToContent = FileManager.MakeRelative(
                fileToAddAbsolute,
                FileManager.GetDirectory(project.ContentProject.FullFileName));
            fileRelativeToContent = fileRelativeToContent.Replace("/", "\\");
            if (!isFileAlreadyPartOfProject && needsToBeInContentProject)
            {
                isFileAlreadyPartOfProject = project.ContentProject.IsFilePartOfProject(fileRelativeToContent, bimt);
                if (!isFileAlreadyPartOfProject)
                {
                    var buildItem = project.ContentProject.GetItem(fileRelativeToContent);
                    if (buildItem != null)
                    {
                        project.ContentProject.RemoveItem(fileRelativeToContent);
                    }
                }
            }
            bool shouldSkipAdd = useContentPipeline &&
                project.ContentProject is VisualStudioProject &&
                !((VisualStudioProject)project.ContentProject).AllowContentCompile;
            bool shouldRemoveFile = shouldSkipAdd && 
                project.ContentProject.IsFilePartOfProject(fileRelativeToContent, bimt);
            if (shouldRemoveFile)
            {
                var buildItem = project.ContentProject.GetItem(fileRelativeToContent);
                if (buildItem != null)
                {
                    project.ContentProject.RemoveItem(fileRelativeToContent);
                }
            }
            if (!isFileAlreadyPartOfProject && !shouldSkipAdd)
            {
                wasProjectModified = true;
                if (needsToBeInContentProject)
                {
                    AddFileToContentProject(project, useContentPipeline, shouldLink, fileToAddAbsolute);
                }
                else
                {
                    ProjectManager.CodeProjectHelper.AddFileToCodeProject(project, fileToAddAbsolute);
                }
            }
            var listOfReferencedFiles = new List<string>();
            if (!fileToAddAbsolute.EndsWith(".cs"))
            {
                FileReferenceManager.Self.GetFilesReferencedBy(fileToAddAbsolute, TopLevelOrRecursive.TopLevel, listOfReferencedFiles);
                if(alreadyReferencedFiles != null)
                {
                    listOfReferencedFiles = listOfReferencedFiles.Except(alreadyReferencedFiles).ToList();
                }
            }
            bool shouldAddChildren = true;
            if (fileName.EndsWith(".x") || useContentPipeline)
            {
                shouldAddChildren = false;
            }
            if (shouldAddChildren && listOfReferencedFiles != null && recursive)
            {
                for (int i = 0; i < listOfReferencedFiles.Count; i++)
                {
                    string file = listOfReferencedFiles[i];
                    if (file.Contains(@"../"))
                    {
                        string message = "The file\n\n" + fileToAddAbsolute + "\n\nincludes the file\n\n" + file + "\n\n" +
                            "This file should not contain ../ in the path.  This likely happened if you saved the file " +
                            "in a FRBDK tool and didn't select the \"Copy to relative\" option.\n\nYou should probably shut " +
                            "down Glue, fix this problem, then re-open your project.";
                        System.Windows.Forms.MessageBox.Show(message);
                    }
                    else
                    {
                        wasProjectModified |= UpdateFileMembershipInProject(project, file, useContentPipeline, shouldLink, fileToAddAbsolute, recursive:true, alreadyReferencedFiles: listOfReferencedFiles);
                    }
                }
            }
            return wasProjectModified;
        }
public bool UpdateFileMembershipInProject ( ProjectBase project , string fileName , bool useContentPipeline , bool shouldLink , string parentFile = null , bool recursive = true , List < string > alreadyReferencedFiles = null ) { bool wasProjectModified = false ; if ( project == null || GlueState . Self . CurrentMainProject == null ) return wasProjectModified ; string fileToAddAbsolute = GlueCommands . Self . GetAbsoluteFileName ( fileName , isContent : true ) ; fileToAddAbsolute = fileToAddAbsolute . Replace ( " " , " \\ " ) ; bool isFileAlreadyPartOfProject = false ; bool needsToBeInContentProject = ShouldFileBeInContentProject ( fileToAddAbsolute ) ; BuildItemMembershipType bimt = BuildItemMembershipType . CopyIfNewer ; if ( ! useContentPipeline ) { useContentPipeline = GetIfShouldUseContentPipeline ( fileToAddAbsolute ) ; } if ( useContentPipeline ) { bimt = BuildItemMembershipType . CompileOrContentPipeline ; } else if ( ! project . ContentProject . ContentCopiedToOutput ) { bimt = BuildItemMembershipType . Content ; } if ( ! needsToBeInContentProject ) { isFileAlreadyPartOfProject = project . IsFilePartOfProject ( fileName , BuildItemMembershipType . CompileOrContentPipeline ) ; } string fileRelativeToContent = FileManager . MakeRelative ( fileToAddAbsolute , FileManager . GetDirectory ( project . ContentProject . FullFileName ) ) ; fileRelativeToContent = fileRelativeToContent . Replace ( " " , " \\ " ) ; if ( ! isFileAlreadyPartOfProject && needsToBeInContentProject ) { isFileAlreadyPartOfProject = project . ContentProject . IsFilePartOfProject ( fileRelativeToContent , bimt ) ; if ( ! isFileAlreadyPartOfProject ) { var buildItem = project . ContentProject . GetItem ( fileRelativeToContent ) ; if ( buildItem != null ) { project . ContentProject . RemoveItem ( fileRelativeToContent ) ; } } } bool shouldSkipAdd = useContentPipeline && project . ContentProject is VisualStudioProject && ! ( ( VisualStudioProject ) project . ContentProject ) . AllowContentCompile ; bool shouldRemoveFile = shouldSkipAdd && project . ContentProject . IsFilePartOfProject ( fileRelativeToContent , bimt ) ; if ( shouldRemoveFile ) { var buildItem = project . ContentProject . GetItem ( fileRelativeToContent ) ; if ( buildItem != null ) { project . ContentProject . RemoveItem ( fileRelativeToContent ) ; } } if ( ! isFileAlreadyPartOfProject && ! shouldSkipAdd ) { wasProjectModified = true ; if ( needsToBeInContentProject ) { AddFileToContentProject ( project , useContentPipeline , shouldLink , fileToAddAbsolute ) ; } else { ProjectManager . CodeProjectHelper . AddFileToCodeProject ( project , fileToAddAbsolute ) ; } } var listOfReferencedFiles = new List < string > ( ) ; if ( ! fileToAddAbsolute . EndsWith ( " " ) ) { FileReferenceManager . Self . GetFilesReferencedBy ( fileToAddAbsolute , TopLevelOrRecursive . TopLevel , listOfReferencedFiles ) ; if ( alreadyReferencedFiles != null ) { listOfReferencedFiles = listOfReferencedFiles . Except ( alreadyReferencedFiles ) . ToList ( ) ; } } bool shouldAddChildren = true ; if ( fileName . EndsWith ( " " ) || useContentPipeline ) { shouldAddChildren = false ; } if ( shouldAddChildren && listOfReferencedFiles != null && recursive ) { for ( int i = 0 ; i < listOfReferencedFiles . Count ; i ++ ) { string file = listOfReferencedFiles [ i ] ; if ( file . Contains ( @"../" ) ) { string message = " \n \n " + fileToAddAbsolute + " \n \n \n \n " + file + " \n \n " + " " + " \" \" \n \n " + " " ; System . Windows . Forms . MessageBox . Show ( message ) ; } else { wasProjectModified |= UpdateFileMembershipInProject ( project , file , useContentPipeline , shouldLink , fileToAddAbsolute , recursive : true , alreadyReferencedFiles : listOfReferencedFiles ) ; } } } return wasProjectModified ; }
Adds the argument fileRelativeToProject to the argument project if it's not already part of the project.
Adds the argument fileRelativeToProject to the argument project if it ' s not already part of the project .
///////////////////Early Out///////////////////// /////////////////End Early Out////////////////// // useContentPipeline can come from the parent file, if it uses content pipeline. But there may be other cases where we want to force content pepeline // Here we're going to get the absolute file name. // We want to get the file name  // The item is here but it's using the wrong build types.  Let's // remove it and readd it so that it gets added with the right options. // Let's remove it and say it's not part of the project so it gets removed and readded // It's using content pipeline, so we use XNBs not PNGs // The item is here but it's using the wrong build types.  Let's // remove it and readd it so that it gets added with the right options. // Let's remove it and say it's not part of the project so it gets removed and readded // Glue is going to assume .cs files can't reference content:
Whether the project was modified.
Whether the project was modified .
project
ProjectBase
None
fileName
string
None
useContentPipeline
bool
Whether this file must be part of the content pipeline. See internal notes on this variable.
Whether this file must be part of the content pipeline . See internal notes on this variable .
shouldLink
bool
None
parentFile
string
None
recursive
bool
alreadyReferencedFiles
List<string>