From 96f4e04f36397ac218a7f4d10e0e4a270440e52a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 12 Oct 2020 16:49:32 +0200 Subject: [PATCH] simplified glob regex matching --- GameBundle/Program.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GameBundle/Program.cs b/GameBundle/Program.cs index cf65c86..8084210 100644 --- a/GameBundle/Program.cs +++ b/GameBundle/Program.cs @@ -118,9 +118,9 @@ namespace GameBundle { var contents = app.CreateSubdirectory("Contents"); var resources = contents.CreateSubdirectory("Resources"); var macOs = contents.CreateSubdirectory("MacOS"); - var resRegex = GlobRegex(options.MacBundleResources); + var resRegex = options.MacBundleResources.Select(GlobRegex).ToArray(); foreach (var file in dir.GetFiles()) { - var destDir = resRegex.IsMatch(file.Name) ? resources : macOs; + var destDir = resRegex.Any(r => r.IsMatch(file.Name)) ? resources : macOs; if (file.Name.EndsWith("plist")) destDir = app; file.MoveTo(Path.Combine(destDir.FullName, file.Name), true); @@ -128,7 +128,7 @@ namespace GameBundle { foreach (var sub in dir.GetDirectories()) { if (sub.Name == app.Name) continue; - var destDir = resRegex.IsMatch(sub.Name) ? resources : macOs; + var destDir = resRegex.Any(r => r.IsMatch(sub.Name)) ? resources : macOs; var dest = new DirectoryInfo(Path.Combine(destDir.FullName, sub.Name)); if (dest.Exists) dest.Delete(true); @@ -136,8 +136,8 @@ namespace GameBundle { } } - private static Regex GlobRegex(IEnumerable strings) { - return new Regex('(' + string.Join("|", strings.Select(s => s.Replace(".", "[.]").Replace("*", ".*").Replace("?", "."))) + ')'); + private static Regex GlobRegex(string s) { + return new Regex(s.Replace(".", "[.]").Replace("*", ".*").Replace("?", ".")); } private static string GetBuildDir(Options options, FileInfo proj, string osName) {