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; } ///