FileSave
This commit is contained in:
parent
8079e18f75
commit
3fb85c16dd
@ -68,40 +68,31 @@ namespace Lab.Generics
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
using FileStream fs = new(filename, FileMode.Create);
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
byte[] info = new
|
{
|
||||||
UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}");
|
writer.WriteLine("CarStorage");
|
||||||
fs.Write(info, 0, info.Length);
|
writer.Write(data.ToString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public bool LoadData(string filename)
|
public bool LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
string bufferTextFromFile = "";
|
using (StreamReader reader = new StreamReader(filename))
|
||||||
using (FileStream fs = new(filename, FileMode.Open))
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
if (strs == null || strs.Length == 0)
|
|
||||||
{
|
{
|
||||||
|
string checker = reader.ReadLine();
|
||||||
|
if (checker == null)
|
||||||
return false;
|
return false;
|
||||||
}
|
string strs = reader.ReadLine();
|
||||||
if (!strs[0].StartsWith("CarStorage"))
|
if (!checker.StartsWith("CarStorage"))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
_carStorages.Clear();
|
_carStorages.Clear();
|
||||||
foreach (string data in strs)
|
foreach (string data in strs.Split(';'))
|
||||||
{
|
{
|
||||||
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (record.Length != 2)
|
if (record.Length != 2)
|
||||||
@ -126,7 +117,7 @@ namespace Lab.Generics
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,12 @@ namespace Lab
|
|||||||
{
|
{
|
||||||
return string.Empty;
|
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)
|
if (Tanker is not GasolineTanker gasTanker)
|
||||||
{
|
{
|
||||||
return str;
|
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)
|
if (position < 0 || position > _maxCount)
|
||||||
return null;
|
return null;
|
||||||
|
if (_places.Count <= position)
|
||||||
|
return null;
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (position < 0 || position > _maxCount)
|
if (position < 0 || position > _maxCount)
|
||||||
return;
|
return;
|
||||||
|
if (_places.Count <= position)
|
||||||
|
return;
|
||||||
_places[position] = value;
|
_places[position] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user