// Makes sure that the map file exists, is properly named, and is loadable.
static void CheckMapFile([NotNull] string worldName)
{
if (worldName == null)
{
throw new ArgumentNullException("worldName");
}
// Check the world's map file
string fullMapFileName = Path.Combine(Paths.MapPath, worldName + ".fcm");
string fileName = Path.GetFileName(fullMapFileName);
if (Paths.FileExists(fullMapFileName, false))
{
if (!Paths.FileExists(fullMapFileName, true))
{
// Map file has wrong capitalization
FileInfo[] matches = Paths.FindFiles(fullMapFileName);
if (matches.Length == 1)
{
// Try to rename the map file to match world's capitalization
Paths.ForceRename(matches[0].FullName, fileName);
if (Paths.FileExists(fullMapFileName, true))
{
Logger.Log(LogType.Warning,
"WorldManager.CheckMapFile: Map file for world \"{0}\" was renamed from \"{1}\" to \"{2}\"",
worldName, matches[0].Name, fileName);
}
else
{
Logger.Log(LogType.Error,
"WorldManager.CheckMapFile: Failed to rename map file of \"{0}\" from \"{1}\" to \"{2}\"",
worldName, matches[0].Name, fileName);
return;
}
}
else
{
Logger.Log(LogType.Warning,
"WorldManager.CheckMapFile: More than one map file exists matching the world name \"{0}\". " +
"Please check the map directory and use /WLoad to load the correct file.",
worldName);
return;
}
}
// Try loading the map header
try {
MapUtility.LoadHeader(fullMapFileName);
} catch (Exception ex) {
Logger.Log(LogType.Warning,
"WorldManager.CheckMapFile: Could not load map file for world \"{0}\": {1}",
worldName, ex);
}
}
else
{
Logger.Log(LogType.Warning,
"WorldManager.CheckMapFile: Map file for world \"{0}\" was not found.",
worldName);
}
}