Browse Source

checked in the initial version of the new HelpViewer addin

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5834 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Mathias Simmack 15 years ago
parent
commit
608d54ffdf
  1. 16
      src/AddIns/Misc/HelpViewer/Configuration/AssemblyInfo.cs
  2. 29
      src/AddIns/Misc/HelpViewer/HelpViewer.addin
  3. 105
      src/AddIns/Misc/HelpViewer/HelpViewer.csproj
  4. 17
      src/AddIns/Misc/HelpViewer/HelpViewer.sln
  5. 29
      src/AddIns/Misc/HelpViewer/Source/BrowserScheme.cs
  6. 193
      src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs
  7. 66
      src/AddIns/Misc/HelpViewer/Source/Core/Help3Catalog.cs
  8. 97
      src/AddIns/Misc/HelpViewer/Source/Core/Help3Environment.cs
  9. 239
      src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs
  10. 129
      src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryAgent.cs
  11. 58
      src/AddIns/Misc/HelpViewer/Source/Core/NativeMethods.cs
  12. 19
      src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml
  13. 79
      src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml.cs
  14. 15
      src/AddIns/Misc/HelpViewer/Source/HelpMenu.cs
  15. 31
      src/AddIns/Misc/HelpViewer/Source/Helper/Help3Configuration.cs
  16. 141
      src/AddIns/Misc/HelpViewer/Source/Helper/HelpClientWatcher.cs
  17. 52
      src/AddIns/Misc/HelpViewer/Source/Helper/ProjectLanguages.cs
  18. 30
      src/AddIns/Misc/HelpViewer/Source/MSHelp3Provider.cs

16
src/AddIns/Misc/HelpViewer/Configuration/AssemblyInfo.cs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
using System.Reflection;
using System.Security.Permissions;
// Information about this assembly is defined by the following
// attributes.
//
// change them to the information which is associated with the assembly
// you compile.
[assembly: AssemblyTitle("Microsoft Help Viewer")]
[assembly: AssemblyDescription("Microsoft Help System v1.0 for SharpDevelop")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: System.CLSCompliant(false)]

29
src/AddIns/Misc/HelpViewer/HelpViewer.addin

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
<AddIn name = "Microsoft Help System v1.0"
author = "Mathias Simmack"
url = ""
description = "Help Integration for SharpDevelop">
<Runtime>
<Import assembly = "HelpViewer.dll"/>
</Runtime>
<Path name = "/SharpDevelop/Services/HelpProvider">
<Class id = "Help3" class = "MSHelpSystem.MSHelp3Provider"/>
</Path>
<Path name = "/SharpDevelop/Views/Browser/SchemeExtensions">
<BrowserSchemeExtension id = "ms-xhelp" class = "MSHelpSystem.BrowserScheme"/>
</Path>
<Path path = "/SharpDevelop/Dialogs/OptionsDialog/ToolsOptions">
<OptionPanel id = "Help3Options" label = "Microsoft Help System v1.0" class = "MSHelpSystem.Help3OptionsPanel" />
</Path>
<Path name = "/SharpDevelop/Workbench/MainMenu/Help">
<MenuItem id = "Help3DisplayCatalog"
class = "MSHelpSystem.SharpDevelopMenu.DisplayCatalogCommand"
label = "Display Help catalog"
shortcut = "Control|Alt|F1"
insertafter = "Help" />
</Path>
</AddIn>

105
src/AddIns/Misc/HelpViewer/HelpViewer.csproj

@ -0,0 +1,105 @@ @@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{80F76D10-0B44-4D55-B4BD-DAEB5464090C}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>MSHelpSystem</RootNamespace>
<AssemblyName>HelpViewer</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>..\..\..\..\AddIns\AddIns\Misc\HelpViewer\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\..\..\..\AddIns\AddIns\Misc\HelpViewer\</OutputPath>
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.Core">
<HintPath>..\..\..\..\bin\ICSharpCode.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ICSharpCode.Core.Presentation">
<HintPath>..\..\..\..\bin\ICSharpCode.Core.Presentation.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ICSharpCode.SharpDevelop">
<HintPath>..\..\..\..\bin\ICSharpCode.SharpDevelop.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<None Include="HelpViewer.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Source\BrowserScheme.cs" />
<Compile Include="Source\Core\DisplayHelp.cs" />
<Compile Include="Source\Core\Help3Catalog.cs" />
<Compile Include="Source\Core\Help3Environment.cs" />
<Compile Include="Source\Core\Help3Service.cs" />
<Compile Include="Source\Core\HelpLibraryAgent.cs" />
<Compile Include="Source\Help3OptionsPanel.xaml.cs">
<DependentUpon>Help3OptionsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Source\Helper\Help3Configuration.cs" />
<Compile Include="Source\Helper\HelpClientWatcher.cs" />
<Compile Include="Source\Helper\ProjectLanguages.cs" />
<Compile Include="Source\HelpMenu.cs" />
<Compile Include="Source\MSHelp3Provider.cs" />
<Compile Include="Source\Core\NativeMethods.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Source" />
<Folder Include="Source\Core" />
<Folder Include="Source\Helper" />
</ItemGroup>
<ItemGroup>
<Page Include="Source\Help3OptionsPanel.xaml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

17
src/AddIns/Misc/HelpViewer/HelpViewer.sln

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.5828
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelpViewer", "HelpViewer.csproj", "{80F76D10-0B44-4D55-B4BD-DAEB5464090C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{80F76D10-0B44-4D55-B4BD-DAEB5464090C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80F76D10-0B44-4D55-B4BD-DAEB5464090C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80F76D10-0B44-4D55-B4BD-DAEB5464090C}.Release|Any CPU.Build.0 = Release|Any CPU
{80F76D10-0B44-4D55-B4BD-DAEB5464090C}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal

29
src/AddIns/Misc/HelpViewer/Source/BrowserScheme.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
using System;
using System.Globalization;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.BrowserDisplayBinding;
using MSHelpSystem.Core;
namespace MSHelpSystem
{
public class BrowserScheme : DefaultSchemeExtension
{
public override void GoHome(HtmlViewPane pane)
{
if (pane == null) {
throw new ArgumentNullException("pane");
}
LoggingService.Info("Help 3.0: Calling browser (\"GoHome()\")");
DisplayHelp.Catalog();
}
public override void GoSearch(HtmlViewPane pane)
{
if (pane == null) {
throw new ArgumentNullException("pane");
}
LoggingService.Info("Help 3.0: Calling browser (\"GoSearch()\")");
pane.Navigate(new Uri(string.Format(@"http://social.msdn.microsoft.com/Search/{0}", CultureInfo.CurrentCulture.Name.ToLower())));
}
}
}

193
src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs

@ -0,0 +1,193 @@ @@ -0,0 +1,193 @@
using System;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.BrowserDisplayBinding;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using MSHelpSystem.Helper;
using MSHelpSystem.Core.Native;
namespace MSHelpSystem.Core
{
internal sealed class DisplayHelp
{
DisplayHelp()
{
}
public static void Catalog()
{
if (!Help3Environment.IsLocalHelp) {
MessageBox.Show("You requested an offline feature in the online help mode. You have to change the mode in order to use this feature.",
"Help Viewer",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
Help3Catalog c = Help3Service.ActiveCatalog;
if (c == null) {
throw new ArgumentNullException("c");
}
string helpCatalogUrl = string.Format(@"ms-xhelp://?method=page&id=-1&product={0}&productVersion={1}&locale={2}", c.ProductCode, c.ProductVersion, c.Locale);
LoggingService.Debug(string.Format("Help 3.0: {0}", helpCatalogUrl));
DisplayLocalHelp(helpCatalogUrl);
}
public static void Page(string pageId)
{
if (string.IsNullOrEmpty(pageId)) {
throw new ArgumentNullException("pageId");
}
if (!Help3Environment.IsLocalHelp) {
MessageBox.Show("You requested an offline feature in the online help mode. You have to change the mode in order to use this feature.",
"Help Viewer",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
Help3Catalog c = Help3Service.ActiveCatalog;
if (c == null) {
throw new ArgumentNullException("c");
}
string helpPageUrl = string.Format(@"ms-xhelp://?method=page&id={3}&product={0}&productVersion={1}&locale={2}", c.ProductCode, c.ProductVersion, c.Locale, pageId);
LoggingService.Debug(string.Format("Help 3.0: {0}", helpPageUrl));
DisplayLocalHelp(helpPageUrl);
}
public static void ContextualHelp(string contextual)
{
if (string.IsNullOrEmpty(contextual)) {
throw new ArgumentNullException("contextual");
}
if (!Help3Environment.IsLocalHelp) {
DisplayHelpOnMSDN(contextual);
return;
}
Help3Catalog c = Help3Service.ActiveCatalog;
if (c == null) {
throw new ArgumentNullException("c");
}
string helpContextualUrl = string.Format(@"ms-xhelp://?method=f1&query={3}&product={0}&productVersion={1}&locale={2}", c.ProductCode, c.ProductVersion, c.Locale, contextual);
LoggingService.Debug(string.Format("Help 3.0: {0}", helpContextualUrl));
DisplayLocalHelp(helpContextualUrl);
}
public static void Search(string searchWords)
{
if (string.IsNullOrEmpty(searchWords)) {
throw new ArgumentNullException("searchWords");
}
if (!Help3Environment.IsLocalHelp) {
DisplaySearchOnMSDN(searchWords);
return;
}
Help3Catalog c = Help3Service.ActiveCatalog;
if (c == null) {
throw new ArgumentNullException("c");
}
string helpSearchUrl = string.Format(@"ms-xhelp://method=search&query={3}&product={0}&productVersion={1}&locale={2}", c.ProductCode, c.ProductVersion, c.Locale, searchWords.Replace(" ", "+"));
LoggingService.Debug(string.Format("Help 3.0: {0}", helpSearchUrl));
DisplayLocalHelp(helpSearchUrl);
}
public static void Keywords(string keywords)
{
if (string.IsNullOrEmpty(keywords)) {
throw new ArgumentNullException("keywords");
}
if (!Help3Environment.IsLocalHelp) {
MessageBox.Show("You requested an offline feature in the online help mode. You have to change the mode in order to use this feature.",
"Help Viewer",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
Help3Catalog c = Help3Service.ActiveCatalog;
if (c == null) {
throw new ArgumentNullException("c");
}
string helpKeywordsUrl = string.Format(@"ms-xhelp://?method=keywords&query={3}&product={0}&productVersion={1}&locale={2}", c.ProductCode, c.ProductVersion, c.Locale, keywords);
LoggingService.Debug(string.Format("Help 3.0: {0}", helpKeywordsUrl));
DisplayLocalHelp(helpKeywordsUrl);
}
static string FormatMsXHelpToHttp(string helpUrl)
{
string output = helpUrl;
if (output.StartsWith("ms-xhelp://?")) {
output = string.Format(
@"http://127.0.0.1:{0}/help/{1}-{2}/ms.help?{3}",
HelpLibraryAgent.PortNumber,
NativeMethods.GetSessionId(),
HelpLibraryAgent.ProcessId,
output.Replace("ms-xhelp://?", ""));
}
return output;
}
static void DisplayLocalHelp(string arguments)
{
// TODO: set "embedded" to TRUE if we have a TOC control or something similar
DisplayLocalHelp(arguments, false);
}
static void DisplayLocalHelp(string arguments, bool embedded)
{
if (!Help3Environment.IsLocalHelp) { return; }
if (!HelpLibraryAgent.IsRunning) {
HelpLibraryAgent.Start();
Thread.Sleep(0x3e8);
}
string helpUrl = string.Format(@"{0}{1}{2}", FormatMsXHelpToHttp(arguments), ProjectLanguages.FormattedAsHttpParam(), (embedded)?"&embedded=true":string.Empty);
BrowserPane browser = ActiveHelp3Browser();
if (browser != null) {
LoggingService.Info(string.Format("Help 3.0: Navigating to {0}", helpUrl));
browser.Navigate(helpUrl);
browser.WorkbenchWindow.SelectWindow();
}
}
static void DisplayHelpOnMSDN(string keyword)
{
string msdnUrl = string.Format(@"http://msdn.microsoft.com/library/{0}.aspx", keyword);
BrowserPane browser = ActiveHelp3Browser();
if (browser != null) {
LoggingService.Info(string.Format("Help 3.0: Navigating to {0}", msdnUrl));
browser.Navigate(msdnUrl);
browser.WorkbenchWindow.SelectWindow();
}
}
static void DisplaySearchOnMSDN(string searchWords)
{
string msdnUrl = string.Format(@"http://social.social.msdn.microsoft.com/Search/{0}/?query={1}&ac=3", CultureInfo.CurrentUICulture.ToString(), searchWords.Replace(" ", "+"));
BrowserPane browser = ActiveHelp3Browser();
if (browser != null) {
LoggingService.Info(string.Format("Help 3.0: Navigating to {0}", msdnUrl));
browser.Navigate(msdnUrl);
browser.WorkbenchWindow.SelectWindow();
}
}
static BrowserPane ActiveHelp3Browser()
{
IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
if (window != null)
{
BrowserPane browser = window.ActiveViewContent as BrowserPane;
if (browser != null && browser.Url.Scheme == "http") return browser;
}
foreach (IViewContent view in WorkbenchSingleton.Workbench.ViewContentCollection)
{
BrowserPane browser = view as BrowserPane;
if (browser != null && browser.Url.Scheme == "http") return browser;
}
BrowserPane tmp = new BrowserPane();
WorkbenchSingleton.Workbench.ShowView(tmp);
return tmp;
}
}
}

66
src/AddIns/Misc/HelpViewer/Source/Core/Help3Catalog.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
using System;
namespace MSHelpSystem.Core
{
public class Help3Catalog
{
public Help3Catalog(string code, string version, string locale, string name, string catPath, string contPath, string brandPackage)
{
productCode = code;
productVersion = version;
productLocale = locale;
displayName = (string.IsNullOrEmpty(name)) ? code:name;
catalogPath = catPath;
contentPath = contPath;
brandingPackage = brandPackage;
}
string productCode;
string productVersion;
string productLocale;
string displayName;
string catalogPath;
string contentPath;
string brandingPackage;
public string ProductCode
{
get { return productCode; }
}
public string ProductVersion
{
get { return productVersion; }
}
public string Locale
{
get { return productLocale.ToUpper(); }
}
public string DisplayName
{
get { return displayName; }
}
public string CatalogPath
{
get { return catalogPath; }
}
public string ContentPath
{
get { return contentPath; }
}
public string BrandingPackage
{
get { return brandingPackage; }
}
public override string ToString()
{
return string.Format(@"{0}/{1}/{2}", productCode, productVersion, productLocale);
}
}
}

97
src/AddIns/Misc/HelpViewer/Source/Core/Help3Environment.cs

@ -0,0 +1,97 @@ @@ -0,0 +1,97 @@
using System;
using System.IO;
using Microsoft.Win32;
using ICSharpCode.Core;
using MSHelpSystem.Helper;
namespace MSHelpSystem.Core
{
internal sealed class Help3Environment
{
Help3Environment()
{
}
public static bool IsHelp3ProtocolRegistered
{
get
{
try {
RegistryKey hkcr = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64).OpenSubKey(@"MS-XHelp\shell\open\command", false);
string helpLibAgent = (string)hkcr.GetValue("", string.Empty);
hkcr.Close();
return (!string.IsNullOrEmpty(helpLibAgent));
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
return false;
}
}
public static bool IsLocalStoreInitialized
{
get
{
string localStore = LocalStore;
return (!string.IsNullOrEmpty(localStore) && Directory.Exists(localStore));
}
}
public static string LocalStore
{
get
{
try {
RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(@"SOFTWARE\Microsoft\Help\v1.0", false);
string localStore = (string)hklm.GetValue("LocalStore", string.Empty);
hklm.Close();
return localStore;
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
return string.Empty;
}
}
public static string BuildLocalStoreFolder
{
get { return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); }
}
public static string AppRoot
{
get
{
try {
RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(@"SOFTWARE\Microsoft\Help\v1.0", false);
string appRoot = (string)hklm.GetValue("AppRoot", string.Empty);
hklm.Close();
return appRoot;
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
return string.Empty;
}
}
public static string ManifestFolder
{
get
{
string manifestFolder = LocalStore;
if (string.IsNullOrEmpty(manifestFolder)) return string.Empty;
manifestFolder = System.IO.Path.Combine(manifestFolder, "manifest");
if (Directory.Exists(manifestFolder)) return manifestFolder;
else return string.Empty;
}
}
public static bool IsLocalHelp
{
get { return HelpClientWatcher.IsLocalHelp; }
}
}
}

239
src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs

@ -0,0 +1,239 @@ @@ -0,0 +1,239 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using ICSharpCode.Core;
using MSHelpSystem.Helper;
namespace MSHelpSystem.Core
{
public sealed class Help3Service
{
Help3Service()
{
HelpLibraryAgent.Start();
}
static Help3Service()
{
Help3Service.CatalogsUpdated += new EventHandler(Help3HasUpdatedTheCatalogs);
Help3Service.CatalogChanged += new EventHandler(Help3ActiveCatalogIdChanged);
Help3Service.ConfigurationUpdated += new EventHandler(Help3ConfigurationUpdated);
LoadHelpConfiguration();
UpdateCatalogs();
if (config.OfflineMode) HelpClientWatcher.EnableLocalHelp();
else HelpClientWatcher.EnableOnlineHelp();
}
static List<Help3Catalog> catalogs = new List<Help3Catalog>();
static Help3Catalog activeCatalog = null;
static Help3Configuration config = new Help3Configuration();
#region Read help catalogs
static void UpdateCatalogs()
{
catalogs.Clear();
if (Help3Environment.IsHelp3ProtocolRegistered && !string.IsNullOrEmpty(Help3Environment.ManifestFolder))
{
try {
DirectoryInfo folder = new DirectoryInfo(Help3Environment.ManifestFolder);
FileInfo[] files = folder.GetFiles(@"queryManifest*.xml");
foreach (FileInfo file in files) {
XmlDocument xml = new XmlDocument();
xml.Load(file.FullName);
XmlNodeList n = xml.SelectNodes("/queryManifest[@version=\"1.0\"]/catalogs/catalog");
foreach (XmlNode node in n) {
catalogs.Add(
new Help3Catalog(node.Attributes["productId"].InnerText,
node.Attributes["productVersion"].InnerText,
node.Attributes["productLocale"].InnerText,
node.Attributes["productDisplayName"].InnerText,
node.SelectSingleNode("catalogPath").InnerText,
node.SelectSingleNode("contentPath").InnerText,
node.SelectSingleNode("brandingPackageFileName").InnerText)
);
}
}
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
}
OnCatalogsUpdated(EventArgs.Empty);
}
static void Help3HasUpdatedTheCatalogs(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(config.ActiveCatalogId)) {
config.ActiveCatalogId = (catalogs.Count > 0) ? catalogs[0].ProductCode:string.Empty;
}
activeCatalog = (string.IsNullOrEmpty(config.ActiveCatalogId)) ? null:FindCatalogByItsString(config.ActiveCatalogId);
}
static void Help3ActiveCatalogIdChanged(object sender, EventArgs e)
{
activeCatalog = (catalogs.Count > 0) ? FindCatalogByItsString(config.ActiveCatalogId) : null;
}
static void Help3ConfigurationUpdated(object sender, EventArgs e)
{
if (config.OfflineMode) {
HelpClientWatcher.EnableLocalHelp();
}
else {
HelpClientWatcher.EnableOnlineHelp();
HelpLibraryAgent.Stop();
}
}
#endregion
public static int Count
{
get
{
return catalogs.Count;
}
}
public static ReadOnlyCollection<Help3Catalog> Items
{
get
{
ReadOnlyCollection<Help3Catalog> c = new ReadOnlyCollection<Help3Catalog>(catalogs);
return c;
}
}
public static Help3Catalog FindCatalogByProductCode(string productCode)
{
foreach (Help3Catalog catalog in catalogs)
{
if (string.Compare(productCode, catalog.ProductCode, true) == 0)
{
return catalog;
}
}
return null;
}
public static Help3Catalog FindCatalogByDisplayName(string displayName)
{
foreach (Help3Catalog catalog in catalogs)
{
if (string.Compare(displayName, catalog.DisplayName, true) == 0)
{
return catalog;
}
}
return null;
}
public static Help3Catalog FindCatalogByItsString(string stringValue)
{
foreach (Help3Catalog catalog in catalogs)
{
if (string.Compare(stringValue, catalog.ToString()) == 0)
{
return catalog;
}
}
return null;
}
public static string ActiveCatalogId
{
get
{
return config.ActiveCatalogId;
}
set
{
config.ActiveCatalogId = value;
OnCatalogChanged(EventArgs.Empty);
}
}
public static Help3Catalog ActiveCatalog
{
get
{
return activeCatalog;
}
}
public static Help3Configuration Config
{
get { return config; }
}
#region Configuration
public static void LoadHelpConfiguration()
{
string configFile = System.IO.Path.Combine(PropertyService.ConfigDirectory, "mshelpsystem.xml");
if (!File.Exists(configFile)) {
return;
}
try {
XmlSerializer serialize = new XmlSerializer(typeof(Help3Configuration));
TextReader file = new StreamReader(configFile);
config = (Help3Configuration)serialize.Deserialize(file);
file.Close();
LoggingService.Info("Help 3.0: Configuration successfully loaded");
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
OnConfigurationUpdated(EventArgs.Empty);
}
public static void SaveHelpConfiguration()
{
string configFile = System.IO.Path.Combine(PropertyService.ConfigDirectory, "mshelpsystem.xml");
try {
XmlSerializer serialize = new XmlSerializer(typeof(Help3Configuration));
TextWriter file = new StreamWriter(configFile);
serialize.Serialize(file, config);
file.Close();
LoggingService.Info("Help 3.0: Configuration successfully saved");
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
OnConfigurationUpdated(EventArgs.Empty);
}
#endregion
#region Event handling
public static event EventHandler CatalogsUpdated;
public static event EventHandler CatalogChanged;
public static event EventHandler ConfigurationUpdated;
static void OnCatalogsUpdated(EventArgs e)
{
LoggingService.Debug("Help 3.0: \"OnCatalogsUpdated\" event raised");
if (CatalogsUpdated != null) CatalogsUpdated(null, e);
}
static void OnCatalogChanged(EventArgs e)
{
LoggingService.Debug("Help 3.0: \"OnCatalogChanged\" event raised");
if (CatalogChanged != null) CatalogChanged(null, e);
}
static void OnConfigurationUpdated(EventArgs e)
{
LoggingService.Debug("Help 3.0: \"OnConfigurationUpdated\" event raised");
if (ConfigurationUpdated != null) ConfigurationUpdated(null, e);
}
#endregion
}
}

129
src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryAgent.cs

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;
using ICSharpCode.Core;
namespace MSHelpSystem.Core
{
internal sealed class HelpLibraryAgent
{
HelpLibraryAgent()
{
}
public static bool IsRunning
{
get
{
Process[] agents = Process.GetProcessesByName("HelpLibAgent");
LoggingService.Debug(string.Format("Help 3.0: {0} {1} of HelpLibraryAgent.exe found", agents.Length, (agents.Length == 1)?"process":"processes"));
return agents.Length > 0;
}
}
public static string Agent
{
get
{
if (string.IsNullOrEmpty(Help3Environment.AppRoot)) return string.Empty;
string agent = Path.Combine(Help3Environment.AppRoot, "HelpLibAgent.exe");
LoggingService.Debug(string.Format("Help 3.0: Help library agent is \"{0}\"", agent));
return (File.Exists(agent)) ? agent : string.Empty;
}
}
public static int PortNumber
{
get
{
try {
RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(@"SOFTWARE\Microsoft\Help\v1.0", false);
string port = (string)hklm.GetValue("AgentPort", "47873");
hklm.Close();
return Convert.ToInt32(port);
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
return 47873; // This is the DEFAULT port number!
}
}
public static int ProcessId
{
get
{
Process[] agents = Process.GetProcessesByName("HelpLibAgent");
int processId = (agents.Length > 0) ? agents[0].Id:0;
LoggingService.Debug(string.Format("Help 3.0: Port number is \"{0}\"", processId));
return processId;
}
}
public static string CurrentViewer
{
get
{
string viewer = string.Empty;
try {
RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(@"SOFTWARE\Microsoft\Help\v1.0", false);
viewer = (string)hklm.GetValue("HelpViewerProgID", string.Empty);
hklm.Close();
if (string.IsNullOrEmpty(viewer)) {
RegistryKey hkcr = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64).OpenSubKey(@"HTTP\shell\open\command", false);
viewer = (string)hkcr.GetValue("", string.Empty);
hkcr.Close();
if (viewer.LastIndexOf(' ') > 0) viewer = viewer.Substring(0, viewer.LastIndexOf(' '));
viewer = viewer.Trim("\"".ToCharArray());
}
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
LoggingService.Debug(string.Format("Help 3.0: Default viewer is \"{0}\"", viewer));
return viewer;
}
}
public static bool Start()
{
if (IsRunning) return true;
if (!Help3Environment.IsLocalHelp) return false;
try {
Process p = Process.Start(Agent);
p.WaitForInputIdle();
LoggingService.Info("Help 3.0: Help library agent started");
return IsRunning;
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
return false;
}
public static bool Stop()
{
return Stop(true);
}
public static bool Stop(bool waitForExit)
{
try {
Process[] agents = Process.GetProcessesByName("HelpLibAgent");
LoggingService.Debug(string.Format("Help 3.0: {0} {1} of HelpLibraryAgent.exe found", agents.Length, (agents.Length == 1)?"process":"processes"));
foreach (Process agent in agents) {
agent.Kill();
if (waitForExit) agent.WaitForExit();
}
LoggingService.Info("Help 3.0: Help library agent stopped");
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
return true;
}
}
}

58
src/AddIns/Misc/HelpViewer/Source/Core/NativeMethods.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
using System;
using System.Runtime.InteropServices;
namespace MSHelpSystem.Core.Native
{
internal sealed class NativeMethods
{
NativeMethods()
{
}
[DllImport("Wtsapi32.dll")]
internal static extern bool WTSQuerySessionInformation(IntPtr hServer, int sessionId, WTSInfoClass wtsInfoClass, out IntPtr ppBuffer, out uint pBytesReturned);
[DllImport("Wtsapi32.dll", ExactSpelling = true, SetLastError = false)]
public static extern void WTSFreeMemory(IntPtr memory);
internal enum WTSInfoClass
{
WTSInitialProgram,
WTSApplicationName,
WTSWorkingDirectory,
WTSOEMId,
WTSSessionId,
WTSUserName,
WTSWinStationName,
WTSDomainName,
WTSConnectState,
WTSClientBuildNumber,
WTSClientName,
WTSClientDirectory,
WTSClientProductId,
WTSClientHardwareId,
WTSClientAddress,
WTSClientDisplay,
WTSClientProtocolType
}
internal static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
internal static int WTS_CURRENT_SESSION = -1;
public static int GetSessionId()
{
IntPtr pSessionId = IntPtr.Zero;
Int32 sessionId = 0;
uint bytesReturned;
try {
bool returnValue = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSInfoClass.WTSSessionId, out pSessionId, out bytesReturned);
if (returnValue) sessionId = Marshal.ReadInt32(pSessionId);
}
finally {
if (pSessionId != IntPtr.Zero) WTSFreeMemory(pSessionId);
}
return sessionId;
}
}
}

19
src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
<gui:OptionPanel x:Class="MSHelpSystem.Help3OptionsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:addin="clr-namespace:MSHelpSystem;assembly=HelpViewer"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<StackPanel>
<GroupBox Header="Installed Help catalogs" Margin="5" Padding="8" Name="groupBox1">
<ComboBox Name="help3Catalogs" SelectionChanged="Help3CatalogsSelectionChanged" />
</GroupBox>
<GroupBox Header="Help Mode" Margin="5" Padding="8" Name="groupBox2">
<StackPanel>
<RadioButton Name="offlineMode" IsChecked="True" Content="I want to use local help" Click="Help3OfflineModeClicked" Margin="0,0,0,5"/>
<RadioButton Name="onlineMode" Content="I want to use online help" Click="Help3OnlineModeClicked" />
</StackPanel>
</GroupBox>
</StackPanel>
</gui:OptionPanel>

79
src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml.cs

@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using MSHelpSystem.Core;
using MSHelpSystem.Helper;
namespace MSHelpSystem
{
public partial class Help3OptionsPanel : OptionPanel
{
public Help3OptionsPanel()
{
InitializeComponent();
LoadCatalogs();
onlineMode.IsChecked = !Help3Service.Config.OfflineMode;
}
void LoadCatalogs()
{
if (Help3Environment.IsLocalHelp) HelpLibraryAgent.Start();
help3Catalogs.Items.Clear();
if (Help3Service.Count > 0) {
foreach (Help3Catalog catalog in Help3Service.Items) {
LoggingService.Debug(string.Format("Help 3.0: Found help catalog \"{0}\"", catalog.ToString()));
ComboBoxItem cbi = new ComboBoxItem();
cbi.Content = catalog.ToString();
help3Catalogs.Items.Add(cbi);
}
}
// TODO: localization needed for "Installed help catalogs"
groupBox1.Header = string.Format("{0} ({1})", "Installed Help catalogs", Help3Service.Count);
if (help3Catalogs.Items.Count == 0) help3Catalogs.SelectedIndex = 0;
else {
foreach (ComboBoxItem item in help3Catalogs.Items) {
if (string.Compare((string)item.Content, Help3Service.ActiveCatalog.ToString(), true) == 0) {
help3Catalogs.SelectedItem = item;
break;
}
}
// TODO: There has to be a much more elegant way to select the catalog?!
}
help3Catalogs.IsEnabled = (help3Catalogs.Items.Count > 1 && Help3Service.Config.OfflineMode);
}
void Help3CatalogsSelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem selectedItem = (ComboBoxItem)help3Catalogs.SelectedItem;
if (selectedItem == null) return;
string activeCatalog = (string)selectedItem.Content;
if (!string.IsNullOrEmpty(activeCatalog)) Help3Service.ActiveCatalogId = activeCatalog;
}
void Help3OfflineModeClicked(object sender, RoutedEventArgs e)
{
LoggingService.Info("Help 3.0: Setting help mode to \"offline\"");
Help3Service.Config.OfflineMode = true;
help3Catalogs.IsEnabled = (help3Catalogs.Items.Count > 1 && Help3Service.Config.OfflineMode);
}
void Help3OnlineModeClicked(object sender, RoutedEventArgs e)
{
LoggingService.Info("Help 3.0: Setting help mode to \"online\"");
Help3Service.Config.OfflineMode = false;
help3Catalogs.IsEnabled = false;
}
public override bool SaveOptions()
{
Help3Service.SaveHelpConfiguration();
return true;
}
}
}

15
src/AddIns/Misc/HelpViewer/Source/HelpMenu.cs

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
using System;
using MSHelpSystem.Core;
using ICSharpCode.Core;
namespace MSHelpSystem.SharpDevelopMenu
{
public class DisplayCatalogCommand : AbstractMenuCommand
{
public override void Run()
{
LoggingService.Info("Help 3.0: Calling menu command \"DisplayHelp.Catalog()\"");
DisplayHelp.Catalog();
}
}
}

31
src/AddIns/Misc/HelpViewer/Source/Helper/Help3Configuration.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
using System;
using System.Xml;
using System.Xml.Serialization;
namespace MSHelpSystem.Helper
{
[XmlRoot("mshelpsystem")]
public class Help3Configuration
{
public Help3Configuration()
{
}
string activeCatalogId = string.Empty;
bool offlineMode = true;
[XmlElement("activeCatalog")]
public string ActiveCatalogId
{
get { return activeCatalogId; }
set { activeCatalogId = value; }
}
[XmlElement("offlineMode")]
public bool OfflineMode
{
get { return offlineMode; }
set { offlineMode = value; }
}
}
}

141
src/AddIns/Misc/HelpViewer/Source/Helper/HelpClientWatcher.cs

@ -0,0 +1,141 @@ @@ -0,0 +1,141 @@
using System;
using System.IO;
using System.Configuration;
using System.Threading;
using ICSharpCode.Core;
using MSHelpSystem.Core;
namespace MSHelpSystem.Helper
{
internal sealed class HelpClientWatcher
{
HelpClientWatcher()
{
}
static HelpClientWatcher()
{
if (!Directory.Exists(clientPath)) {
Directory.CreateDirectory(clientPath);
}
clientFileChanged = new FileSystemWatcher(clientPath);
clientFileChanged.NotifyFilter = NotifyFilters.LastWrite;
clientFileChanged.Filter = "HelpClient.cfg";
clientFileChanged.Changed += new FileSystemEventHandler(OnFileChanged);
clientFileChanged.Created += new FileSystemEventHandler(OnFileChanged);
clientFileChanged.EnableRaisingEvents = true;
helpMode = GetHelpMode();
}
static string clientPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\HelpLibrary");
static FileSystemWatcher clientFileChanged = null;
static string helpMode = string.Empty;
static void OnFileChanged(object sender, FileSystemEventArgs e)
{
helpMode = GetHelpMode();
Help3Service.Config.OfflineMode = IsLocalHelp;
}
public static bool IsLocalHelp
{
get { return string.Compare("offline", helpMode, true) == 0; }
}
public static void EnableLocalHelp()
{
helpMode = "offline";
SetHelpMode();
}
public static void EnableOnlineHelp()
{
helpMode = "online";
SetHelpMode();
}
static string GetHelpMode()
{
Configuration config = null;
try {
string clientFile = Path.Combine(clientPath, "HelpClient.cfg");
if (File.Exists(clientFile)) {
ExeConfigurationFileMap fm = new ExeConfigurationFileMap();
fm.ExeConfigFilename = clientFile;
try {
config = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None);
}
catch (ConfigurationErrorsException) {
Thread.Sleep(0x3e8);
config = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None);
}
if (config != null) {
AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
string tmp = section.Settings["helpMode"].Value;
return (string.IsNullOrEmpty(tmp)) ? "offline":tmp;
}
}
else {
ExeConfigurationFileMap fm = new ExeConfigurationFileMap();
fm.ExeConfigFilename = Path.Combine(Help3Environment.AppRoot, "HelpClient.cfg");
try {
config = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None);
}
catch (ConfigurationErrorsException) {
Thread.Sleep(0x3e8);
config = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None);
}
if (config != null) {
AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
string tmp = section.Settings["helpMode"].Value;
return (string.IsNullOrEmpty(tmp)) ? "offline":tmp;
}
}
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
return "offline";
}
static void SetHelpMode()
{
clientFileChanged.EnableRaisingEvents = false;
LoggingService.Info(string.Format("Help 3.0: Trying to set Help mode to \"{0}\"", helpMode));
Configuration config = null;
try {
string clientFile = Path.Combine(clientPath, "HelpClient.cfg");
if (!File.Exists(clientFile)) {
string sourceFile = Path.Combine(Help3Environment.AppRoot, "HelpClient.cfg");
if (!Directory.Exists(clientPath)) {
Directory.CreateDirectory(clientPath);
}
File.Copy(sourceFile, clientFile);
Thread.Sleep(0x3e8);
}
if (File.Exists(clientFile)) {
ExeConfigurationFileMap fm = new ExeConfigurationFileMap();
fm.ExeConfigFilename = clientFile;
try {
config = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None);
}
catch (ConfigurationErrorsException) {
Thread.Sleep(0x3e8);
config = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None);
}
if (config != null) {
AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
section.Settings["helpMode"].Value = helpMode;
config.Save();
}
}
}
catch (Exception ex) {
LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString()));
}
clientFileChanged.EnableRaisingEvents = true;
}
}
}

52
src/AddIns/Misc/HelpViewer/Source/Helper/ProjectLanguages.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace MSHelpSystem.Helper
{
internal sealed class ProjectLanguages
{
ProjectLanguages()
{
}
#region Supported project languages
static Dictionary<string, string> languages = InitializeLanguages();
static Dictionary<string, string> InitializeLanguages()
{
Dictionary<string, string> result = new Dictionary<string, string>();
result.Add("C++", "C%2B%2B");
result.Add("C#", "CSharp");
result.Add("VBNet", "VB");
return result;
}
#endregion
public static string Formatted()
{
string output = string.Empty;
if (ProjectService.CurrentProject != null) {
string devLang = ProjectService.CurrentProject.Language;
if (string.IsNullOrEmpty(devLang)) { throw new ArgumentNullException("devLang"); }
output = devLang;
if (!languages.ContainsKey(devLang) || !languages.TryGetValue(devLang, out output)) {
output = devLang;
}
LoggingService.Debug(string.Format("Help 3.0: Project language \"{0}\" formatted to \"{1}\"", devLang, output));
}
return output.ToLower();
}
public static string FormattedAsHttpParam()
{
string devLang = Formatted();
if (string.IsNullOrEmpty(devLang)) return string.Empty;
else return string.Format("&category=DevLang%3a{0}", devLang);
}
}
}

30
src/AddIns/Misc/HelpViewer/Source/MSHelp3Provider.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using MSHelpSystem.Core;
namespace MSHelpSystem
{
public class MSHelp3Provider : HelpProvider
{
public override bool TryShowHelp(string fullTypeName)
{
if (string.IsNullOrEmpty(fullTypeName)) {
throw new ArgumentNullException("fullTypeName");
}
LoggingService.Info(string.Format("Help 3.0: Calling \"TryShowHelp\" with {0}", fullTypeName));
DisplayHelp.ContextualHelp(fullTypeName);
return true;
}
public override bool TryShowHelpByKeyword(string keyword)
{
if (string.IsNullOrEmpty(keyword)) {
throw new ArgumentNullException("keyword");
}
LoggingService.Info(string.Format("Help 3.0: Calling \"TryShowHelpByKeyword\" with {0}", keyword));
DisplayHelp.Keywords(keyword);
return true;
}
}
}
Loading…
Cancel
Save