コード例 #1
0
        private static Regex WildcardToRegex(string wildcard)
        {
            string pattern = null;

            if (Path.DirectorySeparatorChar == '/')
            {
                pattern = Regex.Escape(PathUtility.GetPathWithForwardSlashes(wildcard));
                // regex wildcard adjustments for *nix-style file systems
                pattern = pattern
                          .Replace(@"\*\*/", "(.*/)?")  //For recursive wildcards /**/, include the current directory.
                          .Replace(@"\*\*", ".*")       // For recursive wildcards that don't end in a slash e.g. **.txt would be treated as a .txt file at any depth
                          .Replace(@"\*\.\*", @"\*")    // "*.*" is equivalent to "*"
                          .Replace(@"\*", @"[^/]*(/)?") // For non recursive searches, limit it any character that is not a directory separator
                          .Replace(@"\?", ".");         // ? translates to a single any character
            }
            else
            {
                pattern = Regex.Escape(wildcard);
                // regex wildcard adjustments for Windows-style file systems
                pattern = pattern
                          .Replace("/", @"\\")            // On Windows, / is treated the same as \.
                          .Replace(@"\*\*\\", @"(.*\\)?") //For recursive wildcards \**\, include the current directory.
                          .Replace(@"\*\*", ".*")         // For recursive wildcards that don't end in a slash e.g. **.txt would be treated as a .txt file at any depth
                          .Replace(@"\*\.\*", @"\*")      // "*.*" is equivalent to "*"
                          .Replace(@"\*", @"[^\\]*(\\)?") // For non recursive searches, limit it any character that is not a directory separator
                          .Replace(@"\?", ".");           // ? translates to a single any character
            }

            return(new Regex('^' + pattern + '$', RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture));
        }
コード例 #2
0
        private static void CreatePart(ZipArchive package, string path, Stream sourceStream)
        {
            if (PackageHelper.IsManifest(path))
            {
                return;
            }

            var entry = package.CreateEntry(PathUtility.GetPathWithForwardSlashes(path), CompressionLevel.Optimal);

            using (var stream = entry.Open())
            {
                sourceStream.CopyTo(stream);
            }
        }