Изменил(а) на 'ProjectPlane/ProjectPlane/MapsCollection.cs'

This commit is contained in:
devil_1nc 2022-11-08 17:27:10 +04:00
parent 88dcfeef92
commit b516a248df

View File

@ -84,20 +84,13 @@ namespace ProjectPlane
byte[] info = new UTF8Encoding(true).GetBytes(text);
stream.Write(info, 0, info.Length);
}
public bool SaveData(string filename)
public bool SaveDict(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (FileStream fs = new(filename, FileMode.Create))
{
WriteToFile($"MapsCollection{Environment.NewLine}", fs);
foreach (var storage in _mapStorages)
{
WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs);
}
}
return true;
}
@ -114,25 +107,19 @@ namespace ProjectPlane
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
string curLine = sr.ReadLine();
if (!curLine.Contains("MapsCollection"))
{
bufferTextFromFile += temp.GetString(b);
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (!strs[0].Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
return false;
}
//очищаем записи
_mapStorages.Clear();
for (int i = 1; i < strs.Length; ++i)
while ((curLine = sr.ReadLine()) != null)
{
var elem = strs[i].Split(separatorDict);
var elem = curLine.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
@ -150,3 +137,4 @@ namespace ProjectPlane
}
}
}
}