Преобразован класс MapsCollection - добавлено выбрасывание исключений

This commit is contained in:
Сергей Полевой 2022-11-08 00:45:22 +04:00
parent eb4416e7ed
commit c9001dec40

View File

@ -49,7 +49,7 @@ namespace Artilleries
}
}
public bool SaveData(string filename)
public void SaveData(string filename)
{
if (File.Exists(filename))
{
@ -65,15 +65,13 @@ namespace Artilleries
sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
}
}
return true;
}
public bool LoadData(string filename)
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
throw new FileNotFoundException("Файл не найден");
}
using (FileStream fs = new FileStream(filename, FileMode.Open))
@ -83,7 +81,7 @@ namespace Artilleries
if (current_line == null || !current_line.Contains("MapsCollection"))
{
return false;
throw new FileFormatException("Неверный формат файла");
}
_mapsStorage.Clear();
@ -105,8 +103,6 @@ namespace Artilleries
_mapsStorage.Add(elements[0], new MapWithSetArtilleriesGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapsStorage[elements[0]].LoadData(elements[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
return true;
}
}
}