From 62bbc93886531a07a7dd4decd137bc9ac1ff4dba Mon Sep 17 00:00:00 2001 From: GokaPek Date: Sat, 18 Nov 2023 13:06:39 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtentionDrawningSPAU.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs new file mode 100644 index 0000000..1a06126 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/ExtentionDrawningSPAU.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SelfPropelledArtilleryUnit.Entities; + +namespace SelfPropelledArtilleryUnit.DrawningObjects +{ + public static class ExtentionDrawningSPAU + { + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Разделитель даннных + /// Ширина + /// Высота + /// Объект + public static DrawningSPAU? CreateDrawningCar(this string info, char separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawningSPAU(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 6) + { + return new DrawningSPAUchild(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]), width, height); + } + return null; + } + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Разделитель даннных + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningSPAU drawningSPAU, char separatorForObject) + { + var sPAU = drawningSPAU.EntitySPAU; + if (sPAU == null) + { + return string.Empty; + } + var str = $"{sPAU.Speed}{separatorForObject}{sPAU.Weight}{separatorForObject}{sPAU.BodyColor.Name}"; + if (sPAU is not EntitySPAUchild sPAUchild) + { + return str; + } + return $"{str}{separatorForObject}{sPAUchild.AdditionalColor.Name}{separatorForObject}{sPAUchild.BodyKit}{separatorForObject}{sPAUchild.Ballon}"; + } + } +} -- 2.25.1 From 849deb0066a40732e8264dc4fec5d37ad63882f7 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Sat, 18 Nov 2023 13:49:06 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=8D=D1=82=D0=B0=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SPAUGenericCollection.cs | 4 + .../SPAUGenericStorage.cs | 107 +++++++++++++++++- 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs index 0a4a07f..749640c 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs @@ -51,6 +51,10 @@ namespace SelfPropelledArtilleryUnit.Generics _collection = new SetGeneric(width * height); } /// + /// Получение объектов коллекции + /// + public IEnumerable GetCars => _collection.GetSPAUs(); + /// /// Перегрузка оператора сложения /// /// diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs index fb2db48..24fc8d0 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs @@ -79,6 +79,111 @@ namespace SelfPropelledArtilleryUnit.Generics } } } - } + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private static readonly char _separatorForKeyValue = '|'; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly char _separatorRecords = ';'; + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly char _separatorForObject = ':'; + + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename){ + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder data = new(); + foreach (KeyValuePair> record in _SPAUStorages) + { + StringBuilder records = new(); + foreach (DrawningSPAU? elem in record.Value.GetCars) + { + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); + } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + if (data.Length == 0) + { + 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); + return true; + } + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + 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); + } + } + var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, + StringSplitOptions.RemoveEmptyEntries); + if (strs == null || strs.Length == 0) + { + return false; + } + if (!strs[0].StartsWith("CarStorage")) + { + //если нет такой записи, то это не те данные + return false; + } + _SPAUStorages.Clear(); + foreach (string data in strs) + { + string[] record = data.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?.CreateDrawningCar(_separatorForObject, _pictureWidth, _pictureHeight); + if (sPAU != null) + { + if ((collection + sPAU) == -1) + { + return false; + } + } + } + _SPAUStorages.Add(record[0], collection); + } + return true; + } + + } } -- 2.25.1 From 8f8a8ffd6280968d331c7402bbe2d4980af38fe2 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Sat, 18 Nov 2023 21:16:52 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormSPAUCollection.Designer.cs | 69 +++++++++++++++++-- .../FormSPAUCollection.cs | 43 ++++++++++++ .../FormSPAUCollection.resx | 9 +++ .../SPAUGenericStorage.cs | 13 ++-- 4 files changed, 121 insertions(+), 13 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs index f2322bf..79a993d 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.Designer.cs @@ -39,14 +39,21 @@ ButtonDelObject = new Button(); ButtonAddObject = new Button(); textBoxStorageName = new TextBox(); + menuStrip = new MenuStrip(); + toolStripMenuItem1 = new ToolStripMenuItem(); + openFileDialog = new ToolStripMenuItem(); + saveFileDialog = new ToolStripMenuItem(); + openFileDialog_ = new OpenFileDialog(); + saveFileDialog_ = new OpenFileDialog(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); panel1.SuspendLayout(); panel2.SuspendLayout(); + menuStrip.SuspendLayout(); SuspendLayout(); // // pictureBoxCollection // - pictureBoxCollection.Location = new Point(12, 12); + pictureBoxCollection.Location = new Point(12, 40); pictureBoxCollection.Name = "pictureBoxCollection"; pictureBoxCollection.Size = new Size(680, 432); pictureBoxCollection.TabIndex = 0; @@ -95,7 +102,7 @@ panel1.Controls.Add(ButtonRemoveSPAU); panel1.Controls.Add(ButtonAddSPAU); panel1.Controls.Add(maskedTextBoxNumber); - panel1.Location = new Point(711, 217); + panel1.Location = new Point(711, 245); panel1.Name = "panel1"; panel1.Size = new Size(176, 227); panel1.TabIndex = 5; @@ -106,9 +113,9 @@ panel2.Controls.Add(ButtonDelObject); panel2.Controls.Add(ButtonAddObject); panel2.Controls.Add(textBoxStorageName); - panel2.Location = new Point(711, 12); + panel2.Location = new Point(711, 40); panel2.Name = "panel2"; - panel2.Size = new Size(174, 198); + panel2.Size = new Size(174, 199); panel2.TabIndex = 6; // // listBoxStorages @@ -148,14 +155,57 @@ textBoxStorageName.Size = new Size(143, 27); textBoxStorageName.TabIndex = 0; // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1 }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(899, 28); + menuStrip.TabIndex = 7; + menuStrip.Text = "menuStrip1"; + // + // toolStripMenuItem1 + // + toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { openFileDialog, saveFileDialog }); + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new Size(59, 24); + toolStripMenuItem1.Text = "Файл"; + // + // openFileDialog + // + openFileDialog.Name = "openFileDialog"; + openFileDialog.Size = new Size(224, 26); + openFileDialog.Text = "Открыть файл"; + openFileDialog.Click += LoadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Name = "saveFileDialog"; + saveFileDialog.Size = new Size(224, 26); + saveFileDialog.Text = "Сохранить файл"; + saveFileDialog.Click += SaveToolStripMenuItem_Click; + // + // openFileDialog_ + // + openFileDialog_.FileName = "openFileDialog"; + openFileDialog_.Filter = "txt file | *.txt"; + // + // saveFileDialog_ + // + saveFileDialog_.FileName = "saveFileDialog"; + saveFileDialog_.Filter = "txt file | *.txt"; + // // FormSPAUCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(899, 456); + ClientSize = new Size(899, 484); Controls.Add(panel2); Controls.Add(panel1); Controls.Add(pictureBoxCollection); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormSPAUCollection"; Text = "FormSPAUCollection"; ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); @@ -163,7 +213,10 @@ panel1.PerformLayout(); panel2.ResumeLayout(false); panel2.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -179,5 +232,11 @@ private TextBox textBoxStorageName; private Button ButtonDelObject; private ListBox listBoxStorages; + private MenuStrip menuStrip; + private ToolStripMenuItem toolStripMenuItem1; + private ToolStripMenuItem openFileDialog; + private ToolStripMenuItem saveFileDialog; + private OpenFileDialog openFileDialog_; + private OpenFileDialog saveFileDialog_; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index d5753a7..dab2844 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -208,6 +208,49 @@ namespace SelfPropelledArtilleryUnit pictureBoxCollection.Image = obj.ShowSPAUs(); } + // … + /// + /// Обработка нажатия "Сохранение" + /// + /// + /// + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog_.ShowDialog() == DialogResult.OK) + { + if (_storage.SaveData(saveFileDialog_.FileName)) + { + MessageBox.Show("Сохранение прошло успешно", + "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не сохранилось", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + /// + /// Обработка нажатия "Загрузка" + /// + /// + /// + private void LoadToolStripMenuItem_Click(object sender, EventArgs e) + { + if (openFileDialog_.ShowDialog() == DialogResult.OK) + { + if (_storage.LoadData(openFileDialog_.FileName)) + { + MessageBox.Show("Загрузка прошлa успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadObjects(); + } + else + { + MessageBox.Show("Не загрузилось", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx index af32865..375a32c 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 283, 23 + + + 130, 23 + \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs index 24fc8d0..4bd4244 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericStorage.cs @@ -119,7 +119,7 @@ namespace SelfPropelledArtilleryUnit.Generics } using FileStream fs = new(filename, FileMode.Create); byte[] info = new - UTF8Encoding(true).GetBytes($"SpAUStorage{Environment.NewLine}{data}"); + UTF8Encoding(true).GetBytes($"SPAUStorage{Environment.NewLine}{data}"); fs.Write(info, 0, info.Length); return true; } @@ -144,13 +144,12 @@ namespace SelfPropelledArtilleryUnit.Generics bufferTextFromFile += temp.GetString(b); } } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, - StringSplitOptions.RemoveEmptyEntries); + var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); if (strs == null || strs.Length == 0) { return false; } - if (!strs[0].StartsWith("CarStorage")) + if (!strs[0].StartsWith("SPAUStorage")) { //если нет такой записи, то это не те данные return false; @@ -158,16 +157,14 @@ namespace SelfPropelledArtilleryUnit.Generics _SPAUStorages.Clear(); foreach (string data in strs) { - string[] record = data.Split(_separatorForKeyValue, - StringSplitOptions.RemoveEmptyEntries); + string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); if (record.Length != 2) { continue; } SPAUGenericCollection collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, - StringSplitOptions.RemoveEmptyEntries); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { DrawningSPAU? sPAU = -- 2.25.1 From bdf4b0cea95359fc2d2a4e5d44ed1bca08d7d29f Mon Sep 17 00:00:00 2001 From: GokaPek Date: Wed, 22 Nov 2023 10:21:06 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelfPropelledArtilleryUnit/Extention.cs | 12 +++ .../ExtentionDrawningSPAU.cs | 2 +- .../FormSPAUCollection.cs | 1 - .../FormSPAUConfig.Designer.cs | 2 +- .../SPAUGenericStorage.cs | 81 ++++++++++--------- 5 files changed, 55 insertions(+), 43 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Extention.cs 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; } } -- 2.25.1 From e6f5b144bdb2849f5830d194e1207a9f988b0ecf Mon Sep 17 00:00:00 2001 From: GokaPek Date: Wed, 22 Nov 2023 11:08:58 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A2=D0=BE=D1=87=D0=BA=D0=B8=20=D1=83?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelfPropelledArtilleryUnit/FormSPAUCollection.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index 0d55d90..c983750 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -207,8 +207,6 @@ namespace SelfPropelledArtilleryUnit } pictureBoxCollection.Image = obj.ShowSPAUs(); } - - // … /// /// Обработка нажатия "Сохранение" /// -- 2.25.1