Пример #1
0
        static Map LoadFCM(World _world, string fileName)
        {
            FileStream fs  = null;
            Map        map = new Map(_world);

            try {
                fs = File.OpenRead(fileName);
                if (map.ReadHeader(fs))
                {
                    map.ReadMetadata(fs);
                    map.ReadBlocks(fs);
                    if (!map.ValidateBlockTypes())
                    {
                        throw new Exception("Invalid block types detected. File is possibly corrupt.");
                    }
                    _world.log.Log("Loaded map succesfully from {0}", LogType.SystemActivity, fileName);
                    return(map);
                }
                else
                {
                    return(null);
                }
            } catch (EndOfStreamException) {
                _world.log.Log("Map.Load: Unexpected end of file - possible corruption!", LogType.Error);
                return(null);
            } catch (Exception ex) {
                _world.log.Log("Map.Load: Error trying to read from \"{0}\": {1}", LogType.Error, fileName, ex.Message);
                return(null);
            } finally {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }