/// <summary> /// Constructor /// </summary> /// <param name="Reference">Reference to a file or directory in the filesystem</param> public FileSystemName(FileSystemReference Reference) { int Idx = Reference.FullName.LastIndexOf(Path.DirectorySeparatorChar); if (Idx == Reference.FullName.Length - 1) { DisplayName = Reference.FullName; CanonicalName = Reference.CanonicalName; } else { DisplayName = Reference.FullName.Substring(Idx + 1); CanonicalName = Reference.CanonicalName.Substring(Idx + 1); } }
/// <summary> /// Combine several fragments with a base directory, to form a new directory name /// </summary> /// <param name="BaseDirectory">The base directory</param> /// <param name="Fragments">Fragments to combine with the base directory</param> /// <returns>The new directory name</returns> public static DirectoryReference Combine(DirectoryReference BaseDirectory, params string[] Fragments) { string FullName = FileSystemReference.CombineStrings(BaseDirectory, Fragments); return(new DirectoryReference(FullName, FullName.ToLowerInvariant())); }
/// <summary> /// Combine several fragments with a base directory, to form a new filename /// </summary> /// <param name="BaseDirectory">The base directory</param> /// <param name="Fragments">Fragments to combine with the base directory</param> /// <returns>The new file name</returns> public static FileReference Combine(DirectoryReference BaseDirectory, params string[] Fragments) { string FullName = FileSystemReference.CombineStrings(BaseDirectory, Fragments); return(new FileReference(FullName, Sanitize.None)); }
/// <summary> /// Evaluate whether the optional MSBuild condition on an XML element evaluates to true. Currently only supports 'ABC' == 'DEF' style expressions, but can be expanded as needed. /// </summary> /// <param name="Element">The XML element to check</param> /// <param name="Properties">Dictionary mapping from property names to values.</param> /// <returns></returns> static bool EvaluateCondition(XmlElement Element, CsProjectInfo ProjectInfo) { // Read the condition attribute. If it's not present, assume it evaluates to true. string Condition = Element.GetAttribute("Condition"); if (String.IsNullOrEmpty(Condition)) { return(true); } // Expand all the properties Condition = ExpandProperties(Condition, ProjectInfo.Properties); // Parse literal true/false values bool OutResult; if (bool.TryParse(Condition, out OutResult)) { return(OutResult); } // Tokenize the condition string[] Tokens = Tokenize(Condition); char[] TokenQuotes = new[] { '\'', '(', ')', '{', '}', '[', ']' }; // Try to evaluate it. We only support a very limited class of condition expressions at the moment, but it's enough to parse standard projects bool bResult; // Handle Exists('Platform\Windows\Gauntlet.TargetDeviceWindows.cs') if (Tokens[0] == "Exists") { // remove all quotes, apostrophes etc that are either tokens or wrap tokens (The Tokenize() function is a bit suspect). string[] Arguments = Tokens.Select(S => S.Trim(TokenQuotes)).Where(S => S.Length > 0).ToArray(); if (Tokens.Length > 1) { FileSystemReference Dependency = DirectoryReference.Combine(ProjectInfo.ProjectPath.Directory, Arguments[1]); if (File.Exists(Dependency.FullName) || Directory.Exists(Dependency.FullName)) { return(true); } return(false); } } if (Tokens.Length == 3 && Tokens[0].StartsWith("'") && Tokens[1] == "==" && Tokens[2].StartsWith("'")) { bResult = String.Compare(Tokens[0], Tokens[2], StringComparison.InvariantCultureIgnoreCase) == 0; } else if (Tokens.Length == 3 && Tokens[0].StartsWith("'") && Tokens[1] == "!=" && Tokens[2].StartsWith("'")) { bResult = String.Compare(Tokens[0], Tokens[2], StringComparison.InvariantCultureIgnoreCase) != 0; } else { string Msg = string.Format("Couldn't parse condition {0} in project file {1}", Element.ToString(), ProjectInfo.ProjectPath); throw new Exception(Msg); } return(bResult); }