Буп бип
This commit is contained in:
parent
b9442a94dc
commit
8f5f82ad8b
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.DirectoryServices.ActiveDirectory;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -61,13 +62,13 @@ namespace WarmlyShip
|
|||||||
{
|
{
|
||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
using (FileStream fs = new(filename, FileMode.Create))
|
using (StreamWriter sw = new(filename))
|
||||||
{
|
{
|
||||||
WriteToFile($"MapsCollection{Environment.NewLine}", fs);
|
sw.Write($"MapsCollection{Environment.NewLine}");
|
||||||
foreach (var storage in _mapStorages)
|
foreach (var storage in _mapStorages)
|
||||||
{
|
{
|
||||||
|
|
||||||
WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs);
|
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -79,37 +80,45 @@ namespace WarmlyShip
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
string bufferTextFromFile = "";
|
using (StreamReader sr = new(filename))
|
||||||
using (FileStream fs = new(filename, FileMode.Open))
|
|
||||||
{
|
{
|
||||||
byte[] b = new byte[fs.Length];
|
string bufferStr;
|
||||||
UTF8Encoding temp = new(true);
|
bool firstIn = true;
|
||||||
while (fs.Read(b, 0, b.Length) > 0)
|
while ((bufferStr = sr.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
bufferTextFromFile += temp.GetString(b);
|
if (firstIn)
|
||||||
}
|
{
|
||||||
}
|
if (!bufferStr.Contains("MapsCollection"))
|
||||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (!strs[0].Contains("MapsCollection"))
|
|
||||||
{
|
{
|
||||||
//если нет такой записи, то это не те данные
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//очищаем записи
|
else
|
||||||
_mapStorages.Clear();
|
|
||||||
for (int i = 1; i < strs.Length; ++i)
|
|
||||||
{
|
{
|
||||||
var elem = strs[i].Split(separatorDict);
|
_mapStorages.Clear();
|
||||||
|
}
|
||||||
|
firstIn = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var elem = bufferStr.Split(separatorDict);
|
||||||
AbstractMap map = null;
|
AbstractMap map = null;
|
||||||
switch (elem[1])
|
switch (elem[1])
|
||||||
{
|
{
|
||||||
case "SimpleMap":
|
case "SimpleMap":
|
||||||
map = new SimpleMap();
|
map = new SimpleMap();
|
||||||
break;
|
break;
|
||||||
|
case "SecondMap":
|
||||||
|
map = new SecondMap();
|
||||||
|
break;
|
||||||
|
case "LastMap":
|
||||||
|
map = new LastMap();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
_mapStorages.Add(elem[0], new MapWithSetShipGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
_mapStorages.Add(elem[0], new MapWithSetShipGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user