From a7ef4ee63a7740e95984bd2cd89e310f5790c525 Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 Date: Mon, 25 May 2026 15:08:58 +0800 Subject: [PATCH] =?UTF-8?q?-=20Debian=E5=86=99=E5=85=A5=E5=89=8D=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E5=A4=84=E4=BA=8E?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E7=8A=B6=E6=80=81=E7=9A=84=E7=AE=80=E4=BD=93?= =?UTF-8?q?=E4=B8=AD=E6=96=87locale=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=88=99=E8=B7=B3=E8=BF=87=E5=86=99=E5=85=A5=20-=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=96=87=E4=BB=B6=E6=89=93=E5=BC=80=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=EF=BC=8C=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- language.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/language.cpp b/language.cpp index 60a25a4..815cba9 100644 --- a/language.cpp +++ b/language.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #ifdef __linux__ #include @@ -50,10 +51,8 @@ auto GetCurrentSystemType(){ #ifdef __linux__ return System::Linux; - #else - return System::Unsupported; #endif -} + return System::Unsupported; } auto GetCurrentWslDistro(){ #pragma warning(suppress : 4996) @@ -128,9 +127,21 @@ auto Debian(){ cout << "即将开始更新语言配置,请输入y或者yes继续,或者按Ctrl+C终止本程序"; check(); cout << "开始更新语言配置" << endl; - fstream locale_gen("/etc/locale.gen", ios::app); + fstream locale_gen("/etc/locale.gen"); + if (locale_gen.is_open() == false){ + throw system_error(errno, system_category(), "未能正确打开/etc/locale.gen"); } + vector FileContent; + string Buffer = ""; + while (getline(locale_gen, Buffer)){ + FileContent.push_back(Buffer); } + for (auto& Line : FileContent){ + if (Line == "zh_CN.UTF-8 UTF-8"){ + goto skip_write; } } + locale_gen.clear(); + locale_gen.seekp(0, ios::end); locale_gen << '\n' << "zh_CN.UTF-8 UTF-8" << endl; +skip_write: locale_gen.close(); system("locale-gen"); system("update-locale LANG=zh_CN.UTF-8"); @@ -138,7 +149,7 @@ auto Debian(){ cout << "输入y或者yes重启或者按Ctrl+C终止本程序" << endl; check(); RebootIfIsWSL(); - system("reboot");} + system("reboot"); } auto OsType = GetCurrentSystemType();