From 602107fced40376b683240a81fe1cc52cc6a2b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 22 Nov 2023 09:46:13 +0400 Subject: [PATCH] teper' done --- Hydroplane/PlanesGenericStorage.cs | 68 +++++++++++++++--------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/Hydroplane/PlanesGenericStorage.cs b/Hydroplane/PlanesGenericStorage.cs index 7fca678..f0e0bcd 100644 --- a/Hydroplane/PlanesGenericStorage.cs +++ b/Hydroplane/PlanesGenericStorage.cs @@ -2,6 +2,7 @@ using Hydroplane.MovementStrategy; using System; using System.Collections.Generic; +using System.DirectoryServices.ActiveDirectory; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -79,50 +80,51 @@ namespace Hydroplane.Generics { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + + using (StreamReader fs = File.OpenText(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + string str = fs.ReadLine(); + if (str == null || str.Length == 0) { - bufferTextFromFile += temp.GetString(b); + return false; } - } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, - StringSplitOptions.RemoveEmptyEntries); - if (strs.Length == 0 || strs == 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) + if (!str.StartsWith("PlaneStorage")) { - continue; + return false; } - PlanesGenericCollection collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) + + _planeStorages.Clear(); + string strs = ""; + + while ((strs = fs.ReadLine()) != null) { - DrawningPlane? plane = elem.CreateDrawningPlane(_separatorForObject, _pictureWidth, _pictureHeight); - if (plane != null) + if (strs == null) { - if (!(collection + plane)) + return false; + } + + string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) + { + continue; + } + PlanesGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawningPlane? plane = elem?.CreateDrawningPlane(_separatorForObject, _pictureWidth, _pictureHeight); + if (plane != null) { - return false; + if (!(collection + plane)) + { + return false; + } } } + _planeStorages.Add(record[0], collection); } - _planeStorages.Add(record[0], collection); + return true; } - return true; - } + } } } \ No newline at end of file