Example #1
0
        public System.Collections.IEnumerable GetChildren(TreePath treePath)
        {
            const string FragmentArchiveDirectoryRoot = "game/xleres/";

            string          basePath = null;
            BaseItem        parent   = null;
            List <BaseItem> items    = null;

            if (treePath.IsEmpty())
            {
                if (_cache.ContainsKey("ROOT"))
                {
                    items = _cache["ROOT"];
                }
                else
                {
                    basePath = FragmentArchiveDirectoryRoot;
                }
            }
            else
            {
                parent = treePath.LastNode as BaseItem;
                if (parent != null)
                {
                    basePath = parent.ItemPath;
                }
            }

            if (basePath != null)
            {
                if (_cache.ContainsKey(basePath))
                {
                    items = _cache[basePath];
                }
                else
                {
                    items = new List <BaseItem>();
                    var fileAttributes = File.GetAttributes(basePath);
                    if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        // It's a directory...
                        //          Try to find the files within and create child nodes
                        try
                        {
                            foreach (string str in Directory.GetDirectories(basePath))
                            {
                                items.Add(new FolderItem(str, parent, this));
                            }
                            foreach (string str in Directory.GetFiles(basePath))
                            {
                                var extension = Path.GetExtension(str);
                                if (extension.Equals(".shader", StringComparison.CurrentCultureIgnoreCase) ||
                                    extension.Equals(".h", StringComparison.CurrentCultureIgnoreCase) ||
                                    extension.Equals(".vsh", StringComparison.CurrentCultureIgnoreCase) ||
                                    extension.Equals(".psh", StringComparison.CurrentCultureIgnoreCase) ||
                                    extension.Equals(".gsh", StringComparison.CurrentCultureIgnoreCase) ||
                                    extension.Equals(".sh", StringComparison.CurrentCultureIgnoreCase)
                                    )
                                {
                                    var sfi = new ShaderFileItem(str, parent, this);
                                    sfi.FileName = Path.GetFileName(str);
                                    items.Add(sfi);
                                }

                                /*else if (extension.Equals(".param", StringComparison.CurrentCultureIgnoreCase))
                                 * {
                                 *  items.Add(new ParameterItem(str, parent, this));
                                 * }*/
                            }
                        }
                        catch (IOException)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        // It's a file. Let's try to parse it as a shader file and get the information within
                        var fragment = ShaderFragmentArchive.Archive.GetFragment(basePath);

                        ShaderFileItem sfi = (ShaderFileItem)parent;
                        sfi.ExceptionString = fragment.ExceptionString;

                        foreach (var f in fragment.Functions)
                        {
                            ShaderFragmentItem fragItem = new ShaderFragmentItem(parent, this);
                            fragItem.FunctionName = f.Name;
                            if (f.Outputs.Count != 0)
                            {
                                fragItem.ReturnType = f.Outputs[0].Type;
                            }
                            fragItem.Parameters  = f.BuildParametersString();
                            fragItem.ArchiveName = basePath + ":" + f.Name;
                            items.Add(fragItem);
                        }

                        foreach (var p in fragment.ParameterStructs)
                        {
                            ParameterStructItem paramItem = new ParameterStructItem(parent, this);
                            paramItem.StructName  = p.Name;
                            paramItem.Parameters  = p.BuildBodyString();
                            paramItem.ArchiveName = basePath + ":" + p.Name;
                            items.Add(paramItem);
                        }

                        fragment.ChangeEvent += new ShaderFragmentArchive.ChangeEventHandler(OnStructureChanged);
                    }
                    _cache.Add(basePath, items);
                    _itemsToRead.AddRange(items);
                    if (!_worker.IsBusy)
                    {
                        _worker.RunWorkerAsync();
                    }
                }
            }
            return(items);
        }
		public System.Collections.IEnumerable GetChildren(TreePath treePath)
		{
            const string FragmentArchiveDirectoryRoot = "game/xleres/";

            string basePath = null;
            BaseItem parent = null;
            List<BaseItem> items = null;
            if (treePath.IsEmpty())
            {
                if (_cache.ContainsKey("ROOT"))
                    items = _cache["ROOT"];
                else
                {
                    basePath = FragmentArchiveDirectoryRoot;
                }
            }
            else
            {
                parent = treePath.LastNode as BaseItem;
                if (parent != null)
                {
                    basePath = parent.ItemPath;
                }
            }

            if (basePath!=null) 
            {
                if (_cache.ContainsKey(basePath))
                    items = _cache[basePath];
                else
                {
                    items = new List<BaseItem>(); 
                    var fileAttributes = File.GetAttributes(basePath);
                    if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                            // It's a directory... 
                            //          Try to find the files within and create child nodes
                        try
                        {
                            foreach (string str in Directory.GetDirectories(basePath))
                                items.Add(new FolderItem(str, parent, this));
                            foreach (string str in Directory.GetFiles(basePath))
                            {
                                var extension = Path.GetExtension(str);
                                if (extension.Equals(".shader", StringComparison.CurrentCultureIgnoreCase)
                                    || extension.Equals(".h", StringComparison.CurrentCultureIgnoreCase)
                                    || extension.Equals(".vsh", StringComparison.CurrentCultureIgnoreCase)
                                    || extension.Equals(".psh", StringComparison.CurrentCultureIgnoreCase)
                                    || extension.Equals(".gsh", StringComparison.CurrentCultureIgnoreCase)
                                    || extension.Equals(".sh", StringComparison.CurrentCultureIgnoreCase)
                                    || extension.Equals(".tech", StringComparison.CurrentCultureIgnoreCase)
                                    || extension.Equals(".hlsl", StringComparison.CurrentCultureIgnoreCase)
                                    )
                                {
                                    var sfi = new ShaderFileItem(str, parent, this);
                                    sfi.FileName = Path.GetFileName(str);
                                    items.Add(sfi);
                                }
                                /*else if (extension.Equals(".param", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    items.Add(new ParameterItem(str, parent, this));
                                }*/
                            }
                        }
                        catch (IOException)
                        {
                            return null;
                        }
                    }
                    else
                    {
                            // It's a file. Let's try to parse it as a shader file and get the information within
                        var fragment = _archive.GetFragment(basePath);

                        ShaderFileItem sfi = (ShaderFileItem)parent;
                        sfi.ExceptionString = fragment.ExceptionString;

                        foreach (var f in fragment.Functions)
                        {
                            ShaderFragmentItem fragItem = new ShaderFragmentItem(parent, this);
                            fragItem.FunctionName = f.Name;
                            if (f.Outputs.Count!=0)
                                fragItem.ReturnType = f.Outputs[0].Type;
                            fragItem.Parameters = f.BuildParametersString();
                            fragItem.ArchiveName = basePath + ":" + f.Name;
                            items.Add(fragItem);
                        }

                        foreach (var p in fragment.ParameterStructs)
                        {
                            ParameterStructItem paramItem = new ParameterStructItem(parent, this);
                            paramItem.StructName = p.Name;
                            paramItem.Parameters = p.BuildBodyString();
                            paramItem.ArchiveName = basePath + ":" + p.Name;
                            items.Add(paramItem);
                        }

                            // Need to hold a pointer to this fragment, to prevent it from being cleaned up
                            // The archive can sometimes delete and recreate the fragment (and in those
                            // cases, the new fragment won't have our callbacks)
                        fragment.ChangeEvent += OnStructureChanged; 
                        AttachedFragments.Add(fragment);
                    }
                    _cache.Add(basePath, items);
                    _itemsToRead.AddRange(items);
                    if (!_worker.IsBusy)
                        _worker.RunWorkerAsync();
                }
            }
            return items;
		}