This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuldrv.cs
179 lines (164 loc) · 7.18 KB
/
tuldrv.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
using Cosmos.Core.Memory;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ziOS.Libs;
using ziOS.ziSH;
namespace ziOS
{
public class tuldrv
{
public static string Syspath = "0:\\";
public static List<string> CommandHistory = new List<string>();
public static List<string> SyscallContext = new List<string>();
public static List<string> SyscallOut = new List<string>();
public static bool DisableFS = false;
/// <summary>
/// Displays text in VGA text mode with color using one statement.
/// </summary>
/// <param name="s">The text you want to color.</param>
/// <param name="c">The color you want the text to be colored in</param>
public static void ColorTextMode(string s, ConsoleColor c)
{
ConsoleColor oldc = Console.ForegroundColor;
Console.ForegroundColor = c;
Console.Write(s);
Console.ForegroundColor = oldc;
}
/// <summary>
/// A yes/no menu.
/// </summary>
/// <returns>Boolean saying if user said Y or N.</returns>
public static bool YNmenu()
{
while (true)
{
var key = System.Console.ReadKey(true);
if (key.Key == ConsoleKey.N)
return false;
if (key.Key == ConsoleKey.Y)
return true;
}
}
/// <summary>
/// choosing menu. 9 MAX.
/// </summary>
/// <param name="Options">The options you want the user to choose from.</param>
/// <returns>What the user chose.</returns>
public static byte MenuNoGraphics(string[] Options)
{
Console.WriteLine("Please choose a number from 0 to " + Options.Length);
for (int i = 0; i < Options.Length; i++)
{
Console.WriteLine($"{i}. {Options[i]}");
}
while (true)
{
byte Outp = 255;
var key = System.Console.ReadKey(true);
byte.TryParse(key.KeyChar.ToString(), out Outp);
if (Outp > Options.Length)
{
}
else
{
return Outp;
}
}
}
public static void KernelPanic(Exception e)
{
if (Kernel.canvas == null || Kernel.canvas.Width <= 0 || Kernel.canvas.Height <= 0)
{
Console.WriteLine("ziOS X Critical System Error");
Console.WriteLine(e.Message);
Console.WriteLine(e.GetType().Name);
Console.WriteLine("The system cannot continue.");
while (true) { }
}
else
{
Kernel.canvas.Clear(PrismGraphics.Color.Black);
LibTerm.UImode = false;
LibTerm.WriteLine(" .. ziOS has CRASHed!");
LibTerm.WriteLine(" .*+: : ");
LibTerm.WriteLine(" +#*#* -*%+ Error: " + e.Message);
LibTerm.WriteLine(" .: *%%%=..+%##: ");
LibTerm.WriteLine(" *%***:::+**##+: ");
LibTerm.WriteLine(" .-+=:#+****#- If you continue to get this error even after a reboot, try these following tips:");
LibTerm.WriteLine(" +=+=++**+=-:-=*#- ");
LibTerm.WriteLine(" -++#******++=***# 1. Disable or remove any hardware that is not necessary.");
LibTerm.WriteLine(" .-++=---=***#: This can include USB/PCI devices. Networking is not available yet.");
LibTerm.WriteLine(" .++=--*#***##. 2. Disable any BIOS options that modern operating systems might use.");
LibTerm.WriteLine(" .**###%###**#= Because this OS is about on par with ancient Linux.");
LibTerm.WriteLine(" -***##%%%**##= 3. If you need to disable a feature, such as the file system, restart");
LibTerm.WriteLine(" --:==######- your computer and hold shift, then choose an option and ziOS will start in that mode.");
LibTerm.WriteLine(" ++**#: 4. go back to 1992 linux and fix os youself >:]");
LibTerm.WriteLine(" ==**+ ");
LibTerm.WriteLine(" :**+*# ");
LibTerm.WriteLine(" :##+=+#. ");
LibTerm.WriteLine(" :+##+=*#: ");
LibTerm.WriteLine(" :=*%#+=+*= Hope you don't have to meet crash in this OS again!");
LibTerm.WriteLine(" -++#%*==*#- ");
LibTerm.WriteLine(" =++#%**++*# ");
LibTerm.WriteLine(" .:## :+**: Error type: " + e.GetType().Name);
LibTerm.WriteLine(" ::. -*##:.:=#= ");
LibTerm.WriteLine(" -##############%%%: ");
LibTerm.WriteLine(" :+++====*##########* Crash Bandicoot lies in crashed OS.");
LibTerm.WriteLine(" : :=+=. The system is halted.");
while (true) { }
}
}
public static void GenerateConfigFile()
{
string[] lines =
{
"// Default Hostname",
"omniverse"
};
File.WriteAllLines(@"0:\zios.cfg",lines);
}
public static void Error(string s, string caller)
{
LibTerm.ForegroundC = PrismGraphics.Color.GoogleRed;
LibTerm.WriteLine(caller + ": " + s);
LibTerm.ForegroundC = PrismGraphics.Color.White;
}
public static void Success()
{
LibTerm.ForegroundC = PrismGraphics.Color.GoogleGreen;
LibTerm.WriteLine("The operation completed successfully.");
LibTerm.ForegroundC = PrismGraphics.Color.White;
}
/// <summary>
/// Converts an input string into a hex string. It returns the hex string.
/// </summary>
/// <param name="input">What you want to convert to hex.</param>
/// <returns></returns>
public static string ConvertToHex(string input)
{
byte[] bytes = Encoding.Default.GetBytes(input);
string hexString = BitConverter.ToString(bytes);
hexString = hexString.Replace("-", " ");
return hexString;
}
public static void ParseShellScript(string path)
{
if (File.Exists(path))
{
string[] AutoExecLines = File.ReadAllLines(path);
foreach (string AutoExecCmd in AutoExecLines)
{
CmdHandler.Handle(AutoExecCmd);
Heap.Collect();
}
} else
{
throw new Exception("\"" + path +"\" doesn't exist");
}
}
}
}