示例#1
0
        /// <summary>
        /// Adds a node to the tree based on the passed file information. This is useful when building a directory-based tree.
        /// </summary>
        /// <param name="file">File entry.</param>
        public void AddFileNode(PackageEntry file)
        {
            TreeNode currentNode = null;

            if (file.DirectoryName != null)
            {
                var subPaths = file.DirectoryName.Split(Package.DirectorySeparatorChar);

                foreach (var subPath in subPaths)
                {
                    if (currentNode == null)
                    {
                        currentNode = Nodes[subPath] ?? Nodes.Add(subPath, subPath, @"_folder", @"_folder");
                    }
                    else
                    {
                        currentNode = currentNode.Nodes[subPath] ?? currentNode.Nodes.Add(subPath, subPath, @"_folder", @"_folder");
                    }

                    currentNode.Tag = new TreeViewFolder(file.DirectoryName, currentNode.Nodes.Count + 1); //is this enough?
                }
            }

            var fileName = file.GetFileName();
            var ext      = ExtensionIconList[file.TypeName];

            if (currentNode == null)
            {
                currentNode = Nodes.Add(fileName, fileName, ext, ext);
            }
            else
            {
                currentNode = currentNode.Nodes.Add(fileName, fileName, ext, ext);
            }

            currentNode.Tag = file; //so we can use it later
        }
        /// <summary>
        /// Adds a node to the tree based on the passed file information. This is useful when building a directory-based tree.
        /// </summary>
        /// <param name="currentNode">Root node.</param>
        /// <param name="file">File entry.</param>
        /// <param name="vpkFileName">Name of the current vpk file.</param>
        public void AddFileNode(TreeNode currentNode, PackageEntry file, string vpkFileName)
        {
            if (!string.IsNullOrWhiteSpace(file.DirectoryName))
            {
                var subPaths = file.DirectoryName.Split(Package.DirectorySeparatorChar);

                foreach (var subPath in subPaths)
                {
                    currentNode     = currentNode.Nodes[subPath] ?? currentNode.Nodes.Add(subPath, subPath, @"_folder", @"_folder");
                    currentNode.Tag = new TreeViewFolder(file.DirectoryName, currentNode.Nodes.Count + 1); //is this enough?
                }
            }

            var fileName = file.GetFileName();
            var ext      = ExtensionIconList[file.TypeName];

            currentNode     = currentNode.Nodes.Add(fileName, fileName, ext, ext);
            currentNode.Tag = file; //so we can use it later

            var tooltip = new StringBuilder();

            tooltip.AppendLine($"Path: {file.GetFullPath()}");
            tooltip.AppendLine($"Offset: {file.Offset}");
            tooltip.AppendLine($"Size: {file.TotalLength}");

            if (file.SmallData.Length > 0)
            {
                tooltip.AppendLine($"Small data length: {file.SmallData.Length}");
            }

            if (file.ArchiveIndex != 0x7FFF)
            {
                tooltip.AppendLine($"Archive: {vpkFileName}_{file.ArchiveIndex:000}.vpk");
            }

            currentNode.ToolTipText = tooltip.ToString();
        }
        /// <summary>
        /// Adds a node to the tree based on the passed file information. This is useful when building a directory-based tree.
        /// </summary>
        /// <param name="file">File entry.</param>
        public void AddFileNode(PackageEntry file)
        {
            TreeNode currentNode = null;

            if (file.DirectoryName != null)
            {
                var subPaths = file.DirectoryName.Split(Package.DirectorySeparatorChar);

                foreach (var subPath in subPaths)
                {
                    if (currentNode == null)
                    {
                        currentNode = Nodes[subPath] ?? Nodes.Add(subPath, subPath, @"_folder", @"_folder");
                    }
                    else
                    {
                        currentNode = currentNode.Nodes[subPath] ?? currentNode.Nodes.Add(subPath, subPath, @"_folder", @"_folder");
                    }

                    currentNode.Tag = new TreeViewFolder(file.DirectoryName, currentNode.Nodes.Count + 1); //is this enough?
                }
            }

            var fileName = file.GetFileName();
            var ext = ExtensionIconList[file.TypeName];

            if (currentNode == null)
            {
                currentNode = Nodes.Add(fileName, fileName, ext, ext);
            }
            else
            {
                currentNode = currentNode.Nodes.Add(fileName, fileName, ext, ext);
            }

            currentNode.Tag = file; //so we can use it later
        }