public override void OnDoubleMouseClick(TreeView treeview) { IFileFormat file = OpenFile(); if (file == null) //Format not supported so return { return; } if (Utils.HasInterface(file.GetType(), typeof(IEditor <>))) { } else if (file is IArchiveFile) { var FileRoot = new ArchiveRootNodeWrapper(file.FileName, (IArchiveFile)file); FileRoot.FillTreeNodes(); if (file is TreeNode) //It can still be both, so add all it's nodes { foreach (TreeNode n in ((TreeNode)file).Nodes) { FileRoot.Nodes.Add(n); } } ReplaceNode(this.Parent, this, FileRoot); } else if (file is TreeNode) { ReplaceNode(this.Parent, this, (TreeNode)file); } }
public static ArchiveFileWrapper FromPath(string FilePath, ArchiveRootNodeWrapper rootNode) { var ArchiveFileInfo = new ArchiveFileInfo(); ArchiveFileInfo.FileName = FilePath; ArchiveFileInfo.FileData = File.ReadAllBytes(FilePath); return(new ArchiveFileWrapper(Path.GetFileName(FilePath), ArchiveFileInfo, rootNode)); }
public ArchiveFolderNodeWrapper(string text, IArchiveFile archiveFile, ArchiveRootNodeWrapper root) : base(archiveFile) { RootNode = root; Text = text; PropertyDisplay = new GenericFolderProperties(); ((GenericFolderProperties)PropertyDisplay).Name = Text; // ReloadMenus(archiveFile); }
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 ArchiveFileWrapper(string text, ArchiveFileInfo archiveFileInfo, ArchiveRootNodeWrapper rootNode) : base(rootNode.ArchiveFile) { Text = text; RootNode = rootNode; // ReloadMenus(archiveFile); ArchiveFileInfo = archiveFileInfo; string Extension = Utils.GetExtension(text); if (ArchiveFileInfo.CheckFileMagic) { Extension = FindMatch(archiveFileInfo.FileData); } switch (Extension) { case ".bntx": SetImageKey("bntx"); break; case ".byaml": SetImageKey("byaml"); break; case ".byml": SetImageKey("byaml"); break; case ".aamp": SetImageKey("aamp"); break; case ".bfres": SetImageKey("bfres"); break; case ".sbfres": SetImageKey("sbfres"); break; case ".gfbmdl": SetImageKey("model"); break; case ".dds": case ".tga": case ".jpg": case ".jpeg": case ".tiff": case ".png": case ".gif": case ".astc": SetImageKey("texture"); break; default: SetImageKey("fileBlank"); break; } if (ArchiveFileInfo.ExtensionImageKeyLookup != null) { if (ArchiveFileInfo.ExtensionImageKeyLookup.ContainsKey(Extension)) { SetImageKey(ArchiveFileInfo.ExtensionImageKeyLookup[Extension]); } } }
public static string GetFolderAbsoultePath(TreeNode node, ArchiveRootNodeWrapper rootNode) { string nodePath = node.FullPath; int startIndex = nodePath.IndexOf(rootNode.Text); if (startIndex > 0) { nodePath = nodePath.Substring(startIndex); } string slash = Path.DirectorySeparatorChar.ToString(); string slashAlt = Path.AltDirectorySeparatorChar.ToString(); return(nodePath.Replace(rootNode.Text + slash, string.Empty).Replace(slash ?? "", slashAlt)); }
public void OpenFileFormat(TreeView treeview) { IFileFormat file = ArchiveFileInfo.OpenFile(); if (file == null) //Format not supported so return { return; } if (file.IFileInfo != null) { file.IFileInfo.ArchiveParent = ArchiveFile; } if (Utils.HasInterface(file.GetType(), typeof(IEditor <>))) { OpenControlDialog(file); } else if (Utils.HasInterface(file.GetType(), typeof(IEditorForm <>))) { OpenFormDialog(file); } else if (file is IArchiveFile) { var FileRoot = new ArchiveRootNodeWrapper(file.FileName, (IArchiveFile)file); FileRoot.FillTreeNodes(); if (file is TreeNode) //It can still be both, so add all it's nodes { foreach (TreeNode n in ((TreeNode)file).Nodes) { FileRoot.Nodes.Add(n); } } ReplaceNode(this.Parent, treeview, this, FileRoot, RootNode); } else if (file is TreeNode) { ReplaceNode(this.Parent, treeview, this, (TreeNode)file, RootNode); } ArchiveFileInfo.FileFormat = file; }
public GenericArchiveProperties(IArchiveFile archiveFile, string text, ArchiveRootNodeWrapper root) { ArchiveFile = archiveFile; Name = text; rootNode = root; }
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); } } }