From ca9860ba86389275489084c53bfb4a5e8a2c7609 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 20 Nov 2023 18:36:37 +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=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BD=D0=B0=20StreamWriter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlanesGenericStorage.cs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs index 5112af7..8f687d2 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs @@ -89,23 +89,20 @@ namespace ProjectStormtrooper { File.Delete(filename); } - StringBuilder data = new(); - foreach (KeyValuePair> record in _planeStorages) + using (StreamWriter sw = File.CreateText(filename)) { - StringBuilder records = new(); - foreach (DrawingPlane? elem in record.Value.GetPlanes) + sw.WriteLine($"PlaneStorage"); + string storageString; + foreach (var storage in _planeStorages) { - records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); + storageString = ""; + foreach (var plane in storage.Value.GetPlanes) + { + storageString += $"{plane?.GetDataForSave(_separatorForObject)}{_separatorRecords}"; + } + sw.WriteLine($"{storage.Key}{_separatorForKeyValue}{storageString}"); } - data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); } - if (data.Length == 0) - { - return false; - } - using FileStream fs = new(filename, FileMode.Create); - byte[] info = new UTF8Encoding(true).GetBytes($"PlaneStorage{Environment.NewLine}{data}"); - fs.Write(info, 0, info.Length); return true; } ///