Example #1
0
        private static string GetFilenameForNode(ScriptNode node)
        {
            var iterableWorkingObject = (INameSpaceNode)node;
            var filename = iterableWorkingObject.GetName();

            {
                INameSpaceNode tmp = iterableWorkingObject;
                while (!tmp.GetName().EndsWith(".img"))
                {
                    tmp      = (INameSpaceNode)tmp.GetParent();
                    filename = tmp.GetName().Replace(".img", "") + "_" + filename;
                }
            }
            return(filename);
        }
Example #2
0
        public object ActualObject(bool recursiveResolve = false)
        {
            // Go backwards
            var    elements = Path.Split('/');
            object curNode  = this.Parent;

            if (Absolute)
            {
                // Lets go all the way back to the root of the filesystem
                while (true)
                {
                    INameSpaceNode lastNonNullNode = (INameSpaceNode)curNode;

                    // PcomObject -> PcomObject -> WzFileProperty -> NameSpaceNode -> ... -> null

                    curNode = (INameSpaceNode)lastNonNullNode.GetParent();
                    if (curNode == null)
                    {
                        curNode = lastNonNullNode;
                        break;
                    }
                }
            }

            foreach (var element in elements)
            {
                if (element == ".")
                {
                    continue;
                }
                if (element == "..")
                {
                    curNode = ((INameSpaceNode)curNode).GetParent();
                }
                else
                {
                    if (curNode is INameSpaceNode cn)
                    {
                        curNode = cn.GetChild(element);
                    }
                    else if (curNode == null)
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception($"Unable to traverse {curNode?.GetType().FullName ?? "null"} ({curNode}) at {element}");
                    }


                    if (curNode == null)
                    {
                        return(null);
                    }
                }
            }

            if (recursiveResolve && curNode is WzUOL secondUol)
            {
                curNode = secondUol.ActualObject();
            }

            return(curNode);
        }