public void HandleGetFilesReferencedBy(string fileName, TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill) { ProjectOrDisk projectOrDisk = ProjectOrDisk.Project; GetReferencesInProjectOrDisk(fileName, topLevelOrRecursive, listToFill, projectOrDisk); }
private static void TryAddFontFromSizeAndName(TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, int fontSizeValue, string fontNameValue, int outlineThickness, bool useFontSmoothing) { if (!string.IsNullOrEmpty(fontNameValue)) { string fontFileName = global::RenderingLibrary.Graphics.Fonts.BmfcSave.GetFontCacheFileNameFor(fontSizeValue, fontNameValue, outlineThickness, useFontSmoothing); fontFileName = FileManager.RelativeDirectory + fontFileName; listToFill.Add(fontFileName); if (topLevelOrRecursive == TopLevelOrRecursive.Recursive && System.IO.File.Exists(fontFileName)) { string fontDirectory = FileManager.GetDirectory(fontFileName); string fontContents = FileManager.FromFileText(fontFileName); string[] texturesToLoad = BitmapFont.GetSourceTextures(fontContents); foreach (var referencedTexture in texturesToLoad) { string absoluteFileName = fontDirectory + referencedTexture; listToFill.Add(absoluteFileName); } } } }
private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, Gum.DataTypes.Variables.StateSave state) { Gum.DataTypes.RecursiveVariableFinder rvf = new RecursiveVariableFinder(state); foreach (var variable in state.Variables.Where(item => (item.GetRootName() == "Font" || item.GetRootName() == "FontSize" || item.GetRootName() == "OutlineThickness") && item.Value != null )) { string prefix = null; if (variable.Name.Contains('.')) { prefix = FileManager.RemoveExtension(variable.Name) + "."; } bool useCustomFont = rvf.GetValue <bool>(prefix + "UseCustomFont"); if (!useCustomFont) { var fontSizeVariableName = prefix + "FontSize"; var fontNameVariableName = prefix + "Font"; var fontOutlineVariableName = prefix + "OutlineThickness"; int fontSizeValue = rvf.GetValue <int>(fontSizeVariableName); string fontNameValue = rvf.GetValue <string>(fontNameVariableName); int outlineThickness = rvf.GetValue <int>(fontOutlineVariableName); TryAddFontFromSizeAndName(topLevelOrRecursive, listToFill, fontSizeValue, fontNameValue, outlineThickness); } } }
public static List <string> GetFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive) { List <string> referencedFiles = new List <string>(); GetFilesReferencedByAsset(fileName, topLevelOrRecursive, referencedFiles); return(referencedFiles.Distinct().ToList()); }
private void HandleGetFilesReferencedBy(string fileName, TopLevelOrRecursive depth, List <string> referencedFiles) { var extension = FileManager.GetExtension(fileName); if (extension == "atlas") { var associatedPng = FileManager.RemoveExtension(fileName) + ".png"; referencedFiles.Add(associatedPng); // Extend this in the future if we support multiple pages, etc } }
private void AddFilesReferencedBy(TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, ElementSave element, ProjectOrDisk projectOrDisk) { string fullFileName = FileManager.RelativeDirectory + element.Subfolder + "\\" + element.Name + "." + element.FileExtension; fullFileName = FileManager.RemoveDotDotSlash(fullFileName); listToFill.Add(fullFileName); if (topLevelOrRecursive == TopLevelOrRecursive.Recursive) { throw new NotImplementedException("This does not support recursive calls - should use the Glue system to track reference files"); } }
private void AddFilesReferenced(string fileName, List <string> allFiles, TopLevelOrRecursive topLevelOrRecursive, ProjectOrDisk projectOrFile) { // The project may have been unloaded: if (GlueState.CurrentMainContentProject != null) { string absoluteFileName = GlueCommands.GetAbsoluteFileName(fileName, isContent: true); if (File.Exists(absoluteFileName)) { #if GLUE List <string> referencedFiles = null; if (projectOrFile == ProjectOrDisk.Project) { referencedFiles = FlatRedBall.Glue.Managers.FileReferenceManager.Self.GetFilesReferencedBy(absoluteFileName, topLevelOrRecursive); } else { referencedFiles = FlatRedBall.Glue.Managers.FileReferenceManager.Self.GetFilesNeededOnDiskBy(absoluteFileName, topLevelOrRecursive); } #else List <string> referencedFiles = ContentParser.GetFilesReferencedByAsset(absoluteFileName, topLevelOrRecursive); #endif // 12/14/2010 // The referencedFiles // instance may be null // if the absoluteFileName // references a file that doesn't // exist on the file system. This // happens if someone checks in a GLUX // file but forgets to check in a newly- // created file. Not deadly, so Glue shouldn't // crash. Also, Glue displays warning messages in // a different part of the code, so we shouldn't pester // the user here with another one. if (referencedFiles != null) { allFiles.AddRange(referencedFiles); } } else { // Do nothing? } } }
private void FillAllFilesWithFilesInList(List <string> allFiles, ReferencedFileSave[] referencedFileList, TopLevelOrRecursive topLevelOrRecursive, ProjectOrDisk projectOrFile) { foreach (var rfs in referencedFileList) { allFiles.Add(rfs.Name); AddFilesReferenced(rfs.Name, allFiles, topLevelOrRecursive, projectOrFile); for (int i = 0; i < rfs.ProjectSpecificFiles.Count; i++) { ProjectSpecificFile psf = rfs.ProjectSpecificFiles[i]; allFiles.Add(psf.FilePath); AddFilesReferenced(psf.FilePath, allFiles, topLevelOrRecursive, projectOrFile); } } }
private void GetFilesReferencedBy(GumProjectSave gumProjectSave, TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, ProjectOrDisk projectOrDisk) { AppState.Self.GumProjectSave = gumProjectSave; foreach (var element in gumProjectSave.Screens) { AddFilesReferencedBy(topLevelOrRecursive, listToFill, element, projectOrDisk); } foreach (var element in gumProjectSave.Components) { AddFilesReferencedBy(topLevelOrRecursive, listToFill, element, projectOrDisk); } foreach (var element in gumProjectSave.StandardElements) { AddFilesReferencedBy(topLevelOrRecursive, listToFill, element, projectOrDisk); } StringFunctions.RemoveDuplicates(listToFill); }
public List <string> GetAllReferencedFileNames(TopLevelOrRecursive topLevelOrRecursive) { List <string> allFiles = new List <string>(); var allRfses = GetAllRfses(); FillAllFilesWithFilesInList(allFiles, allRfses, topLevelOrRecursive, ProjectOrDisk.Project); string contentProjectDirectory = GlueState.CurrentMainContentProject.GetAbsoluteContentFolder().ToLowerInvariant(); for (int i = 0; i < allFiles.Count; i++) { // This fixes slashes: allFiles[i] = FileManager.Standardize(allFiles[i], contentProjectDirectory, makeAbsolute: false); // This makes the files relative to the content project: if (allFiles[i].ToLowerInvariant().StartsWith(contentProjectDirectory)) { allFiles[i] = allFiles[i].Substring(contentProjectDirectory.Length); } } return(allFiles.Distinct().ToList()); }
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); } } }
private void GetFilesReferencedBy(ElementSave element, TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, ProjectOrDisk projectOrDisk) { if (!string.IsNullOrEmpty(element.FileName) && projectOrDisk == ProjectOrDisk.Disk) { var fileWithoutExtension = FileManager.RemoveExtension(element.FileName); var potentialAnimationName = fileWithoutExtension + "Animations.ganx"; if (System.IO.File.Exists(potentialAnimationName)) { listToFill.Add(potentialAnimationName); } } // Use AllStates so that we get stuff referenced in categorized states too foreach (var state in element.AllStates) { state.ParentContainer = element; TryGetFontReferences(topLevelOrRecursive, listToFill, state); GetRegularVariableFileReferences(listToFill, state, element.Instances, projectOrDisk); foreach (var variableList in state.VariableLists) { if (variableList.IsFile) { throw new NotImplementedException(); } } } foreach (var instance in element.Instances) { var type = instance.BaseType; // find the element. var referencedElement = AppState.Self.GetElementSave(type); if (referencedElement != null) { if (referencedElement is StandardElementSave) { listToFill.Add(FileManager.RelativeDirectory + "Standards/" + referencedElement.Name + ".gutx"); } else if (referencedElement is ComponentSave) { listToFill.Add(FileManager.RelativeDirectory + "Components/" + referencedElement.Name + ".gucx"); } else { throw new Exception(); } if (topLevelOrRecursive == TopLevelOrRecursive.Recursive) { GetFilesReferencedBy(referencedElement, topLevelOrRecursive, listToFill, projectOrDisk); } } } StringFunctions.RemoveDuplicates(listToFill); }
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); }
public static List <SourceReferencingFile> GetSourceReferencingFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive) { string throwAwayString = ""; string throwawayVerboseString = ""; return(GetSourceReferencingFilesReferencedByAsset(fileName, topLevelOrRecursive, ErrorBehavior.ThrowException, ref throwAwayString, ref throwawayVerboseString)); }
public List<string> GetAllReferencedFileNames(TopLevelOrRecursive topLevelOrRecursive) { List<string> allFiles = new List<string>(); var allRfses = GetAllRfses(); FillAllFilesWithFilesInList(allFiles, allRfses, topLevelOrRecursive, ProjectOrDisk.Project); string contentProjectDirectory = ProjectManager.ContentProject.Directory.ToLowerInvariant(); for (int i = 0; i < allFiles.Count; i++) { // This fixes slashes: allFiles[i] = FileManager.Standardize(allFiles[i], contentProjectDirectory, makeAbsolute: false); // This makes the files relative to the content project: if (allFiles[i].ToLowerInvariant().StartsWith(contentProjectDirectory)) { allFiles[i] = allFiles[i].Substring(contentProjectDirectory.Length); } } return allFiles; }
private void FillAllFilesWithFilesInList(List<string> allFiles, IEnumerable<ReferencedFileSave> referencedFileList, TopLevelOrRecursive topLevelOrRecursive, ProjectOrDisk projectOrFile) { foreach(var rfs in referencedFileList) { allFiles.Add(rfs.Name); AddFilesReferenced(rfs.Name, allFiles, topLevelOrRecursive, projectOrFile); for (int i = 0; i < rfs.ProjectSpecificFiles.Count; i++) { ProjectSpecificFile psf = rfs.ProjectSpecificFiles[i]; allFiles.Add(psf.FilePath); AddFilesReferenced(psf.FilePath, allFiles, topLevelOrRecursive, projectOrFile); } } }
private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, Gum.DataTypes.Variables.StateSave state) { Gum.DataTypes.RecursiveVariableFinder rvf = new RecursiveVariableFinder(state); foreach (var variable in state.Variables.Where(item => (item.GetRootName() == "Font" || item.GetRootName() == "FontSize" || item.GetRootName() == "OutlineThickness" || item.GetRootName() == "UseFontSmoothing" ) && item.Value != null )) { string prefix = null; // Just because this has a variable for Font or FontSize or whatever doesn't // necessarily mean that this is a text object - it could have been an instance // that at one time was a text object, but was later converted to a different type // which no longer uses fonts. To handle this case we want to only consider this a referenced // file if Coo var isTextObject = true; if (variable.Name.Contains('.')) { var instanceName = FileManager.RemoveExtension(variable.Name); prefix = FileManager.RemoveExtension(variable.Name) + "."; var instance = state.ParentContainer.GetInstance(instanceName); if (instance != null) { var basicElement = ObjectFinder.Self.GetRootStandardElementSave(instance.GetBaseElementSave()); isTextObject = basicElement?.Name == "Text"; } else { // This code is used to // determine whether a referenced // file is necessary in the project. // Since the instance doesn't exist, we // won't actually use the variable for the // instance, so we don't want to track the file. // We can do this by marking isTextObject as false. isTextObject = false; } } if (isTextObject) { bool useCustomFont = rvf.GetValue <bool>(prefix + "UseCustomFont"); if (!useCustomFont) { var fontSizeVariableName = prefix + "FontSize"; var fontNameVariableName = prefix + "Font"; var fontOutlineVariableName = prefix + "OutlineThickness"; var fontSmoothingVariableName = prefix + "UseFontSmoothing"; int fontSizeValue = rvf.GetValue <int>(fontSizeVariableName); string fontNameValue = rvf.GetValue <string>(fontNameVariableName); int outlineThickness = rvf.GetValue <int>(fontOutlineVariableName); bool useFontSmoothing = rvf.GetValue <bool>(fontSmoothingVariableName); TryAddFontFromSizeAndName(topLevelOrRecursive, listToFill, fontSizeValue, fontNameValue, outlineThickness, useFontSmoothing); } } } }
private void HandleGetFilesReferencedBy(string fileName, TopLevelOrRecursive depth, List<string> referencedFiles) { var extension = FileManager.GetExtension(fileName); if (extension == "atlas") { var associatedPng = FileManager.RemoveExtension(fileName) + ".png"; referencedFiles.Add(associatedPng); // Extend this in the future if we support multiple pages, etc } }
public void HandleGetFilesNeededOnDiskBy(GumProjectSave gumProjectSave, TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill) { }
private GeneralResponse GetReferencesInProjectOrDisk(string fileName, TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, ProjectOrDisk projectOrDisk) { GeneralResponse generalResponse = GeneralResponse.SuccessfulResponse; if (CanTrackDependenciesOn(fileName)) { string extension = FileManager.GetExtension(fileName); string oldRelative = FileManager.RelativeDirectory; string gumxFile = null; FileManager.RelativeDirectory = GetGumxDirectory(fileName); LoadGumxIfNecessaryFromDirectory(FileManager.RelativeDirectory); string absoluteFileName = fileName; if (FileManager.IsRelative(absoluteFileName)) { absoluteFileName = FileManager.RelativeDirectory + absoluteFileName; } string errors = null; if (System.IO.File.Exists(absoluteFileName)) { switch (extension) { case "gumx": { try { LoadGumxIfNecessaryFromDirectory(FileManager.RelativeDirectory, force: true); GetFilesReferencedBy(Gum.Managers.ObjectFinder.Self.GumProjectSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; case "gucx": { ComponentSave gumComponentSave = null; try { gumComponentSave = FileManager.XmlDeserialize <ComponentSave>(absoluteFileName); gumComponentSave.FileName = absoluteFileName; // See an explanation for this in LoadGumxIfNecessaryFromDirectory gumComponentSave.Initialize(gumComponentSave.DefaultState); GetFilesReferencedBy(gumComponentSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; case "gusx": { ScreenSave gumScreenSave = null; try { gumScreenSave = FileManager.XmlDeserialize <ScreenSave>(absoluteFileName); gumScreenSave.FileName = absoluteFileName; // See an explanation for this in LoadGumxIfNecessaryFromDirectory gumScreenSave.Initialize(gumScreenSave.DefaultState); GetFilesReferencedBy(gumScreenSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; case "gutx": { StandardElementSave standardElementSave = null; try { standardElementSave = FileManager.XmlDeserialize <StandardElementSave>(absoluteFileName); standardElementSave.FileName = absoluteFileName; // See an explanation for this in LoadGumxIfNecessaryFromDirectory standardElementSave.Initialize(standardElementSave.DefaultState); GetFilesReferencedBy(standardElementSave, topLevelOrRecursive, listToFill, projectOrDisk); } catch (Exception e) { errors = "Error tracking Gum references for " + absoluteFileName + "\n" + e.ToString(); } } break; } } if (errors != null) { generalResponse = new GeneralResponse { Succeeded = false, Message = errors }; } FileManager.RelativeDirectory = oldRelative; } return(generalResponse); }
private void GetFilesReferencedByFunc(string absoluteFileName, TopLevelOrRecursive topLevelOrRecursive, List<string> files) { if (!string.IsNullOrEmpty(absoluteFileName) && FileManager.GetExtension(absoluteFileName).ToLowerInvariant() == "scml") { var oldDir = FileManager.RelativeDirectory; FileManager.RelativeDirectory = FileManager.GetDirectory(absoluteFileName); var spriterObjectSave = SpriterObjectSave.FromFile(absoluteFileName); foreach (var file in spriterObjectSave.Folder.SelectMany(folder => folder.File)) { var filename = FileManager.MakeAbsolute(file.Name); if (!files.Contains(filename)) { files.Add(filename); } } FileManager.RelativeDirectory = oldDir; } }
private void AddFilesReferenced(string fileName, List<string> allFiles, TopLevelOrRecursive topLevelOrRecursive, ProjectOrDisk projectOrFile) { string absoluteFileName = ProjectManager.MakeAbsolute(fileName); if (File.Exists(absoluteFileName)) { #if GLUE List<string> referencedFiles = null; if (projectOrFile == ProjectOrDisk.Project) { referencedFiles = FlatRedBall.Glue.Managers.FileReferenceManager.Self.GetFilesReferencedBy(absoluteFileName, topLevelOrRecursive); } else { referencedFiles = FlatRedBall.Glue.Managers.FileReferenceManager.Self.GetFilesNeededOnDiskBy(absoluteFileName, topLevelOrRecursive); } #else List<string> referencedFiles = ContentParser.GetFilesReferencedByAsset(absoluteFileName, topLevelOrRecursive); #endif // 12/14/2010 // The referencedFiles // instance may be null // if the absoluteFileName // references a file that doesn't // exist on the file system. This // happens if someone checks in a GLUX // file but forgets to check in a newly- // created file. Not deadly, so Glue shouldn't // crash. Also, Glue displays warning messages in // a different part of the code, so we shouldn't pester // the user here with another one. if (referencedFiles != null) { allFiles.AddRange(referencedFiles); } } else { // Do nothing? } }