Теперь со streamwriter, streamreader, блэкджеком и прочим
This commit is contained in:
parent
4d63b3f06e
commit
ac523a95a4
@ -37,11 +37,11 @@ namespace Monorail.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach(KeyValuePair<string,
|
||||
foreach (KeyValuePair<string,
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> record in _monorailStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach(DrawningMonorail? elem in record.Value.GetMonorails)
|
||||
foreach (DrawningMonorail? elem in record.Value.GetMonorails)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
@ -52,10 +52,17 @@ MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> record in _
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
byte[] info = new
|
||||
UTF8Encoding(true).GetBytes($"MonorailStorage{Environment.NewLine}{data}");
|
||||
fs.Write(info, 0, info.Length);
|
||||
string toWrite = $"MonorailStorage{Environment.NewLine}{data}";
|
||||
var strs = toWrite.Split(new char[] { '\n', '\r' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
using (StreamWriter sw = new(filename))
|
||||
{
|
||||
foreach (var str in strs)
|
||||
{
|
||||
sw.WriteLine(str);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -65,19 +72,10 @@ MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> record in _
|
||||
{
|
||||
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' },
|
||||
string str = sr.ReadLine();
|
||||
var strs = str.Split(new char[] { '\n', '\r' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
@ -88,16 +86,17 @@ StringSplitOptions.RemoveEmptyEntries);
|
||||
return false;
|
||||
}
|
||||
_monorailStorages.Clear();
|
||||
foreach (string data in strs)
|
||||
do
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] record = str.Split(_separatorForKeyValue,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
str = sr.ReadLine();
|
||||
continue;
|
||||
}
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>
|
||||
collection = new(_pictureWidth, _pictureHeight);
|
||||
collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
@ -113,13 +112,19 @@ collection = new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
}
|
||||
_monorailStorages.Add(record[0], collection);
|
||||
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_monorailStorages.Add(name, new MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> (_pictureWidth, _pictureHeight));
|
||||
_monorailStorages.Add(name, new MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
public void DelSet(string name)
|
||||
|
Loading…
Reference in New Issue
Block a user