Exemplo n.º 1
0
        private void AddAppByFile(string strAppCmdLine, string strName)
        {
            if (string.IsNullOrEmpty(strAppCmdLine))
            {
                return;                                                 // No assert
            }
            string strPath = UrlUtil.GetShortestAbsolutePath(
                UrlUtil.GetQuotedAppPath(strAppCmdLine).Trim());

            if (strPath.Length == 0)
            {
                Debug.Assert(false); return;
            }

            foreach (OpenWithItem it in m_lOpenWith)
            {
                if (it.FilePath.Equals(strPath, StrUtil.CaseIgnoreCmp))
                {
                    return;                     // Already have an item for this
                }
            }

            // Filter non-existing/legacy applications
            try { if (!File.Exists(strPath))
                  {
                      return;
                  }
            }
            catch (Exception) { Debug.Assert(false); return; }

            if (string.IsNullOrEmpty(strName))
            {
                strName = UrlUtil.StripExtension(UrlUtil.GetFileName(strPath));
            }

            Image img = UIUtil.GetFileIcon(strPath, 16, 16);

            string       strMenuText = KPRes.OpenWith.Replace(@"{PARAM}", strName);
            OpenWithItem owi         = OpenWithItem.Create(strPath, strMenuText,
                                                           img, m_dynMenu);

            m_lOpenWith.Add(owi);
        }
Exemplo n.º 2
0
        private void AddAppByFile(string strAppCmdLine, string strName)
        {
            if (string.IsNullOrEmpty(strAppCmdLine))
            {
                return;                                                 // No assert
            }
            string strPath = UrlUtil.GetShortestAbsolutePath(
                UrlUtil.GetQuotedAppPath(strAppCmdLine).Trim());

            if (strPath.Length == 0)
            {
                Debug.Assert(false); return;
            }

            foreach (OpenWithItem it in m_lOpenWith)
            {
                if (it.FilePath.Equals(strPath, StrUtil.CaseIgnoreCmp))
                {
                    return;                     // Already have an item for this
                }
            }

            // Filter non-existing/legacy applications
            try { if (!File.Exists(strPath))
                  {
                      return;
                  }
            }
            catch (Exception) { Debug.Assert(false); return; }

            if (string.IsNullOrEmpty(strName))
            {
                strName = UrlUtil.StripExtension(UrlUtil.GetFileName(strPath));
            }

            Image img = null;

            try
            {
                Icon ico = Icon.ExtractAssociatedIcon(strPath);
                if (ico == null)
                {
                    throw new InvalidOperationException();
                }

                img = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
                using (Graphics g = Graphics.FromImage(img))
                {
                    g.Clear(Color.Transparent);
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode     = SmoothingMode.HighQuality;
                    g.DrawIcon(ico, new Rectangle(0, 0, img.Width, img.Height));
                }

                ico.Dispose();
            }
            catch (Exception) { Debug.Assert(false); }

            string       strMenuText = KPRes.OpenWith.Replace(@"{PARAM}", strName);
            OpenWithItem owi         = OpenWithItem.Create(strPath, strMenuText,
                                                           img, m_dynMenu);

            m_lOpenWith.Add(owi);
        }