示例#1
0
            public GraphNode(ResourceGraph graph, IResourceKey originalKey, IResourceNode core,
                             PathPackageTuple origin, ResourceDataActions nodeActions, RFileType fileType = RFileType.Unknown)
            {
                this.Graph        = graph;
                this.key          = new RK(originalKey);
                this.OriginalKey  = new RK(originalKey);
                this.ExtensionTag = s3pi.Extensions.ExtList.Ext[originalKey.ResourceType][0];
                this.NodeActions  = nodeActions;
                this.Core         = core;
                this.Origin       = origin;
                if (fileType == RFileType.Unknown)
                {
                    this.fileType = ResourceGraph.GetFileType(originalKey.ResourceType);
                }
                else
                {
                    this.fileType = fileType;
                }
                switch (this.fileType)
                {
                case RFileType.Game:
                    this.name = NameMap.GameNMap.GetName(originalKey.Instance, origin);
                    break;

                case RFileType.DDS:
                    this.name = NameMap.DDSNMap.GetName(originalKey.Instance, origin);
                    break;

                case RFileType.Thum:
                    this.name = NameMap.ThumNMap.GetName(originalKey.Instance, origin);
                    break;
                }
                this.originalName = this.name;
            }
示例#2
0
 public RFile(string fullName)
 {
     Folder = "";
     Name = "";
     extension = "";
     Type = RFileType.File;
     Size = 0;
     Id = 0;
     obj = null;
     FullName = fullName;
 }
示例#3
0
        private void CreateChildren(GraphNode graphNode, object constraints)
        {
            string                     graphNodeKeyStr = PrintRKTag(graphNode.OriginalKey, graphNode.ExtensionTag);
            int                        i, j, k, count, foundIndex;
            GraphNode                  childNode;
            GraphConnectionRef         childConnection;
            IResourceConnection        child;
            IResourceKey               childKey;
            List <IResourceConnection> children = graphNode.Core.SlurpConnections(constraints);

            count = (children == null) ? 0 : children.Count;
            Diagnostics.Log("Resolving " + count + " RK Refs from " + graphNodeKeyStr);
            for (i = 0; i < count; i++)
            {
                child           = children[i];
                childKey        = child.OriginalChildKey;
                childConnection = new GraphConnectionRef(this, graphNode, child);
                childNode       = null;
                // Try to find an already existing child node in the lookup table.
                foundIndex = -1;
                for (j = 0; j < this.nodeLookupTable.Count && foundIndex < 0; j++)
                {
                    if (this.nodeLookupTable[j].OriginalKey.Equals(childKey))
                    {
                        foundIndex = j;
                    }
                }
                if (foundIndex >= 0 && !child.AlwaysCreateChild)
                {
                    childNode = this.nodeLookupTable[foundIndex];
                }
                else
                {
                    RFileType        fileType  = RFileType.Game;
                    SpecificResource sr        = null;
                    IResourceNode    childCore = null;
                    if (child.ChildDataActions < ResourceDataActions.Find)
                    {
                        childCore = child.CreateChild(null, constraints);
                    }
                    else
                    {
                        List <PathPackageTuple> searchList;// = child.IsChildDDS ? FileTable.DDSImages :
                        //child.IsChildThum ? FileTable.Thumbnails : FileTable.GameContent;
                        if (child.IsChildDDS)
                        {
                            fileType   = RFileType.DDS;
                            searchList = FileTable.DDSImages;
                        }
                        else if (child.IsChildThum)
                        {
                            fileType   = RFileType.Thum;
                            searchList = FileTable.Thumbnails;
                        }
                        else
                        {
                            fileType   = RFileType.Game;
                            searchList = FileTable.GameContent;
                        }
                        sr = new SpecificResource(searchList, child.OriginalChildKey);
                        if (sr.ResourceIndexEntry == null || sr.Resource == null)
                        {
                            Diagnostics.Log("Unresolved RK Ref:" + PrintRKRef(childKey, child.AbsolutePath)
                                            + ((sr.Exception == null) ? "" :
                                               string.Concat(" Error:\r\n", sr.Exception.ToString())));
                        }
                        else
                        {
                            childCore = child.CreateChild(sr.Resource, constraints);
                        }
                    }
                    if (childCore == null)
                    {
                        Diagnostics.Log("CreateChild Failed:" + PrintRKRef(childKey, child.AbsolutePath));
                    }
                    else
                    {
                        childNode = new GraphNode(this, childKey, childCore,
                                                  sr == null ? null : sr.PathPackage, child.ChildDataActions, fileType);
                        if (child.AlwaysCreateChild && foundIndex >= 0)
                        {
                            Diagnostics.Log("Dup Ref Node Added:" + PrintRKRef(childKey, child.AbsolutePath));
                            this.nodeDuplicates.Add(childNode);
                        }
                        else
                        {
                            Diagnostics.Log("New Ref Node Added:" + PrintRKRef(childKey, child.AbsolutePath));
                            this.nodeLookupTable.Add(childNode);
                        }
                        CreateChildren(childNode, constraints);
                    }
                }
                if (childNode != null)
                {
                    graphNode.ChildConnections.Add(childConnection);
                    childConnection.Child = childNode;
                    childNode.ParentConnections.Add(childConnection);
                }
            }
            IResourceIndexEntry       kinKey;
            GraphConnectionKin        kinConnection;
            IResourceKinHelper        kinHelper;
            List <SpecificResource>   kin;
            List <IResourceKinHelper> kinHelpers = graphNode.Core.CreateKinHelpers(constraints);

            count = (kinHelpers == null) ? 0 : kinHelpers.Count;
            Diagnostics.Log("Resolving " + count + " RK Kin types for " + graphNodeKeyStr);
            for (i = 0; i < kinHelpers.Count; i++)
            {
                kinHelper = kinHelpers[i];
                Diagnostics.Log("Slurping " + kinHelper.KinName + " Kin of " + graphNodeKeyStr);
                if (kinHelper is IResourceKinFinder)
                {
                    kin = (kinHelper as IResourceKinFinder).FindKindredResources(graphNode.OriginalKey);
                }
                else
                {
                    kin = SlurpKindredResources(graphNode.OriginalKey, kinHelper);
                }
                for (j = 0; j < kin.Count; j++)
                {
                    kinKey = kin[j].ResourceIndexEntry;
                    if (kinKey == null)
                    {
                        continue;
                    }
                    kinConnection = new GraphConnectionKin(this, graphNode, kinHelper);
                    childNode     = null;
                    // Try to find an already existing kindred node in the lookup table.
                    foundIndex = -1;
                    for (k = 0; k < this.nodeLookupTable.Count && foundIndex < 0; k++)
                    {
                        if (this.nodeLookupTable[k].OriginalKey.Equals(kinKey))
                        {
                            foundIndex = k;
                        }
                    }
                    if (foundIndex >= 0)
                    {
                        childNode = this.nodeLookupTable[foundIndex];
                        if (!childNode.IsKindred)
                        {
                            Diagnostics.Log("Non-Kindred Node "
                                            + PrintRKTag(kinKey, childNode.ExtensionTag)
                                            + " is " + kinHelper.KinName + " Kin of "
                                            + graphNodeKeyStr);
                        }
                        else
                        {
                            Diagnostics.Log("Existing Kindred Node "
                                            + PrintRKTag(kinKey, childNode.ExtensionTag)
                                            + " is " + kinHelper.KinName + " Kin of "
                                            + graphNodeKeyStr);
                        }
                    }
                    else
                    {
                        IResource kinResource = kin[j].Resource;
                        if (kinResource == null)
                        {
                            Diagnostics.Log("Unresolved RK Kin:" + PrintRK(kinKey)
                                            + ((kin[j].Exception == null) ? "" :
                                               string.Concat(" Error:\r\n", kin[j].Exception.ToString())));
                        }
                        else
                        {
                            IResourceNode kinCore = kinHelper.CreateKin(kinResource, kinKey, constraints);
                            if (kinCore == null)
                            {
                                Diagnostics.Log("CreateKin Failed:" + PrintRK(kinKey));
                            }
                            else
                            {
                                childNode = new GraphNode(this, kinKey, kinCore,
                                                          kin[j].PathPackage, ResourceDataActions.FindWrite);
                                this.nodeLookupTable.Add(childNode);
                                Diagnostics.Log("New Kin Node Added:" + PrintRKTag(kinKey, childNode.ExtensionTag));
                                CreateChildren(childNode, constraints);
                            }
                        }
                    }
                    if (childNode != null)
                    {
                        graphNode.KindredConnections.Add(kinConnection);
                        kinConnection.Child = childNode;
                        childNode.KinOwnerConnections.Add(kinConnection);
                    }
                }
            }
        }