private static void CheckMapFile( [NotNull] World world )
{
if ( world == null )
throw new ArgumentNullException( "world" );
// Check the world's map file
string fullMapFileName = world.MapFileName;
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
// ReSharper disable AssignNullToNotNullAttribute
Paths.ForceRename( matches[0].FullName, fileName );
// ReSharper restore AssignNullToNotNullAttribute
if ( Paths.FileExists( fullMapFileName, true ) ) {
Logger.Log( LogType.Warning,
"WorldManager.CheckMapFile: Map file for world \"{0}\" was renamed from \"{1}\" to \"{2}\"",
world.Name, matches[0].Name, fileName );
} else {
Logger.Log( LogType.Error,
"WorldManager.CheckMapFile: Failed to rename map file of \"{0}\" from \"{1}\" to \"{2}\"",
world.Name, 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.",
world.Name );
return;
}
}
// Try loading the map header
try {
MapUtility.LoadHeader( world.MapFileName );
} catch ( Exception ex ) {
Logger.Log( LogType.Warning,
"WorldManager.CheckMapFile: Could not load map file for world \"{0}\": {1}",
world.Name, ex );
}
} else {
Logger.Log( LogType.Warning,
"WorldManager.CheckMapFile: Map file for world \"{0}\" was not found.",
world.Name );
}
}