private static void RunMarkdownConversion(string pathsSpec, Configuration config, Markdown markdownToHtml, Logger log) { // Preview mode must take precedence over logging mode. if (ThisIsPreview) { log.Info(Language.Message("PreviewModeEnabled")); } else if (ThisIsLogOnly) { log.Info(Language.Message("LoggingModeEnabled")); } var folders = GetDirectoriesPathsSpec(pathsSpec, config); var timer = new Stopwatch(); timer.Start(); DirectoryStatistics statistics = new DirectoryStatistics(); foreach (var folder in folders) { if (folder.Directory.GetFiles().Length == 0) { continue; } statistics.IncrementTotal(); foreach (var lang in folder.Languages) { if (folder.Directory.GetFiles(string.Format("*.{0}.udn", lang)).Length == 0) { continue; } var fileName = folder.Directory.GetFiles(string.Format("*.{0}.udn", lang)).First().FullName; var langLinks = config.LinksToAllLangs ? null : folder.Languages.ToArray(); LogConvertingFileInfo(log, fileName, "StartConversion"); var result = ConvertFile(markdownToHtml, fileName, lang, langLinks, config.OutputFormatParam); switch (result) { case ConvertFileResponse.NoChange: { LogConvertingFileInfo(log, fileName, "ConvertNoChange"); statistics.IncrementNoChangesCount(); break; } case ConvertFileResponse.Converted: { var outputFileName = GetTargetFileName(fileName, lang); if (!ThisIsPreview && ThisIsLogOnly) { LogConvertingFileInfo(log, fileName, "ConvertSucceededLogOnly", outputFileName); break; } if (folders.Count == 1 && folders[0].Languages.Count == 1) { LogConvertingFileInfo(log, fileName, "ConvertSucceeded", outputFileName); OpenPageInBrowser(outputFileName); } else { LogConvertingFileInfo(log, fileName, "Converted", outputFileName); } statistics.IncrementConvertedCount(); break; } case ConvertFileResponse.Failed: { LogConvertingFileInfo(log, fileName, "ConvertFailed"); statistics.IncrementFailedCount(); break; } default: LogConvertingFileInfo(log, fileName, "UnknownErrorProcessingFile"); break; } } } timer.Stop(); log.WriteToLog(Language.Message("SummaryStart")); log.WriteToLog(Language.Message("ConvertedIn", (Convert.ToDouble(timer.ElapsedMilliseconds) / 1000).ToString())); statistics.LogCounts(); log.WriteToLog(Language.Message("SummaryEnd")); }
public static void OnProcessExit(object sender, EventArgs e, Configuration config) { User.Default.SupportedAvailability = String.Join(",",config.PublishFlagsParam.ChosenStringOptions); User.Default.SourceDirectory = config.SourceParam.Value; User.Default.OutputDirectory = config.OutputParam.Value; User.Default.SupportedLanguages = String.Join(",", config.LangParam.ChosenStringOptions); User.Default.LogVerbosityParam = config.LogVerbosityParam.ChosenOption.ToString(); User.Default.HelpFlag = config.HelpFlag.Value; User.Default.LogOnlyFlag = config.LogOnlyFlag.Value; User.Default.PreviewFlag = config.PreviewFlag.Value; User.Default.CleanFlag = config.CleanFlag.Value; User.Default.PathsSpec = config.PathsSpec.Value; User.Default.DefaultTemplate = config.TemplateParam.Value; User.Default.OutputFormat = config.OutputFormatParam.ChosenOption.ToString(); User.Default.PathPrefix = config.PathPrefixParam.Value; User.Default.Save(); }
static void Main(string[] args) { Directory.SetCurrentDirectory( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); //Get directory for P4 Document Directory location. //make sure does not start with \ or / or end with them //strip ./ from start if there SourceDirectory = Regex.Replace( Settings.Default.SourceDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2"); OutputDirectory = Regex.Replace( Settings.Default.OutputDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2"); Language.LangID = "INT"; Language.Init( Path.Combine( SourceDirectory, Settings.Default.IncludeDirectory, Settings.Default.InternationalizationDirectory)); DoCompressImages = Settings.Default.DoCompressImages; if (DoCompressImages) { //If we are not compressing an image no need to set other conversion variables JpegCompressionRate = Settings.Default.ImageJPGCompressionValue; try { DefaultImageFillColor = ImageConversion.GetColorFromHexString(Settings.Default.ImageFillColor); } catch (Exception) { DefaultImageFillColor = default(Color); } CompressImageType = Settings.Default.CompressImageType; CompressImageFormat = ImageConversion.GetImageFormat(CompressImageType); if (CompressImageFormat == null) { log.Error(Language.Message("UnsupportedCompressImgType", CompressImageType)); return; } } SupportedLanguages = Settings.Default.SupportedLanguages.ToUpper().Split(','); MetadataErrorIfMissing = Settings.Default.MetadataErrorIfMissing.Split(','); MetadataInfoIfMissing = Settings.Default.MetadataInfoIfMissing.Split(','); MetadataCleanKeepThese = Settings.Default.MetadataCleanKeepThese.ToLower().Split(','); SupportedAvailability = Settings.Default.SupportedAvailability.ToLower().Split(','); PublicAvailabilityFlag = Settings.Default.PublicAvailabilityFlag.ToLower(); //AllSupportedAvailablities needs to include the public and supported availabilities foreach (string Availability in SupportedAvailability) { AllSupportedAvailability.Add(Availability); } AllSupportedAvailability.Add(PublicAvailabilityFlag); var config = new Configuration(SupportedAvailability, PublicAvailabilityFlag, SupportedLanguages, false); if (args.Length == 0) { config = new Configuration(SupportedAvailability, PublicAvailabilityFlag, SupportedLanguages, true); // There are no arguments, so try to obtain them from GUI. var gui = new GUI.GUI(); var wpfLogger = new WPFLogger(); gui.Init(config, wpfLogger); log = wpfLogger; HideConsole(); gui.Run(); } else { log = new LogFileLogger(); try { config.ParamsManager.Parse(args); RunUDNConversion(config, log); } catch (ParsingErrorException e) { if (e.Sender != null) { log.Error(Language.Message("ErrorParsingParam", e.Sender.Name)); } log.Error(e.Message); log.Info(config.ParamsManager.GetHelp()); } catch (Exception e) { // catching all and printing out -- finishing anyway // print out exception and exit gently rather than panic PrintUnhandledException(e); } finally { log.WriteToLog(Language.Message("UnrealDocToolFinished")); } } AppDomain.CurrentDomain.ProcessExit += (sender, e) => OnProcessExit(sender, e, config); }
private static List<ConversionDirectory> GetDirectoriesPathsSpec(string pathsSpec, Configuration config) { var folders = new List<ConversionDirectory>(); var prefix = config.PathPrefixParam.Value; if (FileHelper.IsExistingDirectory(prefix)) { prefix += Path.DirectorySeparatorChar; } foreach (var path in pathsSpec.Split(';')) { var fullPath = prefix + path; if (fullPath.EndsWith("*")) { DoRecursively(fullPath.Substring(0, fullPath.Length - 1), p => AddFolder(config, p, folders)); } else { AddFolder(config, fullPath, folders); } } return folders; }
private static void AddFolder(Configuration config, string fullPath, List<ConversionDirectory> folders) { if (!IsInSubDirectory(fullPath, SourceDirectory)) { throw new ParsingErrorException( null, Language.Message("FileMustBeInASubdirOfSrcDir", fullPath, SourceDirectory)); } var convDir = ConversionDirectory.CreateFromPath(fullPath, config); if (convDir.Languages.Count == 0) { // Nothing to do, ignore. return; } folders.Add(convDir); }
public static void RunUDNConversion(Configuration config, Logger log) { log.WriteToLog(Language.Message("UnrealDocToolStarted")); if (config.HelpFlag) { log.Info(config.ParamsManager.GetHelp()); return; } ThisIsPreview = config.PreviewFlag; if (ThisIsPreview) { //output to a preview file OutputDirectory = Path.Combine(Path.GetTempPath(), "UDT"); } ThisIsLogOnly = config.LogOnlyFlag; PublishFlags = config.PublishFlagsParam.ChosenStringOptions.Union(new string[] { PublicAvailabilityFlag }).ToArray(); SubsetOfSupportedLanguages = config.LangParam.ChosenStringOptions; DefaultTemplate = config.TemplateParam.Value; DoxygenHelper.DoxygenXmlPath = config.DoxygenCacheParam; switch (config.LogVerbosityParam.ChosenOption) { case LogVerbosity.Info: log.SetInfoVerbosityLogLevel(); break; case LogVerbosity.Warn: log.SetWarnVerbosityLogLevel(); break; case LogVerbosity.Error: log.SetErrorVerbosityLogLevel(); break; } // The output directory in app.config is over-ridden with this value // make sure does not start with \ or / or end with them // strip ./ from start if there. if (!ThisIsPreview) { // Preview output temp directory take precedence. OutputDirectory = Regex.Replace(config.OutputParam.Value, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2"); } // The source directory in app.config is over-ridden with this value. SourceDirectory = Regex.Replace(config.SourceParam.Value, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2"); // If this path is set, then we should rebuild doxygen cache. if (!string.IsNullOrWhiteSpace(config.RebuildDoxygenCacheParam)) { var engineDir = new DirectoryInfo(Path.Combine(SourceDirectory, "..", "..")).FullName; log.Info(Language.Message("RebuildingDoxygenCache")); DoxygenHelper.DoxygenExec = new FileInfo(config.RebuildDoxygenCacheParam.Value); DoxygenHelper.DoxygenInputFilter = Path.Combine( engineDir, "Binaries", "DotNET", "UnrealDocToolDoxygenInputFilter.exe"); DoxygenHelper.RebuildCache( Path.Combine(engineDir, "Source"), (sender, eventArgs) => log.Info(eventArgs.Data)); return; } // If running clean really only need the SourceDirectory value. if (config.CleanFlag) { if (SourceDirectory == "") { throw new ParsingErrorException(null, Language.Message("NoOutputDir")); } } else { if (OutputDirectory == "" || SourceDirectory == "") { throw new ParsingErrorException(null, Language.Message("NoOutputOrSourceDir")); } //If the OutputDirectory is relative then find absolute path if (Regex.IsMatch(OutputDirectory, @"\.[/|\\]")) { string tempOutputDirectory = (new Uri(Path.GetDirectoryName(Assembly.GetAssembly(typeof(UnrealDocTool)).CodeBase))).LocalPath; while (OutputDirectory.StartsWith("..")) { tempOutputDirectory = Directory.GetParent(tempOutputDirectory).FullName; OutputDirectory = Regex.Replace(OutputDirectory, @"^\.\.[/|\\](.*)", "$1"); } OutputDirectory = (new DirectoryInfo(Path.Combine(tempOutputDirectory, OutputDirectory))).FullName; } //If the SourceDirectory is relative then find absolute path if (Regex.IsMatch(SourceDirectory, @"\.[/|\\]")) { string tempSourceDirectory = (new Uri(Path.GetDirectoryName(Assembly.GetAssembly(typeof(UnrealDocTool)).CodeBase))).LocalPath; while (SourceDirectory.StartsWith("..")) { tempSourceDirectory = Directory.GetParent(tempSourceDirectory).FullName; SourceDirectory = Regex.Replace(SourceDirectory, @"^\.\.[/|\\](.*)", "$1"); } SourceDirectory = CaseSensitivePath(new DirectoryInfo(Path.Combine(tempSourceDirectory, SourceDirectory))); } } // Delete previously created temp folder. if (Directory.Exists(Path.Combine(Path.GetTempPath(), "UDT"))) { DeleteDirRecursive(Path.Combine(Path.GetTempPath(), "UDT")); } if (config.CleanFlag) { log.Info(Language.Message("CleaningDuplicateLanguageImageFilesAndRecursing", SourceDirectory)); CleanImagesRecursiveDirectory(SourceDirectory); log.Info(Language.Message("CleaningMetadataFromFileInDirAndRecursing", SourceDirectory)); CleanMetaDataRecursiveDirectory(SourceDirectory); } else if (ThisIsLogOnly || InitialDirectoryChecksOk()) { RunMarkdownConversion(config.PathsSpec, config, new MarkdownSharp.Markdown(), log); } }
public static ConversionDirectory CreateFromPath(string filePath, Configuration config) { if (new FileInfo(filePath).Attributes.HasFlag(FileAttributes.Directory)) { return new ConversionDirectory(filePath, config.LangParam.ChosenStringOptions); } return new ConversionDirectory( Path.GetDirectoryName(filePath), new[] { GetLangIdFromFileName(Path.GetFileName(filePath)) }); }