Переписал загрузку на StreamReader
This commit is contained in:
parent
ca9860ba86
commit
b46a5f46b0
@ -116,30 +116,18 @@ namespace ProjectStormtrooper
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string bufferTextFromFile = "";
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
using (StreamReader sr = new StreamReader(filename))
|
||||
{
|
||||
byte[] b = new byte[fs.Length];
|
||||
UTF8Encoding temp = new(true);
|
||||
while (fs.Read(b, 0, b.Length) > 0)
|
||||
string? currentLine = sr.ReadLine();
|
||||
if (currentLine == null || !currentLine.Contains("PlaneStorage"))
|
||||
{
|
||||
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("PlaneStorage"))
|
||||
{
|
||||
// если нет такой записи, то это не те данные
|
||||
return false;
|
||||
}
|
||||
_planeStorages.Clear();
|
||||
foreach (string data in strs)
|
||||
currentLine = sr.ReadLine();
|
||||
while (currentLine != null)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] record = currentLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
@ -158,8 +146,11 @@ namespace ProjectStormtrooper
|
||||
}
|
||||
}
|
||||
_planeStorages.Add(record[0], collection);
|
||||
currentLine = sr.ReadLine();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user