Dolgov D.A. Lab Work 6 #6
@ -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,39 +107,34 @@ 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);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
var elem = strs[i].Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
|
||||
_mapStorages.Clear();
|
||||
while ((curLine = sr.ReadLine()) != null)
|
||||
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "SkyMap":
|
||||
map = new SkyMap();
|
||||
break;
|
||||
var elem = curLine.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "SkyMap":
|
||||
map = new SkyMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetPlanesGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetPlanesGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
не используется