mirror of
https://github.com/TheWhiteDog9487/lag2cn.git
synced 2026-08-11 23:01:29 +08:00
- Debian写入前检查是否存在处于激活状态的简体中文locale,如果存在则跳过写入
- 如果文件打开失败,抛出异常
This commit is contained in:
+15
-4
@@ -4,6 +4,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -50,10 +51,8 @@ auto GetCurrentSystemType(){
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
return System::Linux;
|
return System::Linux;
|
||||||
#else
|
|
||||||
return System::Unsupported;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
return System::Unsupported; }
|
||||||
|
|
||||||
auto GetCurrentWslDistro(){
|
auto GetCurrentWslDistro(){
|
||||||
#pragma warning(suppress : 4996)
|
#pragma warning(suppress : 4996)
|
||||||
@@ -128,9 +127,21 @@ auto Debian(){
|
|||||||
cout << "即将开始更新语言配置,请输入y或者yes继续,或者按Ctrl+C终止本程序";
|
cout << "即将开始更新语言配置,请输入y或者yes继续,或者按Ctrl+C终止本程序";
|
||||||
check();
|
check();
|
||||||
cout << "开始更新语言配置" << endl;
|
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' <<
|
locale_gen << '\n' <<
|
||||||
"zh_CN.UTF-8 UTF-8" << endl;
|
"zh_CN.UTF-8 UTF-8" << endl;
|
||||||
|
skip_write:
|
||||||
locale_gen.close();
|
locale_gen.close();
|
||||||
system("locale-gen");
|
system("locale-gen");
|
||||||
system("update-locale LANG=zh_CN.UTF-8");
|
system("update-locale LANG=zh_CN.UTF-8");
|
||||||
|
|||||||
Reference in New Issue
Block a user