From 28a40c0f5bf460452d0ac63299775c291f228a1b Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 18 Apr 2010 16:11:16 +1200 Subject: [PATCH] dont crash on missing maps/ dirs --- OpenRA.Game/Game.cs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 8330f9eedf..2ba6d8e029 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -105,26 +105,17 @@ namespace OpenRA public static Dictionary AvailableMaps; // TODO: Do this nicer - public static Dictionary FindMaps(string[] mods) + public static Dictionary FindMaps(string[] mods) { Console.WriteLine("Finding maps"); foreach (var mod in mods) Console.WriteLine(mod); - - - List paths = new List(); - foreach (var mod in mods) - paths.AddRange(Directory.GetDirectories("mods/"+mod+"/maps/")); - - paths.AddRange(Directory.GetDirectories("maps/")); - - Dictionary maps = new Dictionary(); - foreach (var path in paths) - { - MapStub stub = new MapStub(new Folder(path)); - maps.Add(stub.Uid,stub); - } - return maps; + + var paths = new[] { "maps/" }.Concat(mods.Select(m => "mods/" + m + "/maps/")) + .Where(p => Directory.Exists(p)) + .SelectMany(p => Directory.GetDirectories(p)).ToList(); + + return paths.Select(p => new MapStub(new Folder(p))).ToDictionary(m => m.Uid); } public static void ChangeMods()