Merge pull request #2823 from ihptru/auto-map-dl

Auto map downloading
This commit is contained in:
Matthias Mailänder
2013-04-01 09:11:25 -07:00
5 changed files with 45 additions and 3 deletions

View File

@@ -458,5 +458,29 @@ namespace OpenRA
Game.JoinServer(host, port);
}
public static bool DownloadMap(string mapHash)
{
try
{
var mod = Game.CurrentMods.FirstOrDefault().Value.Id;
var dirPath = "{1}maps{0}{2}".F(Path.DirectorySeparatorChar, Platform.SupportDir, mod);
if(!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
var mapPath = "{1}{0}{2}".F(Path.DirectorySeparatorChar, dirPath, mapHash+".oramap");
Console.Write("Trying to download map to {0} ... ".F(mapPath));
WebClient webClient = new WebClient();
webClient.DownloadFile(Game.Settings.Game.MapRepository + mapHash, mapPath);
Game.modData.AvailableMaps.Add(mapHash, new Map(mapPath));
Console.WriteLine("done");
return true;
}
catch (WebException e)
{
Log.Write("debug", "Could not download map '{0}'", mapHash);
Log.Write("debug", e.ToString());
return false;
}
}
}
}