mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
输出git哈希值1
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
<CosmosDebugLevel>None</CosmosDebugLevel>
|
<CosmosDebugLevel>None</CosmosDebugLevel>
|
||||||
<OptimizationLevel>2</OptimizationLevel>
|
<OptimizationLevel>2</OptimizationLevel>
|
||||||
<VBEResolution>800x600x32</VBEResolution>
|
<VBEResolution>800x600x32</VBEResolution>
|
||||||
|
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
@@ -62,6 +63,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="font.psf" />
|
<EmbeddedResource Include="font.psf" />
|
||||||
<EmbeddedResource Include="Wallpapers\wallpaper.bmp" />
|
<EmbeddedResource Include="Wallpapers\wallpaper.bmp" />
|
||||||
|
<EmbeddedResource Include="GitCommit.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -82,4 +84,8 @@
|
|||||||
<PackageReference Include="IL2CPU.API" Version="0.1.0-localbuild20260203125852" />
|
<PackageReference Include="IL2CPU.API" Version="0.1.0-localbuild20260203125852" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||||
|
<Exec Command="powershell -ExecutionPolicy Bypass -File GenerateGitCommit.ps1" WorkingDirectory="$(MSBuildProjectDirectory)" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
24
GenerateGitCommit.ps1
Normal file
24
GenerateGitCommit.ps1
Normal file
@@ -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
|
||||||
|
}
|
||||||
1
GitCommit.txt
Normal file
1
GitCommit.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
9ac476e
|
||||||
37
Kernel.cs
37
Kernel.cs
@@ -40,6 +40,9 @@ namespace CMLeonOS
|
|||||||
[IL2CPU.API.Attribs.ManifestResourceStream(ResourceName = "CMLeonOS.font.psf")]
|
[IL2CPU.API.Attribs.ManifestResourceStream(ResourceName = "CMLeonOS.font.psf")]
|
||||||
public static readonly byte[] file;
|
public static readonly byte[] file;
|
||||||
|
|
||||||
|
[IL2CPU.API.Attribs.ManifestResourceStream(ResourceName = "CMLeonOS.GitCommit.txt")]
|
||||||
|
public static readonly byte[] gitCommitFile;
|
||||||
|
|
||||||
public static void ShowError(string message)
|
public static void ShowError(string message)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
@@ -120,6 +123,26 @@ namespace CMLeonOS
|
|||||||
userSystem = new UserSystem();
|
userSystem = new UserSystem();
|
||||||
_logger.Success("Kernel", "User system initialized");
|
_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环境变量
|
// 检查env.dat文件是否存在,如果不存在则创建并设置Test环境变量
|
||||||
string envFilePath = @"0:\system\env.dat";
|
string envFilePath = @"0:\system\env.dat";
|
||||||
if (!System.IO.File.Exists(envFilePath))
|
if (!System.IO.File.Exists(envFilePath))
|
||||||
@@ -321,7 +344,21 @@ namespace CMLeonOS
|
|||||||
Console.Beep();
|
Console.Beep();
|
||||||
Console.WriteLine(":(");
|
Console.WriteLine(":(");
|
||||||
Console.WriteLine("A problem has been detected and CMLeonOS has been shut down to prevent damage to your computer.");
|
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($"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("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 is the first time you've seen this stop error screen, restart your computer.");
|
||||||
Console.WriteLine("If this screen appears again, follow these steps:");
|
Console.WriteLine("If this screen appears again, follow these steps:");
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ namespace CMLeonOS.Commands
|
|||||||
{
|
{
|
||||||
public static void ProcessVersion()
|
public static void ProcessVersion()
|
||||||
{
|
{
|
||||||
Console.WriteLine(Version.DisplayVersion);
|
Console.WriteLine(Version.DisplayVersionWithGit);
|
||||||
Console.WriteLine($"Major: {Version.Major}");
|
Console.WriteLine($"Major: {Version.Major}");
|
||||||
Console.WriteLine($"Minor: {Version.Minor}");
|
Console.WriteLine($"Minor: {Version.Minor}");
|
||||||
Console.WriteLine($"Patch: {Version.Patch}");
|
Console.WriteLine($"Patch: {Version.Patch}");
|
||||||
Console.WriteLine($"Type: {Version.VersionType}");
|
Console.WriteLine($"Type: {Version.VersionType}");
|
||||||
Console.WriteLine($"Full Version: {Version.FullVersion}");
|
Console.WriteLine($"Full Version: {Version.FullVersion}");
|
||||||
|
Console.WriteLine($"Git Commit: {Version.GitCommit}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace CMLeonOS
|
|||||||
public static string Minor = "0";
|
public static string Minor = "0";
|
||||||
public static string Patch = "0";
|
public static string Patch = "0";
|
||||||
public static string VersionType = "PreRelease";
|
public static string VersionType = "PreRelease";
|
||||||
|
public static string GitCommit = "unknown";
|
||||||
|
|
||||||
public static string FullVersion
|
public static string FullVersion
|
||||||
{
|
{
|
||||||
@@ -23,5 +24,10 @@ namespace CMLeonOS
|
|||||||
{
|
{
|
||||||
get { return $"CMLeonOS v{ShortVersion} ({VersionType})"; }
|
get { return $"CMLeonOS v{ShortVersion} ({VersionType})"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string DisplayVersionWithGit
|
||||||
|
{
|
||||||
|
get { return $"CMLeonOS v{ShortVersion} ({VersionType}) - Git: {GitCommit}"; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user