Exemplo n.º 1
0
        public static MapUnits Parse(Stream stream, bool leaveOpen = false)
        {
            try
            {
                var data = new MapUnits();
                using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
                {
                    data._header = MapWidgetsHeader.Parse(stream, true);
                    var unitParser = data._header.UseTftParser
                        ? (Func <Stream, bool, MapUnitData>)MapUnitData.ParseTft
                        : MapUnitData.Parse;

                    for (var i = 0; i < data._header.DataCount; i++)
                    {
                        data._units.Add(unitParser(stream, true));
                    }
                }

                return(data);
            }
            catch (DecoderFallbackException e)
            {
                throw new InvalidDataException($"The '{FileName}' file contains invalid characters.", e);
            }
            catch (EndOfStreamException e)
            {
                throw new InvalidDataException($"The '{FileName}' file is missing data, or its data is invalid.", e);
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public static MapUnits Parse(Stream stream, bool leaveOpen = false)
        {
            var data = new MapUnits();

            using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
            {
                data._header = MapWidgetsHeader.Parse(stream, true);
                Func <Stream, bool, MapUnitData> unitParser = data._header.Version switch
                {
                    MapWidgetsVersion.RoC => MapUnitData.Parse,
                    MapWidgetsVersion.TFT => MapUnitData.ParseTft,
                    _ => throw new NotSupportedException(),
                };

                for (var i = 0; i < data._header.DataCount; i++)
                {
                    data._units.Add(unitParser(stream, true));
                }
            }

            return(data);
        }
Exemplo n.º 3
0
 public static void Serialize(MapUnits mapUnits, Stream stream, bool leaveOpen = false)
 {
     mapUnits.SerializeTo(stream, leaveOpen);
 }