-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurity.cs
More file actions
109 lines (108 loc) · 2.89 KB
/
Copy pathSecurity.cs
File metadata and controls
109 lines (108 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
namespace Cosy
{
public partial class Security : Form
{
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
private bool mouseIsDown;
private Point firstPoint;
public string[] files;
public Security(string[] fileNames, bool mode)
{
files = fileNames;
InitializeComponent();
Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
Exit.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Exit.Width, Exit.Height, 5, 5));
password.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, password.Width, password.Height, 5, 5));
Login.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Login.Width, Login.Height, 5, 5));
KeyPreview = true;
Login.Text = mode ? "ENCRYPT" : "DECRYPT";
}
void Security_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Save_Click(sender, e);
}
}
private void Save_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(password.Text))
{
MessageBox.Show("Password cannot be empty!");
}
try
{
if (Login.Text == "ENCRYPT")
{
foreach (string file in files)
{
byte[] bytes = File.ReadAllBytes(file);
Encryptor.Compile($"{file}.cosy", bytes, password.Text);
File.Delete(file);
}
}
else if (Login.Text == "DECRYPT")
{
foreach (string file in files)
{
byte[] bytes = Encryptor.Decompile(file, password.Text);
File.WriteAllBytes(file[0..^5], bytes);
File.Delete(file);
}
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Save_MouseEnter(object sender, EventArgs e)
{
Login.BackColor = Color.Silver;
}
private void Save_MouseLeave(object sender, EventArgs e)
{
Login.BackColor = Color.DarkGray;
}
private void Exit_MouseEnter(object sender, EventArgs e)
{
Exit.BackColor = Color.Red;
}
private void Exit_MouseLeave(object sender, EventArgs e)
{
Exit.BackColor = Color.DimGray;
}
private void Exit_Click(object sender, EventArgs e)
{
Close();
}
private void TitleBar_MouseDown(object sender, MouseEventArgs e)
{
firstPoint = e.Location;
mouseIsDown = true;
}
private void TitleBar_MouseUp(object sender, MouseEventArgs e)
{
mouseIsDown = false;
}
private void TitleBar_MouseMove(object sender, MouseEventArgs e)
{
if (mouseIsDown)
{
int xDiff = firstPoint.X - e.Location.X;
int yDiff = firstPoint.Y - e.Location.Y;
int x = Location.X - xDiff;
int y = Location.Y - yDiff;
Location = new Point(x, y);
}
}
}
}