初始配置新UI

This commit is contained in:
2026-02-07 13:25:15 +08:00
parent 84c4900f18
commit ae56d2f5b1

View File

@@ -306,87 +306,129 @@ namespace CMLeonOS
public void FirstTimeSetup() public void FirstTimeSetup()
{ {
Console.WriteLine("===================================="); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
Console.WriteLine(" First Time Setup"); global::System.Console.Clear();
Console.WriteLine("====================================");
Console.WriteLine();
Console.WriteLine("User Terms and Conditions:"); var titleBar = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(0, 0, 80, 3), "First Time Setup", () => { }, false);
Console.WriteLine("===================================="); titleBar.Render();
Console.WriteLine("1. This operating system is provided as-is without warranty");
Console.WriteLine("2. You are responsible for your data and backups"); var termsBox = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(5, 5, 70, 18), "User Terms and Conditions", () => { }, true);
Console.WriteLine("3. Unauthorized access attempts may be logged"); termsBox.Render();
Console.WriteLine("4. System administrators have full access to all data");
Console.WriteLine("5. By using this system, you agree to these terms"); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Gray, global::System.ConsoleColor.Black);
Console.WriteLine("6. Data privacy: Your personal data is stored locally"); global::System.Console.SetCursorPosition(7, 7);
Console.WriteLine("7. System updates may be installed automatically"); global::System.Console.WriteLine("1. This operating system is provided as-is without warranty");
Console.WriteLine("8. No liability for data loss or corruption"); global::System.Console.SetCursorPosition(7, 8);
Console.WriteLine("9. Support available at: leonmmcoset@outlook.com"); global::System.Console.WriteLine("2. You are responsible for your data and backups");
Console.WriteLine("10. This license is for personal use only"); global::System.Console.SetCursorPosition(7, 9);
Console.WriteLine("===================================="); global::System.Console.WriteLine("3. Unauthorized access attempts may be logged");
Console.WriteLine(); global::System.Console.SetCursorPosition(7, 10);
global::System.Console.WriteLine("4. System administrators have full access to all data");
global::System.Console.SetCursorPosition(7, 11);
global::System.Console.WriteLine("5. By using this system, you agree to these terms");
global::System.Console.SetCursorPosition(7, 12);
global::System.Console.WriteLine("6. Data privacy: Your personal data is stored locally");
global::System.Console.SetCursorPosition(7, 13);
global::System.Console.WriteLine("7. System updates may be installed automatically");
global::System.Console.SetCursorPosition(7, 14);
global::System.Console.WriteLine("8. No liability for data loss or corruption");
global::System.Console.SetCursorPosition(7, 15);
global::System.Console.WriteLine("9. Support available at: leonmmcoset@outlook.com");
global::System.Console.SetCursorPosition(7, 16);
global::System.Console.WriteLine("10. This license is for personal use only");
bool termsAccepted = false; bool termsAccepted = false;
while (!termsAccepted) while (!termsAccepted)
{ {
Console.Write("Do you accept the User Terms? (yes/no): "); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
string response = Console.ReadLine()?.ToLower(); global::System.Console.SetCursorPosition(5, 24);
global::System.Console.Write("Do you accept the User Terms? (yes/no): ");
string response = global::System.Console.ReadLine()?.ToLower();
if (response == "yes" || response == "y") if (response == "yes" || response == "y")
{ {
termsAccepted = true; termsAccepted = true;
Console.WriteLine("Terms accepted."); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Green, global::System.ConsoleColor.Black);
Console.WriteLine(); global::System.Console.SetCursorPosition(5, 24);
global::System.Console.Write("Terms accepted. ");
} }
else if (response == "no" || response == "n") else if (response == "no" || response == "n")
{ {
Console.WriteLine("You must accept the User Terms to continue."); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
Console.WriteLine("Please restart the setup process."); global::System.Console.SetCursorPosition(5, 24);
Thread.Sleep(2000); global::System.Console.Write("You must accept the User Terms to continue.");
global::System.Threading.Thread.Sleep(2000);
Sys.Power.Reboot(); Sys.Power.Reboot();
} }
else else
{ {
Console.WriteLine("Invalid response. Please enter 'yes' or 'no'."); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(5, 24);
global::System.Console.Write("Invalid response. Please enter 'yes' or 'no'.");
} }
} }
Console.WriteLine("Please set admin username and password:"); global::System.Console.Clear();
titleBar.Render();
Console.Write("Username: "); var setupBox = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(5, 5, 70, 12), "Admin Account Setup", () => { }, true);
string username = Console.ReadLine(); setupBox.Render();
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 7);
global::System.Console.Write("Username: ");
string username = global::System.Console.ReadLine();
while (string.IsNullOrWhiteSpace(username)) while (string.IsNullOrWhiteSpace(username))
{ {
ShowError("Username cannot be empty."); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
Console.Write("Username: "); global::System.Console.SetCursorPosition(7, 24);
username = Console.ReadLine(); global::System.Console.Write("Username cannot be empty. ");
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 7);
global::System.Console.Write("Username: ");
username = global::System.Console.ReadLine();
} }
Console.WriteLine("Password: "); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 8);
global::System.Console.Write("Password: ");
string password = ReadPassword(); string password = ReadPassword();
Console.WriteLine("Please confirm your password:"); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 9);
global::System.Console.Write("Confirm Password: ");
string confirmPassword = ReadPassword(); string confirmPassword = ReadPassword();
while (password != confirmPassword) while (password != confirmPassword)
{ {
ShowError("Passwords do not match. Please try again."); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 24);
Console.Write("Username: "); global::System.Console.Write("Passwords do not match. Please try again. ");
username = Console.ReadLine(); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 7);
global::System.Console.Write("Username: ");
username = global::System.Console.ReadLine();
while (string.IsNullOrWhiteSpace(username)) while (string.IsNullOrWhiteSpace(username))
{ {
ShowError("Username cannot be empty."); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
Console.Write("Username: "); global::System.Console.SetCursorPosition(7, 24);
username = Console.ReadLine(); global::System.Console.Write("Username cannot be empty. ");
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 7);
global::System.Console.Write("Username: ");
username = global::System.Console.ReadLine();
} }
Console.WriteLine("Password: "); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 8);
global::System.Console.Write("Password: ");
password = ReadPassword(); password = ReadPassword();
Console.WriteLine("Please confirm your password:"); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 9);
global::System.Console.Write("Confirm Password: ");
confirmPassword = ReadPassword(); confirmPassword = ReadPassword();
} }
@@ -400,39 +442,51 @@ namespace CMLeonOS
}; };
users.Add(adminUser); users.Add(adminUser);
SaveUsers(); SaveUsers();
ShowSuccess("Admin user created successfully!"); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Green, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 24);
global::System.Console.Write("Admin user created successfully! ");
Console.WriteLine(); global::System.Console.Clear();
Console.WriteLine("Please set system hostname:"); titleBar.Render();
Console.Write("Hostname: ");
string hostname = Console.ReadLine(); var hostnameBox = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(5, 5, 70, 8), "Hostname Setup", () => { }, true);
hostnameBox.Render();
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 7);
global::System.Console.Write("Hostname: ");
string hostname = global::System.Console.ReadLine();
while (string.IsNullOrWhiteSpace(hostname)) while (string.IsNullOrWhiteSpace(hostname))
{ {
ShowError("Hostname cannot be empty."); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
Console.Write("Hostname: "); global::System.Console.SetCursorPosition(7, 24);
hostname = Console.ReadLine(); global::System.Console.Write("Hostname cannot be empty. ");
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 7);
global::System.Console.Write("Hostname: ");
hostname = global::System.Console.ReadLine();
} }
if (users.Count > 0) if (users.Count > 0)
{ {
users[0].Hostname = hostname; users[0].Hostname = hostname;
SaveHostname(); SaveUsers();
ShowSuccess($"Hostname set to: {hostname}");
} }
Console.WriteLine(); CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Green, global::System.ConsoleColor.Black);
Console.WriteLine("System will restart in 3 seconds..."); global::System.Console.SetCursorPosition(7, 24);
Console.WriteLine("Please wait..."); global::System.Console.Write("Hostname set successfully! ");
Console.WriteLine(); global::System.Threading.Thread.Sleep(2000);
for (int i = 3; i > 0; i--) CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
{ global::System.Console.Clear();
Console.Write($"\rRestarting in {i} seconds... "); global::System.Console.SetCursorPosition(30, 12);
Thread.Sleep(1000); global::System.Console.Write("Setup completed!");
} global::System.Console.SetCursorPosition(20, 13);
global::System.Console.Write("System will restart in 3 seconds...");
global::System.Threading.Thread.Sleep(3000);
Console.WriteLine("\rRestarting now!");
Sys.Power.Reboot(); Sys.Power.Reboot();
} }
catch (Exception ex) catch (Exception ex)