Переписал загрузку на StreamReader

This commit is contained in:
Никита Потапов 2023-11-20 18:45:39 +04:00
parent ca9860ba86
commit b46a5f46b0

View File

@ -116,50 +116,41 @@ namespace ProjectStormtrooper
{ {
return false; return false;
} }
string bufferTextFromFile = ""; using (StreamReader sr = new StreamReader(filename))
using (FileStream fs = new(filename, FileMode.Open))
{ {
byte[] b = new byte[fs.Length]; string? currentLine = sr.ReadLine();
UTF8Encoding temp = new(true); if (currentLine == null || !currentLine.Contains("PlaneStorage"))
while (fs.Read(b, 0, b.Length) > 0)
{ {
bufferTextFromFile += temp.GetString(b); return false;
} }
} _planeStorages.Clear();
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); currentLine = sr.ReadLine();
if (strs == null || strs.Length == 0) while (currentLine != null)
{
return false;
}
if (!strs[0].StartsWith("PlaneStorage"))
{
// если нет такой записи, то это не те данные
return false;
}
_planeStorages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{ {
continue; string[] record = currentLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
} if (record.Length != 2)
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawingPlane? plane = elem?.CreateDrawingPlane(_separatorForObject, _pictureWidth, _pictureHeight);
if (plane != null)
{ {
if (collection + plane == -1) continue;
}
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawingPlane? plane = elem?.CreateDrawingPlane(_separatorForObject, _pictureWidth, _pictureHeight);
if (plane != null)
{ {
return false; if (collection + plane == -1)
{
return false;
}
} }
} }
_planeStorages.Add(record[0], collection);
currentLine = sr.ReadLine();
} }
_planeStorages.Add(record[0], collection); return true;
} }
return true;
} }
} }
} }