修复设置bug

This commit is contained in:
2026-03-03 21:25:01 +08:00
parent 29a68b4ca9
commit 6c514df84e
8 changed files with 73 additions and 16 deletions

View File

@@ -1 +1 @@
2026-03-02 21:39:15
2026-03-03 21:19:17

View File

@@ -1 +1 @@
5c952e7
29a68b4

View File

@@ -1,4 +1,4 @@
using CMLeonOS;
using CMLeonOS;
using CMLeonOS.Gui.UILib;
using Cosmos.System.Graphics;
using System.Drawing;

View File

@@ -7,12 +7,22 @@ namespace CMLeonOS.Gui.Apps.CodeStudio
{
private static readonly List<string> Keywords = new List<string>
{
"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while"
"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while",
"goto", "self"
};
private static readonly List<string> Builtins = new List<string>
{
"print", "type", "tostring", "tonumber", "ipairs", "pairs", "table", "string", "math", "io", "os", "coroutine", "debug", "package", "utf8", "bit32"
"print", "type", "tostring", "tonumber", "ipairs", "pairs", "table", "string", "math", "io", "os", "coroutine", "debug", "package", "utf8", "bit32",
"assert", "collectgarbage", "dofile", "error", "getmetatable", "load", "loadfile", "next", "pcall", "rawequal", "rawget", "rawlen", "rawset", "require", "select", "setmetatable", "xpcall",
"byte", "char", "dump", "find", "format", "gmatch", "gsub", "len", "lower", "match", "rep", "reverse", "sub", "upper",
"abs", "acos", "asin", "atan", "atan2", "ceil", "cos", "cosh", "deg", "exp", "floor", "fmod", "frexp", "huge", "ldexp", "log", "log10", "max", "min", "modf", "pi", "pow", "rad", "random", "randomseed", "sin", "sinh", "sqrt", "tan", "tanh",
"close", "flush", "input", "lines", "open", "output", "popen", "read", "tmpfile", "type", "write",
"clock", "date", "difftime", "execute", "exit", "getenv", "remove", "rename", "setlocale", "time", "tmpname",
"create", "resume", "running", "status", "wrap", "yield",
"concat", "insert", "maxn", "remove", "sort",
"getinfo", "getlocal", "getmetatable", "setmetatable", "setlocal", "traceback",
"loadlib", "seeall", "loaded", "loaders", "path", "cpath", "preload"
};
private static readonly List<string> Operators = new List<string>
@@ -27,7 +37,7 @@ namespace CMLeonOS.Gui.Apps.CodeStudio
internal static Color String = Color.FromArgb(163, 21, 21);
internal static Color Number = Color.FromArgb(0, 0, 255);
internal static Color Comment = Color.FromArgb(128, 128, 128);
internal static Color Operator = Color.FromArgb(0, 0, 0);
internal static Color Operator = Color.FromArgb(255, 128, 0);
internal static Color Default = Color.White;
}
@@ -63,6 +73,25 @@ namespace CMLeonOS.Gui.Apps.CodeStudio
continue;
}
if (i + 3 < line.Length && line.Substring(i, 4) == "--[[")
{
int start = i;
i += 4;
int endPos = line.IndexOf("--]]", i);
if (endPos != -1)
{
i = endPos + 4;
}
else
{
i = line.Length;
}
tokens.Add(new HighlightedToken(line.Substring(start, i - start), Colors.Comment));
continue;
}
if (c == '-' && i + 1 < line.Length && line[i + 1] == '-')
{
int start = i;
@@ -98,10 +127,11 @@ namespace CMLeonOS.Gui.Apps.CodeStudio
continue;
}
if (char.IsDigit(c))
if (char.IsDigit(c) || (c == '0' && i + 1 < line.Length && (line[i + 1] == 'x' || line[i + 1] == 'X')))
{
int start = i;
while (i < line.Length && (char.IsDigit(line[i]) || line[i] == '.'))
i++;
while (i < line.Length && (char.IsDigit(line[i]) || line[i] == '.' || line[i] == 'e' || line[i] == 'E' || line[i] == 'x' || line[i] == 'X' || line[i] == 'a' || line[i] == 'A' || line[i] == 'b' || line[i] == 'B' || line[i] == 'c' || line[i] == 'C' || line[i] == 'd' || line[i] == 'D' || line[i] == 'f' || line[i] == 'F'))
{
i++;
}

View File

@@ -253,7 +253,11 @@ namespace CMLeonOS.Gui.Apps
{
base.Start();
window = new AppWindow(this, 256, 256, 448, 272);
window.Closing = TryStop;
window.Closing = () =>
{
SettingsManager.FlushSettings();
TryStop();
};
window.Icon = AppManager.GetAppMetadata("Settings").Icon;
wm.AddWindow(window);

View File

@@ -3,6 +3,7 @@ using Cosmos.System.Graphics;
using CMLeonOS;
using CMLeonOS.Gui.UILib;
using CMLeonOS.UILib.Animations;
using CMLeonOS.Settings;
using System;
using System.Drawing;
@@ -55,13 +56,8 @@ namespace CMLeonOS.Gui.ShellComponents
internal void UpdateTime()
{
if (settingsService == null)
{
settingsService = ProcessManager.GetProcess<SettingsService>();
}
string timeText;
if (settingsService.TwelveHourClock)
if (SettingsManager.GUI_TwelveHourClock)
{
timeText = DateTime.Now.ToString("ddd h:mm tt");
}
@@ -120,6 +116,8 @@ namespace CMLeonOS.Gui.ShellComponents
start.OnClick = StartClicked;
wm.AddWindow(start);
SetLeftHandStartButton(SettingsManager.GUI_LeftHandStartButton);
UpdateTime();
MovementAnimation animation = new MovementAnimation(window)

View File

@@ -2,6 +2,7 @@ using Cosmos.System;
using Cosmos.System.Graphics;
using CMLeonOS;
using CMLeonOS.Gui.ShellComponents;
using CMLeonOS.Settings;
using System;
using System.Collections.Generic;
using System.Drawing;
@@ -381,7 +382,7 @@ namespace CMLeonOS.Gui
RenderWallpaper();
fpsCounter = new Window(this, (int)(ScreenWidth) - 64, (int)(ScreenHeight - 16), 64, 16);
if (settingsService.ShowFps)
if (SettingsManager.GUI_ShowFps)
{
AddWindow(fpsCounter);
}

View File

@@ -8,6 +8,9 @@ namespace CMLeonOS.Settings
{
private static string settingsFilePath = @"0:\system\settings.dat";
private static Dictionary<string, string> settings = new Dictionary<string, string>();
private static bool savePending = false;
private static int pendingSaveCount = 0;
private const int MAX_PENDING_SAVES = 5;
private static Dictionary<string, string> defaultSettings = new Dictionary<string, string>
{
@@ -226,6 +229,8 @@ namespace CMLeonOS.Settings
}
SaveSettings();
}
FlushSettings();
}
catch (Exception e)
{
@@ -235,6 +240,22 @@ namespace CMLeonOS.Settings
public static void SaveSettings()
{
savePending = true;
pendingSaveCount++;
if (pendingSaveCount >= MAX_PENDING_SAVES)
{
FlushSettings();
}
}
public static void FlushSettings()
{
if (!savePending)
{
return;
}
try
{
Directory.CreateDirectory(Path.GetDirectoryName(settingsFilePath));
@@ -250,6 +271,9 @@ namespace CMLeonOS.Settings
writer.WriteLine($"{setting.Key}={setting.Value}");
}
}
savePending = false;
pendingSaveCount = 0;
}
catch (Exception e)
{