Inheritance: IconDirectory
Example #1
0
        public PeContainer(string filename, ushort groupIconName)
        {
            ValidateFilename(filename);

            // load pe
            var datafile = PInvoke.LoadDatafile(filename);
            if (datafile == IntPtr.Zero)
                throw new Win32Exception("Unable to load datafile", PInvoke.GetLastWin32Exception());

            using (var disposableUpdate = new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary))
            {
                // load group icon data
                var groupIconBytes = PInvoke.LoadResourceBytes(datafile,
                    (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName);

                // parse directory from data
                Directory = new PeDirectory(groupIconBytes);

                Images = new IconImage[Directory.Entries.Length];

                // parse images from data
                for (var i = 0; i < Directory.Entries.Length; i++)
                {
                    var imageBytes = PInvoke.LoadResourceBytes(datafile,
                        (ushort)PInvoke.ResourceType.ICON, Directory.Entries[i].Id);

                    Images[i] = new IconImage(imageBytes);
                }

                disposableUpdate.SuppressDispose();
            }
        }
Example #2
0
        public PeContainer(string filename, ushort groupIconName)
        {
            ValidateFilename(filename);

            // load pe
            var datafile = PInvoke.LoadDatafile(filename);

            if (datafile == IntPtr.Zero)
            {
                throw new Win32Exception("Unable to load datafile", PInvoke.GetLastWin32Exception());
            }

            using (var disposableUpdate = new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary))
            {
                // load group icon data
                var groupIconBytes = PInvoke.LoadResourceBytes(datafile,
                                                               (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName);

                // parse directory from data
                Directory = new PeDirectory(groupIconBytes);

                Images = new IconImage[Directory.Entries.Length];

                // parse images from data
                for (var i = 0; i < Directory.Entries.Length; i++)
                {
                    var imageBytes = PInvoke.LoadResourceBytes(datafile,
                                                               (ushort)PInvoke.ResourceType.ICON, Directory.Entries[i].Id);

                    Images[i] = new IconImage(imageBytes);
                }

                disposableUpdate.SuppressDispose();
            }
        }
Example #3
0
        // gets related busy icon names from file
        private ushort[] GetBusyIconNames(string filename, ushort groupIconName)
        {
            var datafile = LoadDatafile(filename);

            ushort[]    busyNames;
            PeDirectory oldDirectory = null;

            using (new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary))
            {
                busyNames = PInvoke.GetResourceNames(datafile,
                                                     (ushort)PInvoke.ResourceType.ICON);

                var directoryExists = PInvoke.GetResourceNames(datafile,
                                                               (ushort)PInvoke.ResourceType.GROUP_ICON).Any(n => n == groupIconName);

                if (directoryExists)
                {
                    var directoryBytes = PInvoke.LoadResourceBytes(datafile,
                                                                   (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName);
                    oldDirectory = new PeDirectory(directoryBytes);
                }
            }

            if (oldDirectory != null)
            {
                var oldNames = oldDirectory.Entries.Select(e => e.Id);
                busyNames = busyNames.Except(oldNames).ToArray();
            }

            return(busyNames);
        }
Example #4
0
        public PeContainer(IcoContainer container)
            : base(container)
        {
            if (container.Directory == null)
                throw new InvalidOperationException("Container Directory is null");

            Directory = new PeDirectory(container.Directory);
        }
Example #5
0
        public PeContainer(IcoContainer container) :
            base(container)
        {
            if (container.Directory == null)
            {
                throw new InvalidOperationException("Container Directory is null");
            }

            Directory = new PeDirectory(container.Directory);
        }
Example #6
0
        public static IcoDirectory ToIco(this PeDirectory directory)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            if (directory.Entries == null || directory.Entries.Any(e => e == null))
            {
                throw new InvalidOperationException("Directory Entries are null");
            }

            return(new IcoDirectory(directory)
            {
                Entries = directory.Entries.Select(e => e.ToIco()).ToArray()
            });
        }
Example #7
0
 public PeContainer()
 {
     Directory = new PeDirectory();
 }
Example #8
0
        // gets related busy icon names from file
        private ushort[] GetBusyIconNames(string filename, ushort groupIconName)
        {
            var datafile = LoadDatafile(filename);

            ushort[] busyNames;
            PeDirectory oldDirectory = null;
            using (new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary))
            {
                busyNames = PInvoke.GetResourceNames(datafile,
                    (ushort)PInvoke.ResourceType.ICON);

                var directoryExists = PInvoke.GetResourceNames(datafile,
                    (ushort)PInvoke.ResourceType.GROUP_ICON).Any(n => n == groupIconName);

                if (directoryExists)
                {
                    var directoryBytes = PInvoke.LoadResourceBytes(datafile,
                        (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName);
                    oldDirectory = new PeDirectory(directoryBytes);
                }
            }

            if (oldDirectory != null)
            {
                var oldNames = oldDirectory.Entries.Select(e => e.Id);
                busyNames = busyNames.Except(oldNames).ToArray();
            }

            return busyNames;
        }
Example #9
0
 public PeDirectory(PeDirectory directory)
     : base(directory)
 {
     Entries = directory.Entries.Select(e => new PeDirectoryEntry(e)).ToArray();
 }
Example #10
0
 public PeContainer()
 {
     Directory = new PeDirectory();
 }
Example #11
0
 public PeDirectory(PeDirectory directory) :
     base(directory)
 {
     Entries = directory.Entries.Select(e => new PeDirectoryEntry(e)).ToArray();
 }