/* Function: GetProjectInfoProperty * If the passed identifier is a project info property like Title, adds it to <currentProjectInfo> and returns true. If it is a recognized * project info property but there's a syntax error in the value, it will add an error to <errorList> and still return true. It only returns * false for unrecognized identifiers. */ protected bool GetProjectInfoProperty(string lcIdentifier, string value, PropertyLocation propertyLocation, ProjectInfo projectInfo) { if (lcIdentifier == "title") { projectInfo.Title = value.ConvertCopyrightAndTrademark(); projectInfo.TitlePropertyLocation = propertyLocation; return(true); } else if (subtitleRegex.IsMatch(lcIdentifier)) { projectInfo.Subtitle = value.ConvertCopyrightAndTrademark(); projectInfo.SubtitlePropertyLocation = propertyLocation; return(true); } else if (lcIdentifier == "copyright") { projectInfo.Copyright = value.ConvertCopyrightAndTrademark(); projectInfo.CopyrightPropertyLocation = propertyLocation; return(true); } else if (timestampRegex.IsMatch(lcIdentifier)) { projectInfo.TimestampCode = value; projectInfo.TimestampCodePropertyLocation = propertyLocation; return(true); } else if (lcIdentifier == "style") { projectInfo.StyleName = value; projectInfo.StyleNamePropertyLocation = propertyLocation; return(true); } else { return(false); } }
// Group: Loading Functions // __________________________________________________________________________ /* Function: Load * Attempts to parse <Project.txt> and return it as a <ProjectConfig>. Any syntax errors found will be added to the * <ErrorList>. The <ProjectConfig> object will always exist, even if all its properties are empty. */ public bool Load(Path path, out ProjectConfig projectConfig, ErrorList errorList) { projectConfig = new ProjectConfig(Source.ProjectFile); this.errorList = errorList; this.projectConfig = projectConfig; int originalErrorCount = errorList.Count; using (var configFile = new ConfigFile()) { // We don't condense value whitespace because some things like title, subtitle, and copyright may want multiple spaces. bool openResult = configFile.Open(path, ConfigFile.FileFormatFlags.CondenseIdentifierWhitespace | ConfigFile.FileFormatFlags.MakeIdentifiersLowercase, errorList); if (openResult == false) { return(false); } string lcIdentifier, value; Targets.Base currentTarget = null; ProjectInfo currentProjectInfo = projectConfig.ProjectInfo; while (configFile.Get(out lcIdentifier, out value)) { var propertyLocation = new PropertyLocation(Source.ProjectFile, configFile.FileName, configFile.LineNumber); Targets.Base target = null; if (GetGlobalProperty(lcIdentifier, value, propertyLocation)) { currentTarget = null; currentProjectInfo = projectConfig.ProjectInfo; } else if (GetTargetHeader(lcIdentifier, value, propertyLocation, out target)) { currentTarget = target; if (target is Targets.OutputBase) { currentProjectInfo = (target as Targets.OutputBase).ProjectInfo; } else { currentProjectInfo = projectConfig.ProjectInfo; } } else if (GetProjectInfoProperty(lcIdentifier, value, propertyLocation, currentProjectInfo)) { } else if (currentTarget != null && GetTargetProperty(lcIdentifier, value, propertyLocation, currentTarget)) { } else { errorList.Add( message: Locale.Get("NaturalDocs.Engine", "ConfigFile.NotAValidIdentifier(identifier)", lcIdentifier), propertyLocation: propertyLocation ); } } configFile.Close(); } return(errorList.Count == originalErrorCount); }