mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
以后就不需要再去PE格式化硬盘了,爽!!
This commit is contained in:
90
Kernel.cs
90
Kernel.cs
@@ -40,6 +40,13 @@ namespace CMLeonOS
|
||||
[IL2CPU.API.Attribs.ManifestResourceStream(ResourceName = "CMLeonOS.font.psf")]
|
||||
public static readonly byte[] file;
|
||||
|
||||
public static void ShowError(string message)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"{message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
protected override void BeforeRun()
|
||||
{
|
||||
// 我认了,我用默认字体
|
||||
@@ -243,6 +250,70 @@ namespace CMLeonOS
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.Message.Contains("Read only"))
|
||||
{
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.Clear();
|
||||
|
||||
var formatWindow = new CMLeonOS.UI.Window(
|
||||
new CMLeonOS.UI.Rect(10, 5, 60, 12),
|
||||
"Format Disk",
|
||||
() => { },
|
||||
true
|
||||
);
|
||||
formatWindow.Render();
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(12, 8);
|
||||
global::System.Console.Write("Disk not formatted");
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Yellow, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(12, 9);
|
||||
global::System.Console.Write("Warning: This will erase all data!");
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(12, 11);
|
||||
global::System.Console.Write("Press any key to format...");
|
||||
|
||||
global::System.Console.ReadKey();
|
||||
|
||||
try {
|
||||
Disk targetDisk = fs.Disks[0];
|
||||
CreateMBRandPartitionTable(targetDisk);
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Green, global::System.ConsoleColor.Black);
|
||||
global::System.Console.Clear();
|
||||
formatWindow.Render();
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(12, 8);
|
||||
global::System.Console.Write("Disk formatted successfully!");
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(12, 9);
|
||||
global::System.Console.Write("Restarting in 3 seconds...");
|
||||
|
||||
System.Threading.Thread.Sleep(3000);
|
||||
Sys.Power.Reboot();
|
||||
}
|
||||
catch (Exception exe)
|
||||
{
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
|
||||
global::System.Console.Clear();
|
||||
formatWindow.Render();
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(12, 8);
|
||||
global::System.Console.Write("Format failed!");
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(12, 9);
|
||||
global::System.Console.Write($"Error: {exe.Message}");
|
||||
|
||||
global::System.Console.ReadKey();
|
||||
}
|
||||
}
|
||||
else{
|
||||
Console.Clear();
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
@@ -254,6 +325,7 @@ namespace CMLeonOS
|
||||
Console.WriteLine("Press any keys to restart.");
|
||||
Console.ReadKey();
|
||||
Sys.Power.Reboot();
|
||||
}
|
||||
// try {
|
||||
// Disk targetDisk = fs.Disks[0];
|
||||
// CreateMBRandPartitionTable(targetDisk);
|
||||
@@ -268,18 +340,18 @@ namespace CMLeonOS
|
||||
}
|
||||
|
||||
// 我他妈居然成功了,我在没有任何文档的情况下研究出来了
|
||||
// private void CreateMBRandPartitionTable(Disk disk)
|
||||
// {
|
||||
// disk.Clear();
|
||||
// ulong diskSize = (ulong)(disk.Size / 1024 / 1024);
|
||||
// uint partSize = (uint)(diskSize - 2);
|
||||
private void CreateMBRandPartitionTable(Disk disk)
|
||||
{
|
||||
disk.Clear();
|
||||
ulong diskSize = (ulong)(disk.Size / 1024 / 1024);
|
||||
uint partSize = (uint)(diskSize - 2);
|
||||
|
||||
// disk.CreatePartition((int)partSize);
|
||||
disk.CreatePartition((int)partSize);
|
||||
|
||||
// var part = disk.Partitions[disk.Partitions.Count - 1];
|
||||
// disk.FormatPartition(0, "FAT32", true);
|
||||
var part = disk.Partitions[disk.Partitions.Count - 1];
|
||||
disk.FormatPartition(0, "FAT32", true);
|
||||
// Console.WriteLine($"Partition type: {part.GetType()}");
|
||||
// }
|
||||
}
|
||||
|
||||
private void ExecuteStartupScript()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user