OOBE GUI版

This commit is contained in:
2026-04-04 18:32:21 +08:00
parent 1341f10ed9
commit 97f35bccb3
6 changed files with 344 additions and 12 deletions

View File

@@ -96,10 +96,7 @@ namespace CMLeonOS
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
bool userDatExists = UserDatExists();
string[] options = userDatExists
? new[] { "CMLeonOS Shell", "CMLeonOS Desktop", "Reboot", "Shutdown" }
: new[] { "CMLeonOS Shell", "Reboot", "Shutdown" };
string[] options = new[] { "CMLeonOS Shell", "CMLeonOS Desktop", "Reboot", "Shutdown" };
int width = Console.WindowWidth;
int height = Console.WindowHeight;
@@ -152,14 +149,13 @@ namespace CMLeonOS
Console.CursorVisible = true;
bool userDatExists = UserDatExists();
int optionIndex = 0;
if (selIdx == optionIndex++)
{
return BootMenuAction.NormalBoot;
}
if (userDatExists && selIdx == optionIndex++)
if (selIdx == optionIndex++)
{
return BootMenuAction.GuiBoot;
}
@@ -179,7 +175,7 @@ namespace CMLeonOS
public static BootMenuAction Show()
{
if (Settings.SettingsManager.SkipToGui && UserDatExists())
if (Settings.SettingsManager.SkipToGui)
{
return BootMenuAction.GuiBoot;
}
@@ -235,7 +231,7 @@ namespace CMLeonOS
}
}
int maxOptionIndex = UserDatExists() ? 3 : 2;
int maxOptionIndex = 3;
if (selIdx < 0)
{

View File

@@ -827,6 +827,69 @@ namespace CMLeonOS
}
}
public bool CreateInitialAdminFromOobe(string username, string password, string hostname, out string error)
{
error = string.Empty;
username = (username ?? string.Empty).Trim();
password = (password ?? string.Empty).Trim();
hostname = (hostname ?? string.Empty).Trim();
if (string.IsNullOrWhiteSpace(username))
{
error = "Username cannot be empty.";
return false;
}
if (ContainsInvalidChars(username))
{
error = "Username contains invalid characters.";
return false;
}
if (string.IsNullOrWhiteSpace(password))
{
error = "Password cannot be empty.";
return false;
}
if (string.IsNullOrWhiteSpace(hostname))
{
error = "Hostname cannot be empty.";
return false;
}
foreach (User user in users)
{
if (user.Username.Equals(username, StringComparison.OrdinalIgnoreCase))
{
error = "Username already exists.";
return false;
}
}
try
{
User admin = new User
{
Username = username,
Password = password,
IsAdmin = true,
Hostname = hostname
};
users.Add(admin);
SaveUsers();
CreateUserFolder(username);
return true;
}
catch (Exception ex)
{
error = ex.Message;
return false;
}
}
public bool DeleteUser(string username)
{
Console.WriteLine("====================================");