-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystem.java
124 lines (101 loc) · 6.14 KB
/
FileSystem.java
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
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
/**
* CS320 Assignment 2
* File System
* @author rdow035 1414352
*/
public class FileSystem {
protected static FList fileStorage;
protected static DirectoryTree dirTree;
protected static int creationTime;
protected static CLI cli;
public static void main(String[] args) {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
String command;
// Initialize Data structures
fileStorage = new FList();
dirTree = new DirectoryTree();
// Create root folder
Link rootNodeLink = new Link("/", "", "folder");
dirTree.addNode(rootNodeLink, "", true, null);
dirTree.setCurrentNode(rootNodeLink);
F rootNodeFile = new F("", creationTime++, "12-12-2012", "root", "folder", 700);
fileStorage.insert(rootNodeFile);
rootNodeLink.setReference(rootNodeFile);
cli = new CLI();
try {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
ArrayList<String> commandList = new ArrayList<String>();
if(System.in.available() != 0) {
while(s.hasNext()) {
commandList.add(s.nextLine());
}
for(int i=0; i<commandList.size(); i++) {
System.out.print("> ");
command = commandList.get(i);
if(command.equals("quit")) break;
else if(command.equals("home")) cli.home();
else if(command.equals("listfiles")) cli.listfiles();
else if(command.startsWith("\"")) cli.comment(command);
else if(command.length()>=6 && command.substring(0, 6).equals("enter ")) cli.enter(command);
else if(command.length()>=5 && command.substring(0, 5).equals("enter")) cli.missingOperand(command.substring(0, 5));
else if(command.length()>=6 && command.substring(0, 6).equals("mkdir ")) cli.mkdir(command);
else if(command.length()>=5 && command.substring(0, 5).equals("mkdir")) cli.missingOperand(command.substring(0, 5));
else if(command.length()>=7 && command.substring(0, 7).equals("create ")) cli.create(command);
else if(command.length()>=6 && command.substring(0, 6).equals("create")) cli.missingOperand(command.substring(0, 6));
else if(command.length()>=7 && command.substring(0, 7).equals("append ")) cli.append(command);
else if(command.length()>=6 && command.substring(0, 6).equals("append")) cli.missingOperand(command.substring(0, 6));
else if(command.length()>=10 && command.substring(0, 10).equals("deleteall ")) cli.deleteall(command);
else if(command.length()>=9 && command.substring(0, 9).equals("deleteall")) cli.missingOperand(command.substring(0, 9));
else if(command.length()>=7 && command.substring(0, 7).equals("delete ")) cli.delete(command);
else if(command.length()>=6 && command.substring(0, 6).equals("delete")) cli.missingOperand(command.substring(0, 6));
else if(command.length()>=5 && command.substring(0, 5).equals("link ")) cli.link(command);
else if(command.length()>=4 && command.substring(0, 4).equals("link")) cli.missingOperand(command.substring(0, 4));
else if(command.length()>=5 && command.substring(0, 5).equals("show ")) cli.show(command);
else if(command.length()>=4 && command.substring(0, 4).equals("show")) cli.missingOperand(command.substring(0, 4));
else if(command.length()>=5 && command.substring(0, 5).equals("move ")) cli.move(command);
else if(command.length()>=4 && command.substring(0, 4).equals("move")) cli.missingOperand(command.substring(0, 4));
else if(command.equals("")) cli.setCurrentPath(cli.getCurrentPath());
else System.out.println("No command '"+command+"' found");
}
} else {
while(true) {
try {
System.out.print("> ");
command = inputReader.readLine().trim();
if(command.equals("quit")) break;
else if(command.equals("home")) cli.home();
else if(command.equals("listfiles")) cli.listfiles();
else if(command.startsWith("\"")) cli.comment(command);
else if(command.length()>=6 && command.substring(0, 6).equals("enter ")) cli.enter(command);
else if(command.length()>=5 && command.substring(0, 5).equals("enter")) cli.missingOperand(command.substring(0, 5));
else if(command.length()>=6 && command.substring(0, 6).equals("mkdir ")) cli.mkdir(command);
else if(command.length()>=5 && command.substring(0, 5).equals("mkdir")) cli.missingOperand(command.substring(0, 5));
else if(command.length()>=7 && command.substring(0, 7).equals("create ")) cli.create(command);
else if(command.length()>=6 && command.substring(0, 6).equals("create")) cli.missingOperand(command.substring(0, 6));
else if(command.length()>=7 && command.substring(0, 7).equals("append ")) cli.append(command);
else if(command.length()>=6 && command.substring(0, 6).equals("append")) cli.missingOperand(command.substring(0, 6));
else if(command.length()>=10 && command.substring(0, 10).equals("deleteall ")) cli.deleteall(command);
else if(command.length()>=9 && command.substring(0, 9).equals("deleteall")) cli.missingOperand(command.substring(0, 9));
else if(command.length()>=7 && command.substring(0, 7).equals("delete ")) cli.delete(command);
else if(command.length()>=6 && command.substring(0, 6).equals("delete")) cli.missingOperand(command.substring(0, 6));
else if(command.length()>=5 && command.substring(0, 5).equals("link ")) cli.link(command);
else if(command.length()>=4 && command.substring(0, 4).equals("link")) cli.missingOperand(command.substring(0, 4));
else if(command.length()>=5 && command.substring(0, 5).equals("show ")) cli.show(command);
else if(command.length()>=4 && command.substring(0, 4).equals("show")) cli.missingOperand(command.substring(0, 4));
else if(command.length()>=5 && command.substring(0, 5).equals("move ")) cli.move(command);
else if(command.length()>=4 && command.substring(0, 4).equals("move")) cli.missingOperand(command.substring(0, 4));
else if(command.equals("")) cli.setCurrentPath(cli.getCurrentPath());
else System.out.println("No command '"+command+"' found");
} catch(Exception e) {
System.out.println(e);
}
}
}
} catch(Exception e) {
System.out.println(e);
}
}
}