From b7335b0bb8ceac26dba69402a34a493d03953c95 Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 Date: Fri, 14 Aug 2026 11:02:51 +0800 Subject: [PATCH] =?UTF-8?q?-=20Debian=E7=B3=BB=E5=AF=B9=E5=8E=9F=E5=A7=8B/?= =?UTF-8?q?etc/locale.gen=E8=BF=9B=E8=A1=8C=E5=A4=87=E4=BB=BD=20-=20Debian?= =?UTF-8?q?=E7=B3=BB=E5=AF=B9/etc/locale.gen=E5=86=85=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8zh=5FCN.UTF-8=20UTF-8=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=85=9C=E5=BA=95=20-=20Debian=E7=B3=BB?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=92=8C=E5=86=99=E5=85=A5/etc/locale.gen?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E4=BD=BF=E7=94=A8BOM=E4=BB=A5=E8=A7=A3?= =?UTF-8?q?=E5=86=B3gzip:=20stdout:=20Broken=20pipe=E5=92=8C=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E8=A1=8C=E6=B3=A8=E9=87=8A=E8=A2=AB=E5=BD=93=E4=BD=9C?= =?UTF-8?q?locale=E9=85=8D=E7=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98=20-=20RHEL?= =?UTF-8?q?=E7=B3=BB=E7=A7=BB=E9=99=A4=E4=B8=8D=E8=A2=AB=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E5=BF=BD=E7=95=A5GPG=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 品控一定要严 --- .github/workflows/build.yml | 2 +- language.cs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85f003f..2d01fd3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,7 +32,7 @@ jobs: alpine:latest /bin/sh -c ' apk update apk add build-base dotnet10-sdk clang - dotnet publish language.cs /t:Rebuild --disable-build-servers --force ' + dotnet publish language.cs ' - name: 重命名 if: ${{ matrix.runner == 'ubuntu-26.04-arm' }} run: sudo mv artifacts/language/language artifacts/language/language_arm diff --git a/language.cs b/language.cs index e44d3b5..55bf011 100644 --- a/language.cs +++ b/language.cs @@ -67,6 +67,7 @@ void ExecuteCommand(string Command, string OsDescription = RuntimeInformation.OSDescription; if (Enum.TryParse(OsDescription.Split(' ')[0], out var CurrentSystem) == false){ + // 对于Arch Linux这种系统名称中间有空格的需要特判 if (OsDescription.Contains("Arch Linux")){ CurrentSystem = SupportedLinuxDistributions.ArchLinux; } else if (OsDescription.Contains("Rocky Linux")){ @@ -98,8 +99,10 @@ switch (CurrentSystem){ CheckUser(); Console.WriteLine("正在检查语言配置"); string[] NewContent = []; + File.Copy("/etc/locale.gen", "/etc/locale.gen.bak", true); + Console.WriteLine("原始 /etc/locale.gen 文件已备份为 /etc/locale.gen.bak"); using var FileStream = new FileStream("/etc/locale.gen", FileMode.Open, FileAccess.ReadWrite, FileShare.None); - using (var StreamReader = new StreamReader(FileStream, Encoding.UTF8, true, 1024, true)){ + using (var StreamReader = new StreamReader(FileStream, new UTF8Encoding(false), true, 1024, true)){ NewContent = [.. StreamReader.ReadToEnd() .Split("\n") .Select(Line => Line.Trim()) @@ -107,9 +110,15 @@ switch (CurrentSystem){ if (Line.Contains("zh_CN.UTF-8 UTF-8")){ Line = "zh_CN.UTF-8 UTF-8"; } return Line; } ) ]; } + if (NewContent.Any(Line => Line.StartsWith("zh_CN.UTF-8 UTF-8")) == false){ + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("警告:在 /etc/locale.gen 中未检测到 zh_CN.UTF-8 UTF-8 条目,这种情况较为反常,建议您关注后续的执行结果"); + Console.WriteLine("如果需要恢复备份,请直接使用 /etc/locale.gen.bak 覆盖 /etc/locale.gen"); + Console.ResetColor(); + NewContent = [.. NewContent, "zh_CN.UTF-8 UTF-8"]; } FileStream.SetLength(0); FileStream.Seek(0, SeekOrigin.Begin); - using (var StreamWriter = new StreamWriter(FileStream, Encoding.UTF8)){ + using (var StreamWriter = new StreamWriter(FileStream, new UTF8Encoding(false), 1024, true)){ foreach (var Line in NewContent){ StreamWriter.WriteLine(Line); } } Console.WriteLine("正在生成语言配置"); @@ -141,7 +150,7 @@ switch (CurrentSystem){ CheckUser("即将开始安装中文语言包"); Console.WriteLine("开始更新语言配置"); Console.WriteLine("正在安装中文语言包"); - ExecuteCommand("dnf", ["install", "-y", "--nogpgcheck", "glibc-langpack-zh", "langpacks-zh_CN"]); + ExecuteCommand("dnf", ["install", "-y", "glibc-langpack-zh", "langpacks-zh_CN"]); Console.WriteLine("正在更新语言配置"); ExecuteCommand("localectl", ["set-locale", "LANG=zh_CN.UTF-8"]);