From 9874caf6909e255c6f480e61b4d06bca5e574c74 Mon Sep 17 00:00:00 2001 From: bocchanskyy Date: Mon, 25 Dec 2023 00:54:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D1=83?= =?UTF-8?q?=D1=8E=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bulldozer/FormBulldozerConfig.Designer.cs | 21 +---- .../Generics/BulldozersGenericStorage.cs | 76 ++++++++++--------- 2 files changed, 41 insertions(+), 56 deletions(-) diff --git a/Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs b/Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs index 3ddc87c..7e07d50 100644 --- a/Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs +++ b/Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs @@ -125,7 +125,6 @@ this.labelModifiedObject.TabIndex = 8; this.labelModifiedObject.Text = "Продвинутый"; this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelModifiedObject.MouseDown += labelObject_MouseDown; // // labelSimpleObject // @@ -138,7 +137,6 @@ this.labelSimpleObject.TabIndex = 7; this.labelSimpleObject.Text = "Простой"; this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelSimpleObject.MouseDown += labelObject_MouseDown; // // groupBoxColors // @@ -158,8 +156,6 @@ this.groupBoxColors.TabIndex = 6; this.groupBoxColors.TabStop = false; this.groupBoxColors.Text = "Цвета"; - this.groupBoxColors.DragDrop += PanelObject_DragDrop; - this.groupBoxColors.DragEnter += PanelObject_DragEnter; // // panelPurple // @@ -169,7 +165,6 @@ this.panelPurple.Name = "panelPurple"; this.panelPurple.Size = new System.Drawing.Size(43, 43); this.panelPurple.TabIndex = 1; - this.panelPurple.MouseDown += panelColor_MouseDown; // // panelBlack // @@ -179,7 +174,6 @@ this.panelBlack.Name = "panelBlack"; this.panelBlack.Size = new System.Drawing.Size(43, 43); this.panelBlack.TabIndex = 1; - this.panelBlack.MouseDown += panelColor_MouseDown; // // panelGray // @@ -189,7 +183,6 @@ this.panelGray.Name = "panelGray"; this.panelGray.Size = new System.Drawing.Size(43, 43); this.panelGray.TabIndex = 1; - this.panelGray.MouseDown += panelColor_MouseDown; // // panelWhite // @@ -199,7 +192,6 @@ this.panelWhite.Name = "panelWhite"; this.panelWhite.Size = new System.Drawing.Size(43, 43); this.panelWhite.TabIndex = 1; - this.panelWhite.MouseDown += panelColor_MouseDown; // // panelYellow // @@ -209,7 +201,6 @@ this.panelYellow.Name = "panelYellow"; this.panelYellow.Size = new System.Drawing.Size(43, 43); this.panelYellow.TabIndex = 1; - this.panelYellow.MouseDown += panelColor_MouseDown; // // panelBlue // @@ -219,17 +210,15 @@ this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(43, 43); this.panelBlue.TabIndex = 1; - this.panelBlue.MouseDown += panelColor_MouseDown; // // panelGreen // - this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.BackColor = System.Drawing.Color.Green; this.panelGreen.Location = new System.Drawing.Point(77, 34); this.panelGreen.Margin = new System.Windows.Forms.Padding(2); this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(43, 43); this.panelGreen.TabIndex = 1; - this.panelGreen.MouseDown += panelColor_MouseDown; // // panelRed // @@ -239,7 +228,6 @@ this.panelRed.Name = "panelRed"; this.panelRed.Size = new System.Drawing.Size(43, 43); this.panelRed.TabIndex = 0; - this.panelRed.MouseDown += panelColor_MouseDown; // // numericUpDownWeight // @@ -327,8 +315,6 @@ this.panelObject.Name = "panelObject"; this.panelObject.Size = new System.Drawing.Size(334, 202); this.panelObject.TabIndex = 2; - this. panelObject.DragDrop += PanelObject_DragDrop; - panelObject.DragEnter += PanelObject_DragEnter; // // labelAddColor // @@ -341,8 +327,6 @@ this.labelAddColor.TabIndex = 3; this.labelAddColor.Text = "Дополн. цвет"; this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelAddColor.DragDrop += labelColor_dragDrop; - this.labelAddColor.DragEnter += labelColor_dragEnter; // // labelColor // @@ -355,8 +339,6 @@ this.labelColor.TabIndex = 2; this.labelColor.Text = "Основной цвет"; this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelColor.DragDrop += labelColor_dragDrop; - this.labelColor.DragEnter += labelColor_dragEnter; // // buttonAdd // @@ -367,7 +349,6 @@ this.buttonAdd.TabIndex = 3; this.buttonAdd.Text = "Добавить"; this.buttonAdd.UseVisualStyleBackColor = true; - this.buttonAdd.Click += buttonAdd_Click; // // buttonCancel // diff --git a/Bulldozer/Bulldozer/Generics/BulldozersGenericStorage.cs b/Bulldozer/Bulldozer/Generics/BulldozersGenericStorage.cs index f6c3a31..2d2620e 100644 --- a/Bulldozer/Bulldozer/Generics/BulldozersGenericStorage.cs +++ b/Bulldozer/Bulldozer/Generics/BulldozersGenericStorage.cs @@ -67,7 +67,7 @@ namespace Bulldozer.Generics /// /// /// - public BulldozersGenericCollection ? this[string ind] + public BulldozersGenericCollection? this[string ind] { get { @@ -118,9 +118,15 @@ namespace Bulldozer.Generics { return false; } - using FileStream fs = new(filename, FileMode.Create); - byte[] info = new UTF8Encoding(true).GetBytes($"BulldozerStorage{Environment.NewLine}{data}"); - fs.Write(info, 0, info.Length); + string toWrite = $"BulldozerStorage{Environment.NewLine}{data}"; + var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + using (StreamWriter sw = new(filename)) + { + foreach (var str in strs) + { + sw.WriteLine(str); + } + } return true; } @@ -135,50 +141,48 @@ namespace Bulldozer.Generics { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader sr = new(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + string str = sr.ReadLine(); + var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + if (strs == null || strs.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("BulldozerStorage")) - { - return false; - } - _bulldozerStorages.Clear(); - foreach (string data in strs) - { - string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - if (record.Length != 2) + if (!strs[0].StartsWith("BulldozerStorage")) { - continue; + return false; } - BulldozersGenericCollection collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - - foreach (string elem in set) + _bulldozerStorages.Clear(); + do { - DrawingBulldozer? bulldozer = elem?.CreateDrawingBulldozer(_separatorForObject, _pictureWidth, _pictureHeight); - if (bulldozer != null) + string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) { - if ((collection + bulldozer) == -1) + str = sr.ReadLine(); + continue; + } + BulldozersGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawingBulldozer? bulldozer = + elem?.CreateDrawingBulldozer(_separatorForObject, _pictureWidth, _pictureHeight); + if (bulldozer != null) { - return false; + if ((collection + bulldozer) == -1) + { + return false; + } } } - } - _bulldozerStorages.Add(record[0], collection); + _bulldozerStorages.Add(record[0], collection); + + str = sr.ReadLine(); + } while (str != null); } return true; } } } +