From a01dd4e10c100875dff143f48ca78b995f092b64 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Mon, 9 Feb 2026 02:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E5=87=BAgit=E5=93=88=E5=B8=8C?= =?UTF-8?q?=E5=80=BC1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMLeonOS.csproj | 8 ++++++- GenerateGitCommit.ps1 | 24 +++++++++++++++++++++ GitCommit.txt | 1 + Kernel.cs | 39 +++++++++++++++++++++++++++++++++- shell/Commands/Info/Version.cs | 3 ++- utils/Version.cs | 6 ++++++ 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 GenerateGitCommit.ps1 create mode 100644 GitCommit.txt diff --git a/CMLeonOS.csproj b/CMLeonOS.csproj index fd8f5d8..1a64a0b 100644 --- a/CMLeonOS.csproj +++ b/CMLeonOS.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -28,6 +28,7 @@ None 2 800x600x32 + Always @@ -62,6 +63,7 @@ + @@ -82,4 +84,8 @@ + + + + diff --git a/GenerateGitCommit.ps1 b/GenerateGitCommit.ps1 new file mode 100644 index 0000000..8201552 --- /dev/null +++ b/GenerateGitCommit.ps1 @@ -0,0 +1,24 @@ +$ErrorActionPreference = "Stop" + +$gitPath = "git" +$commitFile = "GitCommit.txt" + +try { + $commitHash = git rev-parse HEAD 2>&1 + + if ($LASTEXITCODE -eq 0) { + $shortHash = $commitHash.Substring(0, 7).Trim() + $shortHash | Out-File -FilePath $commitFile -Encoding UTF8 -NoNewline + Write-Host "Git Commit Hash: $shortHash" -ForegroundColor Green + Write-Host "Full Hash: $commitHash.Trim()" -ForegroundColor Cyan + } + else { + Write-Host "Warning: Not a git repository or git not found" -ForegroundColor Yellow + Write-Host "Using default commit hash: unknown" -ForegroundColor Yellow + "unknown" | Out-File -FilePath $commitFile -Encoding UTF8 + } +} +catch { + Write-Host "Error: $_" -ForegroundColor Red + "unknown" | Out-File -FilePath $commitFile -Encoding UTF8 +} \ No newline at end of file diff --git a/GitCommit.txt b/GitCommit.txt new file mode 100644 index 0000000..90ea7dc --- /dev/null +++ b/GitCommit.txt @@ -0,0 +1 @@ +9ac476e \ No newline at end of file diff --git a/Kernel.cs b/Kernel.cs index 8979ca5..03ba138 100644 --- a/Kernel.cs +++ b/Kernel.cs @@ -39,7 +39,10 @@ namespace CMLeonOS [IL2CPU.API.Attribs.ManifestResourceStream(ResourceName = "CMLeonOS.font.psf")] public static readonly byte[] file; - + + [IL2CPU.API.Attribs.ManifestResourceStream(ResourceName = "CMLeonOS.GitCommit.txt")] + public static readonly byte[] gitCommitFile; + public static void ShowError(string message) { Console.ForegroundColor = ConsoleColor.Red; @@ -120,6 +123,26 @@ namespace CMLeonOS userSystem = new UserSystem(); _logger.Success("Kernel", "User system initialized"); + // 读取 Git Commit hash + if (gitCommitFile != null && gitCommitFile.Length > 0) + { + try + { + Version.GitCommit = System.Text.Encoding.UTF8.GetString(gitCommitFile); + _logger.Info("Kernel", $"Git Commit: {Version.GitCommit}"); + } + catch + { + Version.GitCommit = "unknown"; + _logger.Warning("Kernel", "Failed to read Git Commit, using 'unknown'"); + } + } + else + { + Version.GitCommit = "unknown"; + _logger.Warning("Kernel", "Git Commit file not found, using 'unknown'"); + } + // 检查env.dat文件是否存在,如果不存在则创建并设置Test环境变量 string envFilePath = @"0:\system\env.dat"; if (!System.IO.File.Exists(envFilePath)) @@ -321,7 +344,21 @@ namespace CMLeonOS Console.Beep(); Console.WriteLine(":("); Console.WriteLine("A problem has been detected and CMLeonOS has been shut down to prevent damage to your computer."); + + string gitCommit = "unknown"; + if (gitCommitFile != null && gitCommitFile.Length > 0) + { + try + { + gitCommit = System.Text.Encoding.UTF8.GetString(gitCommitFile); + } + catch + { + } + } + Console.WriteLine($"Error information: {ex.Message}"); + Console.WriteLine($"Build version: {gitCommit}"); Console.WriteLine("The operating system cannot recover from this exception and has halted immediately."); Console.WriteLine("If this is the first time you've seen this stop error screen, restart your computer."); Console.WriteLine("If this screen appears again, follow these steps:"); diff --git a/shell/Commands/Info/Version.cs b/shell/Commands/Info/Version.cs index dcdfd79..f02506b 100644 --- a/shell/Commands/Info/Version.cs +++ b/shell/Commands/Info/Version.cs @@ -6,12 +6,13 @@ namespace CMLeonOS.Commands { public static void ProcessVersion() { - Console.WriteLine(Version.DisplayVersion); + Console.WriteLine(Version.DisplayVersionWithGit); Console.WriteLine($"Major: {Version.Major}"); Console.WriteLine($"Minor: {Version.Minor}"); Console.WriteLine($"Patch: {Version.Patch}"); Console.WriteLine($"Type: {Version.VersionType}"); Console.WriteLine($"Full Version: {Version.FullVersion}"); + Console.WriteLine($"Git Commit: {Version.GitCommit}"); } } } diff --git a/utils/Version.cs b/utils/Version.cs index 0d14e3c..549206d 100644 --- a/utils/Version.cs +++ b/utils/Version.cs @@ -8,6 +8,7 @@ namespace CMLeonOS public static string Minor = "0"; public static string Patch = "0"; public static string VersionType = "PreRelease"; + public static string GitCommit = "unknown"; public static string FullVersion { @@ -23,5 +24,10 @@ namespace CMLeonOS { get { return $"CMLeonOS v{ShortVersion} ({VersionType})"; } } + + public static string DisplayVersionWithGit + { + get { return $"CMLeonOS v{ShortVersion} ({VersionType}) - Git: {GitCommit}"; } + } } }