@@ -61,7 +61,7 @@ public FileManagement(String username)throws Exception
61
61
// Set the name of the user to the global variable
62
62
_name = new Login (username ).getNameLogic ();
63
63
// Initialize the present working directory
64
- _presentWorkingDirectory = "./ Users/ Cataphract/ " + _username + "/ " ;
64
+ _presentWorkingDirectory = ".| Users| Cataphract| " + _username + "| " ;
65
65
}
66
66
67
67
/*****************************************
@@ -93,7 +93,7 @@ private final boolean login()throws Exception
93
93
*/
94
94
private boolean checkEntityExistence (String fileName )throws Exception
95
95
{
96
- return new File (fileName ).exists ();
96
+ return new File (IOStreams . convertFileSeparator ( fileName ) ).exists ();
97
97
}
98
98
99
99
/**
@@ -106,7 +106,7 @@ private final void deleteEntity(String fileName)throws Exception
106
106
{
107
107
try
108
108
{
109
- fileName = _presentWorkingDirectory +fileName ;
109
+ fileName = IOStreams . convertFileSeparator ( _presentWorkingDirectory +fileName ) ;
110
110
if (checkEntityExistence (fileName ))
111
111
{
112
112
File f =new File (fileName );
@@ -150,7 +150,7 @@ private final void deleteEntityHelper(File fileName)throws Exception
150
150
private void viewDirectoryTree ()throws Exception
151
151
{
152
152
// Create a File object for the present working directory
153
- File treeView = new File (_presentWorkingDirectory );
153
+ File treeView = new File (IOStreams . convertFileSeparator ( _presentWorkingDirectory ) );
154
154
155
155
// Print the header for the tree view
156
156
IOStreams .println ("\n --- [ TREE VIEW ] ---\n " );
@@ -202,10 +202,11 @@ private final void navPreviousDirectory()throws Exception
202
202
203
203
// Replace the last directory in the path with a single slash
204
204
_presentWorkingDirectory = _presentWorkingDirectory .replace (
205
- _presentWorkingDirectory .substring (_presentWorkingDirectory .lastIndexOf ('/ ' ), _presentWorkingDirectory .length ()),"/ " );
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 ("./Users/Cataphract/" )) {
208
+ if (_presentWorkingDirectory .equals (IOStreams .convertFileSeparator (".|Users|Cataphract|" )))
209
+ {
209
210
// Print an error message if access is denied
210
211
IOStreams .printError ("Permission Denied." );
211
212
@@ -219,7 +220,7 @@ private final void navPreviousDirectory()throws Exception
219
220
*/
220
221
private final void resetToHomeDirectory ()
221
222
{
222
- _presentWorkingDirectory = "./ Users/ Cataphract/ " + _username + '/ ' ;
223
+ _presentWorkingDirectory = ".| Users| Cataphract| " + _username + '| ' ;
223
224
}
224
225
225
226
/**
@@ -265,6 +266,10 @@ private final void renameEntity(String fileName, String newFileName) throws Exce
265
266
*/
266
267
private final void copyMoveEntity (String fileName , String destination , boolean move )throws Exception
267
268
{
269
+ // Convert paths from Nion paths to OS specific paths
270
+ fileName = IOStreams .convertFileSeparator (fileName );
271
+ destination = IOStreams .convertFileSeparator (destination );
272
+
268
273
// Check if the specified file or directory is valid
269
274
if (!checkEntityExistence (fileName ) && !checkEntityExistence (destination ))
270
275
IOStreams .printError ("Invalid file name or destination." );
@@ -284,7 +289,8 @@ private final void copyMoveEntity(String fileName, String destination, boolean m
284
289
private final void copyMoveHelper (File source , File destination , boolean move )throws Exception
285
290
{
286
291
// Check if the source is a directory
287
- if (source .isDirectory ()) {
292
+ if (source .isDirectory ())
293
+ {
288
294
// Create the destination directory
289
295
destination .mkdirs ();
290
296
@@ -319,11 +325,13 @@ private final void listEntities()throws Exception
319
325
String format = "%1$-32s| %2$-24s| %3$-10s\n " ;
320
326
String c = "-" ;
321
327
328
+ String ls = IOStreams .convertFileSeparator (_presentWorkingDirectory );
329
+
322
330
// Check if the present working directory exists
323
- if (checkEntityExistence (_presentWorkingDirectory ))
331
+ if (checkEntityExistence (ls ))
324
332
{
325
333
// Create a File object for the present working directory
326
- File dPath = new File (_presentWorkingDirectory );
334
+ File dPath = new File (ls );
327
335
328
336
// Print a newline for better formatting
329
337
System .out .println ("\n " );
@@ -358,7 +366,8 @@ private final void listEntities()throws Exception
358
366
private final void changeDirectory (String destination )throws Exception
359
367
{
360
368
// Check if the destination is the parent directory
361
- if (destination .equals (".." )) {
369
+ if (destination .equals (".." ))
370
+ {
362
371
// Navigate to the previous directory
363
372
navPreviousDirectory ();
364
373
@@ -369,7 +378,7 @@ private final void changeDirectory(String destination)throws Exception
369
378
if (checkEntityExistence (_presentWorkingDirectory + destination ))
370
379
{
371
380
// Update the present working directory to the new destination
372
- _presentWorkingDirectory = _presentWorkingDirectory + destination + "/ " ;
381
+ _presentWorkingDirectory = _presentWorkingDirectory + destination + "| " ;
373
382
}
374
383
else
375
384
{
@@ -396,12 +405,13 @@ public void fileManagementLogic()throws Exception
396
405
// Check if the user is logged in
397
406
if (login ())
398
407
{
408
+ System .out .println (IOStreams .convertToNionSeparator (IOStreams .convertFileSeparator (_presentWorkingDirectory )));
399
409
String inputValue = "" ;
400
410
// Loop to continuously read and execute commands until 'exit' is entered
401
411
do
402
412
{
403
413
// Read a line of input from the console
404
- inputValue = console .readLine (_name + "@" + _presentWorkingDirectory .replace (_username , _name ) + "> " );
414
+ inputValue = console .readLine (_name + "@" + IOStreams . convertFileSeparator ( _presentWorkingDirectory ) .replace (_username , _name ) + "> " );
405
415
406
416
// Interpret and execute the command
407
417
grinchInterpreter (inputValue );
@@ -432,7 +442,8 @@ public void fileManagementLogic(String scriptFileName)throws Exception
432
442
else
433
443
{
434
444
// Check if the user is logged in
435
- if (login ()) {
445
+ if (login ())
446
+ {
436
447
// Initialize a stream to read the given file
437
448
BufferedReader br = new BufferedReader (new FileReader (scriptFileName ));
438
449
@@ -489,7 +500,7 @@ private void grinchInterpreter(String command)throws Exception
489
500
else
490
501
// Call the method to move the entity
491
502
copyMoveEntity (commandArray [1 ], commandArray [2 ], true );
492
- break ;
503
+ break ;
493
504
494
505
case "copy" :
495
506
case "cp" :
@@ -499,7 +510,7 @@ private void grinchInterpreter(String command)throws Exception
499
510
else
500
511
// Call the method to copy the entity
501
512
copyMoveEntity (commandArray [1 ], commandArray [2 ], false );
502
- break ;
513
+ break ;
503
514
504
515
case "delete" :
505
516
case "del" :
@@ -510,7 +521,7 @@ private void grinchInterpreter(String command)throws Exception
510
521
else
511
522
// Call the method to delete the entity
512
523
deleteEntity (commandArray [1 ]);
513
- break ;
524
+ break ;
514
525
515
526
case "rename" :
516
527
// Check if the command has the correct number of arguments
@@ -519,7 +530,7 @@ private void grinchInterpreter(String command)throws Exception
519
530
else
520
531
// Call the method to rename the entity
521
532
renameEntity (commandArray [1 ], commandArray [2 ]);
522
- break ;
533
+ break ;
523
534
524
535
case "mkdir" :
525
536
// Check if the command has the correct number of arguments
@@ -528,7 +539,7 @@ private void grinchInterpreter(String command)throws Exception
528
539
else
529
540
// Call the method to create a directory
530
541
makeDirectory (commandArray [1 ]);
531
- break ;
542
+ break ;
532
543
533
544
case "edit" :
534
545
// Check if the command has the correct number of arguments
@@ -537,7 +548,7 @@ private void grinchInterpreter(String command)throws Exception
537
548
else
538
549
// Call the method to edit a file
539
550
new FileWrite (_username ).editFile (commandArray [1 ], _presentWorkingDirectory );
540
- break ;
551
+ break ;
541
552
542
553
case "read" :
543
554
// Check if the command has the correct number of arguments
@@ -546,12 +557,12 @@ private void grinchInterpreter(String command)throws Exception
546
557
else
547
558
// Call the method to read a file
548
559
new FileRead (_username ).readUserFile (_presentWorkingDirectory + commandArray [1 ]);
549
- break ;
560
+ break ;
550
561
551
562
case "pwd" :
552
563
// Print the present working directory
553
564
IOStreams .println ((_presentWorkingDirectory ).replace (_username , _name ));
554
- break ;
565
+ break ;
555
566
556
567
case "cd" :
557
568
// Check if the command has the correct number of arguments
@@ -560,23 +571,23 @@ private void grinchInterpreter(String command)throws Exception
560
571
else
561
572
// Call the method to change the directory
562
573
changeDirectory (commandArray [1 ]);
563
- break ;
574
+ break ;
564
575
565
576
case "cd.." :
566
577
// Navigate to the previous directory
567
578
navPreviousDirectory ();
568
- break ;
579
+ break ;
569
580
570
581
case "tree" :
571
582
// Display the directory tree
572
583
viewDirectoryTree ();
573
- break ;
584
+ break ;
574
585
575
586
case "dir" :
576
587
case "ls" :
577
588
// List the entities in the current directory
578
589
listEntities ();
579
- break ;
590
+ break ;
580
591
581
592
case "download" :
582
593
// Check if the command has the correct number of arguments
@@ -585,17 +596,17 @@ private void grinchInterpreter(String command)throws Exception
585
596
else
586
597
// Call the method to download a file
587
598
new FileDownload (_username ).downloadFile (commandArray [1 ], commandArray [2 ]);
588
- break ;
599
+ break ;
589
600
590
601
case "home" :
591
602
// Reset to the home directory
592
603
resetToHomeDirectory ();
593
- break ;
604
+ break ;
594
605
595
606
case "exit" :
596
607
case "" :
597
608
// Exit the interpreter
598
- break ;
609
+ break ;
599
610
600
611
default :
601
612
// Pass the command to the Anvil interpreter for further processing
0 commit comments