private void OptimizeClassicStyles(BuildContext context) { BuildLogger logger = context.Logger; string startMessage = "Started style optimization for Classic Style"; string endMessage = "Completed style optimization for Classic Style"; logger.WriteLine(startMessage, BuildLoggerLevel.Info); BuildSettings settings = context.Settings; string sandassistDir = settings.SandAssistDirectory; if (!Directory.Exists(sandassistDir)) { logger.WriteLine("Sandcastle Assist directory does not exists.", BuildLoggerLevel.Warn); logger.WriteLine(endMessage, BuildLoggerLevel.Info); return; } string formatDir = Path.Combine(sandassistDir, @"Optimizations\Vs2005\Chm"); if (!Directory.Exists(formatDir)) { logger.WriteLine("The format directory does not exists.", BuildLoggerLevel.Warn); logger.WriteLine(endMessage, BuildLoggerLevel.Info); return; } // 1. For the icons: the directory must exist and not empty... string iconsDir = Path.Combine(formatDir, @"Icons"); string targetDir = Path.Combine(_helpSource, "icons"); if (Directory.Exists(iconsDir) && Directory.Exists(targetDir) && !DirectoryUtils.IsDirectoryEmpty(iconsDir)) { try { BuildDirCopier dirCopier = new BuildDirCopier(); dirCopier.Overwrite = true; dirCopier.Recursive = false; if (logger != null) { logger.WriteLine("Replacing stock icons with: " + iconsDir, BuildLoggerLevel.Info); } int fileCopies = dirCopier.Copy(iconsDir, targetDir); if (logger != null) { logger.WriteLine(String.Format( "Total of {0} icons or images replaced.", fileCopies), BuildLoggerLevel.Info); } } catch (Exception ex) { if (logger != null) { logger.WriteLine(ex, BuildLoggerLevel.Error); } } } // 2. For the style-sheets: the directory must exist and not empty... string stylesDir = Path.Combine(formatDir, @"Styles"); targetDir = Path.Combine(_helpSource, "styles"); if (Directory.Exists(stylesDir) && Directory.Exists(targetDir) && !DirectoryUtils.IsDirectoryEmpty(stylesDir)) { try { BuildDirCopier dirCopier = new BuildDirCopier(); dirCopier.Overwrite = true; dirCopier.Recursive = false; if (logger != null) { logger.WriteLine("Replacing stock styles with: " + stylesDir, BuildLoggerLevel.Info); } int fileCopies = dirCopier.Copy(stylesDir, targetDir); if (logger != null) { logger.WriteLine(String.Format( "Total of {0} styles replaced.", fileCopies), BuildLoggerLevel.Info); } } catch (Exception ex) { if (logger != null) { logger.WriteLine(ex, BuildLoggerLevel.Error); } } } // 3. For the scripts: the directory must exist and not empty... string scriptsDir = Path.Combine(formatDir, @"Scripts"); targetDir = Path.Combine(_helpSource, "scripts"); if (Directory.Exists(scriptsDir) && Directory.Exists(targetDir) && !DirectoryUtils.IsDirectoryEmpty(scriptsDir)) { try { BuildDirCopier dirCopier = new BuildDirCopier(); dirCopier.Overwrite = true; dirCopier.Recursive = false; if (logger != null) { logger.WriteLine("Replacing stock scripts with: " + scriptsDir, BuildLoggerLevel.Info); } int fileCopies = dirCopier.Copy(scriptsDir, targetDir); if (logger != null) { logger.WriteLine(String.Format( "Total of {0} scripts replaced.", fileCopies), BuildLoggerLevel.Info); } } catch (Exception ex) { if (logger != null) { logger.WriteLine(ex, BuildLoggerLevel.Error); } } } logger.WriteLine(endMessage, BuildLoggerLevel.Info); }
protected override bool OnExecute(BuildContext context) { BuildLogger logger = context.Logger; int itemCount = _listSourceDir.Count; if (itemCount == 0) { if (logger != null) { logger.WriteLine("There is no directory specified to copy.", BuildLoggerLevel.Warn); } return(true); } try { int dirCopied = 0; BuildDirCopier dirCopier = new BuildDirCopier(); dirCopier.Overwrite = _isOverwrite; dirCopier.Recursive = _isRecursive; string baseDir = context.BaseDirectory; for (int i = 0; i < itemCount; i++) { string dirSource = _listSourceDir[i]; string dirDest = _listDestDir[i]; if (Directory.Exists(dirSource) == false) { logger.WriteLine(String.Format("Path does not exists - {0}", dirSource), BuildLoggerLevel.Info); continue; } if (logger != null) { StringBuilder builder = new StringBuilder(); builder.Append("Copying - "); if (dirSource.StartsWith(baseDir, StringComparison.OrdinalIgnoreCase)) { builder.Append(PathUtils.GetRelativePath( baseDir, dirSource)); } else { builder.Append(dirSource); } builder.Append(" -> "); if (dirDest.StartsWith(baseDir, StringComparison.OrdinalIgnoreCase)) { builder.Append(PathUtils.GetRelativePath( baseDir, dirDest)); } else { builder.Append(PathUtils.GetRelativePath( dirSource, dirDest)); } logger.WriteLine(builder.ToString(), BuildLoggerLevel.Info); } int fileCopies = dirCopier.Copy(dirSource, dirDest); if (logger != null) { logger.WriteLine(String.Format( "Completed Copying - Total of {0} files copied.", fileCopies), BuildLoggerLevel.Info); } dirCopied++; } return(dirCopied > 0); } catch (Exception ex) { if (logger != null) { logger.WriteLine(ex, BuildLoggerLevel.Error); } return(false); } }