void OnViewReferencedFilesClick(object sender, EventArgs e) { List <string> allFiles = null; bool didErrorOccur = false; string errorText = null; try { allFiles = ContentParser.GetFilesReferencedByAsset(mLastFileName, TopLevelOrRecursive.Recursive); } catch (Exception exc) { didErrorOccur = true; errorText = e.ToString(); } if (didErrorOccur) { MessageBox.Show("Could not track references because of a missing file: " + errorText); } else { string message = "Referenced files:\n"; foreach (string file in allFiles) { message += file + "\n"; } MessageBox.Show(message); } }
public void GetFilesReferencedBy(string file, EditorObjects.Parsing.TopLevelOrRecursive depth, List <string> listToFill) { if (CanFileReferenceContent(file)) { listToFill.AddRange( ContentParser.GetFilesReferencedByAsset(file)); } }
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); }
void OnViewReferencedFilesClick(object sender, EventArgs e) { List <string> allFiles = ContentParser.GetFilesReferencedByAsset(mLastFileName, TopLevelOrRecursive.Recursive); string message = "Referenced files:\n"; foreach (string file in allFiles) { message += file + "\n"; } MessageBox.Show(message); }
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 static void MoveReferencedFileToDirectory(ReferencedFileSave referencedFileSave, string targetDirectory) { // Things to do: // 1 Move the TreeNode from one parent TreeNode to another UPDATE: We will just refresh the UI for the Element or GlobalContent // 2 Move the file from one folder to another // 3 Remove the BuildItems from the project and add them back in the VisualStudio project // 4 Change the ReferencedFileSave's name // 5 Re-generate the containing Element (Screen or Entity) // 6 Save everything string oldNodeText = referencedFileSave.Name.Replace("/", "\\"); string newNodeText = FlatRedBall.IO.FileManager.MakeRelative(targetDirectory, ProjectManager.ProjectBase.GetAbsoluteContentFolder()) + FileManager.RemovePath(referencedFileSave.Name); newNodeText = newNodeText.Replace("/", "\\"); string oldFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name, true); string targetFile = targetDirectory + FileManager.RemovePath(oldFileName); bool canMove = true; // There's so much error checking and validation that we // could/should do here, but man, I just can't spend forever // on it because I need to get the game I'm working on moving forward // But I'm going to at least improve it a little bit by having the referenced // files get copied over. Dictionary <string, string> mOldNewDependencyFileDictionary = new Dictionary <string, string>(); List <string> referencedFiles = ContentParser.GetFilesReferencedByAsset(oldFileName, TopLevelOrRecursive.Recursive); string oldDirectoryFull = FileManager.GetDirectory(oldFileName); foreach (string file in referencedFiles) { string relativeToRfs = FileManager.MakeRelative(file, FileManager.GetDirectory(oldFileName)); string targetReferencedFileName = targetDirectory + relativeToRfs; mOldNewDependencyFileDictionary.Add(file, targetReferencedFileName); if (!FileManager.IsRelativeTo(targetReferencedFileName, targetDirectory)) { MessageBox.Show("The file\n\n" + file + "\n\nis not relative to the file being moved, so it cannot be moved. You must manually move these files and manually update the file reference."); canMove = false; break; } } if (canMove && File.Exists(targetFile)) { MessageBox.Show("There is already a file by this name located in the directory you're trying to move to."); canMove = false; } if (canMove) { foreach (KeyValuePair <string, string> kvp in mOldNewDependencyFileDictionary) { if (File.Exists(kvp.Value)) { MessageBox.Show("Can't move the file because a dependency will be moved to\n\n" + kvp.Value + "\n\nand a file already exists there."); canMove = false; break; } } } if (canMove) { // 1 Move the TreeNode from one parent TreeNode to another //treeNodeMoving.Parent.Nodes.Remove(treeNodeMoving); //targetNode.Nodes.Add(treeNodeMoving); // This is updated at the bottom of this method // In case it doesn't exist System.IO.Directory.CreateDirectory(FileManager.GetDirectory(targetFile)); // 2 Move the file from one folder to another File.Move(oldFileName, targetFile); foreach (KeyValuePair <string, string> kvp in mOldNewDependencyFileDictionary) { File.Move(kvp.Key, kvp.Value); } // 3 Remove the BuildItems from the project and add them back in the VisualStudio project ProjectBase projectBase = ProjectManager.ProjectBase; if (ProjectManager.ContentProject != null) { projectBase = ProjectManager.ContentProject; } ProjectManager.RemoveItemFromProject(projectBase, oldNodeText, false); projectBase.AddContentBuildItem(targetFile); foreach (KeyValuePair <string, string> kvp in mOldNewDependencyFileDictionary) { string fileFileRelativeToProject = FileManager.MakeRelative(kvp.Key, projectBase.Directory); ProjectManager.RemoveItemFromProject(projectBase, fileFileRelativeToProject, false); projectBase.AddContentBuildItem(kvp.Value); } // TODO: This should also check to see if something else is referencing this content. // I'm going to write it to not make this check now since I'm just getting the initial system set up // 4 Change the ReferencedFileSave's name referencedFileSave.SetNameNoCall(newNodeText.Replace("\\", "/")); // No need for this, it'll get updated automatically // treeNodeMoving.Text = newNodeText; // 5 Re-generate the containing Element (Screen or Entity) if (EditorLogic.CurrentElement != null) { CodeWriter.GenerateCode(EditorLogic.CurrentElement); } else { GlobalContentCodeGenerator.UpdateLoadGlobalContentCode(); } // The new 1: Update if (EditorLogic.CurrentElement != null) { EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); } else { ElementViewWindow.UpdateGlobalContentTreeNodes(false); } // 6 Save everything GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); } }
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); } } } }