Example #1
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);
            }
        }
        private byte[] InternalGetIcon(string appId, int pxSize = 48)
        {
            // extract icon from .exe
            // note: `IconExtractor` use LoadLibrary Win32API, so I need save the command binary into file.
            var tmpPath = ExtractEntryPointCommandFile(appId);

            if (tmpPath == null)
            {
                return(NoImagePng());
            }

            try
            {
                using (var msIco = new MemoryStream())
                    using (var msPng = new MemoryStream())
                    {
                        IconExtractor.Extract1stIconTo(tmpPath, msIco);
                        if (msIco.Length == 0)
                        {
                            return(NoImagePng());
                        }

                        msIco.Seek(0, SeekOrigin.Begin);
                        var icon = new FromMono.System.Drawing.Icon(msIco, pxSize, pxSize);

                        var iconBmp  = icon.ToBitmap();
                        var iconSize = iconBmp.Size.Width;
                        if (iconSize < pxSize)
                        {
                            //var margin = (pxSize - iconSize) / 2;
                            var newBmp = new Bitmap(width: pxSize, height: pxSize);
                            using (var g = Graphics.FromImage(newBmp))
                            {
                                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                                g.DrawImage(iconBmp, 0, 0, pxSize, pxSize);
                            }
                            iconBmp.Dispose();
                            iconBmp = newBmp;
                        }
                        iconBmp.Save(msPng, ImageFormat.Png);
                        iconBmp.Dispose();
                        icon.Dispose();

                        return(msPng.ToArray());
                    }
            }
            finally
            {
                System.IO.File.Delete(tmpPath);
            }
        }
Example #3
0
 private string GetIcon(string path)
 {
     try
     {
         string tempFile = Path.GetTempFileName() + ".ico";
         using (FileStream fs = new FileStream(tempFile, FileMode.Create))
         {
             IconExtractor.Extract1stIconTo(path, fs);
         }
         return(tempFile);
     }
     catch { }
     return("");
 }
Example #4
0
        private byte[] InternalGetIcon(string appId)
        {
            var commandPath = GetEntryPointCommandPath(appId);

            if (commandPath == null)
            {
                return(NoImagePng());
            }

            var commandBytes = this.ClickOnceFileRepository.GetFileContent(appId, commandPath);

            if (commandBytes == null)
            {
                return(NoImagePng());
            }

            // extract icon from .exe
            // note: `IconExtractor` use LoadLibrary Win32API, so I need save the command binary into file.
            var tmpPath = Server.MapPath("~/App_Data/" + Guid.NewGuid().ToString("N") + ".exe");

            System.IO.File.WriteAllBytes(tmpPath, commandBytes);
            try
            {
                using (var msIco = new MemoryStream())
                    using (var msPng = new MemoryStream())
                    {
                        IconExtractor.Extract1stIconTo(tmpPath, msIco);
                        if (msIco.Length == 0)
                        {
                            return(NoImagePng());
                        }

                        msIco.Seek(0, SeekOrigin.Begin);
                        var icon = new FromMono.System.Drawing.Icon(msIco, 48, 48);

                        icon.ToBitmap().Save(msPng, ImageFormat.Png);
                        return(msPng.ToArray());
                    }
            }
            finally
            {
                System.IO.File.Delete(tmpPath);
            }
        }