Изменил(а) на 'ProjectPlane/ProjectPlane/MapsCollection.cs'
This commit is contained in:
parent
88dcfeef92
commit
b516a248df
@ -84,20 +84,13 @@ namespace ProjectPlane
|
|||||||
byte[] info = new UTF8Encoding(true).GetBytes(text);
|
byte[] info = new UTF8Encoding(true).GetBytes(text);
|
||||||
stream.Write(info, 0, info.Length);
|
stream.Write(info, 0, info.Length);
|
||||||
}
|
}
|
||||||
public bool SaveData(string filename)
|
|
||||||
|
public bool SaveDict(string filename)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
File.Delete(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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,25 +107,19 @@ namespace ProjectPlane
|
|||||||
}
|
}
|
||||||
string bufferTextFromFile = "";
|
string bufferTextFromFile = "";
|
||||||
using (FileStream fs = new(filename, FileMode.Open))
|
using (FileStream fs = new(filename, FileMode.Open))
|
||||||
|
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
|
||||||
{
|
{
|
||||||
byte[] b = new byte[fs.Length];
|
string curLine = sr.ReadLine();
|
||||||
UTF8Encoding temp = new(true);
|
|
||||||
while (fs.Read(b, 0, b.Length) > 0)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
//очищаем записи
|
|
||||||
_mapStorages.Clear();
|
_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;
|
AbstractMap map = null;
|
||||||
switch (elem[1])
|
switch (elem[1])
|
||||||
{
|
{
|
||||||
@ -150,3 +137,4 @@ namespace ProjectPlane
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user