Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0105985c98 | ||
|
|
86430cf93c |
@@ -100,13 +100,12 @@ namespace ProjectMachine
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (FileStream fs = new(filename, FileMode.Create))
|
||||
using (StreamWriter f = new(filename))
|
||||
{
|
||||
WriteToFile($"MapsCollection{Environment.NewLine}", fs);
|
||||
f.Write($"MapsCollection{Environment.NewLine}");
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
|
||||
WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict,separatorData)}{Environment.NewLine}", fs);
|
||||
f.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -122,41 +121,31 @@ namespace ProjectMachine
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string bufferTextFromFile = "";
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
using (StreamReader f = new(filename))
|
||||
{
|
||||
byte[] b = new byte[fs.Length];
|
||||
UTF8Encoding temp = new(true);
|
||||
while (fs.Read(b, 0, b.Length) > 0)
|
||||
if (!f.ReadLine().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 (!f.EndOfStream)
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "TownMap":
|
||||
map = new TownMap();
|
||||
break;
|
||||
var elem = f.ReadLine().Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "TownMap":
|
||||
map = new TownMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetTankGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
_mapStorages.Add(elem[0], new
|
||||
MapWithSetTankGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData,StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user