-
Notifications
You must be signed in to change notification settings - Fork 2
/
Kernel.cs
287 lines (252 loc) · 11.8 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
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using Cosmos.System.FileSystem.VFS;
using Cosmos.System.FileSystem;
using System.Drawing;
using Cosmos.System.Graphics;
using Cosmos.System.Network;
using fixbuild.ChaseGraphicsAPI;
namespace fixbuild
{
public class Kernel : Sys.Kernel
{
private static Graphics gui;
public string cddefault;
CosmosVFS FileManager = new Sys.FileSystem.CosmosVFS();
protected override void BeforeRun()
{
Console.WriteLine("Welcome to ChaseOS, the calculator that can store files!");
Console.WriteLine("preparing file system");
Sys.FileSystem.VFS.VFSManager.RegisterVFS(FileManager);
Console.WriteLine("filesys created");
Console.WriteLine("internet loading");
Console.WriteLine("loading UI");
cddefault = @"0:/";
}
protected override void Run()
{
try
{
if (Kernel.gui != null)
{
Kernel.gui.MouseHandler();
return;
}
Console.Write(cddefault + " ChaseOS>");
string cmd = Console.ReadLine();
if (cddefault.EndsWith("/"))
{
}
else
{
cddefault = cddefault + "/";
}
if (cmd == "graphics")
{
Kernel.gui = new Graphics();
}
if (cmd == "shutdown")
{
Sys.Power.Shutdown();
}
if (cmd == "restart")
{
Sys.Power.Reboot();
}
if (cmd == "help")
{
Console.WriteLine("cmds: version, calc, readfile, ls, createfile, editfile, deletefile, help, createdirectory, removedirectory, cd, cdfullpath, time, settings, pwd");
}
if (cmd == "pwd")
{
Console.WriteLine(cddefault);
}
if (cmd == "version")
{
Console.WriteLine("Version: 6.0.0, ChaseOS is an Operating system which is a small project, there is no gui design.");
Console.WriteLine("Credits to Reese or chickendad#3076 for being a developer. Owner: Chase or dff#1307");
}
if (cmd == "createdirectory")
{
Console.WriteLine("directory name?");
string prefolder = Console.ReadLine();
FileManager.CreateDirectory(@cddefault + prefolder);
Console.WriteLine("Directory created.");
}
if (cmd == "cd")
{
Console.WriteLine("Path to get to?");
string precd = Console.ReadLine();
cddefault = @cddefault + precd;
Console.WriteLine("Now in path directory");
}
if (cmd == "cdfullpath")
{
Console.WriteLine("full path?");
string predest = Console.ReadLine();
cddefault = @predest;
}
if (cmd == "time")
{
Console.WriteLine(DateTime.Now.ToString());
}
//Do modifications here
// if statement syntax: if (a statement) {cool code}
if (cmd == "settings")
{
// ASK THEM FOR STUPID COLOR
Console.WriteLine("What color for text color?");
//WAIT FOR ANSWER
string color = Console.ReadLine();
//new if statement color.ToLower(0) = color lowercase
if (color.ToLower() == "blue")
{
// change color
Console.ForegroundColor = ConsoleColor.Blue;
}
// DO IT FOR ALL THE COLORS OK
// yes mam
if (color.ToLower() == "red")
{
Console.ForegroundColor = ConsoleColor.Red;
}
if (color.ToLower() == "yellow")
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
if (color.ToLower() == "green")
{
Console.ForegroundColor = ConsoleColor.Green;
}
if (color.ToLower() == "black")
{
Console.ForegroundColor = ConsoleColor.Black;
}
if (color.ToLower() == "white")
{
Console.ForegroundColor = ConsoleColor.White;
}
}
if (cmd == "calc")
{
// Declare variables and then initialize to zero.
int num1 = 0; int num2 = 0;
// Display title as the C# console calculator app.
Console.WriteLine("Console Calculator in C#\r");
Console.WriteLine("------------------------\n");
// Ask the user to type the first number.
Console.WriteLine("Type a number, and then press Enter");
// Ask the user to choose an option.
Console.WriteLine("Choose an option from the following list:");
Console.WriteLine("\ta - Add");
Console.WriteLine("\ts - Subtract");
Console.WriteLine("\tm - Multiply");
Console.WriteLine("\td - Divide");
Console.WriteLine("\tsq - Square");
Console.Write("Which option do you want to do? ");
// Use a switch statement to do the math.
switch (Console.ReadLine())
{
case "a":
Console.WriteLine("Enter a number");
num1 = Convert.ToInt32(Console.ReadLine());
// Ask the user to type the second number.
Console.WriteLine("Type another number, and then press Enter");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Your result: {num1} + {num2} = " + (num1 + num2));
break;
case "s":
Console.WriteLine("Enter a number");
num1 = Convert.ToInt32(Console.ReadLine());
// Ask the user to type the second number.
Console.WriteLine("Type another number, and then press Enter");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Your result: {num1} - {num2} = " + (num1 - num2));
break;
case "m":
Console.WriteLine("Enter a number");
num1 = Convert.ToInt32(Console.ReadLine());
// Ask the user to type the second number.
Console.WriteLine("Type another number, and then press Enter");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Your result: {num1} * {num2} = " + (num1 * num2));
break;
case "d":
Console.WriteLine("Enter a number");
num1 = Convert.ToInt32(Console.ReadLine());
// Ask the user to type the second number.
Console.WriteLine("Type another number, and then press Enter");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Your result: {num1} / {num2} = " + (num1 / num2));
break;
case "sq":
Console.WriteLine("What number to square?");
num1 = Convert.ToInt32(Console.ReadLine());
// Ask the user to type the second number.
Console.WriteLine($"Your result: " + num1 + " * " + num1 + " = " + (num1 * num1));
break;
}
// Wait for the user to respond before closing.
Console.Write("Press any key to close the Calculator console app...");
Console.ReadKey();
}
if (cmd == "removedirectory")
{
Console.WriteLine("Directory?");
string predir = Console.ReadLine();
FileManager.DeleteDirectory(FileManager.GetDirectory(@cddefault + predir));
}
if (cmd == "createfile")
{
Console.WriteLine("filename");
string filename = Console.ReadLine();
Sys.FileSystem.VFS.VFSManager.CreateFile(@cddefault + filename);
}
if (cmd == "editfile")
{
Console.WriteLine("filename");
string filename1 = Console.ReadLine();
var file = Sys.FileSystem.VFS.VFSManager.GetFile(@cddefault + filename1);
var filestream = file.GetFileStream();
Console.WriteLine("contents");
string contents = Console.ReadLine();
byte[] data = Encoding.ASCII.GetBytes(contents);
filestream.Write(data, 0, (int)contents.Length);
Console.WriteLine("file edited sucessfully");
}
if (cmd == "deletefile")
{
Console.WriteLine("Enter the name of the file");
string prefilename2 = Console.ReadLine();
var preprefilename2 = Sys.FileSystem.VFS.VFSManager.GetFile(@cddefault + prefilename2);
FileManager.DeleteFile(preprefilename2);
}
if (cmd == "ls")
{
var directory_list = Sys.FileSystem.VFS.VFSManager.GetDirectoryListing(@cddefault);
foreach (var directoryEntry in directory_list)
{
Console.WriteLine(directoryEntry.mName);
}
}
if (cmd == "readfile")
{
Console.WriteLine("filename");
var prefile = Console.ReadLine();
var file = Sys.FileSystem.VFS.VFSManager.GetFile(@cddefault + prefile).GetFileStream();
byte[] data = new byte[file.Length];
file.Read(data, 0, (int)file.Length);
Console.WriteLine(Encoding.Default.GetString(data));
}
}
catch (Exception e)
{
Console.WriteLine("oh no your code just got downed");
Console.WriteLine("how to revive: fix " + e.ToString());
BeforeRun();
}
}
}
}