public virtual bool InsertReference(FileEntry fileEntry, bool optional = false)
        {
            LeafNode[] matches = FindAll <LeafNode>(l =>
            {
                if (l.NodeType == RefsNodesType.File ||
                    l.InOptionalBlock() != optional ||
                    l.GetPathSource() != fileEntry.PathSource)
                {
                    return(false);
                }
                string relativePath = l.GetRelativePath();
                if (fileEntry.Fullname.StartsWith(relativePath))
                {
                    return(true);
                }
                return(false);
            });
            LeafNode bestMatch = matches.OrderByDescending(l => l.GetRelativePath().Length).FirstOrDefault();

            if (bestMatch != null)
            {
                for (int i = 0; i < bestMatch.Count; i++)
                {
                    if (bestMatch[i].Count > 0)
                    {
                        bestMatch.AddFile(fileEntry);
                        return(true);
                    }
                }
            }
            else
            {
                RootNode    rootNode           = this as RootNode;
                CommandNode matchedCommandNode = this as CommandNode;
                if (rootNode != null)
                {
                    matchedCommandNode = rootNode.FindAll <CommandNode>(c => c.GetPathSource() == fileEntry.PathSource && c.InOptionalBlock() == optional, 2).FirstOrDefault();
                    if (matchedCommandNode == null)
                    {
                        return(false);
                    }
                }
                string[] pathParts = fileEntry.Fullname.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                if (pathParts.Length == 1)
                {
                    matchedCommandNode.Insert(0, new FileNode(fileEntry.Fullname, fileEntry));
                    return(true);
                }
                RefsNode current = matchedCommandNode;
                for (int i = 0; i < pathParts.Length - 1; i++)
                {
                    LeafNode newLeaf = new LeafNode(pathParts[i] + "/");
                    current.Add(newLeaf);
                    current = newLeaf;
                }
                if (current is LeafNode leaf)
                {
                    leaf.AddFile(fileEntry);
                    return(true);
                }
            }
            return(false);
        }