コード例 #1
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);
            }
        }
コード例 #2
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);
        }