You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: FileSecure-v3/Program.cs
+117-7
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ namespace FileSecure_v3
16
16
classProgram
17
17
{
18
18
//static int CycleSize = 1024 * 1024 * 100; // Increasing this value can reduce the amount of cycle that is required to encrypt an file but also require higher memory consumption
Console.WriteLine("The File ("+OpenPath+") has been successfully encrypted");
42
-
}catch(Exceptionex)
42
+
}catch(UnauthorizedAccessException)
43
+
{
44
+
Console.WriteLine("Permission Denied while accessing the file (Save/Open location for: "+OpenPath+"). Please try again by running the application as administrator. Press enter to close the application.");
45
+
Console.ReadLine();
46
+
return;
47
+
}catch(Exceptionex)
43
48
{
44
49
Console.WriteLine("The File ("+OpenPath+") has encounter an unknown error while encrypting. Error: "+ex.Message);
Console.WriteLine("The File ("+OpenPath+") has been successfully decrypted.");
68
-
}catch(InvalidCipherTextException)
73
+
}catch(UnauthorizedAccessException)
74
+
{
75
+
Console.WriteLine("Permission Denied while accessing the file (Save/Open location for: "+OpenPath+"). Please try again by running the application as administrator. Press enter to close the application.");
76
+
Console.ReadLine();
77
+
return;
78
+
}catch(InvalidCipherTextException)
69
79
{
70
-
Console.Clear();
71
80
Console.WriteLine("The file ("+OpenPath+") cannot be decrypted because you supplied an incorrect key or the file has been tampered.");
81
+
}catch(Exceptionex)
82
+
{
83
+
Console.WriteLine("The File ("+OpenPath+") has encounter an unknown error while decrypting. Error: "+ex.Message);
// Let the user select the folder where they want all the files to be encrypted, subfolder will be excluded though.
173
+
Console.WriteLine("Now type or paste the folder that you want all the files to be encrypted/decrypted: ");
174
+
stringOpenPath=Console.ReadLine();
175
+
while(true)
176
+
{
177
+
if(string.IsNullOrEmpty(OpenPath))
178
+
{
179
+
// Empty stuff not gonna work
180
+
Console.Clear();
181
+
Console.WriteLine("An empty or whitespace only path name is not allowed, please type/paste your path again: ");
182
+
OpenPath=Console.ReadLine();
183
+
}
184
+
elseif(!Directory.Exists(OpenPath))
185
+
{
186
+
// Directory Not Found
187
+
Console.Clear();
188
+
Console.WriteLine("The directory was not found, please try again: ");
189
+
OpenPath=Console.ReadLine();
190
+
}
191
+
elseif(Directory.GetFiles(OpenPath).Length<=0)
192
+
{
193
+
// There is no files in the directory
194
+
Console.Clear();
195
+
Console.WriteLine("There isn't files in the directory, try a different directory instead: ");
196
+
OpenPath=Console.ReadLine();
197
+
}
198
+
else
199
+
break;
200
+
}
201
+
// Now let them choose the location to store the file.
202
+
Console.Clear();
203
+
Console.WriteLine("Now type or paste the folder that you want the file to be saved in: ");
204
+
stringSavePath=Console.ReadLine();
205
+
while(true)
206
+
{
207
+
if(string.IsNullOrEmpty(SavePath))
208
+
{
209
+
// Empty stuff not gonna work
210
+
Console.Clear();
211
+
Console.WriteLine("An empty or whitespace only path name is not allowed, please type/paste your path again: ");
212
+
SavePath=Console.ReadLine();
213
+
}
214
+
elseif(!Directory.Exists(SavePath))
215
+
{
216
+
// Directory Not Found
217
+
Console.Clear();
218
+
Console.WriteLine("The directory was not found, please try again: ");
219
+
SavePath=Console.ReadLine();
220
+
}
221
+
elseif(Directory.GetFiles(SavePath).Length>0)
222
+
{
223
+
// There is file detected in the directory, warn user
224
+
Console.Clear();
225
+
Console.WriteLine("WARNING: There is already file in the directory that you try to save the file in. The files will be overwritten if there is a same name. Press Enter to confirm that you want to proceed, otherwise terminate the application.");
Task.Run(()=>{Encrypt(Password,file,SavePath+"/"+Path.GetFileName(file));TotalProcessedFile=TotalProcessedFile+1;if(TotalProcessedFile>=Files.Length){Console.WriteLine("Mass File Encryption Process completed, press enter to exit.");}});
Task.Run(()=>{Decrypt(Password,file,SavePath+"/"+Path.GetFileName(file));TotalProcessedFile=TotalProcessedFile+1;if(TotalProcessedFile>=Files.Length){Console.WriteLine("Mass File Decryption Process completed, press enter to exit.");}});
0 commit comments