lab_6(storage)

This commit is contained in:
chtzsch ~ 2023-11-28 22:34:30 +03:00
parent e9d5335db9
commit 51f2664d20

View File

@ -80,10 +80,11 @@ namespace speed_Boat.Generics
{
return false;
}
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new
UTF8Encoding(true).GetBytes($"BoatStorage{Environment.NewLine}{data}");
fs.Write(info, 0, info.Length);
using (StreamWriter sw = new (filename))
{
sw.WriteLine($"BoatStorage{Environment.NewLine}{data}");
}
return true;
}
/// <summary>
@ -98,17 +99,10 @@ namespace speed_Boat.Generics
return false;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
using (StreamReader sr = new(filename))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
{
bufferTextFromFile += temp.GetString(b);
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
string str = sr.ReadLine();
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
@ -119,12 +113,13 @@ namespace speed_Boat.Generics
return false;
}
_boatStorages.Clear();
foreach (string data in strs)
do
{
string[] record = data.Split(_separatorForKeyValue,
string[] record = str.Split(_separatorForKeyValue,
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
str = sr.ReadLine();
continue;
}
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>
@ -142,6 +137,8 @@ namespace speed_Boat.Generics
}
}
_boatStorages.Add(record[0], collection);
str = sr.ReadLine();
} while (str != null);
}
return true;
}