public static void AddFiles(TreeNode parentNode, ArchiveRootNodeWrapper rootNode, string[] Files) { var archiveFile = rootNode.ArchiveFile; if (Files == null || Files.Length <= 0 || !archiveFile.CanAddFiles) { return; } for (int i = 0; i < Files.Length; i++) { var File = ArchiveFileWrapper.FromPath(Files[i], rootNode); string FileName = Path.GetFileName(Files[i]); //Don't add the root file name if (parentNode.FullPath != string.Empty && !(parentNode is ArchiveRootNodeWrapper)) { string nodePath = parentNode.FullPath; int startIndex = nodePath.IndexOf(rootNode.Text); if (startIndex > 0) { nodePath = nodePath.Substring(startIndex); } string slash = Path.DirectorySeparatorChar.ToString(); string slashAlt = Path.AltDirectorySeparatorChar.ToString(); string SetPath = nodePath.Replace(rootNode.Text + slash, string.Empty).Replace(slash ?? "", slashAlt); string FullPath = Path.Combine(SetPath, FileName).Replace(slash ?? "", slashAlt); File.ArchiveFileInfo.FileName = FullPath; } else { File.ArchiveFileInfo.FileName = FileName; } bool HasAddedFile = archiveFile.AddFile(File.ArchiveFileInfo); if (HasAddedFile) { //Re apply the newly added archive info File.ArchiveFileInfo = archiveFile.Files.LastOrDefault(); parentNode.Nodes.Add(File); if (parentNode is ArchiveRootNodeWrapper) { ((ArchiveRootNodeWrapper)parentNode).AddFileNode(File); } if (parentNode is ArchiveFolderNodeWrapper) { ((ArchiveFolderNodeWrapper)parentNode).RootNode.AddFileNode(File); } } } }
public static void RemoveFile(ArchiveFileWrapper fileNode, IArchiveFile archiveFile) { if (!archiveFile.CanDeleteFiles) return; var parentNode = fileNode.Parent; bool HasRemovedFile = archiveFile.DeleteFile(fileNode.ArchiveFileInfo); if (HasRemovedFile) parentNode.Nodes.Remove(fileNode); }
public void AddFileNode(ArchiveFileWrapper fileWrapper) { FileNodes.Add(Tuple.Create(fileWrapper.ArchiveFileInfo, (TreeNode)fileWrapper)); string FullName = SetFullPath(fileWrapper, this); if (FullName != string.Empty) { Console.WriteLine($"Updating info {FullName}"); fileWrapper.ArchiveFileInfo.FileName = FullName; } }
public static void ReplaceNode(TreeNode node, TreeView treeview, ArchiveFileWrapper replaceNode, TreeNode NewNode, ArchiveRootNodeWrapper rootNode) { if (NewNode == null) { return; } var fileInfo = replaceNode.ArchiveFileInfo; int index = 0; if (node == null) { index = treeview.Nodes.IndexOf(replaceNode); treeview.Nodes.RemoveAt(index); treeview.Nodes.Insert(index, NewNode); } else { index = node.Nodes.IndexOf(replaceNode); node.Nodes.RemoveAt(index); node.Nodes.Insert(index, NewNode); } NewNode.ImageKey = replaceNode.ImageKey; NewNode.SelectedImageKey = replaceNode.SelectedImageKey; NewNode.Text = replaceNode.Text; NewNode.Tag = fileInfo; rootNode.FileNodes.RemoveAt(index); rootNode.FileNodes.Insert(index, Tuple.Create(fileInfo, NewNode)); if (NewNode is ISingleTextureIconLoader) { ObjectEditor editor = LibraryGUI.GetObjectEditor(); if (editor != null) //The editor isn't always in object editor so check { editor.UpdateTextureIcon((ISingleTextureIconLoader)NewNode); } } }
private void FillDirectory(TreeNode parent, IEnumerable <INode> Nodes, IArchiveFile archiveFile) { foreach (var node in Nodes) { if (node is IDirectoryContainer) { var folder = new ArchiveFolderNodeWrapper(node.Name, archiveFile, this); parent.Nodes.Add(folder); if (((IDirectoryContainer)node).Nodes != null) { FillDirectory(folder, ((IDirectoryContainer)node).Nodes, archiveFile); } } else if (node is ArchiveFileInfo) { ArchiveFileWrapper wrapperFile = new ArchiveFileWrapper(node.Name, (ArchiveFileInfo)node, this); wrapperFile.Name = node.Name; parent.Nodes.Add(wrapperFile); AddFileNode(wrapperFile); } } }
private void FillTreeNodes(TreeNode root, IArchiveFile archiveFile) { Nodes.Clear(); var rootText = root.Text; var rootTextLength = rootText.Length; var nodeFiles = archiveFile.Files; if (archiveFile is IDirectoryContainer) { FillDirectory(root, ((IDirectoryContainer)archiveFile).Nodes, archiveFile); } else //Else create directories by filename paths { foreach (var node in archiveFile.Files) { if (!node.CanLoadFile) { continue; } if (!((IFileFormat)archiveFile).IFileInfo.InArchive && File.Exists(((IFileFormat)archiveFile).FilePath)) { node.SourceFile = ((IFileFormat)archiveFile).FilePath; } string nodeString = node.FileName; var roots = nodeString.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); // The initial parent is the root node var parentNode = root; var sb = new System.Text.StringBuilder(rootText, nodeString.Length + rootTextLength); for (int rootIndex = 0; rootIndex < roots.Length; rootIndex++) { // Build the node name var parentName = roots[rootIndex]; sb.Append("/"); sb.Append(parentName); var nodeName = sb.ToString(); // Search for the node var index = parentNode.Nodes.IndexOfKey(nodeName); if (index == -1) { // Node was not found, add it var folder = new ArchiveFolderNodeWrapper(parentName, archiveFile, this); if (rootIndex == roots.Length - 1) { ArchiveFileWrapper wrapperFile = new ArchiveFileWrapper(parentName, node, this); wrapperFile.Name = nodeName; parentNode.Nodes.Add(wrapperFile); parentNode = wrapperFile; AddFileNode(wrapperFile); } else { folder.Name = nodeName; parentNode.Nodes.Add(folder); parentNode = folder; } } else { // Node was found, set that as parent and continue parentNode = parentNode.Nodes[index]; } } } } }