public static void AddResourceType(string resourceType, bool isFood = false)
 {
     ResourceTypes.Add(resourceType);
     if (isFood)
     {
         FoodTypes.Add(resourceType);
     }
 }
        public static IServiceCollection AddAzureFileStorage(this IServiceCollection services, Action <FileStorageOptions> configureOptions = null)
        {
            if (configureOptions != null)
            {
                services.Configure(configureOptions);
            }

            ResourceTypes.Add <AzureFileStorageLocator>();
            return(services.AddScoped <IFileStorage, AzureFileStorage>());
        }
Example #3
0
        public async void SelectSubscription(SelectionChangedEventArgs args)
        {
            if (args.AddedItems[0] is Subscription sub)
            {
                ResourceTypes.Clear();
                _client.SetSubscription(SelectedSubscription.Value);
                var types = await _client.ResourceTypes();

                foreach (var type in types)
                {
                    ResourceTypes.Add(type);
                }
                SelectedResourceType.Value         = types.First();
                ResourceTypesSelectorEnabled.Value = types.Count() > 1;
            }
        }
Example #4
0
        /// <summary>
        /// Build resources from given folder.
        /// </summary>
        /// <param name="folder"></param>
        public void BuildResources(string folder)
        {
            //TODO: MAKE THIS CLEANER
            string sdsFolder = folder;

            List <string> addedTypes = new List <string>();
            XmlDocument   document   = new XmlDocument();
            XmlDocument   xmlDoc     = new XmlDocument();
            XmlNode       rootNode;

            try
            {
                document = new XmlDocument();
                document.Load(sdsFolder + "/SDSContent.xml");
                xmlDoc   = new XmlDocument();
                rootNode = xmlDoc.CreateElement("xml");
            }
            catch
            {
                MessageBox.Show("Could not find 'SDSContent.xml'. Folder Path: " + sdsFolder + "/SDSContent.xml", "Game Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            xmlDoc.AppendChild(rootNode);

            XPathNavigator nav   = document.CreateNavigator();
            var            nodes = nav.Select("/SDSResource/ResourceEntry");

            while (nodes.MoveNext() == true)
            {
                int exists = -1;
                nodes.Current.MoveToFirstChild();
                string resourceType = nodes.Current.Value;

                if (addedTypes.Count == 0)
                {
                    exists = -1;
                }
                else
                {
                    for (int i = 0; i != addedTypes.Count; i++)
                    {
                        if (addedTypes[i] == resourceType)
                        {
                            exists = i;
                        }
                    }
                }

                if (exists == -1)
                {
                    ResourceType resource = new ResourceType();
                    resource.Name = nodes.Current.Value;
                    resource.Id   = (uint)addedTypes.Count;
                    exists        = addedTypes.Count;

                    //TODO
                    if (resource.Name == "IndexBufferPool" || resource.Name == "PREFAB")
                    {
                        resource.Parent = 3;
                    }
                    else if (resource.Name == "VertexBufferPool" || resource.Name == "NAV_OBJ_DATA")
                    {
                        resource.Parent = 2;
                    }
                    else if (resource.Name == "NAV_HPD_DATA")
                    {
                        resource.Parent = 1;
                    }

                    addedTypes.Add(nodes.Current.Value);
                    ResourceTypes.Add(resource);
                }

                XmlNode resourceNode = xmlDoc.CreateElement("ResourceInfo");
                XmlNode typeNameNode = xmlDoc.CreateElement("TypeName");
                typeNameNode.InnerText = resourceType;
                XmlNode sddescNode = xmlDoc.CreateElement("SourceDataDescription");

                ResourceEntry resourceEntry = new ResourceEntry();
                resourceEntry.TypeId = exists;

                switch (resourceType)
                {
                case "FrameResource":
                case "Effects":
                case "PREFAB":
                case "ItemDesc":
                case "FrameNameTable":
                case "Actors":
                case "NAV_AIWORLD_DATA":
                case "NAV_OBJ_DATA":
                case "NAV_HPD_DATA":
                case "Cutscene":
                case "FxActor":
                case "FxAnimSet":
                case "Translokator":
                case "AudioSectors":
                case "Speech":
                case "SoundTable":
                case "AnimalTrafficPaths":
                    resourceEntry = WriteBasicEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Animated Texture":
                    resourceEntry = WriteAnimatedTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Collisions":
                    resourceEntry = WriteCollisionEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "IndexBufferPool":
                case "VertexBufferPool":
                    resourceEntry = WriteBufferEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "EntityDataStorage":
                    resourceEntry = WriteEntityDataEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Animation2":
                    resourceEntry = WriteAnimationEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Texture":
                    resourceEntry = WriteTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Mipmap":
                    resourceEntry = WriteMipmapEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Sound":
                    resourceEntry = WriteSoundEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "XML":
                    resourceEntry = WriteXMLEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "MemFile":
                    resourceEntry = WriteMemFileEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Script":
                    resourceEntry = WriteScriptEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Table":
                    resourceEntry = WriteTableEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                default:
                    MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }

                resourceNode.AppendChild(typeNameNode);
                resourceNode.AppendChild(sddescNode);
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotRamRequired", 0));   //(int)resourceEntry.SlotRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotVRamRequired", 0));  //(int)resourceEntry.SlotVramRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherRamRequired", 0));  //(int)resourceEntry.OtherRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherVramRequired", 0)); //(int)resourceEntry.OtherVramRequired));
                rootNode.AppendChild(resourceNode);
                ResourceEntries.Add(resourceEntry);
                //SlotRamRequired += resourceEntry.SlotRamRequired;
                //SlotVramRequired += resourceEntry.SlotVramRequired;
                //OtherRamRequired += resourceEntry.OtherRamRequired;
                //OtherVramRequired += resourceEntry.OtherVramRequired;
            }

            ResourceInfoXml = xmlDoc.OuterXml;
        }
        public bool BuildResourcesVersion20(XmlDocument document, XmlDocument xmlDoc, XmlNode rootNode, string sdsFolder)
        {
            XPathNavigator nav   = document.CreateNavigator();
            var            nodes = nav.Select("/SDSResource/ResourceEntry");
            Dictionary <string, List <ResourceEntry> > entries = new Dictionary <string, List <ResourceEntry> >();
            int index = 0;

            while (nodes.MoveNext() == true)
            {
                nodes.Current.MoveToFirstAttribute();
                uint SlotVramRequired = uint.Parse(nodes.Current.Value);
                nodes.Current.MoveToNextAttribute();
                uint SlotRamRequired = uint.Parse(nodes.Current.Value);
                nodes.Current.MoveToParent();
                nodes.Current.MoveToFirstChild();
                string resourceType = nodes.Current.Value;

                if (!entries.ContainsKey(resourceType))
                {
                    ResourceType resource = new ResourceType();
                    resource.Name = nodes.Current.Value;
                    resource.Id   = (uint)entries.Count;

                    //TODO
                    if (resource.Name == "NAV_PATH_DATA")
                    {
                        resource.Parent = 1;
                    }

                    ResourceTypes.Add(resource);
                    entries.Add(resourceType, new List <ResourceEntry>());
                }
                XmlNode resourceNode = xmlDoc.CreateElement("ResourceInfo");
                XmlNode typeNameNode = xmlDoc.CreateElement("TypeName");
                typeNameNode.InnerText = resourceType;
                XmlNode sddescNode = xmlDoc.CreateElement("SourceDataDescription");

                ResourceEntry resourceEntry = new ResourceEntry()
                {
                    SlotRamRequired  = SlotRamRequired,
                    SlotVramRequired = SlotVramRequired,
                };

                if (index == 36)
                {
                    Console.WriteLine("");
                }

                switch (resourceType)
                {
                case "Texture":
                    resourceEntry = WriteTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "hkAnimation":
                    resourceEntry = WriteHavokEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Generic":
                    resourceEntry = WriteGenericEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    resourceEntry.SlotRamRequired  = SlotRamRequired;
                    resourceEntry.SlotVramRequired = SlotVramRequired;
                    break;

                case "NAV_PATH_DATA":
                case "NAV_AIWORLD_DATA":
                case "RoadMap":
                case "EnlightenResource":
                    resourceEntry = WriteBasicEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    resourceEntry.OtherRamRequired += (uint)(resourceEntry.Data.Length);
                    break;

                case "MemFile":
                    resourceEntry = WriteMemFileEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "SystemObjectDatabase":
                    resourceEntry = WriteXBinEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "XML":
                    resourceEntry = WriteXMLEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Script":
                    resourceEntry = WriteScriptEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Flash":
                    resourceEntry = WriteFlashEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                default:
                    MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                resourceNode.AppendChild(typeNameNode);
                resourceNode.AppendChild(sddescNode);
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotRamRequired", (int)resourceEntry.SlotRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotVRamRequired", (int)resourceEntry.SlotVramRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherRamRequired", (int)resourceEntry.OtherRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherVramRequired", (int)resourceEntry.OtherVramRequired));
                rootNode.AppendChild(resourceNode);

                this.SlotVramRequired += resourceEntry.OtherVramRequired;
                this.SlotRamRequired  += resourceEntry.OtherRamRequired;
                resourceEntry.TypeId   = (int)ResourceTypes.Find(s => s.Name.Equals(resourceType)).Id;
                entries[resourceType].Add(resourceEntry);

                index++;
            }
            _ResourceTypes.Reverse();

            for (int i = 0; i < _ResourceTypes.Count; i++)
            {
                var entry = _ResourceTypes[i];
                entry.Id          = (uint)i;
                _ResourceTypes[i] = entry;
            }
            foreach (var collection in entries)
            {
                var key = collection.Key;
                foreach (var entry in collection.Value)
                {
                    entry.TypeId = (int)ResourceTypes.Find(s => s.Name.Equals(key)).Id;
                }
            }

            foreach (var pair in entries)
            {
                _ResourceEntries.AddRange(pair.Value);
            }

            ResourceInfoXml = xmlDoc.OuterXml;
            return(true);
        }
Example #6
0
        public bool BuildResourcesVersion19(XmlDocument document, XmlDocument xmlDoc, XmlNode rootNode, string sdsFolder)
        {
            XPathNavigator nav   = document.CreateNavigator();
            var            nodes = nav.Select("/SDSResource/ResourceEntry");
            Dictionary <string, List <ResourceEntry> > entries = new Dictionary <string, List <ResourceEntry> >();

            while (nodes.MoveNext() == true)
            {
                nodes.Current.MoveToFirstChild();
                string resourceType = nodes.Current.Value;

                if (!entries.ContainsKey(resourceType))
                {
                    ResourceType resource = new ResourceType();
                    resource.Name = nodes.Current.Value;
                    resource.Id   = (uint)entries.Count;

                    //TODO
                    if (resource.Name == "IndexBufferPool" || resource.Name == "PREFAB")
                    {
                        resource.Parent = 3;
                    }
                    else if (resource.Name == "VertexBufferPool" || resource.Name == "NAV_OBJ_DATA")
                    {
                        resource.Parent = 2;
                    }
                    else if (resource.Name == "NAV_HPD_DATA")
                    {
                        resource.Parent = 1;
                    }

                    ResourceTypes.Add(resource);
                    entries.Add(resourceType, new List <ResourceEntry>());
                }
                XmlNode resourceNode = xmlDoc.CreateElement("ResourceInfo");
                XmlNode typeNameNode = xmlDoc.CreateElement("TypeName");
                typeNameNode.InnerText = resourceType;
                XmlNode sddescNode = xmlDoc.CreateElement("SourceDataDescription");

                ResourceEntry resourceEntry = new ResourceEntry();
                switch (resourceType)
                {
                case "FrameResource":
                case "Effects":
                case "PREFAB":
                case "ItemDesc":
                case "FrameNameTable":
                case "Actors":
                case "NAV_AIWORLD_DATA":
                case "NAV_OBJ_DATA":
                case "NAV_HPD_DATA":
                case "Cutscene":
                case "FxActor":
                case "FxAnimSet":
                case "Translokator":
                case "Speech":
                case "SoundTable":
                case "AnimalTrafficPaths":
                    resourceEntry = WriteBasicEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "AudioSectors":
                    resourceEntry = WriteAudioSectorEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Animated Texture":
                    resourceEntry = WriteAnimatedTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Collisions":
                    resourceEntry = WriteCollisionEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "IndexBufferPool":
                case "VertexBufferPool":
                    resourceEntry = WriteBufferEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "EntityDataStorage":
                    resourceEntry = WriteEntityDataEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Animation2":
                    resourceEntry = WriteAnimationEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Texture":
                    resourceEntry = WriteTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Mipmap":
                    resourceEntry = WriteMipmapEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Sound":
                    resourceEntry = WriteSoundEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "XML":
                    resourceEntry = WriteXMLEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "MemFile":
                    resourceEntry = WriteMemFileEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Script":
                    resourceEntry = WriteScriptEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Table":
                    resourceEntry = WriteTableEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                default:
                    MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                resourceNode.AppendChild(typeNameNode);
                resourceNode.AppendChild(sddescNode);
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotRamRequired", (int)resourceEntry.SlotRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotVRamRequired", (int)resourceEntry.SlotVramRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherRamRequired", (int)resourceEntry.OtherRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherVramRequired", (int)resourceEntry.OtherVramRequired));
                rootNode.AppendChild(resourceNode);
                SlotRamRequired   += resourceEntry.SlotRamRequired;
                SlotVramRequired  += resourceEntry.SlotVramRequired;
                OtherRamRequired  += resourceEntry.OtherRamRequired;
                OtherVramRequired += resourceEntry.OtherVramRequired;

                // Find TypeId then add to the big list of resources
                resourceEntry.TypeId = (int)ResourceTypes.Find(s => s.Name.Equals(resourceType)).Id;
                _ResourceEntries.Add(resourceEntry);
            }

            // Update Meta-Info or 'Outer-XML'
            ResourceInfoXml = xmlDoc.OuterXml;

            return(true);
        }
Example #7
0
        /// <summary>
        /// Adds a child KmlItem to this nodes lists of children, depending of its
        /// derived class KmlNode, KmlPart, KmlAttrib or further derived from these.
        /// When an KmlAttrib "Name", "Type" or "Root" are found, their value
        /// will be used for the corresponding property of this node.
        /// </summary>
        /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param>
        /// <param name="newItem">The KmlItem to add</param>
        protected override void Add(KmlItem beforeItem, KmlItem newItem)
        {
            if (newItem is KmlAttrib)
            {
                KmlAttrib attrib = (KmlAttrib)newItem;
                if (attrib.Name.ToLower() == "type" && Type.Length == 0)
                {
                    Type = attrib.Value;

                    // Get notified when Type changes
                    attrib.AttribValueChanged += Type_Changed;
                    attrib.CanBeDeleted        = false;
                }
                else if (attrib.Name.ToLower() == "sit" && Situation.Length == 0)
                {
                    Situation = attrib.Value;

                    // Get notified when Type changes
                    attrib.AttribValueChanged += Situation_Changed;
                    attrib.CanBeDeleted        = false;
                }
                else if (attrib.Name.ToLower() == "root" && RootPart == null)
                {
                    SetRootPart(attrib.Value);

                    // Get notified when Type changes
                    attrib.AttribValueChanged += Root_Changed;
                    attrib.CanBeDeleted        = false;
                }
            }
            else if (newItem is KmlPart)
            {
                KmlPart part = (KmlPart)newItem;
                if (beforeItem != null)
                {
                    KmlPart beforePart = null;
                    int     allIndex   = AllItems.IndexOf(beforeItem);
                    for (int i = allIndex; i < AllItems.Count; i++)
                    {
                        if (AllItems[i] is KmlPart && Parts.Contains((KmlPart)AllItems[i]))
                        {
                            beforePart = (KmlPart)AllItems[i];
                            break;
                        }
                    }
                    if (beforePart != null)
                    {
                        beforePart.InsertionPreparation();
                        Parts.Insert(Parts.IndexOf(beforePart), part);
                        beforePart.InsertionFinalization();
                    }
                    else
                    {
                        Parts.Add(part);
                    }
                }
                else
                {
                    Parts.Add(part);
                }
                if (Parts.Count == rootPartIndex + 1)
                {
                    RootPart = Parts[rootPartIndex];
                }
                if (part.Flag != "" && !Flags.Any(x => x.ToLower() == part.Flag.ToLower()))
                {
                    Flags.Add(part.Flag);
                }
                if (part.HasResources)
                {
                    foreach (string resType in part.ResourceTypes)
                    {
                        ResourceTypes.Add(resType);
                    }
                }
                KmlAttrib flag = part.GetAttrib("flag");
                if (flag != null)
                {
                    flag.AttribValueChanged += Flag_Changed;
                }
            }
            base.Add(beforeItem, newItem);
        }
Example #8
0
        /// <summary>
        /// Adds a child KmlItem to this nodes lists of children, depending of its
        /// derived class KmlNode, KmlPart, KmlAttrib or further derived from these.
        /// When an KmlAttrib "Name", "Type" or "Root" are found, their value
        /// will be used for the corresponding property of this node.
        /// </summary>
        /// <param name="item">The KmlItem to add</param>
        public override void Add(KmlItem item)
        {
            KmlItem newItem = item;

            if (item is KmlAttrib)
            {
                KmlAttrib attrib = (KmlAttrib)item;
                if (attrib.Name.ToLower() == "type")
                {
                    Type = attrib.Value;

                    // Get notified when Type changes
                    attrib.AttribValueChanged += Type_Changed;
                    attrib.CanBeDeleted        = false;
                }
                else if (attrib.Name.ToLower() == "sit")
                {
                    Situation = attrib.Value;

                    // Get notified when Type changes
                    attrib.AttribValueChanged += Situation_Changed;
                    attrib.CanBeDeleted        = false;
                }
                else if (attrib.Name.ToLower() == "root")
                {
                    SetRootPart(attrib.Value);

                    // Get notified when Type changes
                    attrib.AttribValueChanged += Root_Changed;
                    attrib.CanBeDeleted        = false;
                }
            }
            else if (item is KmlPart)
            {
                KmlPart part = (KmlPart)item;
                Parts.Add(part);
                if (Parts.Count == rootPartIndex + 1)
                {
                    RootPart = Parts[rootPartIndex];
                }
                if (part.HasResources)
                {
                    foreach (string resType in part.ResourceTypes)
                    {
                        ResourceTypes.Add(resType);
                    }
                }
            }

            /*else if (Item is KmlNode)
             * {
             *  KmlNode node = (KmlNode)Item;
             *  if (node.Tag.ToLower() == "part")
             *  {
             *      newItem = new KmlPart(node);
             *      Parts.Add((KmlPart)newItem);
             *      if (Parts.Count == rootPartNr + 1)
             *      {
             *          RootPart = Parts[rootPartNr];
             *      }
             *  }
             * }*/
            base.Add(newItem);
        }
Example #9
0
        /// <summary>
        /// Adds a child KmlItem to this nodes lists of children, depending of its
        /// derived class KmlNode, KmlAttrib or further derived from these.
        /// When an KmlAttrib "Name" is found, its value
        /// will be used for the corresponding property of this node.
        /// </summary>
        /// <param name="item">The KmlItem to add</param>
        public override void Add(KmlItem item)
        {
            KmlItem newItem = item;

            if (item is KmlAttrib)
            {
                KmlAttrib attrib = (KmlAttrib)item;
                if (attrib.Name.ToLower() == "uid")
                {
                    Uid = attrib.Value;
                    attrib.AttribValueChanged += Uid_Changed;
                    attrib.CanBeDeleted        = false;
                }
                else if (attrib.Name.ToLower() == "parent")
                {
                    int p = ParentPartIndex;
                    if (int.TryParse(attrib.Value, out p))
                    {
                        ParentPartIndex = p;
                    }
                    else
                    {
                        Syntax.Warning(this, "Unreadable parent part: " + attrib.ToString());
                    }
                    attrib.AttribValueChanged += ParentPart_Changed;
                    attrib.CanBeDeleted        = false;
                }
                else if (attrib.Name.ToLower() == "attn")
                {
                    // Value looks like "top, 12", "bottom, -1", "left, 1", "top2, 3", etc.
                    string[] items = attrib.Value.Split(new char[] { ',' });
                    int      index = -1;
                    if (items.Count() == 2 && int.TryParse(items[1], out index))
                    {
                        if (index >= 0)
                        {
                            AttachedToNodeIndices.Add(index);
                            attrib.CanBeDeleted = false;
                        }
                    }
                    else
                    {
                        Syntax.Warning(this, "Bad formatted part node attachment: " + attrib.ToString());
                    }
                    attrib.AttribValueChanged += AttachmentNode_Changed;
                }
                else if (attrib.Name.ToLower() == "srfn")
                {
                    // Value looks like "srfAttach, 12"
                    string[] items = attrib.Value.Split(new char[] { ',' });
                    int      index = -1;
                    if (items.Count() == 2 && int.TryParse(items[1], out index))
                    {
                        if (index >= 0)
                        {
                            if (AttachedToSurfaceIndex < 0)
                            {
                                AttachedToSurfaceIndex = index;
                                attrib.CanBeDeleted    = false;
                            }
                            else
                            {
                                Syntax.Warning(this, "More than one surface attachment is not allowed, already attached to [" + AttachedToSurfaceIndex + "], could not attach to [" + index + "]");
                            }
                        }
                    }
                    else
                    {
                        Syntax.Warning(this, "Bad formatted part surface attachment: " + attrib.ToString());
                    }
                    attrib.AttribValueChanged += AttachmentSurface_Changed;
                }
                else if (attrib.Name.ToLower() == "position")
                {
                    // Value looks like "0.1,0,-0.3E-07"
                    string[] items = attrib.Value.Split(new char[] { ',' });
                    double   x     = 0;
                    double   y     = 0;
                    double   z     = 0;
                    if (items.Count() == 3 &&
                        double.TryParse(items[0], NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out x) &&
                        double.TryParse(items[1], NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out y) &&
                        double.TryParse(items[2], NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out z))
                    {
                        Position            = new Point3D(x, y, z);
                        attrib.CanBeDeleted = false;
                    }
                    else
                    {
                        Syntax.Warning(this, "Bad formatted part position: " + attrib.ToString());
                    }
                }
            }
            else if (item is KmlResource)
            {
                KmlResource res = (KmlResource)item;
                Resources.Add(res);
                ResourceTypes.Add(res.Name);

                // Get notified when Resources change
                res.MaxAmount.AttribValueChanged += Resources_Changed;
                res.MaxAmount.CanBeDeleted        = false;
                res.Amount.AttribValueChanged    += Resources_Changed;
                res.Amount.CanBeDeleted           = false;
            }

            /*if (Item is KmlNode)
             * {
             *  KmlNode node = (KmlNode)Item;
             *  if (node.Tag.ToLower() == "resource")
             *  {
             *      newItem = new KmlResource(node);
             *  }
             * }*/
            base.Add(newItem);
        }
 /// <summary>
 /// Adds DynamoDB as the repository service behind FIMS
 /// </summary>
 /// <param name="serviceCollection"></param>
 /// <returns></returns>
 public static IServiceCollection AddS3FileStorage(this IServiceCollection serviceCollection)
 {
     ResourceTypes.Add <AwsS3Locator>();
     return(serviceCollection.AddScoped <IFileStorage, S3FileStorage>());
 }
Example #11
0
        /// <summary>
        /// Adds local file storage
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <returns></returns>
        public static IServiceCollection AddLocalFileStorage(this IServiceCollection serviceCollection)
        {
            ResourceTypes.Add <LocalLocator>();

            return(serviceCollection.AddSingleton <IFileStorage, LocalFileStorage>());
        }
Example #12
0
        /// <summary>
        /// Build resources from given folder.
        /// </summary>
        /// <param name="folder"></param>
        public void BuildResources(string folder)
        {
            //TODO: MAKE THIS CLEANER
            string      sdsFolder = folder;
            XmlDocument document  = new XmlDocument();
            XmlDocument xmlDoc    = new XmlDocument();
            XmlNode     rootNode;

            if (!File.Exists(sdsFolder + "/SDSContent.xml"))
            {
                MessageBox.Show("Could not find 'SDSContent.xml'. Folder Path: " + sdsFolder + "/SDSContent.xml", "Game Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                document = new XmlDocument();
                document.Load(sdsFolder + "/SDSContent.xml");
                xmlDoc   = new XmlDocument();
                rootNode = xmlDoc.CreateElement("xml");
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error while parsing SDSContent.XML. \n{0}", ex.Message));
                return;
            }

            xmlDoc.AppendChild(rootNode);

            XPathNavigator nav   = document.CreateNavigator();
            var            nodes = nav.Select("/SDSResource/ResourceEntry");
            Dictionary <string, List <ResourceEntry> > entries = new Dictionary <string, List <ResourceEntry> >();

            while (nodes.MoveNext() == true)
            {
                nodes.Current.MoveToFirstChild();
                string resourceType = nodes.Current.Value;

                if (!entries.ContainsKey(resourceType))
                {
                    ResourceType resource = new ResourceType();
                    resource.Name = nodes.Current.Value;
                    resource.Id   = (uint)entries.Count;

                    //TODO
                    if (resource.Name == "IndexBufferPool" || resource.Name == "PREFAB")
                    {
                        resource.Parent = 3;
                    }
                    else if (resource.Name == "VertexBufferPool" || resource.Name == "NAV_OBJ_DATA")
                    {
                        resource.Parent = 2;
                    }
                    else if (resource.Name == "NAV_HPD_DATA")
                    {
                        resource.Parent = 1;
                    }

                    ResourceTypes.Add(resource);
                    entries.Add(resourceType, new List <ResourceEntry>());
                }
                XmlNode resourceNode = xmlDoc.CreateElement("ResourceInfo");
                XmlNode typeNameNode = xmlDoc.CreateElement("TypeName");
                typeNameNode.InnerText = resourceType;
                XmlNode sddescNode = xmlDoc.CreateElement("SourceDataDescription");

                ResourceEntry resourceEntry = new ResourceEntry();
                switch (resourceType)
                {
                case "FrameResource":
                case "Effects":
                case "PREFAB":
                case "ItemDesc":
                case "FrameNameTable":
                case "Actors":
                case "NAV_AIWORLD_DATA":
                case "NAV_OBJ_DATA":
                case "NAV_HPD_DATA":
                case "Cutscene":
                case "FxActor":
                case "FxAnimSet":
                case "Translokator":
                case "Speech":
                case "SoundTable":
                case "AnimalTrafficPaths":
                    resourceEntry = WriteBasicEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "AudioSectors":
                    resourceEntry = WriteAudioSectorEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Animated Texture":
                    resourceEntry = WriteAnimatedTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Collisions":
                    resourceEntry = WriteCollisionEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "IndexBufferPool":
                case "VertexBufferPool":
                    resourceEntry = WriteBufferEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "EntityDataStorage":
                    resourceEntry = WriteEntityDataEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Animation2":
                    resourceEntry = WriteAnimationEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Texture":
                    resourceEntry = WriteTextureEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Mipmap":
                    resourceEntry = WriteMipmapEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Sound":
                    resourceEntry = WriteSoundEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "XML":
                    resourceEntry = WriteXMLEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "MemFile":
                    resourceEntry = WriteMemFileEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Script":
                    resourceEntry = WriteScriptEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                case "Table":
                    resourceEntry = WriteTableEntry(resourceEntry, nodes, sdsFolder, sddescNode);
                    break;

                default:
                    MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                resourceNode.AppendChild(typeNameNode);
                resourceNode.AppendChild(sddescNode);
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotRamRequired", (int)resourceEntry.SlotRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "SlotVRamRequired", (int)resourceEntry.SlotVramRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherRamRequired", (int)resourceEntry.OtherRamRequired));
                resourceNode.AppendChild(AddRamElement(xmlDoc, "OtherVramRequired", (int)resourceEntry.OtherVramRequired));
                rootNode.AppendChild(resourceNode);
                SlotRamRequired     += resourceEntry.SlotRamRequired;
                SlotVramRequired    += resourceEntry.SlotVramRequired;
                OtherRamRequired    += resourceEntry.OtherRamRequired;
                OtherVramRequired   += resourceEntry.OtherVramRequired;
                resourceEntry.TypeId = (int)ResourceTypes.Find(s => s.Name.Equals(resourceType)).Id;
                entries[resourceType].Add(resourceEntry);
            }
            foreach (var pair in entries)
            {
                _ResourceEntries.AddRange(pair.Value);
            }
            ResourceInfoXml = xmlDoc.OuterXml;
        }