Преобразован класс MapsCollection - добавлено выбрасывание исключений
This commit is contained in:
parent
eb4416e7ed
commit
c9001dec40
@ -49,7 +49,7 @@ namespace Artilleries
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SaveData(string filename)
|
public void SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -65,15 +65,13 @@ namespace Artilleries
|
|||||||
sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
|
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))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
throw new FileNotFoundException("Файл не найден");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (FileStream fs = new FileStream(filename, FileMode.Open))
|
using (FileStream fs = new FileStream(filename, FileMode.Open))
|
||||||
@ -83,7 +81,7 @@ namespace Artilleries
|
|||||||
|
|
||||||
if (current_line == null || !current_line.Contains("MapsCollection"))
|
if (current_line == null || !current_line.Contains("MapsCollection"))
|
||||||
{
|
{
|
||||||
return false;
|
throw new FileFormatException("Неверный формат файла");
|
||||||
}
|
}
|
||||||
|
|
||||||
_mapsStorage.Clear();
|
_mapsStorage.Clear();
|
||||||
@ -105,8 +103,6 @@ namespace Artilleries
|
|||||||
_mapsStorage.Add(elements[0], new MapWithSetArtilleriesGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
_mapsStorage.Add(elements[0], new MapWithSetArtilleriesGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
_mapsStorage[elements[0]].LoadData(elements[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
_mapsStorage[elements[0]].LoadData(elements[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user