From c0136e0a6330d374c292f1713d045cc68b73ee48 Mon Sep 17 00:00:00 2001 From: Anitonchik Date: Tue, 30 Apr 2024 10:40:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=966?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StorageCollection.cs | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs index 061aa07..b2802be 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs @@ -156,30 +156,21 @@ public class StorageCollection { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) - { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) - { - bufferTextFromFile += temp.GetString(b); - } - } - string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); - if (strs == null || strs.Length == 0) + using StreamReader rd = new StreamReader(filename); + + + UTF8Encoding temp = new(true); + string str = rd.ReadLine(); + if (str == null || !str.StartsWith(_collectionKey)) { return false; } - if (!strs[0].Equals(_collectionKey)) - { - //если нет такой записи, то это не те данные - return false; - } + _storages.Clear(); - foreach (string data in strs) + string strs = ""; + while ((strs = rd.ReadLine()) != null) { - string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); if (record.Length != 4) { continue;