修复GUI的一些bug

This commit is contained in:
2026-03-01 19:17:10 +08:00
parent f0a9223520
commit 1f385ac18a
8 changed files with 171 additions and 31 deletions

View File

@@ -1 +1 @@
2026-03-01 17:02:21
2026-03-01 19:12:06

View File

@@ -1 +1 @@
545f40c
f0a9223

View File

@@ -75,7 +75,6 @@ namespace CMLeonOS.Gui.Apps
("CMLeonOS (0:)", @"0:\"),
("My Home", @$"0:\user\{UserSystem.CurrentLoggedInUser.Username}"),
("Users", @"0:\user"),
("etc", @"0:\etc"),
};
private Bitmap GetFileIcon(string path)

View File

@@ -30,9 +30,8 @@ namespace CMLeonOS.Gui.Apps
window.DrawString($"Memory: {Cosmos.Core.CPU.GetAmountOfRAM()} MB", Color.Black, 12, 80);
window.DrawString("Credits", Color.DarkBlue, 12, 108);
window.DrawString("Cosmos Team - OS tooling", Color.Black, 12, 132);
window.DrawString("Microsoft - .NET Runtime", Color.Black, 12, 156);
window.DrawString("Google Fonts - Font", Color.Black, 12, 180);
window.DrawString("Microsoft - .NET Runtime", Color.Black, 12, 132);
window.DrawString("Google Fonts - Font", Color.Black, 12, 156);
Button button = new Button(window, window.Width - 80 - 12, window.Height - 20 - 12, 80, 20);
button.Text = "OK";

View File

@@ -1,6 +1,7 @@
using Cosmos.System.Graphics;
using CMLeonOS;
using CMLeonOS.Gui.UILib;
using CMLeonOS.Settings;
using System.Drawing;
@@ -16,8 +17,6 @@ namespace CMLeonOS.Gui.Apps
WindowManager wm = ProcessManager.GetProcess<WindowManager>();
SettingsService settingsService = ProcessManager.GetProcess<SettingsService>();
private static class Icons
{
[IL2CPU.API.Attribs.ManifestResourceStream(ResourceName = "CMLeonOS.Gui.Resources.Settings.User.bmp")]
@@ -59,22 +58,22 @@ namespace CMLeonOS.Gui.Apps
private void LeftStartButtonChanged(bool @checked)
{
settingsService.LeftHandStartButton = @checked;
SettingsManager.GUI_LeftHandStartButton = @checked;
}
private void TwelveHourClockChanged(bool @checked)
{
settingsService.TwelveHourClock = @checked;
SettingsManager.GUI_TwelveHourClock = @checked;
}
private void ShowFpsChanged(bool @checked)
{
settingsService.ShowFps = @checked;
SettingsManager.GUI_ShowFps = @checked;
}
private void MouseSensitivityChanged(float value)
{
settingsService.MouseSensitivity = value;
SettingsManager.GUI_MouseSensitivity = value;
}
private void ShowAppearanceCategory()
@@ -90,13 +89,13 @@ namespace CMLeonOS.Gui.Apps
Switch leftStartButton = new Switch(appearance, 12, 40, 244, 16);
leftStartButton.Text = "Left-hand start button";
leftStartButton.Checked = settingsService.LeftHandStartButton;
leftStartButton.Checked = SettingsManager.GUI_LeftHandStartButton;
leftStartButton.CheckBoxChanged = LeftStartButtonChanged;
wm.AddWindow(leftStartButton);
Switch showFps = new Switch(appearance, 12, 68, 244, 16);
showFps.Text = "Show frames per second";
showFps.Checked = settingsService.ShowFps;
showFps.Checked = SettingsManager.GUI_ShowFps;
showFps.CheckBoxChanged = ShowFpsChanged;
wm.AddWindow(showFps);
@@ -116,7 +115,7 @@ namespace CMLeonOS.Gui.Apps
Switch twelveHourClock = new Switch(dateTime, 12, 40, 244, 16);
twelveHourClock.Text = "12-hour clock";
twelveHourClock.Checked = settingsService.TwelveHourClock;
twelveHourClock.Checked = SettingsManager.GUI_TwelveHourClock;
twelveHourClock.CheckBoxChanged = TwelveHourClockChanged;
wm.AddWindow(twelveHourClock);
@@ -152,7 +151,7 @@ namespace CMLeonOS.Gui.Apps
{
Mode mode = wm.AvailableModes[i];
resolutionsTable.Cells.Add(new TableCell($"{mode.Width}x{mode.Height}"));
if (mode.Equals(settingsService.Mode))
if (mode.Width == SettingsManager.GUI_ScreenWidth && mode.Height == SettingsManager.GUI_ScreenHeight)
{
resolutionsTable.SelectedCellIndex = i;
}
@@ -161,8 +160,8 @@ namespace CMLeonOS.Gui.Apps
resolutionsTable.TableCellSelected = (int index) =>
{
Mode mode = wm.AvailableModes[index];
settingsService.Mode = mode;
settingsService.Flush();
SettingsManager.GUI_ScreenWidth = (int)mode.Width;
SettingsManager.GUI_ScreenHeight = (int)mode.Height;
MessageBox messageBox = new MessageBox(this, "Restart Required", "Restart your PC to apply changes.");
messageBox.Show();
@@ -242,7 +241,7 @@ namespace CMLeonOS.Gui.Apps
mouse.DrawString("Mouse sensitivity", Color.Gray, 12, 40);
RangeSlider mouseSensitivity = new RangeSlider(mouse, 12, 68, 244, 30, min: 0.25f, value: settingsService.MouseSensitivity, max: 2f);
RangeSlider mouseSensitivity = new RangeSlider(mouse, 12, 68, 244, 30, min: 0.25f, value: SettingsManager.GUI_MouseSensitivity, max: 2f);
mouseSensitivity.Changed = MouseSensitivityChanged;
wm.AddWindow(mouseSensitivity);

View File

@@ -421,7 +421,7 @@ namespace CMLeonOS
}
}
// 我他妈居然成功了,我在没有任何文档的情况下研究出来了
// 我居然成功了,我在没有任何文档的情况下研究出来了
private void CreateMBRandPartitionTable(Disk disk)
{
disk.Clear();

View File

@@ -12,7 +12,14 @@ namespace CMLeonOS.Settings
private static Dictionary<string, string> defaultSettings = new Dictionary<string, string>
{
{ "LoggerEnabled", "true" },
{ "MaxLoginAttempts", "3" }
{ "MaxLoginAttempts", "3" },
{ "GUI_LeftHandStartButton", "false" },
{ "GUI_ShowFps", "true" },
{ "GUI_TwelveHourClock", "false" },
{ "GUI_MouseSensitivity", "1.0" },
{ "GUI_ScreenWidth", "1280" },
{ "GUI_ScreenHeight", "800" },
{ "GUI_DarkNotepad", "false" }
};
public static bool LoggerEnabled
@@ -52,6 +59,134 @@ namespace CMLeonOS.Settings
}
}
public static bool GUI_LeftHandStartButton
{
get
{
if (settings.TryGetValue("GUI_LeftHandStartButton", out string value))
{
return value.ToLower() == "true";
}
return false;
}
set
{
settings["GUI_LeftHandStartButton"] = value ? "true" : "false";
SaveSettings();
}
}
public static bool GUI_ShowFps
{
get
{
if (settings.TryGetValue("GUI_ShowFps", out string value))
{
return value.ToLower() == "true";
}
return true;
}
set
{
settings["GUI_ShowFps"] = value ? "true" : "false";
SaveSettings();
}
}
public static bool GUI_TwelveHourClock
{
get
{
if (settings.TryGetValue("GUI_TwelveHourClock", out string value))
{
return value.ToLower() == "true";
}
return false;
}
set
{
settings["GUI_TwelveHourClock"] = value ? "true" : "false";
SaveSettings();
}
}
public static float GUI_MouseSensitivity
{
get
{
if (settings.TryGetValue("GUI_MouseSensitivity", out string value))
{
if (float.TryParse(value, out float result))
{
return result;
}
}
return 1.0f;
}
set
{
settings["GUI_MouseSensitivity"] = value.ToString();
SaveSettings();
}
}
public static int GUI_ScreenWidth
{
get
{
if (settings.TryGetValue("GUI_ScreenWidth", out string value))
{
if (int.TryParse(value, out int result))
{
return result;
}
}
return 1280;
}
set
{
settings["GUI_ScreenWidth"] = value.ToString();
SaveSettings();
}
}
public static int GUI_ScreenHeight
{
get
{
if (settings.TryGetValue("GUI_ScreenHeight", out string value))
{
if (int.TryParse(value, out int result))
{
return result;
}
}
return 800;
}
set
{
settings["GUI_ScreenHeight"] = value.ToString();
SaveSettings();
}
}
public static bool GUI_DarkNotepad
{
get
{
if (settings.TryGetValue("GUI_DarkNotepad", out string value))
{
return value.ToLower() == "true";
}
return false;
}
set
{
settings["GUI_DarkNotepad"] = value ? "true" : "false";
SaveSettings();
}
}
public static void LoadSettings()
{
settings.Clear();

View File

@@ -15,18 +15,26 @@ namespace CMLeonOS.Utils
string sanitized = path;
sanitized = sanitized.Replace('\\', '/');
sanitized = sanitized.Replace(':', '_');
sanitized = sanitized.Replace('*', '_');
sanitized = sanitized.Replace('?', '_');
sanitized = sanitized.Replace('"', '_');
sanitized = sanitized.Replace('<', '_');
sanitized = sanitized.Replace('>', '_');
sanitized = sanitized.Replace('|', '_');
// 保留驱动器字母和冒号(如 0:
// 检查格式X:\ 其中 X 是单个字符(字母或数字)
bool hasDrive = sanitized.Length >= 2 && sanitized[1] == ':';
string drive = hasDrive ? sanitized.Substring(0, 2) : "";
string rest = hasDrive ? sanitized.Substring(2) : sanitized;
sanitized = sanitized.Trim('/', '\\');
// 不替换反斜杠,因为 Cosmos 文件系统需要反斜杠
rest = rest.Replace(':', '_');
rest = rest.Replace('*', '_');
rest = rest.Replace('?', '_');
rest = rest.Replace('"', '_');
rest = rest.Replace('<', '_');
rest = rest.Replace('>', '_');
rest = rest.Replace('|', '_');
return sanitized;
// 只移除结尾的斜杠,保留开头的斜杠(因为驱动器后面需要斜杠)
rest = rest.TrimEnd('/');
rest = rest.TrimEnd('\\');
return drive + rest;
}
public static string Combine(string path1, string path2)