Пример #1
0
        public static List <SourceReferencingFile> GetSourceReferencingFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive, ErrorBehavior errorBehavior, ref string error, ref string verboseError)
        {
            string fileExtension = FileManager.GetExtension(fileName);

            List <SourceReferencingFile> referencedFiles = null;

            switch (fileExtension)
            {
            case "scnx":
                try
                {
                    SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

                    referencedFiles = ses.GetSourceReferencingReferencedFiles(RelativeType.Absolute);
                }
                catch (Exception e)
                {
                    error           = "Error loading file " + fileName + ": " + e.Message;
                    referencedFiles = new List <SourceReferencingFile>();
                    verboseError    = e.ToString();
                }
                break;

            default:
                referencedFiles = new List <SourceReferencingFile>();
                break;
            }
/**/
            if (topLevelOrRecursive == TopLevelOrRecursive.Recursive)
            {
                //First we need to get a list of all referenced files
                List <string> filesToSearch = new List <string>();

                try
                {
                    // GetFilesReferencedByAsset can throw an error if the file doesn't
                    // exist.  But we don't really care if it's missing if it can't reference
                    // others.  I mean, sure we care, but it's not relevant here.  Other systems
                    // can check for that.
                    if (CanFileReferenceOtherFiles(fileName))
                    {
                        GetFilesReferencedByAsset(fileName, topLevelOrRecursive, filesToSearch);
                    }
                }
                catch (Exception e)
                {
                    if (errorBehavior == ErrorBehavior.ThrowException)
                    {
                        throw e;
                    }
                    else
                    {
                        error += e.Message + "\n";
                    }
                }



                if (filesToSearch != null)
                {
                    for (int i = filesToSearch.Count - 1; i > -1; i--)
                    {
                        string errorForThisFile        = "";
                        string verboseErrorForThisFile = "";
                        List <SourceReferencingFile> subReferencedFiles = GetSourceReferencingFilesReferencedByAsset(filesToSearch[i], topLevelOrRecursive,
                                                                                                                     errorBehavior, ref errorForThisFile, ref verboseErrorForThisFile);
                        // error may have already been set.  If it has already been set, we don't want to dump more errors (which may just be duplicates anyway)
                        if (string.IsNullOrEmpty(error))
                        {
                            error += errorForThisFile;
                        }

                        if (subReferencedFiles != null)
                        {
                            referencedFiles.AddRange(subReferencedFiles);
                        }
                    }
                }
            }
/**/
            return(referencedFiles);
        }