diff --git a/Reseter2/Form1.cs b/Reseter2/Form1.cs
index 8e31c48..bb2faf6 100644
--- a/Reseter2/Form1.cs
+++ b/Reseter2/Form1.cs
@@ -60,8 +60,8 @@ namespace Reseter2
treeView1.Nodes.AddRange(WordsList.ListNodes());
- treeView1.SelectedNode.
- //treeView1.MouseCaptureChanged.;
+ //treeView1.SelectedNode.
+ //treeView1.MouseCaptureChanged.;
tabControl1.SelectedIndex = 1;
diff --git a/Reseter2/Reseter2.csproj b/Reseter2/Reseter2.csproj
index b87b271..da56c66 100644
--- a/Reseter2/Reseter2.csproj
+++ b/Reseter2/Reseter2.csproj
@@ -184,9 +184,6 @@
-
-
-
diff --git a/Reseter2/Resources/comp.png b/Reseter2/Resources/comp.png
deleted file mode 100644
index 428fc37..0000000
Binary files a/Reseter2/Resources/comp.png and /dev/null differ
diff --git a/Reseter2/Setting/SGlobalSetting.cs b/Reseter2/Setting/SGlobalSetting.cs
index bd39de2..762c67c 100644
--- a/Reseter2/Setting/SGlobalSetting.cs
+++ b/Reseter2/Setting/SGlobalSetting.cs
@@ -1,4 +1,5 @@
-using Reseter2.Words;
+using Reseter2.History;
+using Reseter2.Words;
using System;
using System.Collections.Generic;
using System.IO;
@@ -7,14 +8,15 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
+using System.Windows.Forms;
namespace Reseter2.Setting
{
[Serializable]
internal static class SGlobalSetting
{
- public static SettingHistory settingHistory
- public static SettingWords settingWords = new SettingWords();
+ // public static SettingHistory settingHistory
+ public static SettingWords settingWords = new SettingWords();
public static void LoadSetting()
{
@@ -66,9 +68,94 @@ namespace Reseter2.Setting
return (IComp)Clone((object)input);
}
- public static void Save()
+ public static bool SaveClose(WordsCategory output, DialogResult ok = DialogResult.No)
{
-
+ BinaryFormatter binaryFormatter = new BinaryFormatter();
+ MemoryStream Memory = new MemoryStream();
+ binaryFormatter.Serialize(Memory, output);
+ FileStream file = null;
+ Memory.Position = 0;
+ if (settingWords.HashCheck(Memory) )
+ {
+ if (ok == DialogResult.OK)
+ {
+ Memory.Close();
+ Memory.Dispose();
+ return Save(output);
+ }
+ else
+ {
+ DialogResult result = MessageBox.Show("Сохранить внесенные изменения?", "Сохранение измененний", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
+ switch (result)
+ {
+ case DialogResult.Yes:
+
+ try
+ {
+ file = new FileStream(settingWords.PathBase, FileMode.OpenOrCreate);
+ Memory.Position = 0;
+ Memory.CopyTo(file);
+ Memory.Close();
+ Memory.Dispose();
+ file.Close();
+ file.Dispose();
+ }
+ catch
+ {
+ Memory.Close();
+ Memory.Dispose();
+ file.Close();
+ file.Dispose();
+ return SaveCheck(output);
+ }
+
+ WordsList.MainCategory = output;
+ return true;
+ case DialogResult.No:
+ return true;
+ case DialogResult.Cancel:
+ return false;
+ }
+ }
+
+ }
+ return true;
+ }
+ public static bool Save(WordsCategory output)
+ {
+ return Save(settingWords.PathBase, output);
+ }
+ public static bool Save(string path, object output)
+ {
+ BinaryFormatter binaryFormatter = new BinaryFormatter();
+ FileStream file = null;
+ try
+ {
+ file = new FileStream(path, FileMode.OpenOrCreate);
+ binaryFormatter.Serialize(file, output);
+ file.Close();
+ file.Dispose();
+ return true;
+ }
+ catch
+ {
+ file.Close();
+ file.Dispose();
+ return SaveCheck(output);
+
+ }
+ }
+ public static bool SaveCheck(object output)
+ {
+ DialogResult result1 = MessageBox.Show("Файл занят другой программой.\nПовторить еще раз?", "Ошибка сохранения", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
+ switch (result1)
+ {
+ case (DialogResult.Retry):
+ return SaveCheck(output);
+ case (DialogResult.Abort):
+ return true;
+ }
+ return false;
}
diff --git a/Reseter2/Setting/SettingWords.cs b/Reseter2/Setting/SettingWords.cs
index d523839..ed2af6d 100644
--- a/Reseter2/Setting/SettingWords.cs
+++ b/Reseter2/Setting/SettingWords.cs
@@ -35,7 +35,12 @@ namespace Reseter2.Setting
hash = Hash.ComputeHash(memory);
}
-
+ public bool HashCheck(MemoryStream memory)
+ {
+ byte[] hashSave = Hash.ComputeHash(memory);
+ return !hash.SequenceEqual(hashSave);
+ }
+
}
}
\ No newline at end of file
diff --git a/Reseter2/Words/BilderWords.cs b/Reseter2/Words/BilderWords.cs
index cf9059b..c339356 100644
--- a/Reseter2/Words/BilderWords.cs
+++ b/Reseter2/Words/BilderWords.cs
@@ -49,7 +49,7 @@ namespace Reseter2.Words
InitializeComponent();
cb_create.Items.Add("Категория");
cb_create.Items.Add("Компьютер");
- cb_create.SelectedIndex = 0;
+ cb_create.SelectedIndex = 1;
treeView1.ItemDrag += new ItemDragEventHandler(TreeView1_ItemDrag);
treeView1.DragEnter += new DragEventHandler(TreeView1_DragEnter);
treeView1.DragOver += new DragEventHandler(TreeView1_DragOver);
@@ -295,39 +295,16 @@ namespace Reseter2.Words
control.Visible = false;
control.Visible = true;
}
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- MemoryStream Memory = new MemoryStream();
- binaryFormatter.Serialize(Memory, ChangeCategory);
- Memory.Position = 0;
- byte[] hashSave = Hash.ComputeHash(Memory);
- if (!hash.SequenceEqual(hashSave))
+
+ if (!SGlobalSetting.SaveClose(ChangeCategory, this.DialogResult))
{
- DialogResult result = MessageBox.Show("Сохранить внесенные изменения?", "Сохранение измененний", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
- switch (result)
- {
- case DialogResult.Yes:
- FileStream file = new FileStream("base.dat", FileMode.OpenOrCreate);
- Memory.Position = 0;
- Memory.CopyTo(file);
- Memory.Close();
- Memory.Dispose();
- file.Close();
- file.Dispose();
- WordsList.MainCategory = ChangeCategory;
- this.DialogResult = DialogResult.OK;
- break;
- case DialogResult.No:
- this.DialogResult = DialogResult.Abort;
- break;
- case DialogResult.Cancel:
- e.Cancel = true;
- break;
-
- }
-
-
+ e.Cancel = true;
}
-
+ else
+ {
+ WordsList.MainCategory = ChangeCategory;
+ }
+
}
private void bt_deleteItem_Click(object sender, EventArgs e)
@@ -411,20 +388,9 @@ namespace Reseter2.Words
private void bt_saveClose_Click(object sender, EventArgs e)
{
- if (control != null)
- {
- control.Visible = false;
- control.Dispose();
- }
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- FileStream file = new FileStream("base.dat", FileMode.OpenOrCreate);
- binaryFormatter.Serialize(file, ChangeCategory);
- file.Close();
- file.Dispose();
- WordsList.MainCategory = ChangeCategory;
this.DialogResult = DialogResult.OK;
- this.Close();
+
}
private void bt_save_Click(object sender, EventArgs e)
@@ -434,13 +400,8 @@ namespace Reseter2.Words
control.Visible = false;
control.Visible = true;
}
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- FileStream file = new FileStream("base.dat", FileMode.OpenOrCreate);
- binaryFormatter.Serialize(file, ChangeCategory);
- file.Close();
- file.Dispose();
- WordsList.MainCategory = ChangeCategory;
-
+ if(SGlobalSetting.Save(ChangeCategory)) WordsList.MainCategory = ChangeCategory;
+ SGlobalSetting.Clone(WordsList.MainCategory);
}
private void bt_close_Click(object sender, EventArgs e)