public void LoadMap(string map, IReadOnlyPackage package, MapClassification classification, MapGrid mapGrid, string oldMap) { IReadOnlyPackage mapPackage = null; try { using (new Support.PerfTimer(map)) { mapPackage = package.OpenPackage(map, modData.ModFiles); if (mapPackage != null) { var uid = Map.ComputeUID(mapPackage); previews[uid].UpdateFromMap(mapPackage, package, classification, modData.Manifest.MapCompatibility, mapGrid.Type); if (oldMap != uid) { MapUpdated(oldMap, uid); } } } } catch (Exception e) { 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); } }
public void LoadMaps() { // Utility mod that does not support maps if (!modData.Manifest.Contains <MapGrid>()) { return; } 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 = modData.ModFiles.OpenPackage(map, kv.Key); 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); } } } }
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); } } } }