lab_6 #6

Closed
chtzsch wants to merge 4 commits from lab_6 into lab_5
Showing only changes of commit 51f2664d20 - Show all commits

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,50 +99,46 @@ 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)
string str = sr.ReadLine();
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
bufferTextFromFile += temp.GetString(b);
return false;
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].StartsWith("BoatStorage"))
{
//если нет такой записи, то это не те данные
return false;
}
_boatStorages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue,
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
if (!strs[0].StartsWith("BoatStorage"))
{
continue;
//если нет такой записи, то это не те данные
return false;
}
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>
collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
_boatStorages.Clear();
do
{
DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
if (boat != null)
string[] record = str.Split(_separatorForKeyValue,
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
if (!(collection + boat))
str = sr.ReadLine();
continue;
}
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>
collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
if (boat != null)
{
return false;
if (!(collection + boat))
{
return false;
}
}
}
}
_boatStorages.Add(record[0], collection);
_boatStorages.Add(record[0], collection);
str = sr.ReadLine();
} while (str != null);
}
return true;
}