Exemple #1
0
        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);
        }