Exemple #1
0
        internal void CreateOrUpdateResourceTypeResource(string name, string displayName,
                                                         string resourceDisplayNameTemplate, ResourceTypeFlags flags, IPlugin ownerPlugin,
                                                         int ID, bool newType)
        {
            ResourceTypeFlags oldFlags = ResourceTypeFlags.Normal;

            IResource res;

            if (newType)
            {
                try
                {
                    res = CreateResourceTypeResource(ID, name, resourceDisplayNameTemplate);
                }
                catch (ResourceRestrictionException ex)
                {
                    MyPalStorage.Storage.OnIndexCorruptionDetected("ResourceRestrictionException when creating PropType resource: " +
                                                                   ex.Message);
                    return;
                }
            }
            else
            {
                res      = _storage.FindUniqueResource("ResourceType", _storage.Props.Name, name);
                oldFlags = this [name].Flags;
            }

            if (res == null)
            {
                MyPalStorage.Storage.OnIndexCorruptionDetected("Could not find ResourceType resource with name " + name);
            }
            else
            {
                SetResourceTypeFlags(res, flags);
                res.SetProp(_storage.Props.PropDisplayName, displayName);

                _storage.SetOwnerPlugin(res, ownerPlugin);
            }

            UpdateResourceTypeCache(ID, resourceDisplayNameTemplate, flags | oldFlags);

            if (newType)
            {
                _storage.CacheResourceTypePredicate((ResourceTypeItem)_resourceTypeCache [ID]);
            }
        }