From c24ceaf5c37379eb6d97b8a7c790ae174c286afb Mon Sep 17 00:00:00 2001 From: Mathias Simmack Date: Sat, 22 May 2010 13:39:10 +0000 Subject: [PATCH] renamed a few methods and includes the HelpLibraryManager.cs class (unused at this point) git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5840 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- src/AddIns/Misc/HelpViewer/HelpViewer.csproj | 1 + .../HelpViewer/Source/Core/DisplayHelp.cs | 41 ++-- .../Source/Core/Help3Environment.cs | 15 +- .../HelpViewer/Source/Core/Help3Service.cs | 2 - .../Source/Core/HelpLibraryManager.cs | 225 ++++++++++++++++++ .../Source/Helper/ProjectLanguages.cs | 6 +- 6 files changed, 260 insertions(+), 30 deletions(-) create mode 100644 src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs diff --git a/src/AddIns/Misc/HelpViewer/HelpViewer.csproj b/src/AddIns/Misc/HelpViewer/HelpViewer.csproj index 5c45971815..b168f5e917 100644 --- a/src/AddIns/Misc/HelpViewer/HelpViewer.csproj +++ b/src/AddIns/Misc/HelpViewer/HelpViewer.csproj @@ -81,6 +81,7 @@ + Help3OptionsPanel.xaml diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs b/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs index 46c45dabe8..26053d74fe 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs @@ -25,11 +25,12 @@ namespace MSHelpSystem.Core MessageBoxIcon.Error); return; } - Help3Catalog c = Help3Service.ActiveCatalog; - if (c == null) { + Help3Catalog catalog = Help3Service.ActiveCatalog; + if (catalog == 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); + string helpCatalogUrl = string.Format(@"ms-xhelp://?method=page&id=-1&product={0}&productVersion={1}&locale={2}", + catalog.ProductCode, catalog.ProductVersion, catalog.Locale); LoggingService.Debug(string.Format("Help 3.0: {0}", helpCatalogUrl)); DisplayLocalHelp(helpCatalogUrl); } @@ -46,11 +47,12 @@ namespace MSHelpSystem.Core MessageBoxIcon.Error); return; } - Help3Catalog c = Help3Service.ActiveCatalog; - if (c == null) { + Help3Catalog catalog = Help3Service.ActiveCatalog; + if (catalog == 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); + string helpPageUrl = string.Format(@"ms-xhelp://?method=page&id={3}&product={0}&productVersion={1}&locale={2}", + catalog.ProductCode, catalog.ProductVersion, catalog.Locale, pageId); LoggingService.Debug(string.Format("Help 3.0: {0}", helpPageUrl)); DisplayLocalHelp(helpPageUrl); } @@ -64,11 +66,12 @@ namespace MSHelpSystem.Core DisplayHelpOnMSDN(contextual); return; } - Help3Catalog c = Help3Service.ActiveCatalog; - if (c == null) { + Help3Catalog catalog = Help3Service.ActiveCatalog; + if (catalog == 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); + string helpContextualUrl = string.Format(@"ms-xhelp://?method=f1&query={3}&product={0}&productVersion={1}&locale={2}", + catalog.ProductCode, catalog.ProductVersion, catalog.Locale, contextual); LoggingService.Debug(string.Format("Help 3.0: {0}", helpContextualUrl)); DisplayLocalHelp(helpContextualUrl); } @@ -82,11 +85,12 @@ namespace MSHelpSystem.Core DisplaySearchOnMSDN(searchWords); return; } - Help3Catalog c = Help3Service.ActiveCatalog; - if (c == null) { + Help3Catalog catalog = Help3Service.ActiveCatalog; + if (catalog == 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(" ", "+")); + string helpSearchUrl = string.Format(@"ms-xhelp://method=search&query={3}&product={0}&productVersion={1}&locale={2}", + catalog.ProductCode, catalog.ProductVersion, catalog.Locale, searchWords.Replace(" ", "+")); LoggingService.Debug(string.Format("Help 3.0: {0}", helpSearchUrl)); DisplayLocalHelp(helpSearchUrl); } @@ -103,11 +107,12 @@ namespace MSHelpSystem.Core MessageBoxIcon.Error); return; } - Help3Catalog c = Help3Service.ActiveCatalog; - if (c == null) { + Help3Catalog catalog = Help3Service.ActiveCatalog; + if (catalog == 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); + string helpKeywordsUrl = string.Format(@"ms-xhelp://?method=keywords&query={3}&product={0}&productVersion={1}&locale={2}", + catalog.ProductCode, catalog.ProductVersion, catalog.Locale, keywords); LoggingService.Debug(string.Format("Help 3.0: {0}", helpKeywordsUrl)); DisplayLocalHelp(helpKeywordsUrl); } @@ -126,11 +131,13 @@ namespace MSHelpSystem.Core HelpLibraryAgent.Start(); Thread.Sleep(0x3e8); } - string helpUrl = string.Format(@"{0}{1}{2}", Help3Environment.FormatMsXHelpToHttp(arguments), ProjectLanguages.FormattedAsHttpParam(), (embedded)?"&embedded=true":string.Empty); + string helpUrl = string.Format(@"{0}{1}{2}", + arguments, ProjectLanguages.GetCurrentLanguageAsHttpParam(), (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.Navigate(Help3Environment.GetHttpFromMsXHelp(helpUrl)); browser.WorkbenchWindow.SelectWindow(); } } diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Environment.cs b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Environment.cs index b6187fde7b..b228e3e9a8 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Environment.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Environment.cs @@ -95,15 +95,14 @@ namespace MSHelpSystem.Core get { return HelpClientWatcher.IsLocalHelp; } } - public static string FormatMsXHelpToHttp(string helpUrl) + public static string GetHttpFromMsXHelp(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; + if (!HelpLibraryAgent.Start()) { return helpUrl; } + if (!helpUrl.StartsWith("ms-xhelp://?")) { return helpUrl; } + return string.Format( + @"http://127.0.0.1:{0}/help/{1}-{2}/ms.help?{3}", + HelpLibraryAgent.PortNumber, NativeMethods.GetSessionId(), HelpLibraryAgent.ProcessId, helpUrl.Replace("ms-xhelp://?", "") + ); } } } \ No newline at end of file diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs index ee4f059e4e..4b84a7405c 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs @@ -23,8 +23,6 @@ namespace MSHelpSystem.Core Help3Service.ConfigurationUpdated += new EventHandler(Help3ConfigurationUpdated); LoadHelpConfiguration(); UpdateCatalogs(); - if (config.OfflineMode) HelpClientWatcher.EnableLocalHelp(); - else HelpClientWatcher.EnableOnlineHelp(); } static List catalogs = new List(); diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs b/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs new file mode 100644 index 0000000000..c13e564e59 --- /dev/null +++ b/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs @@ -0,0 +1,225 @@ +using System; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Text.RegularExpressions; +using ICSharpCode.Core; + +namespace MSHelpSystem.Core +{ + internal sealed class HelpLibraryManager + { + HelpLibraryManager() + { + } + + public static bool IsRunning + { + get + { + Process[] managers = Process.GetProcessesByName("HelpLibManager"); + LoggingService.Debug(string.Format("Help 3.0: {0} {1} of HelpLibraryManager.exe found", managers.Length, (managers.Length == 1)?"process":"processes")); + return managers.Length > 0; + } + } + + public static string Manager + { + get + { + if (string.IsNullOrEmpty(Help3Environment.AppRoot)) return string.Empty; + string manager = Path.Combine(Help3Environment.AppRoot, "HelpLibManager.exe"); + LoggingService.Debug(string.Format("Help 3.0: Help library manager is \"{0}\"", manager)); + return (File.Exists(manager)) ? manager : string.Empty; + } + } + + #region InitializeLocaleStore + + public static void InitializeLocaleStore(string productCode, string productVersion) + { + InitializeLocaleStore(productCode, productVersion, CultureInfo.CurrentCulture.Name.ToUpper(), string.Empty); + } + + public static void InitializeLocaleStore(string productCode, string productVersion, string locale) + { + InitializeLocaleStore(productCode, productVersion, locale, string.Empty); + } + + public static void InitializeLocaleStore(string productCode, string productVersion, string locale, string brandingPackage) + { + if (Help3Environment.IsLocalStoreInitialized) { return; } + if (string.IsNullOrEmpty(productCode)) { throw new ArgumentNullException("productCode"); } + if (string.IsNullOrEmpty(productVersion)) { throw new ArgumentNullException("productVersion"); } + if (string.IsNullOrEmpty(locale)) { throw new ArgumentNullException("locale"); } + if (!Regex.IsMatch(productVersion, @"^\d{3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("productVersion"); } + if (!Regex.IsMatch(locale, @"^\w{2}-\w{2}", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("locale"); } + + string brandingSwitch = (!string.IsNullOrEmpty(brandingPackage)) ? string.Format("/brandingPackage \"{0}\"", brandingPackage):""; + string arguments = string.Format("/product {0} /version {1} /locale {2} /content \"{3}\" {4}", productCode, productVersion, locale, Help3Environment.BuildLocalStoreFolder, brandingSwitch); + + LoggingService.Debug(string.Format("Help 3.0: Initializing local store with \"{0}\"", arguments)); + HelpLibManagerProcessRunner(arguments); + } + + #endregion + + #region InstallHelpDocumentsFromLocalSource + + public static void InstallHelpDocumentsFromLocalSource(string productCode, string productVersion, string locale, string sourceMedia) + { + InstallHelpDocumentsFromLocalSource(productCode, productVersion, locale, sourceMedia, string.Empty); + } + + public static void InstallHelpDocumentsFromLocalSource(string productCode, string productVersion, string locale, string sourceMedia, string brandingPackage) + { + if (string.IsNullOrEmpty(productCode)) { throw new ArgumentNullException("productCode"); } + if (string.IsNullOrEmpty(productVersion)) { throw new ArgumentNullException("productVersion"); } + if (string.IsNullOrEmpty(locale)) { throw new ArgumentNullException("locale"); } + if (string.IsNullOrEmpty(sourceMedia)) { throw new ArgumentNullException("sourceMedia"); } + if (!File.Exists(sourceMedia)) { throw new FileNotFoundException(); } + if (!Regex.IsMatch(productVersion, @"^\d{3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("productVersion"); } + if (!Regex.IsMatch(locale, @"^\w{2}-\w{2}", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("locale"); } + + string initLS = (!Help3Environment.IsLocalStoreInitialized) ? string.Format("/content \"{0}\"", Help3Environment.BuildLocalStoreFolder):""; + string brandingSwitch = (!string.IsNullOrEmpty(brandingPackage)) ? string.Format("/brandingPackage \"{0}\"", brandingPackage):""; + string arguments = string.Format("/product {0} /version {1} /locale {2} /sourceMedia \"{3}\" {4} {5}", productCode, productVersion, locale, sourceMedia, initLS, brandingSwitch); + + LoggingService.Debug(string.Format("Help 3.0: Installing local help documents with \"{0}\"", arguments)); + HelpLibManagerProcessRunner(arguments); + } + + #endregion + + #region InstallHelpDocumentsFromWebSource + + public static void InstallHelpDocumentsFromWebSource(string productCode, string productVersion, string locale, string sourceWeb) + { + InstallHelpDocumentsFromWebSource(productCode, productVersion, locale, sourceWeb, string.Empty); + } + + public static void InstallHelpDocumentsFromWebSource(string productCode, string productVersion, string locale, string sourceWeb, string brandingPackage) + { + if (string.IsNullOrEmpty(productCode)) { throw new ArgumentNullException("productCode"); } + if (string.IsNullOrEmpty(productVersion)) { throw new ArgumentNullException("productVersion"); } + if (string.IsNullOrEmpty(locale)) { throw new ArgumentNullException("locale"); } + if (string.IsNullOrEmpty(sourceWeb)) { throw new ArgumentNullException("sourceWeb"); } + if (!Regex.IsMatch(productVersion, @"^\d{3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("productVersion"); } + if (!Regex.IsMatch(locale, @"^\w{2}-\w{2}", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("locale"); } + + string initLS = (!Help3Environment.IsLocalStoreInitialized) ? string.Format("/content \"{0}\"", Help3Environment.BuildLocalStoreFolder):""; + string brandingSwitch = (!string.IsNullOrEmpty(brandingPackage)) ? string.Format("/brandingPackage \"{0}\"", brandingPackage):""; + string arguments = string.Format("/product {0} /version {1} /locale {2} /sourceWeb \"{3}\" {4} {5}", productCode, productVersion, locale, sourceWeb, initLS, brandingSwitch); + + LoggingService.Debug(string.Format("Help 3.0: Installing help documents from web with \"{0}\"", arguments)); + HelpLibManagerProcessRunner(arguments); + } + + #endregion + + #region UninstallHelpDocuments + + public static void UninstallHelpDocuments(string productCode, string productVersion, string locale, string vendor, string productName, string mediaBookList) + { + if (!Help3Environment.IsLocalStoreInitialized) { return; } + if (string.IsNullOrEmpty(productCode)) { throw new ArgumentNullException("productCode"); } + if (string.IsNullOrEmpty(productVersion)) { throw new ArgumentNullException("productVersion"); } + if (string.IsNullOrEmpty(locale)) { throw new ArgumentNullException("locale"); } + if (string.IsNullOrEmpty(vendor)) { throw new ArgumentNullException("vendor"); } + if (string.IsNullOrEmpty(productName)) { throw new ArgumentNullException("productName"); } + if (string.IsNullOrEmpty(mediaBookList)) { throw new ArgumentNullException("mediaBookList"); } + if (!Regex.IsMatch(productVersion, @"^\d{3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("productVersion"); } + if (!Regex.IsMatch(locale, @"^\w{2}-\w{2}", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) { throw new ArgumentOutOfRangeException("locale"); } + + string arguments = string.Format("/product {0} /version {1} /locale {2} /vendor \"{3}\" /productName \"{4}\" /mediaBookList {5} /uninstall", productCode, productVersion, locale, vendor, productName, mediaBookList); + + LoggingService.Debug(string.Format("Help 3.0: Uninstalling help documents with \"{0}\"", arguments)); + HelpLibManagerProcessRunner(arguments); + } + + #endregion + + static int HelpLibManagerProcessRunner(string arguments) + { + return HelpLibManagerProcessRunner(arguments, false); + } + + static int HelpLibManagerProcessRunner(string arguments, bool silent) + { + if (string.IsNullOrEmpty(Manager) || string.IsNullOrEmpty(Help3Environment.AppRoot)) return -10; + Stop(); + + ProcessStartInfo psi = new ProcessStartInfo(); + psi.FileName = Manager; + psi.WorkingDirectory = Help3Environment.AppRoot; + psi.Arguments = string.Format("{0} {1}", arguments, (silent)?"/silent":string.Empty); + psi.UseShellExecute = true; + psi.Verb = "runas"; + psi.WindowStyle = ProcessWindowStyle.Normal; + + try { + Process p = Process.Start(psi); + p.WaitForExit(); + return p.ExitCode; + } + catch (Exception ex) { + LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString())); + } + return -1; + } + + + public static bool Start() + { + if (IsRunning) return true; + if (string.IsNullOrEmpty(Manager)) { + throw new ArgumentNullException("Manager"); + } + if (Help3Service.ActiveCatalog == null) { + throw new ArgumentNullException("Help3Service.ActiveCatalog"); + } + ProcessStartInfo psi = new ProcessStartInfo(); + psi.FileName = Manager; + psi.WorkingDirectory = Help3Environment.AppRoot; + psi.Arguments = string.Format("/product {0} /version {1} /locale {2}", + Help3Service.ActiveCatalog.ProductCode, + Help3Service.ActiveCatalog.ProductVersion, + Help3Service.ActiveCatalog.Locale); + psi.UseShellExecute = true; + psi.Verb = "runas"; + psi.WindowStyle = ProcessWindowStyle.Normal; + try { + Process p = Process.Start(psi); + p.WaitForInputIdle(); + LoggingService.Info("Help 3.0: Help library manager 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[] managers = Process.GetProcessesByName("HelpLibManager"); + + foreach (Process manager in managers) { + manager.Kill(); + if (waitForExit) manager.WaitForExit(); + } + LoggingService.Debug(string.Format("Help 3.0: {0} {1} of HelpLibraryManager.exe stopped", managers.Length, (managers.Length == 1)?"process":"processes")); + } + catch (Exception ex) { + LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString())); + } + return true; + } + } +} \ No newline at end of file diff --git a/src/AddIns/Misc/HelpViewer/Source/Helper/ProjectLanguages.cs b/src/AddIns/Misc/HelpViewer/Source/Helper/ProjectLanguages.cs index 47e7e1dbe9..a65da2fe6d 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Helper/ProjectLanguages.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Helper/ProjectLanguages.cs @@ -26,7 +26,7 @@ namespace MSHelpSystem.Helper #endregion - public static string Formatted() + public static string GetCurrentLanguage() { string output = string.Empty; if (ProjectService.CurrentProject != null) { @@ -42,9 +42,9 @@ namespace MSHelpSystem.Helper return output.ToLower(); } - public static string FormattedAsHttpParam() + public static string GetCurrentLanguageAsHttpParam() { - string devLang = Formatted(); + string devLang = GetCurrentLanguage(); if (string.IsNullOrEmpty(devLang)) return string.Empty; else return string.Format("&category=DevLang%3a{0}", devLang); }