/// <summary> /// Get the value of a variable. /// </summary> /// <param name="sourceLineNumbers">The source line information for the function.</param> /// <param name="prefix">The variable prefix.</param> /// <param name="name">The variable name.</param> /// <returns>The variable value or null if the variable is not set.</returns> public string GetVariableValue(SourceLineNumberCollection sourceLineNumbers, string prefix, string name) { if (null == prefix) { throw new ArgumentNullException("prefix"); } if (null == name) { throw new ArgumentNullException("name"); } if (0 == name.Length) { throw new ArgumentException("Empty variable name.", "name"); } switch (prefix) { case "env": return(Environment.GetEnvironmentVariable(name)); case "sys": switch (name) { case "CURRENTDIR": return(String.Concat(Directory.GetCurrentDirectory(), Path.DirectorySeparatorChar)); case "SOURCEFILEDIR": return(String.Concat(Path.GetDirectoryName(this.sourceFile), Path.DirectorySeparatorChar)); case "SOURCEFILEPATH": return(this.sourceFile); default: return(null); } case "var": return((string)this.variables[name]); default: PreprocessorExtension extension = (PreprocessorExtension)this.extensionsByPrefix[prefix]; if (null != extension) { try { return(extension.GetVariableValue(prefix, name)); } catch (Exception e) { throw new WixException(WixErrors.PreprocessorExtensionGetVariableValueFailed(sourceLineNumbers, prefix, name, e.Message)); } } else { return(null); } } }
/// <summary> /// Get the value of a variable. /// </summary> /// <param name="sourceLineNumbers">The source line information for the function.</param> /// <param name="prefix">The variable prefix.</param> /// <param name="name">The variable name.</param> /// <returns>The variable value or null if the variable is not set.</returns> public string GetVariableValue(SourceLineNumberCollection sourceLineNumbers, string prefix, string name) { if (String.IsNullOrEmpty(prefix)) { throw new ArgumentNullException("prefix"); } if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } switch (prefix) { case "env": return(Environment.GetEnvironmentVariable(name)); case "sys": switch (name) { case "CURRENTDIR": return(String.Concat(Directory.GetCurrentDirectory(), Path.DirectorySeparatorChar)); case "SOURCEFILEDIR": return(String.Concat(Path.GetDirectoryName(sourceLineNumbers[0].FileName), Path.DirectorySeparatorChar)); case "SOURCEFILEPATH": return(sourceLineNumbers[0].FileName); case "PLATFORM": this.OnMessage(WixWarnings.DeprecatedPreProcVariable(sourceLineNumbers, "$(sys.PLATFORM)", "$(sys.BUILDARCH)")); goto case "BUILDARCH"; case "BUILDARCH": switch (this.currentPlatform) { case Platform.X86: return("x86"); case Platform.X64: return("x64"); case Platform.IA64: return("ia64"); default: throw new ArgumentException(WixStrings.EXP_UnknownPlatformEnum, this.currentPlatform.ToString()); } default: return(null); } case "var": return((string)this.variables[name]); default: PreprocessorExtension extension = (PreprocessorExtension)this.extensionsByPrefix[prefix]; if (null != extension) { try { return(extension.GetVariableValue(prefix, name)); } catch (Exception e) { throw new WixException(WixErrors.PreprocessorExtensionGetVariableValueFailed(sourceLineNumbers, prefix, name, e.Message)); } } else { return(null); } } }