This commit is contained in:
Alexander 2019-08-30 13:05:29 +03:00
parent 1a7eeb1bc7
commit 300fadf616

View file

@ -1,4 +1,4 @@
using IWshRuntimeLibrary; using IWshRuntimeLibrary;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
@ -507,7 +507,7 @@ private void AutoLock(bool minimize)
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
const int WM_SYSCOMMAND = 0x112; const int WM_SYSCOMMAND = 0x112;
const int SC_MINIMIZE = 0xF020; const int SC_MINIMIZE = 0xF020;
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE && ps.AutoLock && PublicVar.encryptionKey.Get() != null) if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE && ps.AutoLock && PublicVar.encryptionKey.Get() != null)
{ {
if (ps.AutoSave) if (ps.AutoSave)
@ -986,8 +986,6 @@ private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
private void SaveToolStripMenuItem_Click(object sender, EventArgs e) private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{ {
int saveCaret = RichTextBox.SelectionStart;
if (PublicVar.encryptionKey.Get() == null) if (PublicVar.encryptionKey.Get() == null)
{ {
SaveAsToolStripMenuItem_Click(this, new EventArgs()); SaveAsToolStripMenuItem_Click(this, new EventArgs());
@ -997,32 +995,18 @@ private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
} }
PublicVar.okPressed = false; PublicVar.okPressed = false;
} }
string enc = AES.Encrypt(RichTextBox.Text, PublicVar.encryptionKey.Get(), null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
string noenc = RichTextBox.Text; using (StreamWriter writer = new StreamWriter(filePath))
string en;
en = AES.Encrypt(RichTextBox.Text, PublicVar.encryptionKey.Get(), null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = en;
StreamWriter sw = new StreamWriter(filePath);
int i = RichTextBox.Lines.Count();
int j = 0;
i = i - 1;
while (j <= i)
{ {
sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString()); writer.Write(enc);
j = j + 1; writer.Close();
} }
sw.Close(); RichTextBox.Modified = false;
RichTextBox.Text = noenc;
RichTextBox.Select(Convert.ToInt32(saveCaret), 0);
PublicVar.keyChanged = false; PublicVar.keyChanged = false;
} }
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
int saveCaret = RichTextBox.SelectionStart;
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
if (filePath != "") if (filePath != "")
{ {
PublicVar.openFileName = Path.GetFileName(filePath); PublicVar.openFileName = Path.GetFileName(filePath);
@ -1056,23 +1040,15 @@ private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
} }
filePath = SaveFile.FileName; filePath = SaveFile.FileName;
string noenc = RichTextBox.Text; string enc = AES.Encrypt(RichTextBox.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
string en; using (StreamWriter writer = new StreamWriter(filePath))
en = AES.Encrypt(RichTextBox.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = en;
StreamWriter sw = new StreamWriter(filePath);
int i = RichTextBox.Lines.Count();
int j = 0;
i = i - 1;
while (j <= i)
{ {
sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString()); writer.Write(enc);
j = j + 1; writer.Close();
} }
sw.Close();
RichTextBox.Text = noenc; RichTextBox.Modified = false;
Text = PublicVar.appName + " " + Path.GetFileName(filePath); Text = PublicVar.appName + " " + Path.GetFileName(filePath);
RichTextBox.Select(Convert.ToInt32(saveCaret), 0);
PublicVar.encryptionKey.Set(TypedPassword.Value); PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null; TypedPassword.Value = null;
PublicVar.openFileName = Path.GetFileName(SaveFile.FileName); PublicVar.openFileName = Path.GetFileName(SaveFile.FileName);