diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Extention.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Extention.cs new file mode 100644 index 0000000..148030c --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Extention.cs @@ -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 + { + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs index 1a06126..03bf9c1 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs @@ -17,7 +17,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects /// Ширина /// Высота /// Объект - 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) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index dab2844..0d55d90 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -251,6 +251,5 @@ namespace SelfPropelledArtilleryUnit } } } - } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUConfig.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUConfig.Designer.cs index 2dfe2ff..1200f32 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUConfig.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUConfig.Designer.cs @@ -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); diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs index 4bd4244..fb2ea2a 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs @@ -98,7 +98,8 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// Путь и имя файла /// true - сохранение прошло успешно, false - ошибка при сохранении данных - 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> 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; } /// @@ -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 - 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 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; } }