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