-
Notifications
You must be signed in to change notification settings - Fork 2
/
Kernel.cs
351 lines (317 loc) · 15.2 KB
/
Kernel.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using Sys = Cosmos.System;
namespace minios
{
public class Kernel : Sys.Kernel
{
string version = "2019-03-19";
string pass = "";
string error = "Unknown command. For a complete list of commands use help."; //default case of switch case-unknown command
bool useruno = true;
public bool FSinit = false;
string current_path = @"0:\"; //root
public bool SudoY = false;
public string username = "User";
public static string file;
protected override void BeforeRun()
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
filesystem: //initialize filesystem
Console.Write("Do you want to enable the file system (Y/N)?");
var filesys = Console.ReadLine();
if (filesys == "Y" || filesys == "y")
{
FSinit = true;
Console.WriteLine("File System Will Be Initialized!");
var fs = new Sys.FileSystem.CosmosVFS(); //in built function to make a new file system
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
}
else if (filesys == "N" || filesys == "n")
{
Console.WriteLine("File System Will NOT Be Initialized!");
}
else
{
goto filesystem;
}
try
{
file_system.createDir("0:\\System86"); //initial directory creation
file_system.createDir("0:\\User");
file_system.createDir("0:\\User\\Documents");
Sys.KeyboardManager.SetKeyLayout(new Sys.ScanMaps.US_Standard()); //setting keyboard input layout to US standard
}
catch (Exception exc)
{
goto fatto;
}
fatto:
Console.Clear();
logo.Logo(version);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" ");
Console.WriteLine(" Successfully booted ");
Console.WriteLine(" ");
inizia:
Console.Write(username + " do you want to start?(Y/N)");
var sino = Console.ReadLine();
if (sino == "Y" || sino == "y")
{
Console.Clear();
Console.Write("Welcome to IOTA OS!!!!\n");
}
else if (sino == "N" || sino == "n")
{
Stop();
}
else
{
goto inizia;
}
}
protected override void Run()
{
Console.Write(current_path + "@root: ");
var input = Console.ReadLine();
var co = input;
var vars = "";
if (input.ToLower().IndexOf('/') != -1)
{
string[] parts = input.Split('/');
co = parts[0];
vars = parts[1];
}
try
{
switch (co)
{
case "reboot": //Reboots the machine
Cosmos.System.Power.Reboot();
break;
case "shutdown": //Shuts down the machine
if (useruno)
{
Console.WriteLine("now you can power off your system");
Stop();
}
else
{
Console.WriteLine("now you can power off your system");
Stop();
}
break;
case "clear": //Clears the screen
Console.Clear();
break;
case "help": //All the commands
Console.WriteLine("Help 1: Normal Commands");
Console.WriteLine("--------------------------------------------------------");
Console.WriteLine(" ");
Console.WriteLine("Reboot = reboot");
Console.WriteLine("Shutdown = shutdown");
Console.WriteLine("Clear = clear");
Console.WriteLine("About IOTA OS = about");
Console.WriteLine("Lock = lock");
Console.WriteLine("Print something on screen = print/things to print");
Console.WriteLine("Become user with sudo privilges = sudo");
Console.WriteLine("Help page 2 (FileSystem) = help2");
Console.WriteLine("Help page 3 (Calculator) = help3");
break;
case "help2":
Console.WriteLine("Help 2: FileSystem");
Console.WriteLine("--------------------------------------------------------");
Console.WriteLine(" ");
Console.WriteLine("Go to specified directory = cd/directory");
Console.WriteLine("Create directory = md/new directory's name");
Console.WriteLine("Show current directories = dir");
Console.WriteLine("Use basic text editor/ASII art = text_editor");
Console.WriteLine("Deletes the specified directory[sudo] = dd/directory*");
Console.WriteLine(" ");
Console.WriteLine("*type helpdir to know what directories not to delete");
break;
case "help3":
Console.WriteLine("Help 3: Calculator*");
Console.WriteLine("--------------------------------------------------------");
Console.WriteLine(" ");
Console.WriteLine("Add two numbers together = add/num1#num2");
Console.WriteLine("Subtract a number to an other = subtract/num1#num2");
Console.WriteLine("Muliply two numbers together = multiply/num1#num2");
Console.WriteLine("Divide one number with another number = divide/num1#num2");
Console.WriteLine("One nuber to the power of another = power/num1#num2");
Console.WriteLine("Least Common Number of two numbers = lcm/num1#num2");
Console.WriteLine("Greatest Common Factor of two numbers = gcf/num1#num2");
Console.WriteLine(" ");
Console.WriteLine("*it not works with decimals(0.1 for example)");
break;
case "help4":
Console.WriteLine("Help 4 : Miscellaneous");
Console.WriteLine("--------------------------------------------------------");
Console.WriteLine(" ");
Console.WriteLine("Play the game snake=run snake");
break;
case "helpdir":
Console.WriteLine("Do not delete the directories TEST, Testing and 0 because");
Console.WriteLine("they are system's directoryes and deleting them will cause");
Console.WriteLine("the Blue Screen of Error");
break; //HAIL BSOD .. guide to initiate BSOD ^_^ ^_^
case "lock":
Console.Write("Set Passcode: "); //user authentication
pass = Console.ReadLine();
sys_lock.lockpass(pass);
break;
case "print": //Prints something
Console.WriteLine(vars);
break;
case "about": //Some information
Console.WriteLine("IOTA OS Build:1.1.0");
break;
// ver command
case "cd": //Changes current directory
if (FSinit)
{
current_path = current_path + vars;
}
else
{
Console.WriteLine("File System Not Enabled!");
}
break;
case "md": // Makes new directory
if (FSinit)
{
file_system.createDir(current_path + vars);
}
else
{
Console.WriteLine("File System Not Enabled!");
}
break;
case "dir": // Displays current location
if (FSinit)
{
string[] back = file_system.readFiles(current_path);
string[] front = file_system.readDirectories(current_path);
string[] combined = new string[front.Length + back.Length];
Array.Copy(front, combined, front.Length);
Array.Copy(back, 0, combined, front.Length, back.Length);
foreach (var item in combined)
{
Console.WriteLine(item.ToString());
}
}
else
{
Console.WriteLine("File System Not Enabled!");
}
break;
case "add": // Adds given numbers
string[] inputvarsa = vars.Split('#');
Console.WriteLine(Calci.Add(inputvarsa[0], inputvarsa[1]));
break;
case "subtract": // Subtracts given numbers
string[] inputvarsb = vars.Split('#');
Console.WriteLine(Calci.Subtract(inputvarsb[0], inputvarsb[1]));
break;
case "multiply": // Multiplys given numbers
string[] inputvarsc = vars.Split('#');
Console.WriteLine(Calci.Multiply(inputvarsc[0], inputvarsc[1]));
break;
case "divide": // Divides given numbers
string[] inputvarsd = vars.Split('#');
Console.WriteLine(Calci.Divide(inputvarsd[0], inputvarsd[1]));
break;
case "power": // Raises given number to other given number
string[] inputvarse = vars.Split('#');
Console.WriteLine(Calci.ToPower(inputvarse[0], inputvarse[1]));
break;
case "gcd": // Gives gcd conversion of given numbers
string[] inputvarsf = vars.Split('#');
Console.WriteLine(Calci.GcdCon(inputvarsf[0], inputvarsf[1]));
break;
case "lcm": // Gives lcm conversion of given numbers
string[] inputvarsg = vars.Split('#');
Console.WriteLine(Calci.LcmCon(inputvarsg[0], inputvarsg[1]));
break;
case "text_editor": //text_editor
Console.Clear();
text_editor.init();
break;
case "open file": //open a file
Console.Clear();
Kernel.file = Console.ReadLine();
if (File.Exists(@"0:\" + Kernel.file))
{
string[] contents;
contents = file_system.readFile(file);
Console.Write(contents);
Console.ReadKey();
}
else if (!File.Exists(@"0:\" + Kernel.file))
{
Console.Write("No such file exists!");
}
break;
//case "BASIC": working on basic-style programming
//Console.Clear();
//Basic.init();
//break;
case "sudo": //Become sudo user
Console.Write("Are you sure to become a sudo user?(Y/N)");
var sicuro = Console.ReadLine();
if (sicuro == "Y" || sicuro == "y")
{
SudoY = true;
}
else
{
SudoY = false;
}
break;
case "dd": //delete directory
if (SudoY)
{
file_system.deleteDir(current_path + vars);
}
else
{
Console.WriteLine("I'm sorry, you aren't a sudo user");
}
break;
case "run snake": //game implementation
Snake snk = new Snake();
snk.Run();
break;
default:
Console.WriteLine(error);
break;
}
}
catch (Exception e) //BlueScreenOfDeath-like thing I wanted to make noerror false but it bugs
{
Console.BackgroundColor = ConsoleColor.Blue;
Console.Clear();
spegni:
Console.Write(" Do you want to reboot or shutdown?(R/S)");
var risp = Console.ReadLine();
if (risp == "R" || risp == "r")
{
Sys.Power.Reboot();
}
else if (risp == "S" || risp == "s")
{
Stop();
}
else
{
goto spegni;
}
}
}
}
}