Esempio n. 1
0
        /// <summary>Returns an unused integer ResourceIdentifier for a ResourceName that is not currently being used.</summary>
        public virtual ResourceIdentifier GetUnusedName(ResourceTypeIdentifier typeId)
        {
            // get the type then enumerate through all the integer Ids.
            ResourceType type = this.AllTypes[typeId];

            if (type == null)
            {
                // then just use "1"
                return(new ResourceIdentifier(1));
            }

            Int32 biggestIntId = -1;

            foreach (ResourceName name in type.Names)
            {
                ResourceIdentifier id = name.Identifier;

                if (id.IntegerId != null)
                {
                    if (id.IntegerId > biggestIntId)
                    {
                        biggestIntId = id.IntegerId.Value;
                    }
                }
            }
            if (biggestIntId == -1)
            {
                biggestIntId = 0;
            }

            return(new ResourceIdentifier(biggestIntId + 1));
        }
Esempio n. 2
0
        public static ResourceData FromResource(ResourceLang lang, Byte[] rawData)
        {
            ResourceTypeIdentifier typeId = lang.Name.Type.Identifier;

            // get a list of suitable factories

            ResourceDataFactory[] factories = ResourceDataFactory.GetFactoriesForType(typeId);

            // try the factories in order of compatibility.

            Int32        i    = 0;
            ResourceData data = null;

            while (data == null)
            {
                if (i >= factories.Length)
                {
                    throw new Exception("Unable to locate factory for resource data.");
                }

                data = factories[i++].FromResource(lang, rawData);
            }

            return(data);
        }
Esempio n. 3
0
        /// <summary>Constructs a Win32 resource type based on a Win32 resource type LPCTSTR.</summary>
        internal ResourceType(IntPtr typePointer, ResourceSource source)
        {
            Identifier = new ResourceTypeIdentifier(typePointer);
            Source     = source;

            _names = new List <ResourceName>();
            Names  = new ResourceNameCollection(_names);                 // ResourceNameCollection is a read-only decorator of any List
        }
Esempio n. 4
0
        public ResourceLang Remove(ResourceTypeIdentifier typeId, ResourceIdentifier nameId, UInt16 langId)
        {
            if (LoadMode > 0)
            {
                throw new InvalidOperationException("This Remove overload can only be used in Blind mode");
            }

            EnsureReadOnly();

            ResourceType type = _types.Find(t => t.Identifier.Equals(typeId));

            if (type == null)
            {
                // add it
                type = new ResourceType(typeId.NativeId, this);

                UnderlyingAdd(type);
            }

            ResourceName name = null;

            foreach (ResourceName nom in type.Names)
            {
                if (nom.Identifier.Equals(nameId))
                {
                    name = nom; break;
                }
            }
            if (name == null)
            {
                name = new ResourceName(nameId.NativeId, type);

                type.UnderlyingNames.Add(name);
            }

            ResourceLang lang = null;

            foreach (ResourceLang lon in name.Langs)
            {
                if (lon.LanguageId == langId)
                {
                    lang = lon; break;
                }
            }
            if (lang != null && lang.Action != ResourceDataAction.Delete)
            {
                throw new AnolisException("The specified ResourceLang already exists with an Action other than to Delete");
            }

            lang        = new ResourceLang(langId, name);
            lang.Action = ResourceDataAction.Delete;

            name.UnderlyingLangs.Add(lang);

            return(lang);
        }
Esempio n. 5
0
        public static Boolean Equals(ResourceType x, ResourceType y)
        {
            if (Object.ReferenceEquals(x, y))
            {
                return(true);                                           // Object.ReferenceEquals( null, null ) btw
            }
//			if( !Object.ReferenceEquals( x.Source, y.Source ) ) return false;

            return(ResourceTypeIdentifier.Equals(x.Identifier, y.Identifier));
        }
Esempio n. 6
0
        /// <summary>Adds the specified ResourceData to this ResourceSource instance. If the specified ResourceType or ResourceName or ResourceLang does not exist they will be created. If the specified ResourceLang does exist an exception will be thrown (as you're meant to use Update to replace existing resources)</summary>
        public ResourceLang Add(ResourceTypeIdentifier typeId, ResourceIdentifier nameId, UInt16 langId, ResourceData data)
        {
            EnsureReadOnly();

            ResourceType type = _types.Find(t => t.Identifier.Equals(typeId));

            if (type == null)
            {
                // add it
                type = new ResourceType(typeId.NativeId, this);

                UnderlyingAdd(type);
            }

            ResourceName name = null;

            foreach (ResourceName nom in type.Names)
            {
                if (nom.Identifier.Equals(nameId))
                {
                    name = nom; break;
                }
            }
            if (name == null)
            {
                name = new ResourceName(nameId.NativeId, type);

                type.UnderlyingNames.Add(name);
            }

            ResourceLang lang = null;

            if (LoadMode > 0)
            {
                foreach (ResourceLang lon in name.Langs)
                {
                    if (lon.LanguageId == langId)
                    {
                        lang = lon; break;
                    }
                }
            }
            if (lang != null)
            {
                throw new AnolisException("The specified ResourceLang already exists");
            }

            lang        = new ResourceLang(langId, name, data);
            lang.Action = ResourceDataAction.Add;

            name.UnderlyingLangs.Add(lang);

            return(lang);
        }
Esempio n. 7
0
 public ResourceType this[ResourceTypeIdentifier typeId] {
     get {
         foreach (ResourceType type in this)
         {
             if (type.Identifier.Equals(typeId))
             {
                 return(type);
             }
         }
         return(null);
     }
 }
Esempio n. 8
0
        public virtual ResourceLang GetLang(ResourceTypeIdentifier typeId, ResourceIdentifier nameId, UInt16 langId)
        {
            ResourceName name = GetName(typeId, nameId);

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

            foreach (ResourceLang lang in name.Langs)
            {
                if (lang.LanguageId == langId)
                {
                    return(lang);
                }
            }

            return(null);
        }
Esempio n. 9
0
        public virtual ResourceName GetName(ResourceTypeIdentifier typeId, ResourceIdentifier nameId)
        {
            if (LoadMode == 0)
            {
                throw new ArgumentException("The specified ResourceSource has not enumerated its resources");
            }

            foreach (ResourceType type in AllTypes)
            {
                if (type.Identifier.Equals(typeId))
                {
                    foreach (ResourceName name in type.Names)
                    {
                        if (name.Identifier.Equals(nameId))
                        {
                            return(name);
                        }
                    }
                }        //if
            }            //foreach

            return(null);
        }