From efc57bc3d79e9c3c0971a2715a407ad08e030f02 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 6 Aug 2009 02:29:12 +0100 Subject: Allow arbitrary wildcards in config includes. Things like Include-Modules = "addin-modules/*/config/*.ini" will now work. Adds Util.Glob, which will resolve a globbed path into a string list. --- OpenSim/Framework/Util.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'OpenSim/Framework/Util.cs') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0a9b67d..65d4f4d 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -1111,5 +1111,56 @@ namespace OpenSim.Framework return null; } + public static string[] Glob(string path) + { + string vol=String.Empty; + + if (Path.VolumeSeparatorChar != Path.DirectorySeparatorChar) + { + string[] vcomps = path.Split(new char[] {Path.VolumeSeparatorChar}, 2, StringSplitOptions.RemoveEmptyEntries); + + if (vcomps.Length > 1) + { + path = vcomps[1]; + vol = vcomps[0]; + } + } + + string[] comps = path.Split(new char[] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries); + + // Glob + + path = vol; + if (vol != String.Empty) + path += new String(new char[] {Path.VolumeSeparatorChar, Path.DirectorySeparatorChar}); + else + path = new String(new char[] {Path.DirectorySeparatorChar}); + + List paths = new List(); + List found = new List(); + paths.Add(path); + + foreach (string c in comps) + { + List addpaths = new List(); + foreach (string p in paths) + { + string[] dirs = Directory.GetDirectories(p, c); + + if (dirs.Length != 0) + { + foreach (string dir in dirs) + addpaths.Add(Path.Combine(path, dir)); + } + + string[] files = Directory.GetFiles(p, c); + foreach (string f in files) + found.Add(f); + } + paths = addpaths; + } + + return found.ToArray(); + } } } -- cgit v1.1