Example #1
0
        /// <summary>
        /// Extract the information from an executable file
        /// </summary>
        /// <param name="filePath"> Fully qualified name of the file</param>
        /// <param name="entry"> </param>
        private void LoadAnExe(string filePath, TextBox entry)
        {
            // we have an internet shortcut
            FileInfo  lnk       = new FileInfo(filePath);
            MenuEntry thisEntry = new MenuEntry();

            thisEntry.TargetOriginal = filePath;
            thisEntry.Target         = filePath;
            thisEntry.Arguments      = "";
            thisEntry.IconPath       = "";
            thisEntry.IconIndex      = 0;
            thisEntry.PanelName      = entry.Name;
            thisEntry.StartIn        = lnk.DirectoryName;

            string        iconfilename = IconFolder + @"\" + lnk.Name.Substring(0, lnk.Name.Length - lnk.Extension.Length) + ".ico";
            IconExtractor extractor    = new IconExtractor(filePath);
            Icon          icon         = extractor.GetIcon(thisEntry.IconIndex);

            splitIcons = IconUtil.Split(icon);
            iconCount  = splitIcons.GetUpperBound(0);

            Image1.Image    = splitIcons[0].ToBitmap();
            IconNumber.Text = "0";

            thisEntry.IconPath = iconfilename;

            SetItem(thisEntry);
        }
Example #2
0
        private void btnPickFile_Click(object sender, EventArgs e)
        {
            var result = iconPickerDialog.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                var fileName = iconPickerDialog.FileName;
                m_iconIndex = iconPickerDialog.IconIndex;

                Icon   icon       = null;
                Icon[] splitIcons = null;
                try
                {
                    if (Path.GetExtension(iconPickerDialog.FileName).ToLower() == ".ico")
                    {
                        m_iconExtractor = null;
                        icon            = new Icon(iconPickerDialog.FileName);
                    }
                    else
                    {
                        m_iconExtractor = new IconExtractor(fileName);
                        icon            = m_iconExtractor.GetIcon(m_iconIndex);
                    }

                    splitIcons = IconUtil.Split(icon);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                txtFileName.Text = String.Format(
                    "{0}, #{1}, {2} variations", fileName, m_iconIndex, splitIcons.Length);

                // Update icons.

                Icon = icon;
                icon.Dispose();

                lvwIcons.BeginUpdate();
                ClearAllIcons();

                foreach (var i in splitIcons)
                {
                    var item = new IconListViewItem();
                    var size = i.Size;
                    item.BitCount    = IconUtil.GetBitCount(i);
                    item.Bitmap      = IconUtil.ToBitmap(i);
                    item.ToolTipText = String.Format("{0}x{1}, {2} bits", size.Width, size.Height, item.BitCount);
                    i.Dispose();

                    lvwIcons.Items.Add(item);
                }

                lvwIcons.EndUpdate();

                btnSaveAsIco.Enabled = (m_iconExtractor != null);
            }
        }
Example #3
0
        //
        private void ApplicationGridImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (sender is Image img)
            {
                System.Windows.Forms.OpenFileDialog fd = new System.Windows.Forms.OpenFileDialog
                {
                    Filter = "Icon (.ico)|*.ico|Image files (.png)|*.png|Application (.exe)|*.exe"
                };
                int index = applications[ApplicationTable.SelectedIndex].ApplicationPath.LastIndexOf(@"\");
                if (index > 0)
                {
                    fd.InitialDirectory = applications[ApplicationTable.SelectedIndex].ApplicationPath.Substring(0, index + 1);
                }

                System.Windows.Forms.DialogResult result = fd.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
                {
                    IconExtractor iconExtractor = new IconExtractor(fd.FileName);
                    // If any icon is found
                    if (iconExtractor.Count > 0)
                    {
                        // Gets the largest icon from the exe
                        img.Source = iconExtractor.GetIcon(0).ToImageSource();
                    }

                    //img.Source = ImageUtilities.ToImageSource(fd.FileName);
                }
            }
        }
        /// <summary>
        /// Convert a <see cref="IItem"/> into an image representation.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            var item = value as IItem;

            if (item == null)
            {
                return(Binding.DoNothing);
            }

            System.Windows.Media.ImageSource displayIcon = null;

            try
            {
                // a folder can be represented with a seperate icon for its expanded state
                if (item.ItemType == FSItemType.Folder)
                {
                    displayIcon = IconExtractor.GetFolderIcon(item.ItemPath,
                                                              item.IsExpanded).ToImageSource();
                }
                else
                {
                    displayIcon = IconExtractor.GetFileIcon(item.ItemPath).ToImageSource();
                }
            }
            catch
            {
            }

            return(displayIcon);
        }
Example #5
0
        // 获取右侧列表的 文件图片
        protected override Bitmap GetKFBInner(FileSystemInfoEx entry, string key, IconSize size)
        {
            Bitmap bitmap = null;

            if (entry is FileInfoEx)
            {
                string extension = PathEx.GetExtension(entry.Name);
                if (IconExtractor.IsKFBIcon(extension))
                {
                    try
                    {
                        bitmap = GetKFBThumnail(entry.FullName);
                    }
                    catch
                    {
                        bitmap = null;
                    }
                }
                if (bitmap != null)
                {
                    return(bitmap);
                }
            }
            return(bitmap);
        }
Example #6
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            lock (StoreLock)
            {
                var storedIcon = StoredIcons.FirstOrDefault(x => x.IconId == IconId && x.Size == Size);
                if (storedIcon != null)
                {
                    return(storedIcon.ImageSource);
                }

                using (
                    var extractor =
                        new IconExtractor(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86),
                                                       LibraryName)))
                    using (var icon = extractor.GetIconAt(IconId))
                    {
                        var info  = new IconInfo(icon);
                        var index = info.GetBestFitIconIndex(new Size(Size, Size));
                        using (var bestIcon = info.Images[index])
                        {
                            var imageSource = Imaging.CreateBitmapSourceFromHIcon(
                                bestIcon.Handle,
                                Int32Rect.Empty,
                                BitmapSizeOptions.FromEmptyOptions());
                            StoredIcons.Add(new StoredIcon {
                                IconId = IconId, ImageSource = imageSource, Size = Size
                            });
                            return(imageSource);
                        }
                    }
            }
        }
 static ViewDataItem()
 {
     IconExtractor            = new IconExtractor();
     BackEntry                = Resources.Back;
     Nfi                      = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
     Nfi.NumberGroupSeparator = " ";
 }
    public static ImageSource GetIcon(string path, double size)
    {
        ImageSource image = null;

        if (IconCache.TryGetValue(path, out image))
        {
            return(image);
        }

        var pathIndex = TextHelpers.Split2(path, "|");

        try
        {
            IconExtractor extractor = new IconExtractor(pathIndex.Item1);
            int           index     = MiscFunc.parseInt(pathIndex.Item2);
            if (index < extractor.Count)
            {
                image = ToImageSource(extractor.GetIcon(index, new System.Drawing.Size((int)size, (int)size)));
            }
        }
        catch { }

        if (image == null)
        {
            image = ToImageSource(Icon.ExtractAssociatedIcon(MiscFunc.mNtOsKrnlPath));
        }

        IconCache.Add(path, image);

        return(image);
    }
Example #9
0
        private void CreateUI()
        {
            var fp = new FlowLayoutPanel();

            fp.SuspendLayout();
            SuspendLayout();

            foreach (var entry in config.Entries)
            {
                var button = new Button
                {
                    Text   = entry.Description,
                    Width  = config.ButtonWidth,
                    Height = config.ButtonHeight,
                    Tag    = entry.Name
                };
                button.Click += Button_Click;

                buttons.Add(button);
            }

            fp.Controls.AddRange(buttons.ToArray());
            fp.Dock = DockStyle.Fill;

            Icon     = IconExtractor.Extract("shell32.dll", 9, true);
            Location = Properties.Settings.Default.WindowLocation;
            Size     = Properties.Settings.Default.WindowSize;
            Controls.Add(fp);

            fp.ResumeLayout(false);
            ResumeLayout(false);
        }
Example #10
0
        private void btnOpenIconFile_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Title        = "Choose an icon",
                AddExtension = false,
                Filter       = "Icon files|*.ico|Executable files|*.exe",
                FilterIndex  = 2
            };

            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                //var icons = MintPlayer.IconUtils.IconExtractor.Split(ofd.FileName);
                var icons = IconExtractor.Split(ofd.FileName);

                var folder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(ofd.FileName), "Split");
                if (!System.IO.Directory.Exists(folder))
                {
                    System.IO.Directory.CreateDirectory(folder);
                }
                var index = 1;
                foreach (var icon in icons)
                {
                    var filename = System.IO.Path.Combine(folder, "icon_" + (index++).ToString() + ".ico");
                    using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
                    {
                        icon.Save(fs);
                    }
                }
            }
        }
        public static Icon GetHighResIcon(string incPath)
        {
            Icon icon = null;

            try
            {
                try
                {
                    IconExtractor ie = new IconExtractor(incPath);
                    icon = ie.GetIcon(0);
                }
                catch (Exception ex)
                {
                    icon = IconFromFilePath(incPath);
                    ex.Log();
                }
                Icon[] splitIcons  = IconUtil.Split(icon); //icon0
                Icon   biggestIcon = splitIcons[0];
                foreach (var item in splitIcons)
                {
                    biggestIcon = item.Width > biggestIcon.Width ? item : biggestIcon;
                }

                return(biggestIcon);
            }
            catch (Exception ex)
            {
                ex.Log($"Error at 'GetHighResIcon(string incPath={incPath})'\n\n{ex.Message}");
                return(IconFromFilePath(incPath));
            }
        }
 public override sealed void UpdateParameters()
 {
     NativeSystemInfo     = new NativeFileInfo(Path);
     Icon                 = IconExtractor.GetDirectoryIcon(Path, NativeSystemInfo.IconIndex);
     _directoryInfo       = new DirectoryInfo(Path);
     LastModificationDate = _directoryInfo.LastWriteTime;
 }
Example #13
0
        /// <summary>
        /// Ask the shell to feed us the appropriate icon for the given file, but
        /// first try looking in our cache to see if we've already loaded it.
        /// </summary>
        private int ExtractIconIfNecessary(String path)
        {
            Icon   icon;
            Size   size = GetSmallIconSize();
            String ext  = Path.GetExtension(path);

            if (String.IsNullOrEmpty(ext))
            {
                ext = "folder";
            }
            if (this.imageList.Images[ext] != null)
            {
                return(this.imageList.Images.IndexOfKey(ext));
            }
            else
            {
                if (File.Exists(path))
                {
                    icon = IconExtractor.GetFileIcon(path, false, true);
                }
                else
                {
                    icon = IconExtractor.GetFolderIcon(path, false, true);
                }
                Image image = ImageKonverter.ImageResize(icon.ToBitmap(), size.Width, size.Height);
                this.imageList.Images.Add(ext, image); icon.Dispose(); image.Dispose();
                return(this.imageList.Images.Count - 1);
            }
        }
Example #14
0
 public Users()
 {
     InitializeComponent();
     this.Icon    = IconExtractor.Extract("shell32.dll", 86, true);
     connStr      = Properties.Settings.Default.ConnectionUrl;
     label1.Image = IconExtractor.Extract("shell32.dll", 209, false).ToBitmap();
 }
Example #15
0
        // https://stackoverflow.com/questions/22499407/how-to-display-a-bitmap-in-a-wpf-image
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is WindowsPEResourceIcon resIcon)
            {
                var exePath = resIcon.FilePath;

                // check if lnk, if so resolve the executable location first
                if (resIcon.FilePath.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
                {
                    var shell    = new WshShell();
                    var shortcut = (IWshShortcut)shell.CreateShortcut(resIcon.FilePath);
                    exePath = shortcut.TargetPath;
                }

                // extract icon from exe
                try
                {
                    var extractor      = new IconExtractor(exePath);
                    var iconCollection = extractor.GetIcon(resIcon.Index);
                    var biggestIcon    = IconUtil.Split(iconCollection).OrderByDescending(x => x.Width * x.Height).FirstOrDefault();
                    if (biggestIcon != null)
                    {
                        return(CreateBitmapImageFromBitmap(biggestIcon.ToBitmap()));
                    }
                }
                catch (Exception)
                {
                    // no icon, file not found or whatever
                }
            }

            return(null);
        }
Example #16
0
 private string convertExeIconToBase64(Process p)
 {
     try
     {
         if (p != null)
         {
             string filename = p.MainModule.FileName;
             Debug.WriteLine("Application: " + p.MainModule.FileName);
             IntPtr hIcon = IconExtractor.GetJumboIcon(IconExtractor.GetIconIndex(filename));
             // Extract Icon
             string         result;
             ImageConverter converter = new ImageConverter();
             using (Bitmap ico = ((Icon)Icon.FromHandle(hIcon).Clone()).ToBitmap())
             {
                 Bitmap bitmap = IconExtractor.ClipToCircle(ico);
                 result = Convert.ToBase64String((byte[])converter.ConvertTo(bitmap, typeof(byte[])));
                 bitmap.Dispose();
             }
             IconExtractor.Shell32.DestroyIcon(hIcon); // Cleanup
             GC.Collect();
             EmptyWorkingSet(Process.GetCurrentProcess().Handle);
             return(result);
         }
     }
     catch (Exception e) {
         Debug.WriteLine("Exception: " + e.Message);
     }
     return(null);
 }
Example #17
0
        public Icon GetBestIcon(String path)
        {
            if (!path.EndsWith(".exe") && !path.EndsWith(".dll"))
            {
                return(null);
            }
            IconExtractor ie        = new IconExtractor(path);
            string        fileName  = ie.FileName;
            int           iconCount = ie.Count;

            if (iconCount > 0)
            {
                Icon[] allIcons = ie.GetAllIcons();
                Icon   ret      = null;
                foreach (var icon in allIcons)
                {
                    Icon[] splitIcons  = IconUtil.Split(icon);
                    Icon   biggestIcon = splitIcons.OrderBy(x => x.Size.Height).Last();
                    if (ret == null || biggestIcon.Height > ret.Height)
                    {
                        ret = biggestIcon;
                    }
                }

                return(ret);
            }

            return(null);
        }
Example #18
0
 protected override Bitmap GetIconInner(FileSystemInfoEx entry, string key, IconSize size)
 {
     if (key.StartsWith("."))
     {
         throw new Exception("ext item is handled by IconExtractor");
     }
     if (entry is FileInfoEx)
     {
         Bitmap bitmap    = null;
         string extension = PathEx.GetExtension(entry.Name);
         if (IconExtractor.IsJpeg(extension))
         {
             bitmap = IconExtractor.GetExifThumbnail(entry.FullName);
         }
         if (IconExtractor.IsImageIcon(extension))
         {
             try
             {
                 bitmap = new Bitmap(entry.FullName);
             }
             catch
             {
                 bitmap = null;
             }
         }
         if (bitmap != null)
         {
             return(bitmap);
         }
     }
     return(GetBitmap(size, entry.PIDL.Ptr, entry is DirectoryInfoEx, false));
 }
 public void UpdateModel(AdditionalApplicationModel model)
 {
     Ensure.NotNull(model, "model");
     Icon  = IconExtractor.Get(model.Path);
     Path  = model.Path;
     Model = model;
     RaisePropertyChanged(nameof(Name));
 }
Example #20
0
 public NewUser(int rowid)
 {
     InitializeComponent();
     id        = rowid;
     this.Icon = IconExtractor.Extract("shell32.dll", 95, true);
     //btnSave.Image = IconExtractor.Extract("shell32.dll", 301, true).ToBitmap();
     //btnImgAdd.Image = IconExtractor.Extract("shell32.dll", 45, false).ToBitmap();
     //btnImgClear.Image = IconExtractor.Extract("shell32.dll", 31, false).ToBitmap();
 }
Example #21
0
        public static Icon ExtractIconFromFile(string filePath)
        {
            Argument.IsNotNull(() => filePath);

            var extractor = new IconExtractor(filePath);
            var icon      = extractor.GetIcon(0);

            return(icon);
        }
Example #22
0
        public static Icon ExtractIconFromFile(string filePath)
        {
            Argument.IsNotNull(() => filePath);

            var extractor = new IconExtractor(filePath);
            var icon = extractor.GetIcon(0);

            return icon;
        }
Example #23
0
        public DocumentType(string name, string typeMime, IEnumerable <string> extensions, string desc = null)
        {
            Name        = name;
            TypeMime    = typeMime;
            Extensions  = extensions;
            Description = desc;

            Icon = IconExtractor.ExtractSmallIconByExtension(DefaultExtension);
        }
Example #24
0
        private static Icon[] GetIcons(string filename)
        {
            Icon[]        splitIcons = new Icon[0];
            IconExtractor ie         = new IconExtractor(filename);

            if (ie.Count > 0)
            {
                splitIcons = IconUtil.Split(ie.GetIcon(0));
            }
            return(splitIcons);
        }
Example #25
0
 /// <summary>
 /// Assign a certain icon to this item.
 /// </summary>
 /// <param name="src"></param>
 public void SetDisplayIcon(ImageSource src = null)
 {
     if (src == null)
     {
         this.DisplayIcon = IconExtractor.GetFolderIcon(this.FullPath, true).ToImageSource();
     }
     else
     {
         this.DisplayIcon = src;
     }
 }
Example #26
0
        ///<exception cref="Exception"></exception>
        public static BitmapSource ExtractIconFromEXEDLL(string exeordllPath, int iconIndex, int width, int height)
        {
            System.Drawing.Icon   fullIcon  = new IconExtractor(exeordllPath).GetIcon(iconIndex);          //Throws if invalid path or index
            System.Drawing.Icon[] splitIcon = IconUtil.Split(fullIcon);
            System.Drawing.Icon   selectedIcon;
            if (splitIcon.Count() == 0)
            {
                throw new InvalidOperationException("The icon contains no sizes");
            }
            try {
                selectedIcon = (
                    splitIcon
                    .Last((icon) => {
                    return(icon.Width == width && icon.Height == height);
                })                         //Throws if no icons match
                    );
            } catch (InvalidOperationException) {
                IEnumerable <System.Drawing.Icon> largerIcons = (
                    splitIcon
                    .Where((icon) => {
                    return(icon.Width >= width && icon.Height >= height);
                })
                    );
                IEnumerable <System.Drawing.Icon> selectedIcons1;
                if (largerIcons.Count() == 0)
                {
                    selectedIcons1 = splitIcon;
                }
                else
                {
                    selectedIcons1 = largerIcons;
                }

                IEnumerable <System.Drawing.Icon> inProportionIcons = (
                    selectedIcons1.Where((icon) => {
                    return(icon.Width / icon.Height == width / height);
                })
                    );

                if (inProportionIcons.Count() == 0)
                {
                    selectedIcon = inProportionIcons.Best((icon) => {
                        return(Math.Abs((icon.Width - width)) * -1);
                    }, true);
                }
                else
                {
                    selectedIcon = selectedIcons1.Best((icon) => {
                        return(Math.Abs(((icon.Width * icon.Height) - (width * height))) * -1);
                    }, true);
                }
            }
            return(BitmapToBitmapSource(IconUtil.ToBitmap(selectedIcon)));            //Might throw exceptions
        }
        private void BuildListView()
        {
            //reset the list view items
            lvwIcons.Items.Clear();

            //validate the path exists
            var targetPath = txtPathToExtractFrom.Text;

            if (!File.Exists(targetPath))
            {
                return;
            }

            lvwIcons.BeginUpdate();
            try
            {
                //icon files don't need extraction
                if (string.Equals(Path.GetExtension(targetPath), ".ico", StringComparison.InvariantCultureIgnoreCase))
                {
                    _icons = new[] { new Icon(targetPath) };
                }
                else
                {
                    var iconExtraction = new IconExtractor(targetPath);
                    _icons = iconExtraction.GetAllIcons();
                }

                foreach (var i in _icons)
                {
                    var splitIcons = IconUtil.Split(i);

                    var largestIcon = splitIcons.OrderByDescending(k => k.Width)
                                      .ThenByDescending(k => Math.Max(k.Height, k.Width))
                                      .First();

                    var item = new IconListViewItem {
                        Bitmap = IconUtil.ToBitmap(largestIcon)
                    };
                    i.Dispose();
                    largestIcon.Dispose();

                    lvwIcons.Items.Add(item);
                }
            }
            catch
            {
                // ignored
            }
            finally
            {
                lvwIcons.EndUpdate();
            }
        }
Example #28
0
        public Msg(string strmsg, Int32 iconum)
        {
            //221 -OK
            //237 -Error

            InitializeComponent();
            this.Icon = IconExtractor.Extract("shell32.dll", 144, true);

            lblMsgText.Text  = msgtext = strmsg;
            lblMsgText.Image = IconExtractor.Extract("shell32.dll", iconum, true).ToBitmap();
            btnOK.Image      = IconExtractor.Extract("shell32.dll", 176, false).ToBitmap();
        }
Example #29
0
        protected override void OnDispose()
        {
            base.OnDispose();

            _iconExtractor = null;
            _embeddedModel = null;

            JumboIcon = null;
            LargeIcon = null;
            Icon      = null;
            SmallIcon = null;
        }
Example #30
0
        public IEnumerable <WindowsApp> GetWindowsApps()
        {
            foreach (var app in GetExecutablePaths())
            {
                using var ms = new MemoryStream();
                IconExtractor.Extract1stIconTo(app.ExecutableLocation, ms);
                app.IconPath = CopyIcons(ms, app.ExecutableLocation);
                app.IconB64  = ConvertIconToBase64(ms);

                yield return(app);
            }
        }
Example #31
0
    public static ImageSource GetIcon(string path, double size)
    {
        string key = path + "@" + size.ToString();

        ImageSource image = null;

        IconCacheLock.EnterReadLock();
        bool bFound = IconCache.TryGetValue(key, out image);

        IconCacheLock.ExitReadLock();
        if (bFound)
        {
            return(image);
        }

        try
        {
            var pathIndex = TextHelpers.Split2(path, "|");

            IconExtractor extractor = new IconExtractor(pathIndex.Item1);
            int           index     = MiscFunc.parseInt(pathIndex.Item2);
            if (index < extractor.Count)
            {
                image = ToImageSource(extractor.GetIcon(index, new System.Drawing.Size((int)size, (int)size)));
            }

            if (image == null)
            {
                if (File.Exists(MiscFunc.NtOsKrnlPath)) // if running in WOW64 this does not exist
                {
                    image = ToImageSource(Icon.ExtractAssociatedIcon(MiscFunc.NtOsKrnlPath));
                }
                else // fall back to an other icon
                {
                    image = ToImageSource(Icon.ExtractAssociatedIcon(MiscFunc.Shell32Path));
                }
            }

            image.Freeze();
        }
        catch (Exception err)
        {
            AppLog.Exception(err);
        }

        IconCacheLock.EnterWriteLock();
        if (!IconCache.ContainsKey(key))
        {
            IconCache.Add(key, image);
        }
        IconCacheLock.ExitWriteLock();
        return(image);
    }
Example #32
0
        public static Icon ExtractIconFromFile(string filePath)
        {
            Argument.IsNotNull(() => filePath);

            try
            {
                var extractor = new IconExtractor(filePath);
                var icon = extractor.GetIcon(0);
                return icon;
            }
            catch (Exception)
            {
                return null;
            }
        }
Example #33
0
        void Client_DataReceived(object sender, NWR_Client.DataReceivedEventArgs e)
        {
            Invoke((MethodInvoker)delegate
            {
                PacketReader r = e.Reader;

                switch ((Header)e.Header)
                {
                    case Header.BUILD:
                        int len = r.ReadInt32();
                        byte[] b = r.ReadBytes(len);
                        string binderResName = r.ReadString();
                        string pluginResName = r.ReadString();
                        MemoryStream ms = new MemoryStream(b);
                        AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(ms);
                        ms.Close();
                        ms.Dispose();
                        len = 0;
                        Invoke((MethodInvoker)delegate
                        {
                            len = lstBinder.Items.Count;
                        });
                        if (len > 0)
                        {
                            ms = new MemoryStream();
                            BinaryWriter wr = new BinaryWriter(ms);
                            for (int i = 0; i < lstBinder.Items.Count; i++)
                            {
                                Invoke((MethodInvoker)delegate
                                {
                                    string name = lstBinder.Items[i].Text;
                                    string fileName = lstBinder.Items[i].SubItems[1].Text;
                                    byte[] file = File.ReadAllBytes(fileName);
                                    wr.Write(name);
                                    wr.Write(file.Length);
                                    wr.Write(file);
                                });
                            }
                            wr.Close();
                            byte[] bData = Encryption.Encrypt(ms.ToArray(), false);
                            EmbeddedResource bRes = new EmbeddedResource(binderResName, ManifestResourceAttributes.Private, bData);
                            asm.MainModule.Resources.Add(bRes);
                            ms.Dispose();
                        }
                        Invoke((MethodInvoker)delegate
                        {
                            len = lstPlugins.CheckedItems.Count;
                        });
                        if (len > 0)
                        {
                            ms = new MemoryStream();
                            BinaryWriter br = new BinaryWriter(ms);
                            Invoke((MethodInvoker)delegate
                            {
                                for (int i = 0; i < lstPlugins.CheckedItems.Count; i++)
                                {
                                    byte[] plugin = GlobalProperties.RawPlugins[(Guid)lstPlugins.CheckedItems[i].Tag];
                                    plugin = Encryption.Encrypt(plugin, false);
                                    br.Write(plugin.Length);
                                    br.Write(plugin);
                                }
                            });
                            br.Close();
                            byte[] data = Encryption.Encrypt(ms.ToArray(), false);
                            EmbeddedResource res = new EmbeddedResource(pluginResName, ManifestResourceAttributes.Private, data);
                            asm.MainModule.Resources.Add(res);
                        }

                        asm.Write(saveLoc);
                        //if (!xCrypt.Checked)
                        //{
                        if (GlobalProperties.BuildAssembly != null)
                        {
                            if (!string.IsNullOrEmpty(GlobalProperties.BuildAssembly.IconPath))
                            {
                                if (GlobalProperties.BuildAssembly.IconPath.ToLower().EndsWith(".exe"))
                                {
                                    try
                                    {
                                        IconExtractor iconEx = new IconExtractor(GlobalProperties.BuildAssembly.IconPath);
                                        Icon icon = null;
                                        if (iconEx.IconCount > 1)
                                        {
                                            SortedList<int, Icon> icons = new SortedList<int, Icon>();
                                            for (int i = 0; i < iconEx.IconCount; i++)
                                            {
                                                icons.Add(i, iconEx.GetIcon(i));
                                            }
                                            IconSelecterDialog isd = new IconSelecterDialog(icons);
                                            if (isd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                                            {
                                                icon = iconEx.GetIcon(0);
                                            }
                                            isd.Dispose();
                                            icon = iconEx.GetIcon(isd.Selected);
                                        }
                                        else if (iconEx.IconCount == 1)
                                        {
                                            icon = iconEx.GetIcon(0);
                                        }
                                        else
                                        {
                                            throw new Exception();
                                        }
                                        FileStream fs = new FileStream("Icon.ico", FileMode.Create);
                                        icon.Save(fs);
                                        fs.Close();
                                    }
                                    catch
                                    {
                                    }
                                }
                                else if (GlobalProperties.BuildAssembly.IconPath.ToLower().EndsWith(".ico"))
                                {
                                    File.Copy(GlobalProperties.BuildAssembly.IconPath, "Icon.ico");
                                }
                                if (File.Exists("Icon.ico"))
                                {
                                    IconInjector.InjectIcon("Icon.ico", saveLoc);
                                    File.Delete("Icon.ico");
                                }
                            }
                        }
                        //}
                        //else
                        //{
                        //    byte[] file = File.ReadAllBytes(saveLoc);
                        //    File.Delete(saveLoc);
                        //    BuildCry(file, saveLoc);
                        //}
                        MessageBox.Show("Build Successful!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                }
            });
        }