Исправление LoadData

This commit is contained in:
Валерия Никифорова 2022-11-15 15:24:11 +04:00
parent 2902f0361e
commit ebd225334b

View File

@ -90,12 +90,12 @@ namespace AccordionBus
{
File.Delete(filename);
}
using (StreamWriter fs = new(filename))
using (StreamWriter sw = new(filename))
{
fs.Write($"MapsCollection{Environment.NewLine}");
sw.Write($"MapsCollection{Environment.NewLine}");
foreach (var storage in _mapStorages)
{
fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
}
}
return true;
@ -111,18 +111,23 @@ namespace AccordionBus
{
return false;
}
using (StreamReader fs = new(filename))
using (StreamReader sr = new(filename))
{
if (!fs.ReadLine().Contains("MapsCollection"))
string str = "";
if ((str = sr.ReadLine()) == null)
{
return false;
}
if (!str.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
return false;
}
//очищаем записи
_mapStorages.Clear();
while (!fs.EndOfStream)
while ((str = sr.ReadLine()) != null)
{
var elem = fs.ReadLine().Split(separatorDict);
var elem = str.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
@ -136,8 +141,8 @@ namespace AccordionBus
_mapStorages.Add(elem[0], new MapWithSetBusesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
return true;
}
return true;
}
}
}