@@ -205,7 +205,7 @@ private final void navPreviousDirectory()throws Exception
205
205
_presentWorkingDirectory .substring (_presentWorkingDirectory .lastIndexOf ('|' ), _presentWorkingDirectory .length ()),"|" );
206
206
207
207
// Check if the present working directory is the restricted user home directory
208
- if (_presentWorkingDirectory .equals (IOStreams .convertFileSeparator (".|Users|Cataphract|" )))
208
+ if (_presentWorkingDirectory .equals (IOStreams .convertFileSeparator (".|Users|Cataphract|" )))
209
209
{
210
210
// Print an error message if access is denied
211
211
IOStreams .printError ("Permission Denied." );
@@ -269,7 +269,7 @@ private final void copyMoveEntity(String fileName, String destination, boolean m
269
269
// Convert paths from Nion paths to OS specific paths
270
270
fileName = IOStreams .convertFileSeparator (fileName );
271
271
destination = IOStreams .convertFileSeparator (destination );
272
-
272
+
273
273
// Check if the specified file or directory is valid
274
274
if (!checkEntityExistence (fileName ) && !checkEntityExistence (destination ))
275
275
IOStreams .printError ("Invalid file name or destination." );
@@ -289,7 +289,7 @@ private final void copyMoveEntity(String fileName, String destination, boolean m
289
289
private final void copyMoveHelper (File source , File destination , boolean move )throws Exception
290
290
{
291
291
// Check if the source is a directory
292
- if (source .isDirectory ())
292
+ if (source .isDirectory ())
293
293
{
294
294
// Create the destination directory
295
295
destination .mkdirs ();
@@ -319,34 +319,29 @@ private final void copyMoveHelper(File source, File destination, boolean move)th
319
319
*
320
320
* @throws Exception Throws any exceptions encountered during runtime.
321
321
*/
322
- private final void listEntities ()throws Exception
322
+ private final void listEntities () throws Exception
323
323
{
324
324
// Define the format for displaying the directory/file information
325
- String format = "%1$-32s| %2$-24s| %3$-10s\n " ;
325
+ String format = "%1$-32s| %2$-24s| %3$-10s| %4$-32s \n " ;
326
326
String c = "-" ;
327
-
328
327
String ls = IOStreams .convertFileSeparator (_presentWorkingDirectory );
329
-
330
328
// Check if the present working directory exists
331
329
if (checkEntityExistence (ls ))
332
330
{
333
331
// Create a File object for the present working directory
334
332
File dPath = new File (ls );
335
-
336
333
// Print a newline for better formatting
337
334
System .out .println ("\n " );
338
-
339
335
// Format and print the header for the directory listing
340
- String disp = String .format (format , "Directory/File Name" , "File Size [In KB]" , "Type" );
336
+ String disp = String .format (format , "Directory/File Name" , "File Size [In KB]" , "Type" , "MD5 Hash" );
341
337
System .out .println (disp + c .repeat (disp .length ()) + "\n " );
342
338
343
339
// Iterate through each file in the directory
344
340
for (File file : dPath .listFiles ())
345
341
{
346
342
// Format and print the file or directory information
347
- System .out .format (String . format ( format , file .getName ().replace (_username , _name ), file .length () / 1024 + " KB" , file .isDirectory () ? "Directory" : "File" ));
343
+ System .out .format (format , file .getName ().replace (_username , _name ), file .length () / 1024 + " KB" , file .isDirectory () ? "Directory" : "File" , Cryptography . fileToMD5 ( file ));
348
344
}
349
-
350
345
// Print a newline for better formatting
351
346
System .out .println ();
352
347
}
@@ -357,6 +352,7 @@ private final void listEntities()throws Exception
357
352
}
358
353
}
359
354
355
+
360
356
/**
361
357
* Logic to change the present working directory to a given directory
362
358
*
@@ -366,7 +362,7 @@ private final void listEntities()throws Exception
366
362
private final void changeDirectory (String destination )throws Exception
367
363
{
368
364
// Check if the destination is the parent directory
369
- if (destination .equals (".." ))
365
+ if (destination .equals (".." ))
370
366
{
371
367
// Navigate to the previous directory
372
368
navPreviousDirectory ();
@@ -401,23 +397,23 @@ public void fileManagementLogic()throws Exception
401
397
{
402
398
// Check if file management policy is enabled or if the user has the necessary privileges
403
399
if (new PolicyCheck ().retrievePolicyValue ("filemgmt" ).equals ("on" ) || new Login (_username ).checkPrivilegeLogic ())
404
- {
400
+ {
405
401
// Check if the user is logged in
406
402
if (login ())
407
403
{
408
404
System .out .println (IOStreams .convertToNionSeparator (IOStreams .convertFileSeparator (_presentWorkingDirectory )));
409
405
String inputValue = "" ;
410
406
// Loop to continuously read and execute commands until 'exit' is entered
411
- do
407
+ do
412
408
{
413
409
// Read a line of input from the console
414
410
inputValue = console .readLine (_name + "@" + IOStreams .convertFileSeparator (_presentWorkingDirectory ).replace (_username , _name ) + "> " );
415
-
411
+
416
412
// Interpret and execute the command
417
413
grinchInterpreter (inputValue );
418
- }
414
+ }
419
415
while (!inputValue .equalsIgnoreCase ("exit" ));
420
- }
416
+ }
421
417
else
422
418
IOStreams .printError ("Invalid Credentials." );
423
419
}
@@ -437,12 +433,12 @@ public void fileManagementLogic(String scriptFileName)throws Exception
437
433
if ((new PolicyCheck ().retrievePolicyValue ("filemgmt" ).equals ("on" ) && new PolicyCheck ().retrievePolicyValue ("script" ).equals ("on" )) || new Login (_username ).checkPrivilegeLogic ())
438
434
{
439
435
// Validate the script file name
440
- if (scriptFileName == null || scriptFileName .equalsIgnoreCase ("" ) || scriptFileName .startsWith (" " ) || new File (scriptFileName ).isDirectory () || !(new File ("./ Users/Truncheon/ " + _username + "/ " + scriptFileName + ".fmx" ).exists ()))
436
+ if (scriptFileName == null || scriptFileName .equalsIgnoreCase ("" ) || scriptFileName .startsWith (" " ) || new File (scriptFileName ).isDirectory () || !(new File (IOStreams . convertFileSeparator ( ".| Users|Cataphract| " + _username + "| " + scriptFileName + ".fmx" ) ).exists ()))
441
437
IOStreams .printError ("Invalid Script File!" );
442
438
else
443
439
{
444
440
// Check if the user is logged in
445
- if (login ())
441
+ if (login ())
446
442
{
447
443
// Initialize a stream to read the given file
448
444
BufferedReader br = new BufferedReader (new FileReader (scriptFileName ));
@@ -451,7 +447,7 @@ public void fileManagementLogic(String scriptFileName)throws Exception
451
447
String scriptLine ;
452
448
453
449
// Read the script file, line by line
454
- while (!(scriptLine = br .readLine ()).equalsIgnoreCase ("<EndGrinch> " ))
450
+ while (!(scriptLine = br .readLine ()).equalsIgnoreCase ("End Grinch " ))
455
451
{
456
452
// Check if the line is a comment or is blank in the script file and skip the line
457
453
if (scriptLine .startsWith ("#" ) || scriptLine .equalsIgnoreCase ("" ))
@@ -486,9 +482,9 @@ private void grinchInterpreter(String command)throws Exception
486
482
{
487
483
// Split the command string into an array of command arguments
488
484
String [] commandArray = Anvil .splitStringToArray (command );
489
-
485
+
490
486
// Switch statement to handle different commands
491
- switch (commandArray [0 ].toLowerCase ())
487
+ switch (commandArray [0 ].toLowerCase ())
492
488
{
493
489
case "cut" :
494
490
case "move" :
0 commit comments