Ejemplo 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.
            var type = AllTypes[typeId];

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

            var biggestIntId = -1;

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

                if (id.IntegerId == null)
                {
                    continue;
                }

                if (id.IntegerId > biggestIntId)
                {
                    biggestIntId = id.IntegerId.Value;
                }
            }

            if (biggestIntId == -1)
            {
                biggestIntId = 0;
            }

            return(new ResourceIdentifier(biggestIntId + 1));
        }
Ejemplo n.º 2
0
        private static StatelessResult OneOffDelete(string sourceFilename,
                                                    ResourceTypeIdentifier typeId,
                                                    ResourceIdentifier nameId)
        {
            var source = ResourceSource.Open(sourceFilename, false, ResourceSourceLoadMode.EnumerateOnly);

            // delete all the ResourceLangs that match this typeId/nameId criterion. When reloaded the ResourceName should no-longer exist

            var name = source.GetName(typeId, nameId);

            if (name == null)
            {
                return(new StatelessResult("Could not find name " + GetResPath(typeId, nameId, null) + " to delete."));
            }
            ;

            foreach (var lang in name.Langs)
            {
                source.Remove(lang);
            }

            source.CommitChanges();

            return(StatelessResult.Success);
        }
Ejemplo n.º 3
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType == Win32ResourceType.Html)
            {
                return(Compatibility.Yes);
            }
            if (typeId.KnownType == Win32ResourceType.Manifest)
            {
                return(Compatibility.Yes);
            }

            if (typeId.StringId != null)
            {
                if (String.Equals(typeId.StringId, "XML", StringComparison.OrdinalIgnoreCase))
                {
                    return(Compatibility.Yes);
                }
                if (String.Equals(typeId.StringId, "HTML", StringComparison.OrdinalIgnoreCase))
                {
                    return(Compatibility.Yes);
                }
                if (String.Equals(typeId.StringId, "SGML", StringComparison.OrdinalIgnoreCase))
                {
                    return(Compatibility.Yes);
                }
            }

            return(Compatibility.Maybe);
        }
Ejemplo n.º 4
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 AnolisException("Unable to locate factory for resource data.");
                }

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

            return(data);
        }
Ejemplo n.º 5
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType == Win32ResourceType.Unknown)
            {
                return(Compatibility.Maybe);
            }
            if (typeId.KnownType == Win32ResourceType.Html)
            {
                return(Compatibility.Maybe);
            }

            if (typeId.KnownType != Win32ResourceType.Custom)
            {
                return(Compatibility.No);
            }

            if (typeId.StringId == "JPEG")
            {
                return(Compatibility.Yes);
            }
            if (typeId.StringId == "JPG")
            {
                return(Compatibility.Yes);
            }
            if (typeId.StringId == "JPEGFILE")
            {
                return(Compatibility.Yes);
            }

            return(Compatibility.Maybe);
        }
Ejemplo n.º 6
0
        /// <summary>Provides an alternative way to update a ResourceLang's data, originally designed for use in Blind mode.</summary>
        public ResourceLang Update(ResourceTypeIdentifier typeId,
                                   ResourceIdentifier nameId,
                                   ushort langId,
                                   ResourceData newData)
        {
            EnsureReadOnly();

            var 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 (var 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 (var lon in name.Langs)
                {
                    if (lon.LanguageId == langId)
                    {
                        lang = lon;
                        break;
                    }
                }
            }

            if (lang == null)
            {
                lang = new ResourceLang(langId, name, newData);
            }

            lang.Action = ResourceDataAction.Update;

            name.UnderlyingLangs.Add(lang);

            return(lang);
        }
Ejemplo n.º 7
0
        private void DataImport(String dataFilename)
        {
            AddResourceForm form = new AddResourceForm();

            if (dataFilename != null)
            {
                form.LoadFile(dataFilename);
            }

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                ResourceData data = form.ResourceData;

                ResourceTypeIdentifier typeId = form.ResourceTypeIdentifier;
                ResourceIdentifier     nameId = form.ResourceNameIdentifier;
                UInt16 langId = form.ResourceLangId;

                ResourceLang lang = CurrentSource.Add(typeId, nameId, langId, data);

                TreeAdd(lang);

                //TreeRefresh( lang );
                MainFormRefresh();
            }
        }
Ejemplo n.º 8
0
        private static StatelessResult OneOffUpdate(string sourceFilename,
                                                    ResourceTypeIdentifier typeId,
                                                    ResourceIdentifier nameId,
                                                    string dataFilename)
        {
            var source = ResourceSource.Open(sourceFilename, false, ResourceSourceLoadMode.LazyLoadData);

            // for each lang in name, update
            var name = source.GetName(typeId, nameId);

            if (name == null)
            {
                return(new StatelessResult("Could not find name " + GetResPath(typeId, nameId, null) + " to extract."));
            }

            foreach (var lang in name.Langs)
            {
                var newData = ResourceData.FromFileToUpdate(dataFilename, lang);
                lang.SwapData(newData);
            }

            source.CommitChanges();

            return(StatelessResult.Success);
        }
Ejemplo n.º 9
0
        /// <summary>Gets all the factories that support a resource type in order of compatibility.</summary>
        public static ResourceDataFactory[] GetFactoriesForType(ResourceTypeIdentifier typeId)
        {
            if (!_forType.ContainsKey(typeId))
            {
                var yes = new List <ResourceDataFactory>();
                var may = new List <ResourceDataFactory>();
                var all = new List <ResourceDataFactory>();

                foreach (var factory in GetFactories())
                {
                    switch (factory.HandlesType(typeId))
                    {
                    case Compatibility.Yes:
                        yes.Add(factory);
                        break;

                    case Compatibility.Maybe:
                        may.Add(factory);
                        break;

                    case Compatibility.All:
                        all.Add(factory);
                        break;
                    }
                }

                yes.AddRange(may);
                yes.AddRange(all);

                _forType.Add(typeId, yes.ToArray());
            }

            return(_forType[typeId]);
        }
Ejemplo n.º 10
0
        private static Byte[] ReconstructRawData(IconDirectory dir, FileIconDirectoryEntry[] ents, IconCursorImageResourceData[] images, ResourceSource source)
        {
            Int32 sizeOfIconDirectory = Marshal.SizeOf(typeof(IconDirectory));
            Int32 sizeOfResIconDirEnt = Marshal.SizeOf(typeof(ResIconDirectoryEntry));

            Int32 sizeOfData =
                sizeOfIconDirectory +
                sizeOfResIconDirEnt * dir.wCount;

            IntPtr p = Marshal.AllocHGlobal(sizeOfData);

            Marshal.StructureToPtr(dir, p, true);

            IntPtr q = Inc(p, Marshal.SizeOf(typeof(IconDirectory)));

            for (int i = 0; i < ents.Length; i++)
            {
                FileIconDirectoryEntry e = ents[i];

                ResourceTypeIdentifier iconImageTypeId = new ResourceTypeIdentifier(new IntPtr((int)Win32ResourceType.IconImage));
                ResourceIdentifier     nameId          = source.GetUnusedName(iconImageTypeId);
                source.Add(iconImageTypeId, nameId, 1033, images[i]);

                ResIconDirectoryEntry d = new ResIconDirectoryEntry()
                {
                    bWidth       = e.bWidth,
                    bHeight      = e.bHeight,
                    bColorCount  = e.bColorCount,
                    bReserved    = e.bReserved,
                    wPlanes      = e.wPlanes,
                    wBitCount    = e.wPlanes,
                    dwBytesInRes = e.dwBytesInRes,
                    wId          = (ushort)images[i].Lang.Name.Identifier.NativeId
                };

                Marshal.StructureToPtr(d, q, true);
                q = Inc(q, sizeOfResIconDirEnt);
            }

            Byte[] data = new Byte[sizeOfData];
            Marshal.Copy(p, data, 0, sizeOfData);

            Marshal.FreeHGlobal(p);

            return(data);

            // Major problem:
            // RawData of a directory contains the ResourceNames of the entries in the ResourceSource
            // seeming as this source does not exist, what should go in their place?

            // idea:
            // when a ResourceData is created from a file it is passed the current ResourceSource which it can 'preliminarily add' the datas to
            //	a UI will need to be presented to prompt the user for details if not in Simple Mode. A UI is presented anyway, so this works.

            // this way the IconCursorImageResourceData has been added to the ResourceSource (with the Action.Add property) and this method can
            //	just query ResourceName. Simple (sort-of)
        }
Ejemplo n.º 11
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType == Win32ResourceType.CursorDirectory)
            {
                return(Compatibility.Yes);
            }

            return(Compatibility.No);
        }
Ejemplo n.º 12
0
        internal ResourceType(ResourceTypeIdentifier typeId, ResourceSource source)
        {
            Identifier = typeId;
            Source     = source;

            UnderlyingNames = new List <ResourceName>();
            Names           = new ResourceNameCollection(
                UnderlyingNames
                ); // ResourceNameCollection is a read-only decorator of any List
        }
Ejemplo n.º 13
0
        private static StatelessResult OneOffDelete(String sourceFilename, ResourceTypeIdentifier typeId, ResourceIdentifier nameId, UInt16 langId)
        {
            ResourceSource source = ResourceSource.Open(sourceFilename, false, ResourceSourceLoadMode.Blind);

            source.Remove(typeId, nameId, langId);

            source.CommitChanges();

            return(StatelessResult.Success);
        }
Ejemplo n.º 14
0
 public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
 {
     if (typeId.KnownType == Win32ResourceType.Version)
     {
         return(Compatibility.Yes);
     }
     else
     {
         return(Compatibility.No);
     }
 }
Ejemplo n.º 15
0
        //////////////////////////////

        private void CreateResourceData()
        {
            MainForm parent = Owner as MainForm;

            _data = ResourceData.FromFileToAdd(__file.Text, 1033, parent.CurrentSource);

            _data.Tag["sourceFile"] = __file.Text;

            SetDetailsEnabled(true);

            ///////////////////////////
            // Recommended Type

            ResourceTypeIdentifier typeId = _data.RecommendedTypeId;

            if (typeId.KnownType != Win32ResourceType.Custom)
            {
                if (typeId.KnownType == Win32ResourceType.Unknown)
                {
                    // add the type to the list

                    // for now, just throw
                    throw new NotSupportedException("Resourcer does not support Unknown Win32 types.");
                }
                else
                {
                    __typeWin32Rad.Checked = true;

                    foreach (Pair <String, Win32ResourceType> item in __typeKnown.Items)
                    {
                        if (item.Y == typeId.KnownType)
                        {
                            __typeKnown.SelectedItem = item;
                            break;
                        }
                    }
                }
            }
            else
            {
                __typeStringRad.Checked = true;

                __typeString.Text = typeId.StringId;
            }

            // Set recommended control values

            ///////////////////////////
            // Recommended Name

            __nameAuto.Checked = true;
            __nameCustom.Value = MainForm.LatestInstance.CurrentSource.GetUnusedName(typeId).IntegerId.Value;
        }
Ejemplo n.º 16
0
        private static StatelessResult OneOffAdd(String sourceFilename, ResourceTypeIdentifier typeId, ResourceIdentifier nameId, UInt16 langId, String dataFilename)
        {
            ResourceSource source = ResourceSource.Open(sourceFilename, false, ResourceSourceLoadMode.EnumerateOnly);

            ResourceData data = ResourceData.FromFileToAdd(dataFilename, langId, source);

            source.Add(typeId, nameId, langId, data);

            source.CommitChanges();

            return(StatelessResult.Success);
        }
Ejemplo n.º 17
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType == Win32ResourceType.CursorImage)
            {
                return(Compatibility.Yes);
            }
            if (typeId.KnownType == Win32ResourceType.Bitmap)
            {
                return(Compatibility.Maybe);
            }

            return(Compatibility.No);
        }
Ejemplo n.º 18
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType != Win32ResourceType.Custom)
            {
                return(Compatibility.No);
            }

            if (typeId.StringId == "GIF")
            {
                return(Compatibility.Yes);
            }

            return(Compatibility.Maybe);
        }
Ejemplo n.º 19
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType != Win32ResourceType.Custom)
            {
                return(Compatibility.No);
            }

            if (typeId.StringId.IndexOf("TIF", StringComparison.OrdinalIgnoreCase) > -1)
            {
                return(Compatibility.Yes);
            }

            return(Compatibility.Maybe);
        }
Ejemplo n.º 20
0
 public ResourceType this[ResourceTypeIdentifier typeId]
 {
     get
     {
         foreach (var type in this)
         {
             if (type.Identifier.Equals(typeId))
             {
                 return(type);
             }
         }
         return(null);
     }
 }
Ejemplo n.º 21
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType == Win32ResourceType.Custom)
            {
                if (String.Equals(typeId.StringId, "JPEG", StringComparison.InvariantCultureIgnoreCase) ||
                    String.Equals(typeId.StringId, "JPG", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(Compatibility.Yes);
                }

                return(Compatibility.Maybe);
            }

            return(Compatibility.No);
        }
Ejemplo n.º 22
0
        /// <summary>Associates all of the IconImages in this directory with the ResourceSource by creating IconCursorResourceData instances for each IconImage (with the specified Lang)</summary>
        public void BindToSource(ResourceSource source, UInt16 langId)
        {
            IconCursorImageResourceDataFactory factory = GetImageFactory();

            ResourceTypeIdentifier typeId = Type == IconType.Icon ? _iiTypeId : _ciTypeId;

            foreach (IconImage image in _images)
            {
                IconCursorImageResourceData rd = (IconCursorImageResourceData)factory.FromFileData(null, image.ImageData, Type == IconType.Icon);

                image.ResourceDataTyped = rd;

                source.Add(typeId, source.GetUnusedName(typeId), langId, rd);
            }
        }
Ejemplo n.º 23
0
        private static StatelessResult OneOffExtract(String sourceFilename, ResourceTypeIdentifier typeId, ResourceIdentifier nameId, UInt16 langId, String dataFilename)
        {
            ResourceSource source = ResourceSource.Open(sourceFilename, true, ResourceSourceLoadMode.LazyLoadData);

            ResourceLang lang = source.GetLang(typeId, nameId, langId);

            if (lang == null)
            {
                return(new StatelessResult("Could not find lang " + GetResPath(typeId, nameId, langId) + " to extract."));
            }

            lang.Data.Save(dataFilename);

            return(StatelessResult.Success);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Get specified resource type.
        /// </summary>
        /// <param name="resourceTypeIdentifier">Resource type identifier.</param>
        /// <param name="localeId">Locale id.</param>
        /// <returns>Resource type.</returns>
        public static WebResourceType GetResourceType(ResourceTypeIdentifier resourceTypeIdentifier,
                                                      Int32 localeId)
        {
            WebResourceType resourceType;

            resourceType            = new WebResourceType();
            resourceType.Id         = (Int32)(resourceTypeIdentifier);
            resourceType.Identifier = resourceTypeIdentifier.ToString();
            switch (localeId)
            {
            case ((Int32)LocaleId.sv_SE):
                switch (resourceTypeIdentifier)
                {
                case ResourceTypeIdentifier.Database:
                    resourceType.Name = Settings.Default.ResourceTypeDatabaseSwedishName;
                    break;

                case ResourceTypeIdentifier.WebService:
                    resourceType.Name = Settings.Default.ResourceTypeWebServiceSwedishName;
                    break;

                default:
                    throw new ArgumentException("Not supported resource type =" + resourceTypeIdentifier);
                }
                break;

            default:
                // English is default and also returned if not
                // supported language is requested.
                switch (resourceTypeIdentifier)
                {
                case ResourceTypeIdentifier.Database:
                    resourceType.Name = Settings.Default.ResourceTypeDatabaseEnglishName;
                    break;

                case ResourceTypeIdentifier.WebService:
                    resourceType.Name = Settings.Default.ResourceTypeWebServiceEnglishName;
                    break;

                default:
                    throw new ArgumentException("Not supported resource type =" + resourceTypeIdentifier);
                }
                break;
            }

            return(resourceType);
        }
Ejemplo n.º 25
0
        public override Compatibility HandlesType(ResourceTypeIdentifier typeId)
        {
            if (typeId.KnownType != Win32ResourceType.Custom)
            {
                return(Compatibility.No);
            }

            switch (typeId.StringId.ToUpperInvariant())
            {
            case "RIFF":
            case "WAV":
            case "WAVE":
            case "AVI":
                return(Compatibility.Yes);
            }

            return(Compatibility.No);
        }
Ejemplo n.º 26
0
        internal static String GetTreeNodeImageListTypeKey(ResourceTypeIdentifier typeId)
        {
            switch (typeId.KnownType)
            {
            case Win32ResourceType.Accelerator:
                return("Accelerator");

            case Win32ResourceType.Bitmap:
                return("Bitmap");

            case Win32ResourceType.CursorDirectory:
            case Win32ResourceType.CursorImage:
                return("Cursor");

            case Win32ResourceType.Dialog:
                return("Dialog");

            case Win32ResourceType.Menu:
                return("Menu");

            case Win32ResourceType.IconDirectory:
            case Win32ResourceType.IconImage:
                return("Icon");

            case Win32ResourceType.Html:
                return("Html");

            case Win32ResourceType.Manifest:
                return("Xml");

            case Win32ResourceType.StringTable:
                return("StringTable");

            case Win32ResourceType.ToolBar:
                return("Toolbar");

            case Win32ResourceType.Version:
                return("Version");

            case Win32ResourceType.Custom:
            default:
                return("Binary");
            }
        }
Ejemplo n.º 27
0
        public virtual ResourceLang GetLang(ResourceTypeIdentifier typeId, ResourceIdentifier nameId, ushort langId)
        {
            var name = GetName(typeId, nameId);

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

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

            return(null);
        }
Ejemplo n.º 28
0
        private static StatelessResult OneOffUpdate(String sourceFilename, ResourceTypeIdentifier typeId, ResourceIdentifier nameId, UInt16 langId, String dataFilename)
        {
            ResourceSource source = ResourceSource.Open(sourceFilename, false, ResourceSourceLoadMode.LazyLoadData);

            ResourceLang lang = source.GetLang(typeId, nameId, langId);

            if (lang == null)
            {
                return(new StatelessResult("Could not find lang " + GetResPath(typeId, nameId, langId) + " to update."));
            }

            ResourceData newData = ResourceData.FromFileToUpdate(dataFilename, lang);

            lang.SwapData(newData);

            source.CommitChanges();

            return(StatelessResult.Success);
        }
Ejemplo n.º 29
0
        public void AddUpdate(IconImage image)
        {
            IconImage original = FindMatch(image);

            if (original == null)
            {
                ResourceTypeIdentifier typeId = AppropriateType.Identifier;

                Source.Add(typeId, Source.GetUnusedName(typeId), DirectoryLang.LanguageId, image.ResourceDataTyped);
            }
            else
            {
                ResourceLang lang = original.ResourceData.Lang;
                lang.SwapData(image.ResourceData);

                _images.Remove(original);
            }

            _images.Add(image);
            _images.Sort();
        }
Ejemplo n.º 30
0
        private static IconImageResourceDataFactory GetIconImageFactory()
        {
            if (_factory != null)
            {
                return(_factory);
            }

            ResourceTypeIdentifier typeId = new ResourceTypeIdentifier(new IntPtr((int)Win32ResourceType.IconImage));

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

            foreach (ResourceDataFactory f in factories)
            {
                IconImageResourceDataFactory iif = f as IconImageResourceDataFactory;
                if (iif != null)
                {
                    return(_factory = iif);
                }
            }

            return(_factory);
        }