Exemplo n.º 1
0
        private void UpdateKnownFileTypes()
        {
            IncludedExtensions.Clear();

            foreach (var extension in _knownFileTypes.All
                     .OrderBy(x => x)
                     .Select(x => CreateIncludedExtension(x))
                     .ToList())
            {
                _searchOptions.IncludeExtensions.Add(extension.Name);
                IncludedExtensions.Add(extension);
                SearchAllSearchableFileTypes = true;
            }
        }
Exemplo n.º 2
0
        public override bool Execute()
        {
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                Log.LogMessage(MessageImportance.High, $"Skipping WiX update, we're not on Windows.");
                return(true);
            }

            if (!File.Exists(InputManifestPath))
            {
                throw new ArgumentException($"Input manifest {InputManifestPath} does not exist.", nameof(InputManifestPath));
            }

            if (!Directory.Exists(SourceDirectory))
            {
                throw new ArgumentException($"Source directory {SourceDirectory} does not exist.", nameof(SourceDirectory));
            }

            XDocument wixManifest;

            using (var sr = new StreamReader(InputManifestPath))
                wixManifest = XDocument.Load(sr);

            var targetComponentGroup = GetComponentGroup(wixManifest, ComponentGroupId);

            if (targetComponentGroup == null)
            {
                throw new ArgumentException($"Could not find ComponentGroup with ID {ComponentGroupId}.");
            }

            var hasChanges = false;

            // Handle the easy case first, scanning just the single directory.
            var sourcePath   = new FilePath(SourceDirectory);
            var searchOption = ScanRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
            var sourceFiles  = IncludedExtensions.SelectMany(
                extension => sourcePath.EnumerateFiles($"*.{extension}", searchOption));
            var excludedHash = new HashSet <string> (ExcludedExtensions, StringComparer.OrdinalIgnoreCase);

            var newFiles = new List <string> ();

            foreach (var file in sourceFiles)
            {
                var fileName     = file.Name;
                var extension    = Path.GetExtension(file).TrimStart('.');
                var relativePath = file.GetRelativePath(sourcePath);

                if (excludedHash.Contains(extension))
                {
                    Log.LogMessage(
                        MessageImportance.Low,
                        $"Skipping file {fileName}, its extension matches the exclusion list.");
                    continue;
                }

                // Look up by relative path--in the case of non-recursion, relativePath == fileName.
                var hasExisting = HasExistingFileElement(targetComponentGroup, relativePath);
                if (hasExisting)
                {
                    Log.LogMessage(
                        MessageImportance.Low,
                        $"Skipping file {fileName}, it's already present in the component group.");
                    continue;
                }

                // Use the relative path for generating ID hashes--hash IDs are useful for generating
                // a full tree that may have repeated file names.
                var id           = UseHashForId ? Hash(file.FullPath) : GenerateIdForFile(IdPrefix, fileName);
                var newComponent = CreateComponentForFile(id, DirectoryVariable, relativePath);

                targetComponentGroup.Add(newComponent);
                hasChanges = true;

                newFiles.Add(fileName);

                Log.LogMessage(
                    MessageImportance.Low,
                    $"Added file {fileName} (id: {id}) to target component group.");
            }

            if (hasChanges)
            {
                using (var fs = File.Open(InputManifestPath, FileMode.Create))
                    wixManifest.Save(fs);
            }

            if (hasChanges && FailOnManifestChanges)
            {
                var manifestFileName = Path.GetFileNameWithoutExtension(InputManifestPath);

                Log.LogError(
                    $"Manifest {manifestFileName} has changes, and FailOnManifestChanges is true. " +
                    $"Please check the manifest output and commit it if it's correct.");

                newFiles.ForEach(newFile => Log.LogError(
                                     $"New file {newFile} added to manifest {InputManifestPath}."));

                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        bool ShouldProcessFile(string file)
        {
            var extension = Helpers.File.Extension(file);
            var included  = IncludedExtensions == null || IncludedExtensions.Count == 0 || IncludedExtensions.Any(e => extension.EndsWith(e, System.StringComparison.OrdinalIgnoreCase));
            var exclude   = IgnoredExtensions.Contains(extension);

            return(included && !exclude);
        }