public List <string> GetFilesNeededOnDiskBy(string absoluteName, EditorObjects.Parsing.TopLevelOrRecursive topLevelOrRecursive) { List <string> topLevelOnly = null; bool handledByCache = false; string standardized = FileManager.Standardize(absoluteName); if (filesNeededOnDisk.ContainsKey(standardized)) { // compare dates: bool isOutOfDate = File.Exists(standardized) && //File.GetLastWriteTime(standardized) > filesNeededOnDisk[standardized].LastWriteTime; // Do a != in case the user reverts a file File.GetLastWriteTime(standardized) != filesNeededOnDisk[standardized].LastWriteTime; if (!isOutOfDate) { handledByCache = true; topLevelOnly = filesNeededOnDisk[standardized].References; } } if (!handledByCache) { // todo: do we want to change this to use topLevelOnly = ContentParser.GetFilesReferencedByAsset(absoluteName, TopLevelOrRecursive.TopLevel); PluginManager.GetFilesNeededOnDiskBy(absoluteName, TopLevelOrRecursive.TopLevel, topLevelOnly); // let's remove ../ if we can: for (int i = 0; i < topLevelOnly.Count; i++) { topLevelOnly[i] = FlatRedBall.IO.FileManager.RemoveDotDotSlash(topLevelOnly[i]); } filesNeededOnDisk[standardized] = new FileReferenceInformation { LastWriteTime = File.Exists(standardized) ? File.GetLastWriteTime(standardized) : DateTime.MinValue, References = topLevelOnly }; } List <string> toReturn = new List <string>(); toReturn.AddRange(topLevelOnly); if (topLevelOrRecursive == TopLevelOrRecursive.Recursive) { foreach (var item in topLevelOnly) { toReturn.AddRange(GetFilesNeededOnDiskBy(item, TopLevelOrRecursive.Recursive)); } } return(toReturn); }
public void GetFilesReferencedBy(string absoluteName, EditorObjects.Parsing.TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill) { List <string> topLevelOnly = null; bool handledByCache = false; string standardized = FileManager.Standardize(absoluteName); if (fileReferences.ContainsKey(standardized)) { // compare dates: bool isOutOfDate = File.Exists(standardized) && //File.GetLastWriteTime(standardized) > fileReferences[standardized].LastWriteTime; // Do a != in case the user reverts a file File.GetLastWriteTime(standardized) != fileReferences[standardized].LastWriteTime; if (!isOutOfDate) { handledByCache = true; topLevelOnly = fileReferences[standardized].References; } } if (!handledByCache) { bool succeeded = false; try { topLevelOnly = ContentParser.GetFilesReferencedByAsset(absoluteName, TopLevelOrRecursive.TopLevel); succeeded = true; } // August 26, 2017 // I used to have this throw an error when a file was missing, but plugins may not know to handle it, so let's just print // output instead catch (FileNotFoundException e) { PluginManager.ReceiveError(e.ToString()); } if (succeeded) { var response = PluginManager.GetFilesReferencedBy(absoluteName, TopLevelOrRecursive.TopLevel, topLevelOnly); if (response.Succeeded) { // let's remove ../ if we can: for (int i = 0; i < topLevelOnly.Count; i++) { topLevelOnly[i] = FlatRedBall.IO.FileManager.RemoveDotDotSlash(topLevelOnly[i]); } var referenceInfo = new FileReferenceInformation { LastWriteTime = File.Exists(standardized) ? File.GetLastWriteTime(standardized) : DateTime.MinValue, References = topLevelOnly }; try { fileReferences[standardized] = referenceInfo; } catch (Exception e) { int m = 3; throw e; } if (FilesWithFailedGetReferenceCalls.ContainsKey(absoluteName)) { FilesWithFailedGetReferenceCalls.Remove(absoluteName); } } else { FilesWithFailedGetReferenceCalls[absoluteName] = response; // todo - need to raise an event here on parse error: PluginManager.HandleFileReadError(absoluteName, response); } } } // topLevelOnly could be null if a file wasn't found if (topLevelOnly != null) { var newFiles = topLevelOnly.Except(listToFill).ToList(); listToFill.AddRange(newFiles); if (topLevelOrRecursive == TopLevelOrRecursive.Recursive) { foreach (var item in newFiles) { GetFilesReferencedBy(item, TopLevelOrRecursive.Recursive, listToFill); } } } }