public static List <string> GetFilesReferencedByAsset(string file, bool readRecursively) { string fileExtension = FileManager.GetExtension(file); List <string> referencedFiles = null; // = new List<string>(); switch (fileExtension) { #region Scene (.scnx) case "scnx": SpriteEditorScene ses = SpriteEditorScene.FromFile(file); referencedFiles = ses.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region Emitter List (.emix) case "emix": EmitterSaveList esl = EmitterSaveList.FromFile(file); referencedFiles = esl.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region SpriteRig (.srgx) case "srgx": SpriteRigSave srs = SpriteRigSave.FromFile(file); referencedFiles = srs.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region AnimationChain List case "achx": AnimationChainListSave acls = AnimationChainListSave.FromFile(file); referencedFiles = acls.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region Bitmap Font Generator Config File (.bmfc) case "bmfc": referencedFiles = new List <string>(); // These are only referenced IF they actually exist string referencedFileToAdd = FileManager.RemoveExtension(file) + ".png"; if (FileManager.FileExists(referencedFileToAdd)) { referencedFiles.Add(referencedFileToAdd); } referencedFileToAdd = FileManager.RemoveExtension(file) + ".fnt"; if (FileManager.FileExists(referencedFileToAdd)) { referencedFiles.Add(referencedFileToAdd); } break; #endregion #region X File (.x) case "x": referencedFiles = GetTextureReferencesInX(file); break; #endregion #region WME File (.wme) case "wme": referencedFiles = new List <string>(); WMELoader.GetReferencedFiles(file, referencedFiles, RelativeType.Absolute); break; #endregion #region Spline List (.slpx) - falls to default case "splx": #endregion default: referencedFiles = new List <string>(); break; } if (readRecursively) { for (int i = referencedFiles.Count - 1; i > -1; i--) { referencedFiles.AddRange(GetFilesReferencedByAsset(referencedFiles[i], true)); } } // Files may include "../", so let's get rid of that stuff for (int i = 0; i < referencedFiles.Count; i++) { referencedFiles[i] = FileManager.Standardize(referencedFiles[i], "", false); } return(referencedFiles); }
public static void GetFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive, List <string> referencedFiles) { List <string> newReferencedFiles = new List <string>(); if (!CanFileReferenceOtherFiles(fileName)) { return; } else if (!FileManager.FileExists(fileName)) { throw new FileNotFoundException("Could not find file " + fileName, fileName); } else { string fileExtension = FileManager.GetExtension(fileName); switch (fileExtension) { #region Scene (.scnx) case "scnx": SceneSave ses = SceneSave.FromFile(fileName); try { newReferencedFiles = ses.GetReferencedFiles(RelativeType.Absolute); } catch (InvalidOperationException e) { MessageBox.Show("There is an invalid file reference in the file\n\n" + fileName + "\n\nGlue will skip this file. You should investigate this file in a text editor " + "to identify the issue.\n\nAdditional error information:\n\n" + e.ToString()); } break; #endregion #region Emitter List (.emix) case "emix": EmitterSaveList esl = EmitterSaveList.FromFile(fileName); newReferencedFiles = esl.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region AnimationChain List case "achx": AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName); newReferencedFiles = acls.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region X File (.x) case "x": newReferencedFiles = GetTextureReferencesInX(fileName); break; #endregion #region Spline List (.slpx) - falls to default case "splx": #endregion #region Font File (.fnt) case "fnt": newReferencedFiles = GetTextureReferencesInFnt(fileName); break; #endregion default: break; } // We still want to construct as good of a reference structure as possible // even if there are missing files. Therefore, we'll just keep track of errors and report them // at the end of the method bool didErrorOccur = false; string errorMessage = ""; if (topLevelOrRecursive == TopLevelOrRecursive.Recursive) { for (int i = newReferencedFiles.Count - 1; i > -1; i--) { // If this file can't reference other files, no need to even do a file check or throw errors. if (CanFileReferenceOtherFiles(newReferencedFiles[i]) == true) { if (File.Exists(newReferencedFiles[i])) { try { GetFilesReferencedByAsset(newReferencedFiles[i], topLevelOrRecursive, newReferencedFiles); } catch (Exception e) { didErrorOccur = true; errorMessage += e.Message; } } else { didErrorOccur = true; errorMessage += "Could not find the file " + newReferencedFiles[i] + " which is referenced in the file " + fileName + "\n"; } } } } // Files may include "../", so let's get rid of that stuff for (int i = 0; i < newReferencedFiles.Count; i++) { newReferencedFiles[i] = FileManager.Standardize(newReferencedFiles[i], "", false); } referencedFiles.AddRange(newReferencedFiles); if (didErrorOccur) { throw new Exception(errorMessage); } } }