public override string EvaluateFunction(string prefix, string function, string[] args) { switch (function) { case "VarNullOrEmpty": if (args.Length != 1 || string.IsNullOrEmpty(args[0])) { throw new WixException(WixErrors.InvalidPreprocessorFunction(null, function)); } string val = Core.GetVariableValue(null, args[0], true); return(string.IsNullOrEmpty(val) ? "1" : "0"); case "AutoGuid": if (args.Length == 0) { throw new WixException(WixErrors.InvalidPreprocessorFunction(null, function)); } string key = args.Aggregate((a, c) => $"{a}\\{c}"); string guid = CompilerCore.NewGuid(new Guid("{F026BBCE-4776-402C-BF36-352781805165}"), key); return(guid); case "FileExists": if (args.Length != 1 || string.IsNullOrEmpty(args[0])) { throw new WixException(WixErrors.InvalidPreprocessorFunction(null, function)); } return(File.Exists(args[0]) ? "1" : "0"); case "DirExists": if (args.Length != 1 || string.IsNullOrEmpty(args[0])) { throw new WixException(WixErrors.InvalidPreprocessorFunction(null, function)); } return(Directory.Exists(args[0]) ? "1" : "0"); case "DirEmpty": if (args.Length != 1 || string.IsNullOrEmpty(args[0])) { throw new WixException(WixErrors.InvalidPreprocessorFunction(null, function)); } return((Directory.Exists(args[0]) && (Directory.GetFiles(args[0], "*", SearchOption.AllDirectories).Length > 0)) ? "0" : "1"); default: return(null); } }
/// <summary> /// Parses a CfgException element. /// </summary> /// <param name="node">The element to parse.</param> private void ParseCfgProductElement(XElement node) { SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); string name = null; string version = null; string publickey = null; string feature = null; foreach (XAttribute attrib in node.Attributes()) { if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) { switch (attrib.Name.LocalName) { case "Name": name = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "Version": version = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "PublicKey": publickey = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "Feature": feature = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; default: this.Core.UnexpectedAttribute(sourceLineNumbers, attrib); break; } } else { this.Core.ParseExtensionAttribute(node, attrib); } } // Id and Name are required if (null == name) { this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); } if (null == version) { this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Version")); } if (null == publickey) { this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "PublicKey")); } if (null == feature) { this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Feature")); } this.Core.ParseForExtensionElements(node); if (!this.Core.EncounteredError) { string componentGuid = CompilerCore.NewGuid(CfgConstants.wixCfgGuidNamespace, name + "_" + version + "_" + publickey); string componentId = "Cfg_" + componentGuid.Substring(1, componentGuid.Length - 2).Replace("-", "_"); // Cutoff the curly braces and switch dashes to underscrores to get the componentID string regId = "Reg_" + componentId; Row componentRow = this.Core.CreateRow(sourceLineNumbers, "Component"); componentRow[0] = componentId; componentRow[1] = componentGuid; componentRow[2] = "TARGETDIR"; componentRow[3] = MsidbComponentAttributesRegistryKeyPath; componentRow[4] = ""; componentRow[5] = regId; Row featureComponentRow = this.Core.CreateRow(sourceLineNumbers, "FeatureComponents"); featureComponentRow[0] = feature; featureComponentRow[1] = componentId; Row cfgRow = this.Core.CreateRow(sourceLineNumbers, "WixCfgProducts"); cfgRow[0] = name; cfgRow[1] = version; cfgRow[2] = publickey; cfgRow[3] = componentId; Row regRow = this.Core.CreateRow(sourceLineNumbers, "Registry"); regRow[0] = regId; regRow[1] = MsidbRegistryRootLocalMachine; regRow[2] = "SOFTWARE\\Wix\\SettingsStore\\Products"; regRow[3] = name + ", " + version + ", " + publickey; regRow[4] = "#1"; regRow[5] = componentId; this.Core.CreateWixSimpleReferenceRow(sourceLineNumbers, "Feature", feature); this.Core.CreateWixSimpleReferenceRow(sourceLineNumbers, "CustomAction", "SchedCfgProductsInstall"); this.Core.CreateWixSimpleReferenceRow(sourceLineNumbers, "CustomAction", "SchedCfgProductsUninstall"); } }