Inheritance: IconDirectory
コード例 #1
0
ファイル: PEContainer.cs プロジェクト: vitalyobukhov/WebSaver
        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();
            }
        }
コード例 #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();
            }
        }
コード例 #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);
        }
コード例 #4
0
ファイル: PEContainer.cs プロジェクト: vitalyobukhov/WebSaver
        public PeContainer(IcoContainer container)
            : base(container)
        {
            if (container.Directory == null)
                throw new InvalidOperationException("Container Directory is null");

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

            Directory = new PeDirectory(container.Directory);
        }
コード例 #6
0
ファイル: IconConvertor.cs プロジェクト: tjoen/WebSaver
        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()
            });
        }
コード例 #7
0
ファイル: PEContainer.cs プロジェクト: vitalyobukhov/WebSaver
 public PeContainer()
 {
     Directory = new PeDirectory();
 }
コード例 #8
0
ファイル: PEContainer.cs プロジェクト: vitalyobukhov/WebSaver
        // 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;
        }
コード例 #9
0
ファイル: PEDirectory.cs プロジェクト: vitalyobukhov/WebSaver
 public PeDirectory(PeDirectory directory)
     : base(directory)
 {
     Entries = directory.Entries.Select(e => new PeDirectoryEntry(e)).ToArray();
 }
コード例 #10
0
 public PeContainer()
 {
     Directory = new PeDirectory();
 }
コード例 #11
0
ファイル: PEDirectory.cs プロジェクト: tjoen/WebSaver
 public PeDirectory(PeDirectory directory) :
     base(directory)
 {
     Entries = directory.Entries.Select(e => new PeDirectoryEntry(e)).ToArray();
 }