public bool Run(BuildContext context) { int lcid = _options.LangID; string lcidText = lcid.ToString(); string workingDir = Path.Combine(_options.OutputDirectory, "html"); _context = context; _logger = context.Logger; if (_logger != null) { _verbosity = _logger.Verbosity; } string configFile = Path.Combine(context.SandcastleToolsDirectory, "DBCSFix.exe.config"); if (!File.Exists(configFile)) { return(false); } using (XmlReader reader = XmlReader.Create(configFile)) { XmlNodeType nodeType = XmlNodeType.None; while (reader.Read()) { nodeType = reader.NodeType; if (nodeType == XmlNodeType.Element) { if (String.Equals(reader.Name, "add")) { _appSettings.Add(reader.GetAttribute("key"), reader.GetAttribute("value")); } } else if (nodeType == XmlNodeType.EndElement) { string nodeName = reader.Name; if (String.Equals(nodeName, "appSettings") || String.Equals(nodeName, "configuration")) { break; } } } } // Step 1: Convert unsupported high-order chars to ASCII equivalents FormatChmEncoder chmEncoder = new FormatChmAsciiSubstitute(_appSettings); chmEncoder.Initialize(workingDir, lcidText); _listEncoders.Add(chmEncoder); // Step 2: For the non-English code-pages, we do more processing... if (lcid != 1033) { // Step 2-1: Convert unsupported chars to named entities chmEncoder = new FormatChmEntitiesSubstitute(_appSettings); chmEncoder.Initialize(workingDir, lcidText); _listEncoders.Add(chmEncoder); // Step 2-2: Convert charset declarations from UTF-8 to proper // ANSI code-page value chmEncoder = new FormatChmCodepageSubstitute(_appSettings); chmEncoder.Initialize(workingDir, lcidText); _listEncoders.Add(chmEncoder); // Step 2-3: Convert char encodings from UTF-8 to ANSI FormatChmUtf8ToAnsiConverter chmConverter = new FormatChmUtf8ToAnsiConverter(_appSettings); chmConverter.Initialize(workingDir, lcidText); _listEncoders.Add(chmConverter); _outputEncoding = chmConverter.OutputEncoding; } // Finally, process the files... Process(workingDir); return(true); }
public virtual void Initialize(BuildContext context) { BuildExceptions.NotNull(context, "context"); base.Initialize(context.Logger); BuildSettings settings = context.Settings; if (settings == null) { this.IsInitialized = false; return; } _context = context; _sandcastleDir = context.SandcastleDirectory; _sandcastleAssistDir = settings.SandAssistDirectory; // Make sure the default component handlers are added... //Keyword: "$(SandcastleComponent)"; if (!_dicConfigMap.ContainsKey("SandcastleComponent")) { string sandcastleComponents = null; if (context.IsDirectSandcastle) { if (!String.IsNullOrEmpty(_sandcastleAssistDir) || Directory.Exists(_sandcastleAssistDir)) { sandcastleComponents = Path.Combine(_sandcastleAssistDir, "Sandcastle.BuildAssembler.dll"); } } else { if (!String.IsNullOrEmpty(_sandcastleDir) || Directory.Exists(_sandcastleDir)) { sandcastleComponents = Path.Combine(_sandcastleDir, @"ProductionTools\BuildComponents.dll"); } } if (!String.IsNullOrEmpty(sandcastleComponents) && File.Exists(sandcastleComponents)) { _dicConfigMap.Add("SandcastleComponent", sandcastleComponents); } } //Keyword: "$(SandAssistComponent)"; if (_dicConfigMap.ContainsKey("SandAssistComponent") == false) { if (String.IsNullOrEmpty(_sandcastleAssistDir) == false || Directory.Exists(_sandcastleAssistDir)) { // If the Sandcastle Assist component assembly is in the same // directory as the Sandcastle Helpers... string assistComponents = Path.Combine(_sandcastleAssistDir, "Sandcastle.Components.dll"); if (File.Exists(assistComponents)) { _dicConfigMap.Add("SandAssistComponent", assistComponents); } else { // Otherwise, if in the "Components" sub-directory... assistComponents = Path.Combine(_sandcastleAssistDir, @"Components\Sandcastle.Components.dll"); if (File.Exists(assistComponents)) { _dicConfigMap.Add("SandAssistComponent", assistComponents); } } } } this.IsInitialized = true; }