コード例 #1
0
ファイル: Shortcut.cs プロジェクト: swix-dsl/swix
        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
ファイル: DirectoriesSection.cs プロジェクト: swix-dsl/swix
        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
ファイル: ZipSemanticContext.cs プロジェクト: swix-dsl/swix
        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);
            }
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #6
0
ファイル: DirectoriesSection.cs プロジェクト: swix-dsl/swix
 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);
     }
 }
コード例 #7
0
ファイル: WixTargetDirectory.cs プロジェクト: swix-dsl/swix
        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 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);
     }
 }
コード例 #9
0
ファイル: ServicesSection.cs プロジェクト: swix-dsl/swix
 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);
         }
     }));
 }
コード例 #10
0
 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;
 }
コード例 #11
0
ファイル: CabFilesSection.cs プロジェクト: swix-dsl/swix
 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 }));
         }
     }));
 }
コード例 #12
0
ファイル: CabFilesSection.cs プロジェクト: swix-dsl/swix
        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;
            }
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #15
0
ファイル: CabFile.cs プロジェクト: swix-dsl/swix
        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);
        }
コード例 #16
0
 public BaseSwixSemanticContext(int sourceLine, IAttributeContext attributeContext)
 => _currentContexts.Push(new AttributeContextFrame(sourceLine, attributeContext));
コード例 #17
0
ファイル: ServicesSection.cs プロジェクト: swix-dsl/swix
 public ServicesSection(int line, IAttributeContext attributeContext, List <Service> services)
     : base(line, attributeContext)
 {
     _services = services;
     _toAdd    = new List <Service>();
 }
コード例 #18
0
 public ComponentsSection(int line, IAttributeContext attributeContext, List <WixComponent> components)
     : base(line, attributeContext)
 {
     _components = components;
     _toAdd      = new List <WixComponent>();
 }
コード例 #19
0
 public ShortcutsSection(int line, IAttributeContext attributeContext, List <Shortcut> shortcuts)
     : base(line, attributeContext)
 {
     _shortcuts = shortcuts;
     _toAdd     = new List <Shortcut>();
 }
コード例 #20
0
 public ISemanticContext HandleMetaZip(string key, IAttributeContext metaContext)
 {
     return(new ZipSemanticContext(CurrentLine, key, metaContext, _toAdd));
 }
コード例 #21
0
 public ISemanticContext M1(string key, IAttributeContext metaContext)
 {
     return(M1Func(key, metaContext));
 }
コード例 #22
0
ファイル: ComponentItem.cs プロジェクト: swix-dsl/swix
 public ComponentItem(int line, IAttributeContext inheritedContext, WixComponent component)
     : base(line, inheritedContext)
 {
     _component = component;
 }
コード例 #23
0
ファイル: ComponentItem.cs プロジェクト: swix-dsl/swix
 public ISemanticContext Services(IAttributeContext sectionContext)
 {
     return(new ServicesSection(CurrentLine, sectionContext, _component.Services));
 }
コード例 #24
0
ファイル: ComponentItem.cs プロジェクト: swix-dsl/swix
 public ISemanticContext Shortcuts(IAttributeContext sectionContext)
 {
     return(new ShortcutsSection(CurrentLine, sectionContext, _component.Shortcuts));
 }
コード例 #25
0
ファイル: StubSwixElement.cs プロジェクト: swix-dsl/swix
 public StubSwixElement(int line, IAttributeContext attributeContext, Action onFinish)
     : base(line, attributeContext)
 {
     _onFinish = onFinish;
 }
コード例 #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);
        }
コード例 #27
0
 public ISemanticContext ItemHandler(string key, IAttributeContext itemContext)
 {
     return(ItemFunc(key, itemContext));
 }
コード例 #28
0
ファイル: Service.cs プロジェクト: swix-dsl/swix
        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);
        }
コード例 #29
0
 public HarvestSemanticContext(int line, string folder, IAttributeContext context, List <WixComponent> components)
     : base(line, AddFromFolder(context, folder), components)
 {
     _folder = folder;
     _directlySetAttributes = CurrentAttributeContext.GetDirectlySetAttributes();
 }
コード例 #30
0
 public ISemanticContext S1(IAttributeContext childContext)
 {
     return(S1Func(childContext));
 }