Esempio n. 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;
        }
Esempio n. 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));
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        private static IAttributeContext AddFromFolder(IAttributeContext attributeContext, string folder)
        {
            if (!attributeContext.GetDirectlySetAttributes().ContainsKey("from"))
            {
                // we imitate that harvest's key is also treated as 'from' specification, thus making
                // nested components searched by default in the directory being harvested
                attributeContext.SetAttributes(new[] { new AhlAttribute("from", folder) });
            }

            return(attributeContext);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public ISemanticContext RootDirectory(string key, IAttributeContext itemContext)
 {
     try
     {
         var dir = WixTargetDirectory.FromAttributes(key, itemContext, _currentDir);
         _subdirs.Add(dir);
         return(new DirectoriesSection(CurrentLine, CurrentAttributeContext, dir));
     }
     catch (SwixItemParsingException e)
     {
         throw new SwixSemanticException(CurrentLine, e.Message);
     }
 }
Esempio n. 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);
        }
Esempio n. 8
0
 public virtual ISemanticContext Component(string key, IAttributeContext itemContext)
 {
     try
     {
         var component           = WixComponent.FromContext(key, itemContext);
         var itemSemanticContext = new ComponentItem(CurrentLine, CurrentAttributeContext, component);
         itemSemanticContext.OnFinished += (s, e) => _toAdd.Add(component);
         return(itemSemanticContext);
     }
     catch (SwixSemanticException e)
     {
         throw new SwixSemanticException(CurrentLine, e.Message);
     }
 }
Esempio n. 9
0
 public ISemanticContext HandleService(string key, IAttributeContext attributes)
 {
     return(new StubSwixElement(CurrentLine, attributes, () =>
     {
         try
         {
             _toAdd.Add(Service.FromContext(key, attributes));
         }
         catch (SwixItemParsingException e)
         {
             throw new SwixSemanticException(CurrentLine, e.Message);
         }
     }));
 }
 public StartTagAttributeValueSuggestion(
     DataTypes dataTypes,
     IElementContext targetElement,
     IElementContext parentElement,
     IAttributeContext lastAttribute,
     ICodeReader codeReader,
     IDictionary <string, string> namespaceDeclarations)
 {
     _dataTypes             = dataTypes;
     _targetElement         = targetElement;
     _parentElement         = parentElement;
     _lastAttribute         = lastAttribute;
     _codeReader            = codeReader;
     _namespaceDeclarations = namespaceDeclarations;
 }
Esempio n. 11
0
 public ISemanticContext HandleFile(string key, IAttributeContext attributes)
 {
     return(new StubSwixElement(CurrentLine, CurrentAttributeContext, () =>
     {
         try
         {
             var cabFile = CabFile.FromContext(key, attributes);
             _model.CabFiles.Add(cabFile);
         }
         catch (SwixItemParsingException e)
         {
             throw new SwixSemanticException(CurrentLine, string.Format("{0}", new[] { e.Message }));
         }
     }));
 }
Esempio n. 12
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;
            }
        }
Esempio n. 13
0
        public override ISemanticContext Component(string key, IAttributeContext itemContext)
        {
            // we can't allow here non-rooted paths or paths with wix variables, because in this case
            // we won't be able to identify which harvested component we should replace with manually
            // specified one.
            // So, here is the check that SourcePath of resulting component is full, such file exists etc
            var fullPath         = WixComponent.GetFullSourcePath(key, itemContext);
            var invalidPathChars = Path.GetInvalidPathChars();

            if (fullPath.IndexOfAny(invalidPathChars) != -1)
            {
                throw new SwixSemanticException(CurrentLine, "Components inside ?harvest meta should reference existing files without WIX variables.");
            }
            if (!File.Exists(fullPath))
            {
                throw new SwixSemanticException(CurrentLine, $"File {fullPath} is not found. Components inside ?harvest meta should reference existing files without WIX variables.");
            }
            return(base.Component(key, itemContext));
        }
Esempio n. 14
0
        public ISemanticContext DefineSwixVariable(string key, IAttributeContext defineContext)
        {
            var name = new Regex(@"^\w+$");

            if (!name.IsMatch(key))
            {
                throw new SwixSemanticException(CurrentLine, "You have to specify name of new SWIX variable and it should match '^\\w+$' regex");
            }

            string value;

            if (!defineContext.GetDirectlySetAttributes().TryGetValue("value", out value))
            {
                throw new SwixSemanticException(CurrentLine, "?define meta should have 'value' argument");
            }

            CurrentAttributeContext.SwixVariableDefinitions[key] = ExpandSwixVariables(value);
            return(new StubSwixElement(CurrentLine, null, null));
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
 public BaseSwixSemanticContext(int sourceLine, IAttributeContext attributeContext)
 => _currentContexts.Push(new AttributeContextFrame(sourceLine, attributeContext));
Esempio n. 17
0
 public ServicesSection(int line, IAttributeContext attributeContext, List <Service> services)
     : base(line, attributeContext)
 {
     _services = services;
     _toAdd    = new List <Service>();
 }
Esempio n. 18
0
 public ComponentsSection(int line, IAttributeContext attributeContext, List <WixComponent> components)
     : base(line, attributeContext)
 {
     _components = components;
     _toAdd      = new List <WixComponent>();
 }
Esempio n. 19
0
 public ShortcutsSection(int line, IAttributeContext attributeContext, List <Shortcut> shortcuts)
     : base(line, attributeContext)
 {
     _shortcuts = shortcuts;
     _toAdd     = new List <Shortcut>();
 }
Esempio n. 20
0
 public ISemanticContext HandleMetaZip(string key, IAttributeContext metaContext)
 {
     return(new ZipSemanticContext(CurrentLine, key, metaContext, _toAdd));
 }
Esempio n. 21
0
 public ISemanticContext M1(string key, IAttributeContext metaContext)
 {
     return(M1Func(key, metaContext));
 }
Esempio n. 22
0
 public ComponentItem(int line, IAttributeContext inheritedContext, WixComponent component)
     : base(line, inheritedContext)
 {
     _component = component;
 }
Esempio n. 23
0
 public ISemanticContext Services(IAttributeContext sectionContext)
 {
     return(new ServicesSection(CurrentLine, sectionContext, _component.Services));
 }
Esempio n. 24
0
 public ISemanticContext Shortcuts(IAttributeContext sectionContext)
 {
     return(new ShortcutsSection(CurrentLine, sectionContext, _component.Shortcuts));
 }
Esempio n. 25
0
 public StubSwixElement(int line, IAttributeContext attributeContext, Action onFinish)
     : base(line, attributeContext)
 {
     _onFinish = onFinish;
 }
Esempio n. 26
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);
        }
Esempio n. 27
0
 public ISemanticContext ItemHandler(string key, IAttributeContext itemContext)
 {
     return(ItemFunc(key, itemContext));
 }
Esempio n. 28
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);
        }
Esempio n. 29
0
 public HarvestSemanticContext(int line, string folder, IAttributeContext context, List <WixComponent> components)
     : base(line, AddFromFolder(context, folder), components)
 {
     _folder = folder;
     _directlySetAttributes = CurrentAttributeContext.GetDirectlySetAttributes();
 }
Esempio n. 30
0
 public ISemanticContext S1(IAttributeContext childContext)
 {
     return(S1Func(childContext));
 }