diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index bd6e01b0ff..4cf460c0aa 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -16,6 +16,7 @@ using System.Linq; using System.Net; using System.Text; using System.Threading; +using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Primitives; @@ -45,7 +46,8 @@ namespace OpenRA { // Expand the dictionary (dir path, dir type) to a dictionary of (map path, dir type) var mapPaths = modData.Manifest.MapFolders.SelectMany(kv => - FindMapsIn(kv.Key).ToDictionary(p => p, p => string.IsNullOrEmpty(kv.Value) ? MapClassification.Unknown : Enum.Parse(kv.Value))); + FindMapsIn(modData.ModFiles, kv.Key).ToDictionary(p => p, p => string.IsNullOrEmpty(kv.Value) + ? MapClassification.Unknown : Enum.Parse(kv.Value))); foreach (var path in mapPaths) { @@ -111,7 +113,7 @@ namespace OpenRA new Download(url, _ => { }, onInfoComplete); } - public static IEnumerable FindMapsIn(string dir) + public static IEnumerable FindMapsIn(FileSystem.FileSystem context, string dir) { string[] noMaps = { }; @@ -119,9 +121,15 @@ namespace OpenRA if (dir.StartsWith("~")) dir = dir.Substring(1); - dir = Platform.ResolvePath(dir); - - if (!Directory.Exists(dir)) + // HACK: We currently only support maps loaded from Folders + // This is a temporary workaround that resolves the filesystem paths to a system directory + IReadOnlyPackage package; + string filename; + if (context.TryGetPackageContaining(dir, out package, out filename)) + dir = Path.Combine(package.Name, filename); + else if (Directory.Exists(Platform.ResolvePath(dir))) + dir = Platform.ResolvePath(dir); + else return noMaps; var dirsWithMaps = Directory.GetDirectories(dir) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 1b47f86aea..f9046f9592 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using OpenRA.FileSystem; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic @@ -29,6 +30,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public SaveMapLogic(Widget widget, Action onSave, Action onExit, Map map, List playerDefinitions, List actorDefinitions) { + var modData = Game.ModData; var title = widget.Get("TITLE"); title.Text = map.Title; @@ -59,14 +61,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic Func makeMapDirectory = dir => { - var f = Platform.UnresolvePath(dir); - if (f.StartsWith("~")) - f = f.Substring(1); + if (dir.StartsWith("~")) + dir = dir.Substring(1); - return f; + IReadOnlyPackage package; + string f; + if (modData.ModFiles.TryGetPackageContaining(dir, out package, out f)) + dir = Path.Combine(package.Name, f); + + return Platform.UnresolvePath(dir); }; - var mapDirectories = Game.ModData.Manifest.MapFolders + var mapDirectories = modData.Manifest.MapFolders .ToDictionary(kv => makeMapDirectory(kv.Key), kv => Enum.Parse(kv.Value)); var directoryDropdown = widget.Get("DIRECTORY_DROPDOWN"); @@ -147,7 +153,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (playerDefinitions != null) map.PlayerDefinitions = playerDefinitions; - map.RequiresMod = Game.ModData.Manifest.Mod.Id; + map.RequiresMod = modData.Manifest.Mod.Id; // Create the map directory if required Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text)); @@ -156,13 +162,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Invalidate the old map metadata if (map.Uid != null && combinedPath == map.Path) - Game.ModData.MapCache[map.Uid].Invalidate(); + modData.MapCache[map.Uid].Invalidate(); map.Save(combinedPath); // Update the map cache so it can be loaded without restarting the game var classification = mapDirectories[directoryDropdown.Text]; - Game.ModData.MapCache[map.Uid].UpdateFromMap(map, classification); + modData.MapCache[map.Uid].UpdateFromMap(map, classification); Console.WriteLine("Saved current map at {0}", combinedPath); Ui.CloseWindow();