public static bool GenerateSummaryFile(string workDir, Config configuration, ILog log) { FsPath source = new FsPath(workDir, ".chapters"); if (source.IsExisting) { log.Info(".chapters file doesn't exist."); return(false); } StringBuilder buffer = new StringBuilder(); List <Chapter>?chapters = source.DeserializeYaml <List <Chapter> >(log); if (chapters == null) { log.Detail(".chapters file reading failed. Bad markup?"); return(false); } ConvertChaptersToMarkdown(workDir, log, buffer, chapters); FsPath destination = new FsPath(workDir, configuration.TOCFile); if (destination.IsExisting) { destination.CreateBackup(log); } destination.WriteFile(log, buffer.ToString()); return(true); }
public bool TryLoadAndValidateConfig(out Config?config) { config = null; if (!_configfile.IsExisting) { _log.Info("No bookgen.json config found."); return(false); } config = _configfile.DeserializeJson <Config>(_log); if (config == null) { _log.Critical("bookgen.json deserialize error. Invalid config file"); return(false); } if (config.Version < Program.CurrentState.ConfigVersion) { _configfile.CreateBackup(_log); config.UpgradeTo(Program.CurrentState.ConfigVersion); _configfile.SerializeJson(config, _log, true); _log.Info("Configuration file migrated to new version."); _log.Info("Review configuration then run program again"); return(false); } ConfigValidator validator = new ConfigValidator(config, _workdir); validator.Validate(); if (!validator.IsValid) { _log.Warning("Errors found in configuration: "); foreach (var error in validator.Errors) { _log.Warning(error); } return(false); } return(true); }