Подправил 6 лабу
This commit is contained in:
parent
37a802cde6
commit
923224c02e
@ -127,46 +127,52 @@ where T : DrawningGun
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool LoadData(string filename)
|
public bool LoadData(string filename)
|
||||||
{
|
{
|
||||||
if(!File.Exists(filename)) return false;
|
if (!File.Exists(filename))
|
||||||
|
|
||||||
string bufferTextFromFile = "";
|
|
||||||
using(FileStream fs = new(filename, FileMode.Open))
|
|
||||||
{
|
{
|
||||||
byte[] b=new byte[fs.Length];
|
|
||||||
UTF8Encoding temp = new(true);
|
|
||||||
while (fs.Read(b, 0, b.Length) > 0) bufferTextFromFile += temp.GetString(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
|
|
||||||
if(strs ==null || strs.Length == 0) return false;
|
|
||||||
if (!strs[0].Equals(_collectionKey))
|
|
||||||
// Если нет такой записи, то это не те данные
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_storages.Clear();
|
|
||||||
foreach (string data in strs)
|
|
||||||
{
|
|
||||||
string[] record=data.Split(_separatorForKeyValue,StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (record.Length != 4) continue;
|
|
||||||
|
|
||||||
CollectionType collectionType=(CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
|
||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
|
||||||
if(collection == null) return false;
|
|
||||||
|
|
||||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
|
||||||
|
|
||||||
string[] set = record[3].Split(_separatorItems,StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
foreach (string elem in set)
|
|
||||||
{
|
|
||||||
if(elem?.CreateDrawningCar() is T gun)
|
|
||||||
{
|
|
||||||
if(!collection.Insert(gun)) return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_storages.Add(record[0], collection);
|
|
||||||
}
|
}
|
||||||
return true;
|
using (StreamReader reader = File.OpenText(filename))
|
||||||
|
{
|
||||||
|
string str = reader.ReadLine();
|
||||||
|
if (str == null || str.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!str.StartsWith(_collectionKey))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_storages.Clear();
|
||||||
|
string strs = "";
|
||||||
|
while ((strs = reader.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 4)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||||
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||||
|
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
if (elem?.CreateDrawningCun() is T gun)
|
||||||
|
{
|
||||||
|
if (!collection.Insert(gun))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_storages.Add(record[0], collection);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ public static class ExtentionDrawningGun
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="info">Строка с данными для создания объекта</param>
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
/// <returns>Объект</returns>
|
/// <returns>Объект</returns>
|
||||||
public static DrawningGun? CreateDrawningCar(this string info)
|
public static DrawningGun? CreateDrawningCun(this string info)
|
||||||
{
|
{
|
||||||
string[] strs = info.Split(_separatorForObject);
|
string[] strs = info.Split(_separatorForObject);
|
||||||
EntityGun? gun = EntityAntiAircraftGun.CreateEntityAntiaircraftGun(strs);
|
EntityGun? gun = EntityAntiAircraftGun.CreateEntityAntiaircraftGun(strs);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace AntiAircraftGun.Entities;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.Entities;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущности "Орудие"
|
/// Класс-сущности "Орудие"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user