-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
519 lines (465 loc) · 16.4 KB
/
main.cpp
File metadata and controls
519 lines (465 loc) · 16.4 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#include "header.h"
//-------------------------------------------------------
User U;
vector <User> Log;
int p[3],U_Type=-1;
string CMD, ROOT="%USERPROFILE%\\Desktop\\FMS_Root", PATH=ROOT;
string Date_Time()
{
struct tm *tmp;
char MY_TIME[50];
time_t t = time(0);
tmp = localtime( &t );
strftime(MY_TIME, sizeof(MY_TIME), "%A : %d %B, %Y - %I:%M%p", tmp);
return MY_TIME;
}
//-------------------------------------------------------
int Hash_Table::hash(string str)
{
int G=12,SEED=19,i,n,next,result,val=0;
n = str.rfind(".");
if(n!=-1)
for(i=0;i<n;i++)
val += str[i];
else
for(i=0;i<str.size();i++)
val+=str[i];
val = val % SIZE;
SEED = SEED % SIZE;
next = SEED ^ val;
result = G;
next = next<<7;
next = next%SIZE;
result = result^next;
result = result+val;
result = result%SIZE;
return result;
}
int Hash_Table::Copy_Paste(Hash_Table& T)
{
int n;
string temp,src,New;
cout<<"Enter name of the source file/folder:\n";
cin.ignore();
getline(cin,temp);
Folder* fo=D_Search(temp);
vector <File*> fi=Search(temp);
if(!fo && !fi.size())
return 1; //No such File Exists!
if(!p[1])
if(!U.Admin_access())
return 2; //Permission denied!
cout<<"Enter path of the destination file/folder:\n";
getline(cin,New);
Write_Data(T);
src=PATH+"\\";
New=ROOT+"\\"+New;
temp=PATH;
PATH=New;
Read_Data(T);
system("cls");
if(fo)
{
Folder F;
F.size=0;
F.name=fo->name;
F.CDT=Date_Time();
Fentry[hash(F.name)].push_back(F);
CMD="xcopy \""+src+F.name+"\" \""+New+"\\"+F.name+"\" /E /I";
system(CMD.c_str());
cout<<F<<endl;
}
if(fi.size())
{
File F;
for(int i=0;i<fi.size();i++)
{
F.name = fi[i]->name;
F.CDT = Date_Time();
F.extension = fi[i]->extension;
F.size=0;
entry[hash(F.name)].push_back(F);
CMD="copy \""+src+F.name+"\" \""+New+"\"";
system(CMD.c_str());
cout<<F<<endl;
}
}
Write_Data(T);
PATH=temp;
Read_Data(T);
system("cls");
return 0;
}
void Hash_Table::Show()
{
int i,j;
cout<<"\nFiles' Hash Table:\n";
for(i=0;i<SIZE;i++)
{
cout<<i<<"\t";
for(j=0;j<entry[i].size();j++)
cout<<entry[i][j].name<<" ---> ";
cout<<"."<<endl;
}
cout<<"\n==============================================\n";
cout<<"\nFolders' Hash Table:\n";
for(i=0;i<SIZE;i++)
{
cout<<i<<"\t";
for(j=0;j<Fentry[i].size();j++)
cout<<Fentry[i][j].name<<" ---> ";
cout<<"."<<endl;
}
}
//-------------------------------------------------------
void Write_Data(Hash_Table& T)
{
int i,j;
fstream f;
string src=PATH+"\\$data.txt";
f.open(src.c_str(),ios::out|ios::trunc);
for(i=0;i<SIZE;i++)
for(j=0;j<T.entry[i].size();j++)
f<<T.entry[i][j];
f<<"=============================================\n";
for(i=0;i<SIZE;i++)
for(j=0;j<T.Fentry[i].size();j++)
f<<T.Fentry[i][j];
for(i=0;i<SIZE;i++)
{
T.entry[i].clear();
T.Fentry[i].clear();
}
f.close();
}
void Read_Data(Hash_Table& T)
{
fstream f;
File F;
Folder FO;
string src=PATH+"\\$data.txt";
f.open(src.c_str(),ios::in);
if(!f) return;
while(!f.eof())
{
getline(f,src);
if(src=="=============================================")
break;
F.name=src;
f>>F.extension;
f>>F.size;
f.ignore();
getline(f,F.CDT);
f.ignore();
T.entry[T.hash(F.name)].push_back(F);
}
f.ignore();
while(!f.eof())
{
getline(f,FO.name);
f>>FO.size;
f.ignore();
getline(f,FO.CDT);
f.ignore();
T.Fentry[T.hash(FO.name)].push_back(FO);
}
f.close();
}
//-------------------------------------------------------
void EXEQ()
{
int i,n=0,ch;
string s,s2;
Folder* T;
vector <File*> S;
Hash_Table HT;
Read_Data(HT);
while(s!="Signed Out!")
{
n=0;
T=NULL;
S.clear();
system("cls");
cout<<"\n------------------------------------------------------------------";
cout<<"\n\t --------: File Management System :--------";
cout<<"\n------------------------------------------------------------------";
cout<<"\n01.\t Create a file.";
cout<<"\n02.\t Rename a file.";
cout<<"\n03.\t Search a file.";
cout<<"\n04.\t Delete a file.";
cout<<"\n05.\t Launch a file.";
cout<<"\n06.\t File Description.";
cout<<"\n07.\t Create a directory.";
cout<<"\n08.\t Rename a directory.";
cout<<"\n09.\t Search a directory.";
cout<<"\n10.\t Delete a directory.";
cout<<"\n11.\t Folder Description.";
cout<<"\n12.\t Move up to Parent Directory.";
cout<<"\n13.\t Move in to a Child Directory.";
cout<<"\n14.\t List the Directory.";
cout<<"\n15.\t Create a Shortcut.";
cout<<"\n16.\t Copy & Paste.";
cout<<"\n17.\t View Hash Table.";
cout<<"\n18.\t Sign Out.";
cout<<"\n=================================================================";
cout<<"\nEnter your choice : ";
cin>>ch;
cout<<"=================================================================\n\n";
switch(ch)
{
case 1: cout<<"Enter the filename : ";
cin.ignore();
getline(cin,s);
n=HT.Create(s);
if(!n)
cout<<"\nFile created."<<endl;
else if(n==1)
cout<<"\nInvalid Input!!!!!\nNo Extension specified.";
else if(n==2)
cout<<"\nInvalid Input!!!!!\nFile with same name already exists.";
else if(n==3)
cout<<"\nPermission Denied! Admin access required.";
getch();
break;
case 2: cout<<"Enter old name : ";
cin.ignore();
getline(cin,s);
cout<<"Enter New name: ";
getline(cin,s2);
n=HT.Rename(s,s2);
if(!n)
cout<<"\nFile "<<s<<" renamed.";
else if(n==1)
cout<<"\nInvalid Input!!!!!\nPlease Enter full name.";
else if(n==2)
cout<<"\nInvalid Input!!!!!\nFilename already exists.";
else if(n==3)
cout<<"\nInvalid Input!!!!!\nNo such file found.";
else if(n==4)
cout<<"\nPermission Denied! Admin access required.";
else if(n==5)
cout<<"\nInvalid Input!!!!!\nFile's extension can't be changed.";
getch();
break;
case 3: cout<<"File to be searched : ";
cin.ignore();
getline(cin,s);
S=HT.Search(s);
if(!S.size())
cout<<endl<<s<<" Not Found!"<<endl;
else
{
cout<<"\nFound Matches:\n";
for(i=0;i<S.size();i++)
cout<<*S[i]<<endl;
}
getch();
break;
case 4: cout<<"File to be Deleted : ";
cin.ignore();
getline(cin,s);
n=HT.Delete(s);
if(!n)
cout<<"\nFile "<<s<<" deleted.";
else if(n==1)
cout<<"\nInvalid Input!!!!!\nPlease Enter full name.";
else if(n==2)
cout<<"\nInvalid Input!!!!!\nNo such file found.";
else if(n==3)
cout<<"\nPermission Denied! Admin access required.";
getch();
break;
case 5: cout<<"Enter file to be opened : ";
cin.ignore();
getline(cin,s);
n=HT.Open(s);
if(!n)
cout<<"\n"<<s<<" opened.";
else if(n==1)
cout<<"\nInvalid Input!!!!!\nPlease Enter full name.";
else if(n==2)
cout<<"\nInvalid Input!!!!!\nNo such file found.";
getch();
break;
case 6: cout<<"Enter the file name: ";
cin.ignore();
getline(cin,s);
HT.Describe(s);
getch();
break;
case 7: cout<<"Enter the folder name: ";
cin.ignore();
getline(cin,s);
n=HT.D_Create(s);
if(!n)
cout<<"\nFolder created."<<endl;
else if(n==1)
cout<<"\nInvalid Input!!!!!\nName Already exists.";
else if(n==2)
cout<<"\nPermission Denied! Admin access required.";
getch();
break;
case 8: cout<<"Enter the Folder name: ";
cin.ignore();
getline(cin,s);
cout<<"Enter the New name: ";
getline(cin,s2);
n=HT.D_Rename(s,s2);
if(!n)
cout<<"\nFolder "<<s<<" renamed.";
else if(n==1)
cout<<"\nInvalid Input!!!!!\nNo such folder found.";
else if(n==2)
cout<<"\nPermission Denied! Admin access required.";
getch();
break;
case 9: cout<<"Enter the folder name: ";
cin.ignore();
getline(cin,s);
T=HT.D_Search(s);
if(T)
cout<<"\nFound Match:\n"<<*T<<endl;
else
cout<<endl<<s<<" Not Found!"<<endl;
getch();
break;
case 10: cout<<"Enter the folder name: ";
cin.ignore();
getline(cin,s);
n=HT.D_Delete(s);
if(!n)
cout<<"\nFolder "<<s<<" deleted.";
else if(n==1)
cout<<"\nInvalid Input!!!!!\nNo such folder found.";
else if(n==2)
cout<<"\nPermission Denied! Admin access required.";
getch();
break;
case 11: cout<<"Enter the folder name: ";
cin.ignore();
getline(cin,s);
HT.D_Describe(s);
getch();
break;
case 12: n=HT.D_MoveUp(HT);
if(n)
cout<<"\nInvalid Input!!!!!\nThis is the Root Directory!";
getch();
break;
case 13: cout<<"Enter the folder name: ";
cin.ignore();
getline(cin,s);
n=HT.D_MoveDown(HT,s);
if(n)
cout<<"\nInvalid Input!!!!!\nNo such folder found.";
getch();
break;
case 14: HT.D_List();
getch();
break;
case 15: n=HT.Shortcut(HT);
if(!n)
cout<<"\nShortcut created."<<endl;
else if(n==1)
cout<<"\nInvalid Input!!!!!\nNo such Folder exists.";
else if(n==2)
cout<<"\nPermission Denied! Admin access required.";
getch();
break;
case 16: n=HT.Copy_Paste(HT);
if(!n)
cout<<"\nFiles Copied."<<endl;
else if(n==1)
cout<<"\nInvalid Input!!!!!\nNo such File/Folder exists.";
else if(n==2)
cout<<"\nPermission Denied! Admin access required.";
getch();
break;
case 17: HT.Show();
getch();
break;
case 18: Write_Data(HT);
system("cls");
U.Sign_out(s);
break;
default: cout<<"Please Enter a valid Choice !!!!!!\n";
Sleep(1500);
cin.clear();
cin.ignore(100, '\n');
break;
}
}
}
//-------------------------------------------------------
int main()
{
int n;
CMD="mkdir "+PATH;
system(CMD.c_str());
system("cls");
User P;
P.id="admin";
P.pw="kernel";
P.admin=1;
Log.push_back(P);
while(1)
{
system("cls");
cout<<"\n------------------------------------------------------------------";
cout<<"\n\t --------: File Management System :--------";
cout<<"\n------------------------------------------------------------------";
cout<<"\n01.\t Sign In.";
cout<<"\n02.\t Sign Up.";
cout<<"\n03.\t Change Password.";
cout<<"\n04.\t Shutdown.";
cout<<"\n=================================================================";
cout<<"\nEnter your choice : ";
cin>>n;
cout<<"=================================================================\n\n";
switch(n)
{
case 1: n=U.Sign_in();
if(!n)
{
system("cls");
cout<<"\n\n\n\t\t\tWelcome "<<U.id<<" !";
Sleep(1200);
EXEQ();
}
else if(n==1)
cout<<"\nNo such user found!";
else if(n==2)
cout<<"\nInvalid Password!";
Sleep(1500);
break;
case 2: n=U.Sign_up();
if(!n)
cout<<"\nAccount created.";
else if(n==1)
cout<<"\nUsername already exists!";
else if(n==2)
cout<<"\nInvalid Admin Password!";
Sleep(1500);
break;
case 3: n=U.change();
if(!n)
cout<<"\nPassword changed.";
else if(n==1)
cout<<"\nNo such user found!";
else if(n==2)
cout<<"\nInvalid Password!";
Sleep(1500);
break;
case 4: system("cls");
cout<<"\n\n\n\t\t\tShutting Down.....\n\n\n\n\n\n\n\n\n\n\n\n";
Sleep(1200);
return 0;
break;
default: cout<<"Please Enter a valid Choice !!!!!!\n";
Sleep(1500);
cin.clear();
cin.ignore(100, '\n');
break;
}
}
}