修复部分bug

This commit is contained in:
2026-02-01 15:21:17 +08:00
parent b8cabfd1c0
commit 3fb0697045
6 changed files with 637 additions and 88 deletions

View File

@@ -17,6 +17,7 @@ namespace CMLeonOS
private string userFilePath;
private List<User> users;
public bool fixmode = Kernel.FixMode;
private User currentLoggedInUser;
public UserSystem()
{
@@ -25,6 +26,9 @@ namespace CMLeonOS
// 设置用户文件路径
userFilePath = Path.Combine(sysDirectory, "user.dat");
// 初始化当前登录用户
currentLoggedInUser = null;
// 加载用户数据
LoadUsers();
}
@@ -304,9 +308,11 @@ namespace CMLeonOS
if (foundUser.Password == password)
{
Console.WriteLine("Login successful!");
Console.Beep();
// 设置当前登录用户
currentLoggedInUser = foundUser;
// 创建用户文件夹
CreateUserFolder(foundUser.Username);
@@ -477,18 +483,8 @@ namespace CMLeonOS
Console.Write("Please enter your current password: ");
string currentPassword = ReadPassword();
// 查找当前登录用户
User currentUser = null;
foreach (User user in users)
{
if (user.Username.ToLower() == "current")
{
currentUser = user;
break;
}
}
if (currentUser == null)
// 检查是否有用户登录
if (currentLoggedInUser == null)
{
Console.WriteLine("Error: No user logged in.");
return false;
@@ -504,7 +500,7 @@ namespace CMLeonOS
{
try
{
currentUser.Password = newPassword;
currentLoggedInUser.Password = newPassword;
SaveUsers();
Console.WriteLine("Password changed successfully!");
return true;