-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
187 lines (157 loc) · 6.29 KB
/
MainWindow.xaml.cs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using Microsoft.Win32;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Collections.Generic;
using System.IO;
using static System.Net.WebRequestMethods;
namespace Cripto1
{
public partial class MainWindow : Window
{
private string input_file_path;
private string key_file_path;
public MainWindow()
{
InitializeComponent();
}
private void buttonQuit_Click(object sender, RoutedEventArgs e)
{
Window mainWindow = Application.Current.MainWindow;
//if main window exists, handle closing event //TODO: messy
if (mainWindow != null)
{
mainWindow.Closing += (s, args) =>
{
args.Cancel = false;
};
mainWindow.Close();
}
Application.Current.Shutdown();
}
private void buttonEncrypt_Click(object sender, RoutedEventArgs e)
{
try
{
foreach (string xlsFile in xlsListing.Items)
{
if (Path.GetExtension(xlsFile).Equals(".xls", StringComparison.OrdinalIgnoreCase))
{
input_file_path = xlsFile;
Program.encrypt_excel_file_with_key("functions", input_file_path, key_file_path, textBlockDllPath.Text, textBlockScriptPath.Text);
MessageBox.Show(Path.GetFileName(xlsFile) + " " + "encrypted successfully");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Encryption Error. Already Encrypted?");
}
}
private void buttonDecrypt_Click(object sender, RoutedEventArgs e)
{
try
{
foreach (string xlsFile in xlsListing.Items)
{
if (Path.GetExtension(xlsFile).Equals(".xls", StringComparison.OrdinalIgnoreCase))
{
input_file_path = xlsFile;
Program.decript_excel_file_with_key("functions", input_file_path, key_file_path, textBlockDllPath.Text, textBlockScriptPath.Text);
MessageBox.Show(Path.GetFileName(xlsFile) + " " + "decrypted successfully");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Encryption Error. Wrong Encryption Key?");
}
}
private void buttonChooseKey_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "All files (*.*)|*.*";
openFileDialog.InitialDirectory = @"C:\";
bool? result = openFileDialog.ShowDialog();
if (result == true)
{
string selectedFilePath = openFileDialog.FileName;
key_file_path = selectedFilePath;
textBlockKeyPath.Text = selectedFilePath;
}
}
private void buttonChooseTargetDirectory_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.ValidateNames = false;
openFileDialog.CheckFileExists = false;
openFileDialog.CheckPathExists = true;
openFileDialog.FileName = "Select Folder";
if (openFileDialog.ShowDialog() == true)
{
string selectedDirectory = Path.GetDirectoryName(openFileDialog.FileName);
PopulateXlsFilesList(selectedDirectory);
}
}
private void PopulateXlsFilesList(string directory)
{
List<string> xlsFiles = new List<string>();
try
{
string[] files = Directory.GetFiles(directory);
xlsFiles.AddRange(files);
xlsListing.ItemsSource = xlsFiles;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void buttonCreateKey_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.ValidateNames = false;
openFileDialog.CheckFileExists = false;
openFileDialog.CheckPathExists = true;
openFileDialog.FileName = "Select Folder";
if (openFileDialog.ShowDialog() == true)
{
string selectedDirectory = Path.GetDirectoryName(openFileDialog.FileName);
key_file_path = selectedDirectory + "\\cipher_file";
Program.create_key("functions", key_file_path, textBlockDllPath.Text, textBlockScriptPath.Text);
MessageBox.Show("Key Generated.");
}
}
private void buttonChooseDll_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "All files (*.*)|*.*";
openFileDialog.InitialDirectory = @"C:\";
bool? result = openFileDialog.ShowDialog();
if (result == true)
{
string selectedFilePath = openFileDialog.FileName;
textBlockDllPath.Text = selectedFilePath;
}
}
private void buttonChooseScriptPath_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.ValidateNames = false;
openFileDialog.CheckFileExists = false;
openFileDialog.CheckPathExists = true;
openFileDialog.FileName = "Select Folder";
if (openFileDialog.ShowDialog() == true)
{
string selectedDirectory = Path.GetDirectoryName(openFileDialog.FileName);
textBlockScriptPath.Text = selectedDirectory;
}
}
}
}