map api: use new site and fallbacks

This commit is contained in:
Igor Popov
2014-02-25 01:52:47 +04:00
parent 10e8a44151
commit ec50906296
2 changed files with 29 additions and 23 deletions

View File

@@ -515,34 +515,40 @@ namespace OpenRA
var mod = Game.modData.Manifest.Mod; var mod = Game.modData.Manifest.Mod;
var dirPath = new[] { Platform.SupportDir, "maps", mod.Id }.Aggregate(Path.Combine); var dirPath = new[] { Platform.SupportDir, "maps", mod.Id }.Aggregate(Path.Combine);
var tempFile = Path.Combine(dirPath, Path.GetRandomFileName()); var tempFile = Path.Combine(dirPath, Path.GetRandomFileName());
try
{
if (!Directory.Exists(dirPath)) if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath); Directory.CreateDirectory(dirPath);
var url = Game.Settings.Game.MapRepository + mapHash; foreach (var MapRepository in Game.Settings.Game.MapRepositories)
{
try
{
var url = MapRepository + mapHash;
var request = WebRequest.Create(url); var request = WebRequest.Create(url);
request.Method = "HEAD"; request.Method = "HEAD";
var res = request.GetResponse(); var res = request.GetResponse();
var mapPath = Path.Combine(dirPath, res.Headers["Content-Disposition"].Replace("attachment; filename = ", "")); if (res.Headers["Content-Disposition"] == null)
Console.Write("Trying to download map to {0} ... ".F(mapPath)); continue;
var mapPath = Path.Combine(dirPath, res.Headers ["Content-Disposition"].Replace("attachment; filename = ", ""));
Log.Write("debug", "Trying to download map to '{0}' using {1}", mapPath, MapRepository);
WebClient webClient = new WebClient(); WebClient webClient = new WebClient();
webClient.DownloadFile(url, tempFile); webClient.DownloadFile(url, tempFile);
File.Move(tempFile, mapPath); File.Move(tempFile, mapPath);
Game.modData.AvailableMaps.Add(mapHash, new Map(mapPath)); Game.modData.AvailableMaps.Add(mapHash, new Map(mapPath));
Console.WriteLine("done"); Log.Write("debug", "New map has been downloaded to '{0}'", mapPath);
return true; return true;
} }
catch (WebException e) catch (WebException e)
{ {
Log.Write("debug", "Could not download map '{0}'", mapHash); Log.Write("debug", "Could not download map '{0}' using {1}", mapHash, MapRepository);
Log.Write("debug", e.ToString()); Log.Write("debug", e.ToString());
File.Delete(tempFile); File.Delete(tempFile);
continue;
}
}
return false; return false;
} }
} }
}
} }

View File

@@ -139,7 +139,7 @@ namespace OpenRA.GameRules
public int Timestep = 40; public int Timestep = 40;
public bool AllowDownloading = true; public bool AllowDownloading = true;
public string MapRepository = "http://content.open-ra.org/map/"; public string[] MapRepositories = { "http://resource.openra.net/map/", "http://resource.ihptru.net:8080/map/" };
} }
public class KeySettings public class KeySettings