public TemporaryZipFile(string inputFileName, string filter, ILogger logger) { this.inputFileName = inputFileName; this.logger = logger; dataDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(dataDirectory); logger.LogInformation($"Extracting zip file {inputFileName}"); ZipFile.ExtractToDirectory(inputFileName, dataDirectory); var filesInDir = Directory.EnumerateFiles(dataDirectory, "*.*", SearchOption.AllDirectories); FilesInDirectory = filesInDir.ToList(); // don't allow parent directory traversal filter = filter.Replace(@"..\", "").Replace("../", ""); var globs = filter.Split('\n').Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); if (globs.Count > 0) { var files = Globber.GetFiles(new DirectoryInfo(dataDirectory), globs); FilteredFilesInDirectory = files.Select(f => f.FullName).ToList(); } // If no filtered, default to all if (FilteredFilesInDirectory == null) { FilteredFilesInDirectory = FilesInDirectory.ToList(); } FilesExceptFiltered = FilesInDirectory.Except(FilteredFilesInDirectory).ToList(); }
public AppxFile(string inputFileName, string publisher, ILogger logger, IDirectoryUtility directoryUtility, string makeAppxPath, string filter) { this.inputFileName = inputFileName; this.publisher = publisher; this.logger = logger; this.directoryUtility = directoryUtility; this.makeAppxPath = makeAppxPath; dataDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(dataDirectory); Unpack(); UpdateManifestPublisher(); var filesInDir = Directory.EnumerateFiles(dataDirectory, "*.*", SearchOption.AllDirectories); FilesInDirectory = filesInDir.ToList(); // don't allow parent directory traversal filter = filter.Replace(@"..\", "").Replace("../", ""); var globs = filter.Split('\n').Where(s => (!string.IsNullOrWhiteSpace(s))) .Where(s => (!s.StartsWith("!"))) .ToList(); var antiglobs = filter.Split('\n').Where(s => (!string.IsNullOrWhiteSpace(s))) .Where(s => (s.StartsWith("!"))) .Select(s => s.Substring(1)) .ToList(); if (globs.Count > 0) { var files = Globber.GetFiles(new DirectoryInfo(dataDirectory), globs); FilteredFilesInDirectory = files.Select(f => f.FullName).ToList(); } // If no filtered, default to all if (FilteredFilesInDirectory == null) { FilteredFilesInDirectory = FilesInDirectory.ToList(); } if (antiglobs.Count > 0) { var antifiles = Globber.GetFiles(new DirectoryInfo(dataDirectory), antiglobs) .Select(f => f.FullName) .ToList(); FilteredFilesInDirectory = FilteredFilesInDirectory.Except(antifiles).ToList(); } FilesExceptFiltered = FilesInDirectory.Except(FilteredFilesInDirectory).ToList(); }
public TemporaryZipFile(string inputFileName, string filter, ILogger logger, bool filterHasPath = true) { this.inputFileName = inputFileName; this.logger = logger; dataDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(dataDirectory); logger.LogInformation($"Extracting zip file {inputFileName}"); ZipFile.ExtractToDirectory(inputFileName, dataDirectory); var filesInDir = Directory.EnumerateFiles(dataDirectory, "*.*", SearchOption.AllDirectories); FilesInDirectory = filesInDir.ToList(); if (filterHasPath) { var filterSet = new HashSet <string>(filter.Split('\n').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => Path.Combine(dataDirectory, s)), StringComparer.OrdinalIgnoreCase); if (filterSet.Count > 0) { FilteredFilesInDirectory = FilesInDirectory.Intersect(filterSet, StringComparer.OrdinalIgnoreCase).ToList(); } } else { var filterSet = new HashSet <string>(filter.Split('\n').Where(s => !string.IsNullOrWhiteSpace(s)), StringComparer.OrdinalIgnoreCase); if (filterSet.Count > 0) // match on file name only { FilteredFilesInDirectory = FilesInDirectory.Where(f => filterSet.Contains(Path.GetFileName(f))).ToList(); } } // If no filtered, default to all if (FilteredFilesInDirectory == null) { FilteredFilesInDirectory = FilesInDirectory.ToList(); } FilesExceptFiltered = FilesInDirectory.Except(FilteredFilesInDirectory).ToList(); }