Финал 6
This commit is contained in:
parent
8f8a8ffd62
commit
bdf4b0cea9
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SelfPropelledArtilleryUnit
|
||||
{
|
||||
internal class Extention
|
||||
{
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningSPAU? CreateDrawningCar(this string info, char separatorForObject, int width, int height)
|
||||
public static DrawningSPAU? CreateDrawningSPAU(this string info, char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
|
@ -251,6 +251,5 @@ namespace SelfPropelledArtilleryUnit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
panelPurple.BackColor = Color.FromArgb(192, 0, 192);
|
||||
panelPurple.BackColor = Color.Magenta;
|
||||
panelPurple.Location = new Point(91, 123);
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new Size(60, 25);
|
||||
|
@ -98,7 +98,8 @@ namespace SelfPropelledArtilleryUnit.Generics
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public bool SaveData(string filename){
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
@ -107,7 +108,7 @@ namespace SelfPropelledArtilleryUnit.Generics
|
||||
foreach (KeyValuePair<string, SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU>> record in _SPAUStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningSPAU? elem in record.Value.GetCars)
|
||||
foreach (DrawningSPAU? elem in record.Value.GetCars.Reverse())
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
@ -117,10 +118,11 @@ namespace SelfPropelledArtilleryUnit.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
byte[] info = new
|
||||
UTF8Encoding(true).GetBytes($"SPAUStorage{Environment.NewLine}{data}");
|
||||
fs.Write(info, 0, info.Length);
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.WriteLine("SPAUStorage");
|
||||
writer.Write(data.ToString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -134,52 +136,51 @@ namespace SelfPropelledArtilleryUnit.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string bufferTextFromFile = "";
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
{
|
||||
byte[] b = new byte[fs.Length];
|
||||
UTF8Encoding temp = new(true);
|
||||
while (fs.Read(b, 0, b.Length) > 0)
|
||||
string str = fs.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
bufferTextFromFile += temp.GetString(b);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!strs[0].StartsWith("SPAUStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
}
|
||||
_SPAUStorages.Clear();
|
||||
foreach (string data in strs)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
if (!str.StartsWith("SPAUStorage"))
|
||||
{
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU>
|
||||
collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
|
||||
_SPAUStorages.Clear();
|
||||
string strs = "";
|
||||
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
{
|
||||
DrawningSPAU? sPAU =
|
||||
elem?.CreateDrawningCar(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (sPAU != null)
|
||||
if (strs == null)
|
||||
{
|
||||
if ((collection + sPAU) == -1)
|
||||
return false;
|
||||
}
|
||||
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawningSPAU? sPAU = elem?.CreateDrawningSPAU(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (sPAU != null)
|
||||
{
|
||||
return false;
|
||||
if ((collection + sPAU) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_SPAUStorages.Add(record[0], collection);
|
||||
}
|
||||
_SPAUStorages.Add(record[0], collection);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user