-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOS_Main.cs
More file actions
102 lines (101 loc) · 4.21 KB
/
DOS_Main.cs
File metadata and controls
102 lines (101 loc) · 4.21 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
namespace Gen_DOS{
public static class MainClass{
public static string currentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
private static string? input;
private static string[]? argumants;
private static string? comm;
private static string? val;
private static string? val2;
public static void Main(string[] args){
Console.WriteLine("using Gen_DOS version 5.1.0");
Directory.SetCurrentDirectory(currentDirectory);
do{
Console.Write($"{currentDirectory} ");
input = Console.ReadLine();
short access = configComm(input);
// commands for needs parameters
if(access == 2){
switch(comm){
case "chloc":
CommClass.chloc(val); break;
case "newdir":
CommClass.newdir(val); break;
case "write":
CommClass.write(val); break;
case "read":
CommClass.readfile(val); break;
case "del":
CommClass.delete(val); break;
case "modfile":
CommClass.modfile(val); break;
case "list":
CommClass.list(Path.Combine(currentDirectory, val)); break;
case "say":
CommClass.say(val); break;
case "run":
CommClass.run(val); break;
case "destroy":
CommClass.Destroy(Path.Combine(currentDirectory, val)); break;
default:
Console.WriteLine("Invalid command"); continue;
}
}
else if(access == 3){
switch(comm){
case "movefile":
CommClass.movefile(val, val2); break;
case "copyfile":
CommClass.copyfile(val, val2); break;
default:
Console.WriteLine("Invalid command"); continue;
}
}
// for commands that alone
else{
switch(input){
case "show":
CommClass.show(currentDirectory); break;
case "clear":
Console.Clear(); break;
case "desktop":
CommClass.desktop(); break;
case "list":
CommClass.list(currentDirectory); break;
case "help":
CommClass.help(); break;
case "hello":
CommClass.hello(); break;
default:
if (input != "end") Console.WriteLine("Invalid command"); continue;
}
}
} while(input != "end");
}
private static short configComm(string? input){
try{
if (input.Contains(" ")){
argumants = input.Split(" ");
short lenght = Convert.ToInt16(argumants.Length);
if (lenght == 2){
comm = argumants[0];
val = argumants[1];
return 2;
}
else if (lenght == 3){
comm = argumants[0];
val = argumants[1];
val2 = argumants[2];
return 3;
}
}
else if (string.IsNullOrEmpty(input)){
return -1; // empty input
}
return 1; // only command self
} catch(IndexOutOfRangeException){
Console.WriteLine("Invalid command or parameter name");
return -1;
}
}
}
}