Пример #1
0
        public void LoadArchive(NexonArchive narFile)
        {
            Nodes.Clear();

            if (narFile == null)
            {
                return;
            }

            TreeNode rootNode = new TreeNode("(NAR File)");

            foreach (NexonArchiveFileEntry entry in narFile.FileEntries)
            {
                TreeNode node = FolderTreeView.FindOrCreateNodePath(rootNode, Path.GetDirectoryName(entry.Path));

                if (!(node.Tag is IList <NexonArchiveFileEntry> nodeList))
                {
                    nodeList = new List <NexonArchiveFileEntry>();
                    node.Tag = nodeList;
                }
                nodeList.Add(entry);
            }
            rootNode.Expand();
            Nodes.Add(rootNode);
            SelectedNode = rootNode;
        }
Пример #2
0
        private static TreeNode FindOrCreateNodePath(TreeNode rootNode, string path)
        {
            if (path.Length == 0)
            {
                return(rootNode);
            }

            int startIndex = 0;

            while (path[startIndex] == '/' || path[startIndex] == '\\')
            {
                startIndex++;
            }

            int separatorIndex = path.IndexOfAny(new char[] { '/', '\\' }, startIndex);

            string name;

            if (separatorIndex >= 0)
            {
                name = path.Substring(startIndex, separatorIndex - startIndex);
            }
            else
            {
                name = path.Substring(startIndex);
            }

            TreeNode finalNode = null;

            foreach (object obj in rootNode.Nodes)
            {
                TreeNode node = (TreeNode)obj;
                if (string.Compare(node.Name, name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    finalNode = node;
                    break;
                }
            }

            if (finalNode == null)
            {
                finalNode      = new TreeNode(name);
                finalNode.Name = name;
                rootNode.Nodes.Add(finalNode);
            }

            if (separatorIndex >= 0)
            {
                return(FolderTreeView.FindOrCreateNodePath(finalNode, path.Substring(separatorIndex + 1)));
            }

            return(finalNode);
        }