- Debian写入前检查是否存在处于激活状态的简体中文locale,如果存在则跳过写入

- 如果文件打开失败,抛出异常
This commit is contained in:
TheWhiteDog9487
2026-05-25 15:08:58 +08:00
parent f4678ef4a6
commit a7ef4ee63a
+15 -4
View File
@@ -4,6 +4,7 @@
#include <fstream>
#include <filesystem>
#include <ciso646>
#include <vector>
#ifdef __linux__
#include <unistd.h>
@@ -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<string> 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");