初始配置新UI

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

View File

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