public IEnumerable <Map> EnumerateMapsWithoutCaching(MapClassification classification = MapClassification.System) { // Utility mod that does not support maps if (!modData.Manifest.Contains <MapGrid>()) { yield break; } // Enumerate map directories foreach (var kv in modData.Manifest.MapFolders) { MapClassification packageClassification; if (!Enum.TryParse(kv.Value, out packageClassification)) { continue; } if (!classification.HasFlag(packageClassification)) { continue; } var name = kv.Key; var optional = name.StartsWith("~", StringComparison.Ordinal); if (optional) { name = name.Substring(1); } // Don't try to open the map directory in the support directory if it doesn't exist if (Platform.IsPathRelativeToSupportDirectory(name)) { var resolved = Platform.ResolvePath(name); if (!Directory.Exists(resolved) || !File.Exists(resolved)) { continue; } } using (var package = (IReadWritePackage)modData.ModFiles.OpenPackage(name)) { foreach (var map in package.Contents) { var mapPackage = package.OpenPackage(map, modData.ModFiles); if (mapPackage != null) { yield return(new Map(modData, mapPackage)); } } } } }
public void LoadMaps() { // Utility mod that does not support maps if (!modData.Manifest.Contains <MapGrid>()) { return; } // Enumerate map directories foreach (var kv in modData.Manifest.MapFolders) { var name = kv.Key; var classification = string.IsNullOrEmpty(kv.Value) ? MapClassification.Unknown : Enum <MapClassification> .Parse(kv.Value); IReadOnlyPackage package; var optional = name.StartsWith("~", StringComparison.Ordinal); if (optional) { name = name.Substring(1); } try { // HACK: If the path is inside the the support directory then we may need to create it if (Platform.IsPathRelativeToSupportDirectory(name)) { // Assume that the path is a directory if there is not an existing file with the same name var resolved = Platform.ResolvePath(name); if (!File.Exists(resolved)) { Directory.CreateDirectory(resolved); } } package = modData.ModFiles.OpenPackage(name); } catch { if (optional) { continue; } throw; } mapLocations.Add(package, classification); } var mapGrid = modData.Manifest.Get <MapGrid>(); foreach (var kv in MapLocations) { foreach (var map in kv.Key.Contents) { IReadOnlyPackage mapPackage = null; try { using (new Support.PerfTimer(map)) { mapPackage = kv.Key.OpenPackage(map, modData.ModFiles); if (mapPackage == null) { continue; } var uid = Map.ComputeUID(mapPackage); previews[uid].UpdateFromMap(mapPackage, kv.Key, kv.Value, modData.Manifest.MapCompatibility, mapGrid.Type); } } catch (Exception e) { if (mapPackage != null) { mapPackage.Dispose(); } Console.WriteLine("Failed to load map: {0}", map); Console.WriteLine("Details: {0}", e); Log.Write("debug", "Failed to load map: {0}", map); Log.Write("debug", "Details: {0}", e); } } } }