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, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)); string strMenuText = KPRes.OpenWith.Replace(@"{PARAM}", strName); OpenWithItem owi = new OpenWithItem(strPath, OwFilePathType.Executable, strMenuText, img, m_dynMenu); m_lOpenWith.Add(owi); }
private void AddAppByShellExpand(string strShell, string strName, string strIconExe) { if(string.IsNullOrEmpty(strShell)) return; if(string.IsNullOrEmpty(strName)) strName = strShell; Image img = null; if(!string.IsNullOrEmpty(strIconExe)) img = UIUtil.GetFileIcon(strIconExe, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)); string strMenuText = KPRes.OpenWith.Replace(@"{PARAM}", strName); OpenWithItem owi = new OpenWithItem(strShell, OwFilePathType.ShellExpand, strMenuText, img, m_dynMenu); m_lOpenWith.Add(owi); }
private void FinishOpenWithList() { OpenWithItem itEdge = null; // New (Chromium-based) Edge OpenWithItem itVivaldi = null; foreach (OpenWithItem it in m_lOpenWith) { if (it.FilePathType != OwFilePathType.Executable) { continue; } string strFile = it.FilePath; if ((strFile.IndexOf("\\Microsoft", StrUtil.CaseIgnoreCmp) >= 0) && strFile.EndsWith("\\msedge.exe", StrUtil.CaseIgnoreCmp)) { if ((itEdge == null) || it.Name.Equals("Microsoft Edge", StrUtil.CaseIgnoreCmp)) { itEdge = it; } else { Debug.Assert(false); } // Duplicate? } else if (strFile.EndsWith("\\vivaldi.exe", StrUtil.CaseIgnoreCmp)) { if ((itVivaldi == null) || it.Name.Equals("Vivaldi", StrUtil.CaseIgnoreCmp)) { itVivaldi = it; } else { Debug.Assert(false); } // Duplicate? } } if (itEdge != null) { // The legacy Edge (EdgeHTML) doesn't register itself in the // 'StartMenuInternet' registry key, whereas the new one // (Chromium) does; so, the one that we found must be the // new Edge, which supports a command line option for the // private mode AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine( itEdge.FilePath) + "\" --inprivate \"" + PlhTargetUri + "\"", itEdge.Name + " (" + KPRes.Private + ")", itEdge.FilePath); } else // Add the legacy Edge (EdgeHTML), if available { if (AppLocator.EdgeProtocolSupported) { AddAppByShellExpand("microsoft-edge:" + PlhTargetUri, "Microsoft Edge", AppLocator.EdgePath); } } if (itVivaldi != null) { AddAppByShellExpand("cmd://\"" + SprEncoding.EncodeForCommandLine( itVivaldi.FilePath) + "\" --incognito \"" + PlhTargetUri + "\"", itVivaldi.Name + " (" + KPRes.Private + ")", itVivaldi.FilePath); } m_lOpenWith.Sort(OpenWithItem.CompareByName); }