From b46a5f46b0d44350ecc7f4c453e8c1a357e784be Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 20 Nov 2023 18:45:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BD=D0=B0=20StreamReader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlanesGenericStorage.cs | 59 ++++++++----------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs index 8f687d2..5e87d18 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs @@ -116,50 +116,41 @@ namespace ProjectStormtrooper { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader sr = new StreamReader(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + string? currentLine = sr.ReadLine(); + if (currentLine == null || !currentLine.Contains("PlaneStorage")) { - bufferTextFromFile += temp.GetString(b); + return false; } - } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); - if (strs == null || strs.Length == 0) - { - 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) + _planeStorages.Clear(); + currentLine = sr.ReadLine(); + while (currentLine != null) { - continue; - } - PlanesGenericCollection 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) + string[] record = currentLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) { - if (collection + plane == -1) + continue; + } + PlanesGenericCollection 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; + } } }