From efc57bc3d79e9c3c0971a2715a407ad08e030f02 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 6 Aug 2009 02:29:12 +0100 Subject: [PATCH] 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 +++++++++++++++++++ .../Region/Application/ConfigurationLoader.cs | 7 +-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0a9b67d467..65d4f4d465 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(); + } } } diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs index 1be36ca851..7bb8864fa3 100644 --- a/OpenSim/Region/Application/ConfigurationLoader.cs +++ b/OpenSim/Region/Application/ConfigurationLoader.cs @@ -188,10 +188,11 @@ namespace OpenSim { string path = Path.GetFullPath( Path.Combine(Util.configDir(), file)); - if (File.Exists(path)) + string[] paths = Util.Glob(path); + foreach (string p in paths) { - if (!sources.Contains(path)) - sources.Add(path); + if (!sources.Contains(p)) + sources.Add(p); } } }