Rework IReadWritePackage interface.
This commit is contained in:
@@ -14,6 +14,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.FileFormats;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
@@ -95,7 +96,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Map.FixOpenAreas(Rules);
|
||||
|
||||
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||
var package = modData.ModFiles.CreatePackage(dest);
|
||||
var package = new ZipFile(modData.ModFiles, dest, true);
|
||||
Map.Save(package);
|
||||
Console.WriteLine(dest + " saved.");
|
||||
}
|
||||
|
||||
@@ -785,17 +785,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
yaml.Nodes.First(n => n.Key == "MapFormat").Value = new MiniYaml(Map.SupportedMapFormat.ToString());
|
||||
|
||||
var entries = new Dictionary<string, byte[]>();
|
||||
entries.Add("map.yaml", Encoding.UTF8.GetBytes(yaml.Nodes.WriteToString()));
|
||||
foreach (var file in package.Contents)
|
||||
{
|
||||
if (file == "map.yaml")
|
||||
continue;
|
||||
|
||||
entries.Add(file, package.GetStream(file).ReadAllBytes());
|
||||
}
|
||||
|
||||
package.Write(entries);
|
||||
package.Update("map.yaml", Encoding.UTF8.GetBytes(yaml.Nodes.WriteToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,8 +169,32 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (map.Uid != null && combinedPath == mapPath)
|
||||
modData.MapCache[map.Uid].Invalidate();
|
||||
|
||||
var package = modData.ModFiles.CreatePackage(combinedPath);
|
||||
map.Save(package);
|
||||
var package = map.Package as IReadWritePackage;
|
||||
if (package == null || package.Name != combinedPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (fileType == MapFileType.OraMap)
|
||||
{
|
||||
if (File.Exists(combinedPath))
|
||||
File.Delete(combinedPath);
|
||||
|
||||
package = new ZipFile(modData.DefaultFileSystem, combinedPath, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Directory.Exists(combinedPath))
|
||||
Directory.Delete(combinedPath, true);
|
||||
package = new Folder(combinedPath);
|
||||
}
|
||||
|
||||
map.Save(package);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Failed to save map at {0}", combinedPath);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the map cache so it can be loaded without restarting the game
|
||||
var classification = mapDirectories[directoryDropdown.Text];
|
||||
|
||||
Reference in New Issue
Block a user