mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
初始配置新UI
This commit is contained in:
@@ -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();
|
var titleBar = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(0, 0, 80, 3), "First Time Setup", () => { }, false);
|
||||||
|
titleBar.Render();
|
||||||
Console.WriteLine("User Terms and Conditions:");
|
|
||||||
Console.WriteLine("====================================");
|
var termsBox = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(5, 5, 70, 18), "User Terms and Conditions", () => { }, true);
|
||||||
Console.WriteLine("1. This operating system is provided as-is without warranty");
|
termsBox.Render();
|
||||||
Console.WriteLine("2. You are responsible for your data and backups");
|
|
||||||
Console.WriteLine("3. Unauthorized access attempts may be logged");
|
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Gray, global::System.ConsoleColor.Black);
|
||||||
Console.WriteLine("4. System administrators have full access to all data");
|
global::System.Console.SetCursorPosition(7, 7);
|
||||||
Console.WriteLine("5. By using this system, you agree to these terms");
|
global::System.Console.WriteLine("1. This operating system is provided as-is without warranty");
|
||||||
Console.WriteLine("6. Data privacy: Your personal data is stored locally");
|
global::System.Console.SetCursorPosition(7, 8);
|
||||||
Console.WriteLine("7. System updates may be installed automatically");
|
global::System.Console.WriteLine("2. You are responsible for your data and backups");
|
||||||
Console.WriteLine("8. No liability for data loss or corruption");
|
global::System.Console.SetCursorPosition(7, 9);
|
||||||
Console.WriteLine("9. Support available at: leonmmcoset@outlook.com");
|
global::System.Console.WriteLine("3. Unauthorized access attempts may be logged");
|
||||||
Console.WriteLine("10. This license is for personal use only");
|
global::System.Console.SetCursorPosition(7, 10);
|
||||||
Console.WriteLine("====================================");
|
global::System.Console.WriteLine("4. System administrators have full access to all data");
|
||||||
Console.WriteLine();
|
global::System.Console.SetCursorPosition(7, 11);
|
||||||
|
global::System.Console.WriteLine("5. By using this system, you agree to these terms");
|
||||||
bool termsAccepted = false;
|
global::System.Console.SetCursorPosition(7, 12);
|
||||||
while (!termsAccepted)
|
global::System.Console.WriteLine("6. Data privacy: Your personal data is stored locally");
|
||||||
{
|
global::System.Console.SetCursorPosition(7, 13);
|
||||||
Console.Write("Do you accept the User Terms? (yes/no): ");
|
global::System.Console.WriteLine("7. System updates may be installed automatically");
|
||||||
string response = Console.ReadLine()?.ToLower();
|
global::System.Console.SetCursorPosition(7, 14);
|
||||||
|
global::System.Console.WriteLine("8. No liability for data loss or corruption");
|
||||||
if (response == "yes" || response == "y")
|
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")
|
|
||||||
{
|
global::System.Console.Clear();
|
||||||
Console.WriteLine("You must accept the User Terms to continue.");
|
titleBar.Render();
|
||||||
Console.WriteLine("Please restart the setup process.");
|
|
||||||
Thread.Sleep(2000);
|
var setupBox = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(5, 5, 70, 12), "Admin Account Setup", () => { }, true);
|
||||||
Sys.Power.Reboot();
|
setupBox.Render();
|
||||||
}
|
|
||||||
else
|
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||||
{
|
global::System.Console.SetCursorPosition(7, 7);
|
||||||
Console.WriteLine("Invalid response. Please enter 'yes' or 'no'.");
|
global::System.Console.Write("Username: ");
|
||||||
}
|
string username = global::System.Console.ReadLine();
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Please set admin username and password:");
|
|
||||||
|
|
||||||
Console.Write("Username: ");
|
|
||||||
string username = Console.ReadLine();
|
|
||||||
|
|
||||||
while (string.IsNullOrWhiteSpace(username))
|
|
||||||
{
|
|
||||||
ShowError("Username cannot be empty.");
|
|
||||||
Console.Write("Username: ");
|
|
||||||
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: ");
|
||||||
Console.WriteLine("Please confirm your password:");
|
string password = ReadPassword();
|
||||||
confirmPassword = ReadPassword();
|
|
||||||
}
|
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||||
|
global::System.Console.SetCursorPosition(7, 9);
|
||||||
try
|
global::System.Console.Write("Confirm Password: ");
|
||||||
{
|
string confirmPassword = ReadPassword();
|
||||||
User adminUser = new User
|
|
||||||
|
while (password != confirmPassword)
|
||||||
{
|
{
|
||||||
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. ");
|
||||||
while (string.IsNullOrWhiteSpace(hostname))
|
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||||
{
|
global::System.Console.SetCursorPosition(7, 7);
|
||||||
ShowError("Hostname cannot be empty.");
|
global::System.Console.Write("Username: ");
|
||||||
Console.Write("Hostname: ");
|
username = global::System.Console.ReadLine();
|
||||||
hostname = Console.ReadLine();
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user