public URLType UrlInfo(String sURL, out HelpQuery helpQuery) { String url = sURL.Replace("&", "&"); helpQuery = new HelpQuery(url); // Indexed Topic -- ms-xhelp:///?method=page&id=SouthPark.Index&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US // or an unrendered url: ms-xhelp:///?Id=SouthPark.EricCartman if ((!String.IsNullOrEmpty(helpQuery.AssetId)) && (String.IsNullOrEmpty(helpQuery.Method) || helpQuery.Method.ToLower() == "page")) return URLType.Topic; // F1Keyword query "ms-xhelp:///?method=f1&query=SouthPark.Text" if ((!String.IsNullOrEmpty(helpQuery.QueryValue)) && !String.IsNullOrEmpty(helpQuery.Method) && helpQuery.Method.ToLower() == "f1") return URLType.F1Keyword; // Branding package path "ms-xhelp:///?76555C51-8CF1-4FEB-81C4-BED857D94EBB_EN-US_Microsoft;/branding.js" else if (url.IndexOf("?76555C51-8CF1-4FEB-81C4-BED857D94EBB_", StringComparison.OrdinalIgnoreCase) > 0) // ms-xhelp:///?xxxxx.css return URLType.Branding; // Asset -- "ms-xhelp:///?method=asset&id=XyzStyles.css&package=SOURCE HELP.mshc&topiclocale=EN-US" // Or some unrendered asset link ms-xhelp:///?xxxxx.css else if ((!String.IsNullOrEmpty(helpQuery.AssetId) && !String.IsNullOrEmpty(helpQuery.Method) && helpQuery.Method.ToLower() == "asset") // ms-xhelp:///?method=asset&id=xxx || (String.IsNullOrEmpty(helpQuery.Method) && String.IsNullOrEmpty(helpQuery.AssetId))) // ms-xhelp:///?xxxxx.css return URLType.Asset; else return URLType.Unknown; }
private void ExpandImageSrc(XmlNode node) //only pass in <img > node. Expand the src=url { // Before: <img class="mtps-img-src" alt="Welcome to Visual Studio 2010" src="IC348421" /> // After: <img class="mtps-img-src" src="ms-xhelp:///?method=asset&id=IC348421&package=Visual_Studio_21800791_VS_100_en-us_6.mshc&topiclocale=EN-US" alt="Welcome to Visual Studio 2010" title="Welcome to Visual Studio 2010" /> // Windows help: <img src="mshelp://windows/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> // Windows help: <img src="mshelp://Help/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> // Windows OEM: <img src="mshelp://OEM/?id=TopicID493dg3789k4f"> ... int i; foreach (XmlAttribute attr in node.Attributes) { if (attr.Name.ToLower() == "src") { String ID = attr.Value; if (attr.Value.StartsWith("ms-xhelp:///?Id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("ms-xhelp:///?Id=".Length); } else if (attr.Value.StartsWith("mshelp://windows/?id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("mshelp://windows/?id=".Length); } else if (attr.Value.StartsWith("mshelp://help/?id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("mshelp://help/?id=".Length); } else if (attr.Value.StartsWith("mshelp://OEM/?id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("mshelp://OEM/?id=".Length); } else if (attr.Value.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { ID = ""; } if (ID != "") { //Windows Help weirdness -- /basic8/Resources/file.jpg --> /Resources/file.jpg i = ID.IndexOf("/resources/", StringComparison.OrdinalIgnoreCase); if (i > 0 && ID[0] == '/') { ID = ID.Substring(i); } ID = ID.Replace('/', '\\'); //ms-xhelp:///?method=asset&id=IC348421&package=Visual_Studio_21800791_VS_100_en-us_6.mshc&topiclocale=EN-US HelpQuery helpQuery = new HelpQuery("asset", ID, null, _helpQuery.TopicVersion, _helpQuery.TopicLocale, _helpQuery.Locale, _helpQuery.Vendor); helpQuery.Package = _helpQuery.Package; attr.Value = helpQuery.ToString(); //.Replace("&", "&"); } break; } } }
public static String GetMshcTopicID(String url) { if (!String.IsNullOrEmpty(url) && UrlType(url) == TopicLinkType.mshc) { HelpQuery helpQuery = new HelpQuery(url); if (!String.IsNullOrEmpty(helpQuery.Method) && helpQuery.Method.Equals("page", StringComparison.OrdinalIgnoreCase)) { return helpQuery.AssetId; // ms-xhelp:///?method=page&id=AssetId (return AssetID) } } return ""; }
public TopicStreamExpand(Stream stream, HelpQuery helpQuery) { _helpQuery = new HelpQuery(helpQuery.ToString()); if (String.IsNullOrEmpty(_helpQuery.Locale)) _helpQuery.Locale = MSLocales.ThreadLocale; xbrandingPath = msxhelpPrefix + DefaultBrandPathBase + _helpQuery.Locale + "_Microsoft"; //eg ms-xhelp:///?method=asset&id=SomeAssetPath&package=SomePackage.mshc&topiclocale=EN-US xAssetPathTemplate = msxhelpPrefix + "method=asset&id={0}&package=" + helpQuery.Package + "&topiclocale=" + _helpQuery.Locale; //Rip all meta data metaData = new MetaData(stream); //Render DoRender(stream); }
public TopicStreamExpand(Stream stream, HelpQuery helpQuery) { _helpQuery = new HelpQuery(helpQuery.ToString()); if (String.IsNullOrEmpty(_helpQuery.Locale)) { _helpQuery.Locale = MSLocales.ThreadLocale; } xbrandingPath = msxhelpPrefix + DefaultBrandPathBase + _helpQuery.Locale + "_Microsoft"; //eg ms-xhelp:///?method=asset&id=SomeAssetPath&package=SomePackage.mshc&topiclocale=EN-US xAssetPathTemplate = msxhelpPrefix + "method=asset&id={0}&package=" + helpQuery.Package + "&topiclocale=" + _helpQuery.Locale; //Rip all meta data metaData = new MetaData(stream); //Render DoRender(stream); }
private void ExpandAnchorHref(XmlNode node) //only pass in <a > node. Expand the href=url { // Before: <a href="ms-xhelp:///?Id=SouthPark.KyleBroflovski">KyleBroflovski</a> // After: <a href="ms-xhelp:///?method=page&id=SouthPark.KyleBroflovski&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US"> // Windows help: <a href="mshelp://windows/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> // Windows help: <a href="mshelp://Help/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> //variation used by images // Windows OEM: <a href="mshelp://OEM/?id=TopicID493dg3789k4f"> ... foreach (XmlAttribute attr in node.Attributes) { if (attr.Name.ToLower() == "href") { String ID = ""; if (attr.Value.StartsWith("ms-xhelp:///?Id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("ms-xhelp:///?Id=".Length); } else if (attr.Value.StartsWith("mshelp://windows/?id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("mshelp://windows/?id=".Length); } else if (attr.Value.StartsWith("mshelp://help/?id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("mshelp://help/?id=".Length); } else if (attr.Value.StartsWith("mshelp://OEM/?id=", StringComparison.OrdinalIgnoreCase)) { ID = attr.Value.Substring("mshelp://OEM/?id=".Length); } //update value with full path if (ID != "") { ID = ID.Replace('/', '\\'); //ms-xhelp:///?method=page&id=SouthPark.KyleBroflovski&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US HelpQuery helpQuery = new HelpQuery("page", ID, null, _helpQuery.TopicVersion, _helpQuery.TopicLocale, _helpQuery.Locale, _helpQuery.Vendor); attr.Value = helpQuery.ToString(); //.Replace("&", "&"); } break; } } }
public URLType UrlInfo(String sURL, out HelpQuery helpQuery) { String url = sURL.Replace("&", "&"); helpQuery = new HelpQuery(url); // Indexed Topic -- ms-xhelp:///?method=page&id=SouthPark.Index&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US // or an unrendered url: ms-xhelp:///?Id=SouthPark.EricCartman if ((!String.IsNullOrEmpty(helpQuery.AssetId)) && (String.IsNullOrEmpty(helpQuery.Method) || helpQuery.Method.ToLower() == "page")) { return(URLType.Topic); } // F1Keyword query "ms-xhelp:///?method=f1&query=SouthPark.Text" if ((!String.IsNullOrEmpty(helpQuery.QueryValue)) && !String.IsNullOrEmpty(helpQuery.Method) && helpQuery.Method.ToLower() == "f1") { return(URLType.F1Keyword); } // Branding package path "ms-xhelp:///?76555C51-8CF1-4FEB-81C4-BED857D94EBB_EN-US_Microsoft;/branding.js" else if (url.IndexOf("?76555C51-8CF1-4FEB-81C4-BED857D94EBB_", StringComparison.OrdinalIgnoreCase) > 0) // ms-xhelp:///?xxxxx.css { return(URLType.Branding); } // Asset -- "ms-xhelp:///?method=asset&id=XyzStyles.css&package=SOURCE HELP.mshc&topiclocale=EN-US" // Or some unrendered asset link ms-xhelp:///?xxxxx.css else if ((!String.IsNullOrEmpty(helpQuery.AssetId) && !String.IsNullOrEmpty(helpQuery.Method) && helpQuery.Method.ToLower() == "asset") || // ms-xhelp:///?method=asset&id=xxx (String.IsNullOrEmpty(helpQuery.Method) && String.IsNullOrEmpty(helpQuery.AssetId))) // ms-xhelp:///?xxxxx.css { return(URLType.Asset); } else { return(URLType.Unknown); } }
public Stream UrlToStream(String sURL, Boolean okToRender) { if (MsxhelpProtocol.Catalog == null || !MsxhelpProtocol.Catalog.IsOpen) return null; HelpQuery helpQuery; URLType urltype = UrlInfo(sURL, out helpQuery); String url = sURL.Replace("&", "&"); Stream stream = null; String assetPath = ""; CatalogRead _catalogRead = new CatalogRead(); // Indexed Topic -- ms-xhelp:///?method=page&id=SouthPark.Index&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US // or an unrendered url: ms-xhelp:///?Id=SouthPark.EricCartman if (urltype == URLType.Topic) { _helpQuery = new HelpQuery(helpQuery.ToString()); HelpFilter filter = new HelpFilter(); if (!String.IsNullOrEmpty(_helpQuery.Vendor)) filter.Add("vendor", _helpQuery.Vendor); if (!String.IsNullOrEmpty(_helpQuery.TopicLocale)) filter.Add("topiclocale", _helpQuery.TopicLocale); if (!String.IsNullOrEmpty(_helpQuery.TopicVersion)) filter.Add("topicversion", _helpQuery.TopicVersion); //Get topic obj frome store String [] root = _helpQuery.AssetId.Split(new String[] {"%7c"}, StringSplitOptions.None); if (root.Length == 1) { _topic = (Topic)_catalogRead.GetIndexedTopicDetails(MsxhelpProtocol.Catalog, _helpQuery.AssetId, filter); } else if (root.Length == 3 && root[0] == "VS") { String[] path = root[2].Split(new string[] {"%5c"}, StringSplitOptions.None); if (root[1] == "winui") { // Create keyword list String name = path[path.Length-1]; if (name.IndexOf(".") != -1) name = name.Substring(0, name.IndexOf(".")); String[] prioritizedF1Keywords = new String[1]; prioritizedF1Keywords[0] = "winuser/" + name; //Get topic obj frome store _topic = (Topic)_catalogRead.GetTopicDetailsForF1Keyword(MsxhelpProtocol.Catalog, prioritizedF1Keywords, filter); } } if (_topic != null) { // _topic.Package == _topic.Url = package.mshc;\\path (so we need to split to get the package) String[] url2 = _topic.Url.Split(new char[] { ';' }); if (url2.Length > 0) helpQuery.Package = url2[0]; // "package.mshc" _helpQuery.Package = helpQuery.Package; if (!String.IsNullOrEmpty(_topic.Locale)) _helpQuery.Locale = _topic.Locale; if (String.IsNullOrEmpty(_helpQuery.Locale)) _helpQuery.Locale = MSLocales.ThreadLocale; if (!String.IsNullOrEmpty(_topic.TopicLocale)) _helpQuery.TopicLocale = _topic.TopicLocale; if (!String.IsNullOrEmpty(_topic.TopicVersion)) _helpQuery.TopicVersion = _topic.TopicVersion; if (!String.IsNullOrEmpty(_topic.Vendor)) _helpQuery.Vendor = _topic.Vendor; //Special Case: Force modified text if (!String.IsNullOrEmpty(MsxhelpProtocol.UserTopicText)) { stream = MsxhelpProtocol.GetUserTopicAsStream(); } else { try { stream = (Stream)_topic.FetchContent(); //Normal fetch topic from store //this would also return the stream //stream = (Stream)_catalogRead.GetIndexedTopic(MsxhelpProtocol.Catalog, _topic.Id, null); } catch { stream = null; } } if (stream != null && okToRender) { new TopicStreamExpand(stream, helpQuery); // expand all links etc in the stream } } } // F1Keyword query "ms-xhelp:///?method=f1&query=SouthPark.Text" else if (urltype == URLType.F1Keyword) { _helpQuery = new HelpQuery(helpQuery.ToString()); MessageBox.Show(_helpQuery.QueryValue,"hi",MessageBoxButtons.OK); HelpFilter filter = new HelpFilter(); if (!String.IsNullOrEmpty(_helpQuery.Vendor)) filter.Add("vendor", _helpQuery.Vendor); if (!String.IsNullOrEmpty(_helpQuery.TopicLocale)) filter.Add("topiclocale", _helpQuery.TopicLocale); if (!String.IsNullOrEmpty(_helpQuery.TopicVersion)) filter.Add("topicversion", _helpQuery.TopicVersion); // Create keyword list String[] prioritizedF1Keywords = new String[1]; prioritizedF1Keywords[0] = _helpQuery.QueryValue; //Get topic obj frome store _topic = (Topic)_catalogRead.GetTopicDetailsForF1Keyword(MsxhelpProtocol.Catalog, prioritizedF1Keywords, filter); if (_topic != null) { // _topic.Package == _topic.Url = package.mshc;\\path (so we need to split to get the package) String[] url2 = _topic.Url.Split(new char[] { ';' }); if (url2.Length > 0) helpQuery.Package = url2[0]; // "package.mshc" _helpQuery.Package = helpQuery.Package; if (!String.IsNullOrEmpty(_topic.Locale)) _helpQuery.Locale = _topic.Locale; if (String.IsNullOrEmpty(_helpQuery.Locale)) _helpQuery.Locale = MSLocales.ThreadLocale; if (!String.IsNullOrEmpty(_topic.TopicLocale)) _helpQuery.TopicLocale = _topic.TopicLocale; if (!String.IsNullOrEmpty(_topic.TopicVersion)) _helpQuery.TopicVersion = _topic.TopicVersion; if (!String.IsNullOrEmpty(_topic.Vendor)) _helpQuery.Vendor = _topic.Vendor; //Special Case: Force modified text if (!String.IsNullOrEmpty(MsxhelpProtocol.UserTopicText)) { stream = MsxhelpProtocol.GetUserTopicAsStream(); } else { try { stream = (Stream)_topic.FetchContent(); //Normal fetch topic from store //this would also return the stream //stream = (Stream)_catalogRead.GetIndexedTopic(MsxhelpProtocol.Catalog, _topic.Id, null); } catch { stream = null; } } if (stream != null && okToRender) { new TopicStreamExpand(stream, helpQuery); // expand all links etc in the stream } } } // Branding package path "ms-xhelp:///?76555C51-8CF1-4FEB-81C4-BED857D94EBB_EN-US_Microsoft;/branding.js" else if (urltype == URLType.Branding) { if (url.StartsWith("76555C51-8CF1-4FEB-81C4-BED857D94EBB_", StringComparison.OrdinalIgnoreCase)) // xxxxx.css assetPath = url.Replace("/", @"\"); else assetPath = url.Substring("ms-xhelp:///?".Length).Replace("/", @"\"); String[] parts = assetPath.Split(new char[] { '_' }); String brandingLocale = parts[1]; assetPath = url.Split(new char[] { ';' })[1]; assetPath = assetPath.TrimStart(new char[] { '/' }); // For now we have branding files in a folder ".\Branding" Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); String BrandingDir = Path.Combine(Path.GetDirectoryName(thisAssembly.Location), "Branding"); String filePath = Path.Combine(BrandingDir, assetPath); if (!Directory.Exists(BrandingDir)) { MessageBox.Show("Branding folder not found: " + BrandingDir); stream = null; } else if (!File.Exists(filePath)) { MessageBox.Show("Branding file not found: " + filePath); stream = null; } else { FileStream fs = File.OpenRead(filePath); byte[] b = new byte[fs.Length]; fs.Read(b, 0, b.Length); fs.Close(); stream = new MemoryStream(b); } } // Asset -- "ms-xhelp:///?method=asset&id=XyzStyles.css&package=SOURCE HELP.mshc&topiclocale=EN-US" // Or some unrendered asset link ms-xhelp:///?xxxxx.css else if (urltype == URLType.Asset) { if (!String.IsNullOrEmpty(helpQuery.AssetId)) assetPath = helpQuery.AssetId.Replace("/", @"\"); else assetPath = url.Substring("ms-xhelp:///".Length).Replace("/", @"\"); if (String.IsNullOrEmpty(_helpQuery.Package) && !String.IsNullOrEmpty(helpQuery.Package)) _helpQuery.Package = helpQuery.Package; if (!String.IsNullOrEmpty(_helpQuery.Package) && !String.IsNullOrEmpty(assetPath)) stream = (Stream)_catalogRead.GetLinkedAsset(MsxhelpProtocol.Catalog, _helpQuery.Package, assetPath, _helpQuery.Locale); } return stream; }
public Stream UrlToStream(String sURL, Boolean okToRender) { if (MsxhelpProtocol.Catalog == null || !MsxhelpProtocol.Catalog.IsOpen) { return(null); } HelpQuery helpQuery; URLType urltype = UrlInfo(sURL, out helpQuery); String url = sURL.Replace("&", "&"); Stream stream = null; String assetPath = ""; CatalogRead _catalogRead = new CatalogRead(); // Indexed Topic -- ms-xhelp:///?method=page&id=SouthPark.Index&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US // or an unrendered url: ms-xhelp:///?Id=SouthPark.EricCartman if (urltype == URLType.Topic) { _helpQuery = new HelpQuery(helpQuery.ToString()); HelpFilter filter = new HelpFilter(); if (!String.IsNullOrEmpty(_helpQuery.Vendor)) { filter.Add("vendor", _helpQuery.Vendor); } if (!String.IsNullOrEmpty(_helpQuery.TopicLocale)) { filter.Add("topiclocale", _helpQuery.TopicLocale); } if (!String.IsNullOrEmpty(_helpQuery.TopicVersion)) { filter.Add("topicversion", _helpQuery.TopicVersion); } //Get topic obj frome store String [] root = _helpQuery.AssetId.Split(new String[] { "%7c" }, StringSplitOptions.None); if (root.Length == 1) { _topic = (Topic)_catalogRead.GetIndexedTopicDetails(MsxhelpProtocol.Catalog, _helpQuery.AssetId, filter); } else if (root.Length == 3 && root[0] == "VS") { String[] path = root[2].Split(new string[] { "%5c" }, StringSplitOptions.None); if (root[1] == "winui") { // Create keyword list String name = path[path.Length - 1]; if (name.IndexOf(".") != -1) { name = name.Substring(0, name.IndexOf(".")); } String[] prioritizedF1Keywords = new String[1]; prioritizedF1Keywords[0] = "winuser/" + name; //Get topic obj frome store _topic = (Topic)_catalogRead.GetTopicDetailsForF1Keyword(MsxhelpProtocol.Catalog, prioritizedF1Keywords, filter); } } if (_topic != null) { // _topic.Package == _topic.Url = package.mshc;\\path (so we need to split to get the package) String[] url2 = _topic.Url.Split(new char[] { ';' }); if (url2.Length > 0) { helpQuery.Package = url2[0]; // "package.mshc" } _helpQuery.Package = helpQuery.Package; if (!String.IsNullOrEmpty(_topic.Locale)) { _helpQuery.Locale = _topic.Locale; } if (String.IsNullOrEmpty(_helpQuery.Locale)) { _helpQuery.Locale = MSLocales.ThreadLocale; } if (!String.IsNullOrEmpty(_topic.TopicLocale)) { _helpQuery.TopicLocale = _topic.TopicLocale; } if (!String.IsNullOrEmpty(_topic.TopicVersion)) { _helpQuery.TopicVersion = _topic.TopicVersion; } if (!String.IsNullOrEmpty(_topic.Vendor)) { _helpQuery.Vendor = _topic.Vendor; } //Special Case: Force modified text if (!String.IsNullOrEmpty(MsxhelpProtocol.UserTopicText)) { stream = MsxhelpProtocol.GetUserTopicAsStream(); } else { try { stream = (Stream)_topic.FetchContent(); //Normal fetch topic from store //this would also return the stream //stream = (Stream)_catalogRead.GetIndexedTopic(MsxhelpProtocol.Catalog, _topic.Id, null); } catch { stream = null; } } if (stream != null && okToRender) { new TopicStreamExpand(stream, helpQuery); // expand all links etc in the stream } } } // F1Keyword query "ms-xhelp:///?method=f1&query=SouthPark.Text" else if (urltype == URLType.F1Keyword) { _helpQuery = new HelpQuery(helpQuery.ToString()); MessageBox.Show(_helpQuery.QueryValue, "hi", MessageBoxButtons.OK); HelpFilter filter = new HelpFilter(); if (!String.IsNullOrEmpty(_helpQuery.Vendor)) { filter.Add("vendor", _helpQuery.Vendor); } if (!String.IsNullOrEmpty(_helpQuery.TopicLocale)) { filter.Add("topiclocale", _helpQuery.TopicLocale); } if (!String.IsNullOrEmpty(_helpQuery.TopicVersion)) { filter.Add("topicversion", _helpQuery.TopicVersion); } // Create keyword list String[] prioritizedF1Keywords = new String[1]; prioritizedF1Keywords[0] = _helpQuery.QueryValue; //Get topic obj frome store _topic = (Topic)_catalogRead.GetTopicDetailsForF1Keyword(MsxhelpProtocol.Catalog, prioritizedF1Keywords, filter); if (_topic != null) { // _topic.Package == _topic.Url = package.mshc;\\path (so we need to split to get the package) String[] url2 = _topic.Url.Split(new char[] { ';' }); if (url2.Length > 0) { helpQuery.Package = url2[0]; // "package.mshc" } _helpQuery.Package = helpQuery.Package; if (!String.IsNullOrEmpty(_topic.Locale)) { _helpQuery.Locale = _topic.Locale; } if (String.IsNullOrEmpty(_helpQuery.Locale)) { _helpQuery.Locale = MSLocales.ThreadLocale; } if (!String.IsNullOrEmpty(_topic.TopicLocale)) { _helpQuery.TopicLocale = _topic.TopicLocale; } if (!String.IsNullOrEmpty(_topic.TopicVersion)) { _helpQuery.TopicVersion = _topic.TopicVersion; } if (!String.IsNullOrEmpty(_topic.Vendor)) { _helpQuery.Vendor = _topic.Vendor; } //Special Case: Force modified text if (!String.IsNullOrEmpty(MsxhelpProtocol.UserTopicText)) { stream = MsxhelpProtocol.GetUserTopicAsStream(); } else { try { stream = (Stream)_topic.FetchContent(); //Normal fetch topic from store //this would also return the stream //stream = (Stream)_catalogRead.GetIndexedTopic(MsxhelpProtocol.Catalog, _topic.Id, null); } catch { stream = null; } } if (stream != null && okToRender) { new TopicStreamExpand(stream, helpQuery); // expand all links etc in the stream } } } // Branding package path "ms-xhelp:///?76555C51-8CF1-4FEB-81C4-BED857D94EBB_EN-US_Microsoft;/branding.js" else if (urltype == URLType.Branding) { if (url.StartsWith("76555C51-8CF1-4FEB-81C4-BED857D94EBB_", StringComparison.OrdinalIgnoreCase)) // xxxxx.css { assetPath = url.Replace("/", @"\"); } else { assetPath = url.Substring("ms-xhelp:///?".Length).Replace("/", @"\"); } String[] parts = assetPath.Split(new char[] { '_' }); String brandingLocale = parts[1]; assetPath = url.Split(new char[] { ';' })[1]; assetPath = assetPath.TrimStart(new char[] { '/' }); // For now we have branding files in a folder ".\Branding" Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); String BrandingDir = Path.Combine(Path.GetDirectoryName(thisAssembly.Location), "Branding"); String filePath = Path.Combine(BrandingDir, assetPath); if (!Directory.Exists(BrandingDir)) { MessageBox.Show("Branding folder not found: " + BrandingDir); stream = null; } else if (!File.Exists(filePath)) { MessageBox.Show("Branding file not found: " + filePath); stream = null; } else { FileStream fs = File.OpenRead(filePath); byte[] b = new byte[fs.Length]; fs.Read(b, 0, b.Length); fs.Close(); stream = new MemoryStream(b); } } // Asset -- "ms-xhelp:///?method=asset&id=XyzStyles.css&package=SOURCE HELP.mshc&topiclocale=EN-US" // Or some unrendered asset link ms-xhelp:///?xxxxx.css else if (urltype == URLType.Asset) { if (!String.IsNullOrEmpty(helpQuery.AssetId)) { assetPath = helpQuery.AssetId.Replace("/", @"\"); } else { assetPath = url.Substring("ms-xhelp:///".Length).Replace("/", @"\"); } if (String.IsNullOrEmpty(_helpQuery.Package) && !String.IsNullOrEmpty(helpQuery.Package)) { _helpQuery.Package = helpQuery.Package; } if (!String.IsNullOrEmpty(_helpQuery.Package) && !String.IsNullOrEmpty(assetPath)) { stream = (Stream)_catalogRead.GetLinkedAsset(MsxhelpProtocol.Catalog, _helpQuery.Package, assetPath, _helpQuery.Locale); } } return(stream); }
// Update Details view when user clicks a link in the browser private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { String url = e.Url.AbsoluteUri; if (url.StartsWith("ms-xhelp:", StringComparison.OrdinalIgnoreCase)) { HelpQuery helpQuery = new HelpQuery(url); if (helpQuery.Method.Equals("page", StringComparison.OrdinalIgnoreCase)) { //get topic from ID try { Topic topic = (Topic)Globals.catalogRead.GetIndexedTopicDetails(Globals.catalog, helpQuery.AssetId, null); UpdateTopicDetails(topic); //update details only } catch { } } } }
//only pass in <img > node. Expand the src=url private void ExpandImageSrc(XmlNode node) { // Before: <img class="mtps-img-src" alt="Welcome to Visual Studio 2010" src="IC348421" /> // After: <img class="mtps-img-src" src="ms-xhelp:///?method=asset&id=IC348421&package=Visual_Studio_21800791_VS_100_en-us_6.mshc&topiclocale=EN-US" alt="Welcome to Visual Studio 2010" title="Welcome to Visual Studio 2010" /> // Windows help: <img src="mshelp://windows/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> // Windows help: <img src="mshelp://Help/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> // Windows OEM: <img src="mshelp://OEM/?id=TopicID493dg3789k4f"> ... int i; foreach (XmlAttribute attr in node.Attributes) { if (attr.Name.ToLower() == "src") { String ID = attr.Value; if (attr.Value.StartsWith("ms-xhelp:///?Id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("ms-xhelp:///?Id=".Length); else if (attr.Value.StartsWith("mshelp://windows/?id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("mshelp://windows/?id=".Length); else if (attr.Value.StartsWith("mshelp://help/?id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("mshelp://help/?id=".Length); else if (attr.Value.StartsWith("mshelp://OEM/?id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("mshelp://OEM/?id=".Length); else if (attr.Value.StartsWith("http", StringComparison.OrdinalIgnoreCase)) ID = ""; if (ID != "") { //Windows Help weirdness -- /basic8/Resources/file.jpg --> /Resources/file.jpg i = ID.IndexOf("/resources/", StringComparison.OrdinalIgnoreCase); if (i > 0 && ID[0] == '/') ID = ID.Substring(i); ID = ID.Replace('/', '\\'); //ms-xhelp:///?method=asset&id=IC348421&package=Visual_Studio_21800791_VS_100_en-us_6.mshc&topiclocale=EN-US HelpQuery helpQuery = new HelpQuery("asset", ID, null, _helpQuery.TopicVersion, _helpQuery.TopicLocale, _helpQuery.Locale, _helpQuery.Vendor); helpQuery.Package = _helpQuery.Package; attr.Value = helpQuery.ToString(); //.Replace("&", "&"); } break; } } }
//only pass in <a > node. Expand the href=url private void ExpandAnchorHref(XmlNode node) { // Before: <a href="ms-xhelp:///?Id=SouthPark.KyleBroflovski">KyleBroflovski</a> // After: <a href="ms-xhelp:///?method=page&id=SouthPark.KyleBroflovski&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US"> // Windows help: <a href="mshelp://windows/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> // Windows help: <a href="mshelp://Help/?id=bf416877-c83f-4476-a3da-8ec98dcf5f10"> //variation used by images // Windows OEM: <a href="mshelp://OEM/?id=TopicID493dg3789k4f"> ... foreach (XmlAttribute attr in node.Attributes) { if (attr.Name.ToLower() == "href") { String ID = ""; if (attr.Value.StartsWith("ms-xhelp:///?Id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("ms-xhelp:///?Id=".Length); else if (attr.Value.StartsWith("mshelp://windows/?id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("mshelp://windows/?id=".Length); else if (attr.Value.StartsWith("mshelp://help/?id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("mshelp://help/?id=".Length); else if (attr.Value.StartsWith("mshelp://OEM/?id=", StringComparison.OrdinalIgnoreCase)) ID = attr.Value.Substring("mshelp://OEM/?id=".Length); //update value with full path if (ID != "") { ID = ID.Replace('/', '\\'); //ms-xhelp:///?method=page&id=SouthPark.KyleBroflovski&vendor=ACME Company&topicVersion=-1&topicLocale=EN-US HelpQuery helpQuery = new HelpQuery("page", ID, null, _helpQuery.TopicVersion, _helpQuery.TopicLocale, _helpQuery.Locale, _helpQuery.Vendor); attr.Value = helpQuery.ToString(); //.Replace("&", "&"); } break; } } }