Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
262 lines (261 loc) · 9.9 KB
/
Copy pathmain.cpp
File metadata and controls
262 lines (261 loc) · 9.9 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include <cstdio>
#include "FileSystem.h"
template<class T>
int getNum(T &a);
int main() {
FILE *associatedFile;
associatedFile = fopen("C:\\disk.txt", "r+");
if (associatedFile != nullptr) {
System::FileSystem sys(associatedFile);
int choice;
while (true) {
std::cout << "\n\n";
std::cout << "Choose options: " << std::endl
<< "0. exit" << std::endl
<< "1. pwd" << std::endl
<< "2. cd" << std::endl
<< "3. create dir in current directory" << std::endl
<< "4. create file in current directory" << std::endl
<< "5. move dir from current directory" << std::endl
<< "6. move file from current directory" << std::endl
<< "7. copy dir from current directory" << std::endl
<< "8. copy file from current directory" << std::endl
<< "9. delete dir from current directory" << std::endl
<< "10. delete file from current directory" << std::endl
<< "11. write to file" << std::endl
<< "12. edit file" << std::endl
<< "13. cat file" << std::endl
<< "14. info about system" << std::endl
<< "15. print current user" << std::endl
<< "16. info about file" << std::endl
<< "17. login as another user" << std::endl
<< "18. print table of users" << std::endl;
getNum(choice);
if (choice == 0)
break;
switch (choice) {
case 1: {
std::cout << "Current dir: " << sys.getPwd();
}
break;
case 2: {
std::string path;
std::cout << "Enter dir to go to: ";
std::cin >> path;
try {
sys.setCurrDir(path);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 3: {
std::string dirname;
std::cout << "Enter name of new dir: ";
std::cin >> dirname;
try {
sys.createDir(dirname);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 4: {
std::string filename;
std::cout << "Enter name of new file: ";
std::cin >> filename;
try {
sys.createFile(filename, sys.controlVirtualMem());
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 5: {
std::string dirname;
std::string path;
std::cout << "Enter name of dir from current directory you want to move: ";
std::cin >> dirname;
std::cout << "Enter path to move to: ";
std::cin >> path;
try {
sys.moveDir(dirname, path);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 6: {
std::string filename;
std::string path;
std::cout << "Enter name of file from current directory you want to move: ";
std::cin >> filename;
std::cout << "Enter path to move to: ";
std::cin >> path;
try {
sys.moveFile(filename, path);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 7: {
std::string dirname;
std::string path;
std::cout << "Enter name of dir from current directory you want to copy: ";
std::cin >> dirname;
std::cout << "Enter path to copy to: ";
std::cin >> path;
try {
sys.copyDir(dirname, path);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 8: {
std::string filename;
std::string path;
std::cout << "Enter name of file from current directory you want to copy: ";
std::cin >> filename;
std::cout << "Enter path to copy to: ";
std::cin >> path;
try {
sys.copyFile(filename, path);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 9: {
std::string dirname;
std::cout << "Enter name of dir from current directory you want to delete: ";
std::cin >> dirname;
try {
sys.deleteDir(dirname);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 10: {
std::string filename;
std::cout << "Enter name of file from current directory you want to delete: ";
std::cin >> filename;
try {
sys.deleteFile(filename);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 11: {
std::string filePath;
std::string data;
std::cout << "Enter path to file: ";
std::cin >> filePath;
std::cout << "Enter data: ";
std::cin >> data;
try {
sys.writeToFile(filePath, data);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 12: {
std::string filePath;
std::string toAdd;
std::cout << "Enter path to file: ";
std::cin >> filePath;
std::cout << "Enter data to add to file: ";
std::cin >> toAdd;
try {
sys.editFile(filePath, toAdd);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 13: {
std::string filePath;
std::cout << "Enter path to file: ";
std::cin >> filePath;
try {
std::cout << sys.catFile(filePath);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 14: {
std::cout << sys.infoSystem();
}
break;
case 15: {
std::cout << sys.getCurrUser()->getName();
}
break;
case 16: {
std::string filePath;
std::cout << "Enter path of your file: ";
std::cin >> filePath;
std::cout << sys.infoFile(filePath);
}
break;
case 17: {
std::string username;
std::cout << "Enter username: ";
std:: cin >> username;
try {
sys.login(username);
}
catch (std::invalid_argument &msg) {
std::cout << msg.what() << std::endl;
}
}
break;
case 18: {
std::cout << sys.tableOfUserInfo();
}
break;
default : {
std::cout << "Invalid type option. Try again.";
}
}
}
return 0;
}
else {
std::cout << "Cannot open file" << std::endl;
}
}
template<typename T>
int getNum(T &a) {
int indic;
do {
std::cin >> a;
indic = 1;
if (std::cin.eof())
indic = -1;
if (!std::cin.good()) {
std::cout << "Incorrect input. Try again" << std::endl;
indic = 0;
std::cin.clear();
std::cin.ignore(INT_MAX, '\n');
}
} while (indic == 0);
return indic < 0 ? -1 : 1;
}