Пример #1
0
        public static Shortcut FromContext(string name, IAttributeContext context)
        {
            var result = new Shortcut(name);

            var shortcutTargetDirRef = context.GetInheritedAttribute("shortcutTargetDirRef");
            if (shortcutTargetDirRef != null)
                result.TargetDirRef = shortcutTargetDirRef;
            else
                throw new SwixItemParsingException("shortcutTargetDirRef attribute is mandatory for all shortcuts");

            var shortcutTargetDir = context.GetInheritedAttribute("shortcutTargetDir");
            if (shortcutTargetDir != null)
                result.TargetDir = shortcutTargetDir;

            var workingDir = context.GetInheritedAttribute("workingDir");
            if (workingDir != null)
                result.WorkingDir = workingDir;

            var args = context.GetInheritedAttribute("args");
            if (args != null && string.IsNullOrWhiteSpace(args))
                throw new SwixItemParsingException("Shortcut's 'args' cannot be empty. Either set it to some value or remove altogether");
            result.Args = args;

            return result;
        }
Пример #2
0
        public ISemanticContext MakeCustomizable(string key, IAttributeContext attributes)
        {
            var publicWixPathPropertyName = key;
            var registryStorageKey        = attributes.GetInheritedAttribute("regKey");
            var defaultValue = attributes.GetInheritedAttribute("defaultValue");

            if (key == null)
            {
                throw new SwixSemanticException(CurrentLine, "Key attribute for ?makeCustomizable is mandatory and specifies property name with which user can customize the value");
            }
            if (registryStorageKey == null)
            {
                throw new SwixSemanticException(CurrentLine, "registryStorageKey attribute for ?makeCustomizable is mandatory");
            }
            if (_currentDir.Customization != null)
            {
                throw new SwixSemanticException(CurrentLine, "This directory already has customization assigned");
            }
            WixTargetDirCustomization customization;

            try
            {
                customization = new WixTargetDirCustomization(_currentDir, registryStorageKey, publicWixPathPropertyName);
            }
            catch (SwixItemParsingException e)
            {
                throw new SwixSemanticException(CurrentLine, e.Message);
            }

            customization.DefaultValue = defaultValue;
            return(new StubSwixElement(CurrentLine, attributes, () => _currentDir.Customization = customization));
        }
Пример #3
0
        public static string GetFullSourcePath(string key, IAttributeContext context)
        {
            var fromBase = context.GetInheritedAttribute("fromBase");
            var from     = context.GetInheritedAttribute("from");
            var path     = @from == null ? key : Path.Combine(@from, key);

            if (fromBase != null)
            {
                path = Path.Combine(fromBase, path);
            }

            return(path);
        }
Пример #4
0
        public ZipSemanticContext(int line, string archivePath, IAttributeContext context, List <WixComponent> components)
            : base(line, context, components)
        {
            var originalFrom = context.GetInheritedAttribute("from");

            if (originalFrom != null)
            {
                archivePath = Path.Combine(originalFrom, archivePath);
            }

            if (!File.Exists(archivePath))
            {
                throw new SwixSemanticException(line, $"File {archivePath} not found");
            }

            var tmp          = SwixProcessor.TempDir;
            var g            = context.GuidProvider.Get(SwixGuidType.ZipArchive, archivePath.ToLowerInvariant()).ToString("N");
            var unpackedPath = Path.GetFullPath(Path.Combine(tmp, g));

            try
            {
                ZipFile.ExtractToDirectory(archivePath, unpackedPath);
            }
            catch (Exception e)
            {
                throw new SwixSemanticException(line, $"Error while unzipping {archivePath} to {unpackedPath}: {e}");
            }

            context.SetAttributes(new[]
            {
                new AhlAttribute("fromBase", unpackedPath),
                new AhlAttribute("from", null)
            });

            int rootSubstringLength = unpackedPath.Length;

            var files = Directory.GetFiles(unpackedPath);

            foreach (string path in files)
            {
                var component = WixComponent.FromContext(path, context);
                if (path[rootSubstringLength] == '\\')
                {
                    rootSubstringLength++;
                }
                var relativeDir = Path.GetDirectoryName(path.Substring(rootSubstringLength));
                if (relativeDir != null)
                {
                    component.TargetDir = component.TargetDir == null
                        ? relativeDir
                        : Path.Combine(component.TargetDir, relativeDir);
                }

                GatheredComponents.Add(component);
            }
        }
Пример #5
0
        public static CabFile FromContext(string name, IAttributeContext attributeContext)
        {
            var result = new CabFile(name);

            var compressionLevel = attributeContext.GetInheritedAttribute("compressionLevel");

            result.CompressionLevel = compressionLevel ?? "none";

            var splitStr = attributeContext.GetInheritedAttribute("split") ?? "1";

            if (!int.TryParse(splitStr, out var split))
            {
                throw new SwixItemParsingException($"Can't parse split number for cabFile '{name}'");
            }
            if (split <= 0 || split >= 100)
            {
                throw new SwixItemParsingException($"Split number must be positive integer less than 100 in the cabFile '{name}'");
            }
            result.Split = split;

            return(result);
        }
Пример #6
0
        public CabFilesSection(int line, IAttributeContext attributeContext, SwixModel model)
            : base(line, attributeContext)
        {
            _model = model;

            string startFromStr = attributeContext.GetInheritedAttribute("startFrom");

            if (startFromStr != null)
            {
                int startFrom;
                if (!int.TryParse(startFromStr, out startFrom))
                {
                    throw new SwixSemanticException(CurrentLine, "Can't parse startFrom number for cabFiles section");
                }
                _diskIdsStartFrom = startFrom;
            }
        }
Пример #7
0
        public static WixTargetDirectory FromAttributes(string key, IAttributeContext attributeContext, WixTargetDirectory parent)
        {
            var result = new WixTargetDirectory(key, parent);
            var id     = attributeContext.GetInheritedAttribute("id");

            if (id != null)
            {
                result.Id = id;
            }

            var refOnly = attributeContext.GetInheritedAttribute("refOnly");

            if (refOnly != null && refOnly != "yes" && refOnly != "no")
            {
                throw new SwixItemParsingException("Attribute 'refOnly' should be either 'yes' or 'no'.");
            }
            result.RefOnly = refOnly == "yes";

            var removeOnUninstall = attributeContext.GetInheritedAttribute("removeOnUninstall");

            if (removeOnUninstall != null && removeOnUninstall != "yes" && removeOnUninstall != "no")
            {
                throw new SwixItemParsingException("Attribute 'removeOnUninstall' should be either 'yes' or 'no'.");
            }
            result.RemoveOnUninstall = removeOnUninstall == "yes";

            var createOnInstall = attributeContext.GetInheritedAttribute("createOnInstall");

            if (createOnInstall != null && createOnInstall != "yes" && createOnInstall != "no")
            {
                throw new SwixItemParsingException("Attribute 'createOnInstall' should be either 'yes' or 'no'.");
            }
            result.CreateOnInstall = createOnInstall == "yes";

            var componentGroupRef = attributeContext.GetInheritedAttribute("componentGroupRef");

            if (componentGroupRef != null)
            {
                result.ComponentGroupRef = componentGroupRef;
            }

            var multiInstance = attributeContext.GetInheritedAttribute("multiInstance");

            if (multiInstance != "yes" && multiInstance != "no" && multiInstance != null)
            {
                throw new SwixItemParsingException("Optional 'multiInstance' attribute could be only 'yes' or 'no'");
            }
            result.MultiInstance = multiInstance;

            return(result);
        }
Пример #8
0
        public static WixComponent FromContext(string key, IAttributeContext context)
        {
            var result = new WixComponent(GetFullSourcePath(key, context));

            var fileName = context.GetInheritedAttribute("name");

            if (fileName != null)
            {
                result.FileName = fileName;
            }
            else
            {
                var idx = key.LastIndexOf('\\');
                result.FileName = key.Substring(idx + 1);
            }

            var targetDirRef = context.GetInheritedAttribute("targetDirRef");

            if (targetDirRef != null)
            {
                result.TargetDirRef = targetDirRef;
            }
            else
            {
                throw new SwixItemParsingException("targetDirRef attribute is mandatory for all components");
            }

            var targetDir = context.GetInheritedAttribute("targetDir");

            if (targetDir != null)
            {
                result.TargetDir = targetDir;
            }

            var cabFileRef = context.GetInheritedAttribute("cabFileRef");

            if (cabFileRef != null)
            {
                result.CabFileRef = cabFileRef;
            }

            var moduleRef = context.GetInheritedAttribute("moduleRef");

            if (moduleRef != null)
            {
                result.ModuleRef = moduleRef;
            }

            if (cabFileRef == null && moduleRef == null)
            {
                throw new SwixItemParsingException("cabFileRef or moduleRef attribute is mandatory for all components");
            }

            if (cabFileRef != null && moduleRef != null)
            {
                throw new SwixItemParsingException("You can't specify both cabFileRef and moduleRef for same component");
            }

            result.OutputTag = context.GetInheritedAttribute("outputTag");
            result.Condition = context.GetInheritedAttribute("condition");

            var componentGroupRef = context.GetInheritedAttribute("componentGroupRef");

            if (componentGroupRef != null)
            {
                result.ComponentGroupRef = componentGroupRef;
            }

            var multiInstance = context.GetInheritedAttribute("multiInstance");

            if (multiInstance != "yes" && multiInstance != "no" && multiInstance != null)
            {
                throw new SwixItemParsingException("Optional 'multiInstance' attribute could be only 'yes' or 'no'");
            }
            result.MultiInstance = multiInstance;

            var win64 = context.GetInheritedAttribute("win64");

            if (win64 != "yes" && win64 != "no" && win64 != null)
            {
                throw new SwixItemParsingException("Optional 'win64' attribute could be only 'yes' or 'no'");
            }
            result.Win64 = win64;

            var id = context.GetInheritedAttribute("id");

            if (id != null)
            {
                result.Id = id;
            }

            var sddl = context.GetInheritedAttribute("sddl");

            if (sddl != null)
            {
                result.Sddl = sddl;
            }

            return(result);
        }
Пример #9
0
        public static Service FromContext(string key, IAttributeContext attributes)
        {
            var result = new Service(key);

            var id = attributes.GetInheritedAttribute("id");

            if (id != null)
            {
                result.Id = id;
            }

            var displayName = attributes.GetInheritedAttribute("displayName");

            if (displayName != null)
            {
                result.DisplayName = displayName;
            }

            var description = attributes.GetInheritedAttribute("description");

            if (description != null)
            {
                result.Description = description;
            }

            var args = attributes.GetInheritedAttribute("args");

            if (args != null)
            {
                result.Args = args;
            }

            var account = attributes.GetInheritedAttribute("account");

            if (account != null)
            {
                result.Account = account;
            }

            var password = attributes.GetInheritedAttribute("password");

            if (password != null)
            {
                result.Password = password;
            }

            var startStr = attributes.GetInheritedAttribute("start");

            if (startStr != null)
            {
                ServiceStartupType start;
                if (!Enum.TryParse(startStr, true, out start))
                {
                    throw new SwixItemParsingException("'start' attribute should be one of these values: 'auto', 'demand' or 'disabled'");
                }
                result.Start = start;
            }

            var vital = attributes.GetInheritedAttribute("vital");

            if (vital != null && vital != "yes" && vital != "no")
            {
                throw new SwixItemParsingException("'vital' attribute should be either 'yes' or 'no'");
            }
            result.Vital = vital;

            var typeStr = attributes.GetInheritedAttribute("type");

            if (startStr != null)
            {
                ServiceHostingType type;
                if (!Enum.TryParse(typeStr, true, out type))
                {
                    throw new SwixItemParsingException("'type' attribute should be one of these values: 'ownProcess', 'sharedProcess', 'systemDriver' or 'kernelDriver'");
                }
                result.Type = type;
            }

            var errorControlStr = attributes.GetInheritedAttribute("errorControl");

            if (errorControlStr != null)
            {
                ServiceErrorControl errorControl;
                if (!Enum.TryParse(errorControlStr, true, out errorControl))
                {
                    throw new SwixItemParsingException("'errorControl' attribute should be one of these values: 'ignore', 'normal' or 'critical'");
                }
                result.ErrorControl = errorControl;
            }

            return(result);
        }