diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index ea17fed72d..8507769745 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -344,6 +344,13 @@ namespace OpenRA using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); + if (ModData.Manifest.Contains()) + { + var reload = ModData.Manifest.Get().Run(); + if (reload) + InitializeMod(mod, args); + } + var content = ModData.Manifest.Get(); var isModContentInstalled = content.Packages .Where(p => p.Value.Required) diff --git a/OpenRA.Game/Migrations.cs b/OpenRA.Game/Migrations.cs new file mode 100644 index 0000000000..bf48fa96d5 --- /dev/null +++ b/OpenRA.Game/Migrations.cs @@ -0,0 +1,65 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace OpenRA +{ + public class Migrations : IGlobalModData + { + [FieldLoader.Ignore] + readonly List rules; + + public Migrations(MiniYaml yaml) + { + rules = yaml.Nodes; + } + + public bool Run() + { + var appliedRule = false; + foreach (var rule in rules) + { + var path = Platform.ResolvePath(rule.Value.Value); + if (!File.Exists(path)) + continue; + + var lengthNode = rule.Value.Nodes.FirstOrDefault(n => n.Key == "Length"); + if (lengthNode != null) + { + var matchLength = FieldLoader.GetValue("Length", lengthNode.Value.Value); + var actualLength = new FileInfo(path).Length; + if (matchLength != actualLength) + continue; + } + + switch (rule.Key) + { + case "delete": + Log.Write("debug", "Migration: Deleting file {0}", path); + Console.WriteLine("Migration: Deleting file {0}", path); + + File.Delete(path); + appliedRule = true; + break; + default: + Log.Write("debug", "Unknown migration command {0} - ignoring", rule.Value.Value); + break; + } + } + + return appliedRule; + } + } +} diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 534f05ec3d..27a5fe5ffe 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -248,6 +248,7 @@ +