IFileInfo[] GetFiles() { IDirectoryContents dir = packageProvider.FileProvider.GetDirectoryContents(null); IFileInfo[] files = dir.ToArray(); // Convert package entries to package file infos for (int i = 0; i < files.Length; i++) { // Get file reference string filename = files[i].Name; // Match to package file extensions (e.g. *.zip) Match match = packageProvider.Pattern.Match(filename); // Don't replace if (!match.Success) { continue; } // Convert path to structured format PackageFileReference fileReference = new PackageFileReference(filename, match.Success, null, filename); // Create file entry PackageFileInfo newFileInfo = new PackageFileInfo(packageProvider, fileReference); newFileInfo.filename = filename; // Set new entry files[i] = newFileInfo; } return(files); }
IFileInfo[] GetFiles() { IFileInfo[] files = null; string subdir = null; // Open as package PackageFileReference package_to_open = directoryReference.IsPackageFile ? directoryReference : directoryReference.Parent; using (var fp = packageProvider.TryOpenPackage(package_to_open)) { if (fp != null) { subdir = directoryReference.IsPackageFile ? "" : directoryReference.Name; files = fp.GetDirectoryContents(subdir).ToArray(); } } // Open as directory if (files == null) { using (var fp = packageProvider.TryOpenPackage(directoryReference.Parent)) { if (fp != null) { subdir = directoryReference.Name; IDirectoryContents dir = fp.GetDirectoryContents(subdir); files = fp.GetDirectoryContents(subdir).ToArray(); } } } // Convert package entries to package file infos if (files != null) { for (int i = 0; i < files.Length; i++) { // Get file reference string filename = files[i].Name; // Match to package file extensions (e.g. *.zip) Match match = packageProvider.Pattern.Match(filename); // don't replace //if (!match.Success) continue; // Convert path to structured format PackageFileReference fileReference = new PackageFileReference(subdir == "" || subdir == "/" ? filename : subdir + "/" + filename, match.Success, package_to_open, null); // Create file entry PackageFileInfo newFileInfo = new PackageFileInfo(packageProvider, fileReference); newFileInfo.filename = filename; // Set new entry files[i] = newFileInfo; } return(files); } return(no_files); }
/// <summary> /// Create contents reader. /// </summary> /// <param name="packageProvider"></param> /// <param name="directoryReference"></param> public PackageDirectoryContents(PackageFileProvider packageProvider, PackageFileReference directoryReference) { this.packageProvider = packageProvider ?? throw new ArgumentNullException(nameof(packageProvider)); this.directoryReference = directoryReference ?? throw new ArgumentNullException(nameof(directoryReference)); }
public PackageEntry(PackageFileReference packageReference, Action disposeAction) { this.packageReference = packageReference ?? throw new ArgumentNullException(nameof(packageReference)); this.disposeAction = disposeAction; }
/// <summary> /// Create package info /// </summary> /// <param name="packageProvider"></param> /// <param name="fileReference"></param> public PackageFileInfo(IPackageProvider packageProvider, PackageFileReference fileReference) { this.packageProvider = packageProvider ?? throw new ArgumentNullException(nameof(packageProvider)); this.fileReference = fileReference ?? throw new ArgumentNullException(nameof(fileReference)); }