FileSave
This commit is contained in:
parent
8079e18f75
commit
3fb85c16dd
@ -68,11 +68,13 @@ namespace Lab.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
byte[] info = new
|
||||
UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}");
|
||||
fs.Write(info, 0, info.Length);
|
||||
return true;
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.WriteLine("CarStorage");
|
||||
writer.Write(data.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool LoadData(string filename)
|
||||
@ -81,52 +83,41 @@ namespace Lab.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string bufferTextFromFile = "";
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
using (StreamReader reader = new StreamReader(filename))
|
||||
{
|
||||
byte[] b = new byte[fs.Length];
|
||||
UTF8Encoding temp = new(true);
|
||||
while (fs.Read(b, 0, b.Length) > 0)
|
||||
string checker = reader.ReadLine();
|
||||
if (checker == null)
|
||||
return false;
|
||||
string strs = reader.ReadLine();
|
||||
if (!checker.StartsWith("CarStorage"))
|
||||
return false;
|
||||
_carStorages.Clear();
|
||||
foreach (string data in strs.Split(';'))
|
||||
{
|
||||
bufferTextFromFile += temp.GetString(b);
|
||||
}
|
||||
}
|
||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!strs[0].StartsWith("CarStorage"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_carStorages.Clear();
|
||||
foreach (string data in strs)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CarsGenericCollection<DrawTanker, DrawingObjectTanker> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawTanker? car =
|
||||
elem?.CreateDrawTanker(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (car != null)
|
||||
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
if (!(collection + car))
|
||||
continue;
|
||||
}
|
||||
CarsGenericCollection<DrawTanker, DrawingObjectTanker> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawTanker? car =
|
||||
elem?.CreateDrawTanker(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (car != null)
|
||||
{
|
||||
return false;
|
||||
if (!(collection + car))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_carStorages.Add(record[0], collection);
|
||||
}
|
||||
_carStorages.Add(record[0], collection);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ namespace Lab
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{Tanker.Speed}{separatorForObject}{Tanker.Weight}{separatorForObject}{Tanker.BodyColor.Name}";
|
||||
var str = $"{Tanker.Speed}{separatorForObject}{Tanker.Weight}{separatorForObject}{Tanker.BodyColor}";
|
||||
if (Tanker is not GasolineTanker gasTanker)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForObject}{gasTanker.AdditionalColor.Name}{separatorForObject}{gasTanker.BodyKit}{separatorForObject}{gasTanker.Wing}{separatorForObject}{gasTanker.SportLine}";
|
||||
return $"{str}{separatorForObject}{gasTanker.AdditionalColor}{separatorForObject}{gasTanker.BodyKit}{separatorForObject}{gasTanker.Wing}{separatorForObject}{gasTanker.SportLine}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,12 +49,16 @@ namespace Lab.Generics
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return null;
|
||||
if (_places.Count <= position)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return;
|
||||
if (_places.Count <= position)
|
||||
return;
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user