This commit is contained in:
Dengrb 2024-10-05 17:32:34 +08:00
parent 0bb0f93abf
commit 1aa72c6ea3
4 changed files with 36 additions and 33 deletions

Binary file not shown.

Binary file not shown.

View File

@ -7,53 +7,53 @@
using namespace std; using namespace std;
// 函数声明 // 函数声明
bool fileExists(const std::string& filename); bool fileExists(const std::string& filename);
bool createDefaultConfig(const std::string& filename); bool createDefaultConfig(const std::string& filename);
bool renameFolder(const std::string& oldName, const std::string& newName); // 使用 MoveFile bool renameFolder(const std::string& oldName, const std::string& newName); // 使用 MoveFile
int main() { int main() {
const std::string configFile = "config.ini"; const std::string configFile = "config.ini";
// 检查 config.ini 是否存在 // 检查 config.ini 是否存在
if (!fileExists(configFile)) { if (!fileExists(configFile)) {
cout << "未检测到 " << configFile << " 文件,正在创建默认配置..." << endl; cout << "未检测到 " << configFile << " 文件,正在创建默认配置..." << endl;
if (createDefaultConfig(configFile)) { if (createDefaultConfig(configFile)) {
cout << "默认配置文件创建成功。" << endl; cout << "默认配置文件创建成功。" << endl;
} else { } else {
cout << "创建默认配置文件失败。" << endl; cout << "创建默认配置文件失败。" << endl;
return 1; // 退出程序,因为无法创建配置文件 return 1; // 退出程序,因为无法创建配置文件
} }
} }
// 初始化INI文件 // 初始化INI文件
CSimpleIniA ini; CSimpleIniA ini;
ini.SetUnicode(); ini.SetUnicode();
ini.SetMultiKey(true); ini.SetMultiKey(true);
SI_Error rc = ini.LoadFile(configFile.c_str()); SI_Error rc = ini.LoadFile(configFile.c_str());
if (rc < 0) { if (rc < 0) {
cout << "无法加载配置文件 " << configFile << endl; cout << "无法加载配置文件 " << configFile << endl;
return 1; return 1;
} }
const char* name = ini.GetValue("User", "name", "0"); const char* name = ini.GetValue("User", "name", "0");
cout << "欢迎使用CSSO与CS起源切换程序" << endl; cout << "欢迎使用CSSO与CS起源切换程序" << endl;
cout << "当前模式: " << name <<"(0为CSSO1为CS起源)"<< endl; cout << "当前模式: " << name <<"(0为CSSO1为CS起源)"<< endl;
cout << "请选择操作:" << endl; cout << "请选择操作:" << endl;
cout << "1. CSSO" << endl; cout << "1. CSSO" << endl;
cout << "2. CS起源" << endl; cout << "2. CS起源" << endl;
cout << "3. 退出" << endl; cout << "3. 退出" << endl;
int choice; int choice;
cin >> choice; cin >> choice;
if (choice == 1) { if (choice == 1) {
if (strcmp(name, "0") == 0) { if (strcmp(name, "0") == 0) {
cout << "你已是CSSO模式!" << endl; cout << "你已是CSSO模式!" << endl;
} else { } else {
// 切换到CSSO模式 // 切换到CSSO模式
bool result1 = renameFolder("bin", "bin_backup"); bool result1 = renameFolder("bin", "bin_backup");
bool result2 = renameFolder("bin2", "bin"); bool result2 = renameFolder("bin2", "bin");
@ -61,21 +61,21 @@ int main() {
ini.SetValue("User", "name", "0"); ini.SetValue("User", "name", "0");
SI_Error saveRc = ini.SaveFile(configFile.c_str()); SI_Error saveRc = ini.SaveFile(configFile.c_str());
if (saveRc >= 0) { if (saveRc >= 0) {
cout << "成功切换到CSSO模式!" << endl; cout << "成功切换到CSSO模式!" << endl;
} else { } else {
cout << "保存配置文件失败!" << endl; cout << "保存配置文件失败!" << endl;
} }
} else { } else {
cout << "切换失败!检查文件路径或权限。" << endl; cout << "切换失败!检查文件路径或权限。" << endl;
} }
Sleep(1500); Sleep(1500);
} }
} }
else if (choice == 2) { else if (choice == 2) {
if (strcmp(name, "1") == 0) { if (strcmp(name, "1") == 0) {
cout << "你已是CS起源模式!" << endl; cout << "你已是CS起源模式!" << endl;
} else { } else {
// 切换到CS起源模式 // 切换到CS起源模式
bool result1 = renameFolder("bin", "bin2"); bool result1 = renameFolder("bin", "bin2");
bool result2 = renameFolder("bin_backup", "bin"); bool result2 = renameFolder("bin_backup", "bin");
@ -83,56 +83,56 @@ int main() {
ini.SetValue("User", "name", "1"); ini.SetValue("User", "name", "1");
SI_Error saveRc = ini.SaveFile(configFile.c_str()); SI_Error saveRc = ini.SaveFile(configFile.c_str());
if (saveRc >= 0) { if (saveRc >= 0) {
cout << "成功切换到CS起源模式!" << endl; cout << "成功切换到CS起源模式!" << endl;
} else { } else {
cout << "保存配置文件失败!" << endl; cout << "保存配置文件失败!" << endl;
} }
} else { } else {
cout << "切换失败!检查文件路径或权限。" << endl; cout << "切换失败!检查文件路径或权限。" << endl;
} }
Sleep(1500); Sleep(1500);
} }
} }
else if (choice == 3) { else if (choice == 3) {
cout << "退出程序." << endl; cout << "退出程序." << endl;
Sleep(100); Sleep(100);
return 0; return 0;
} }
else { else {
cout << "无效的选项,请重新运行程序并选择正确的选项。" << endl; cout << "无效的选项,请重新运行程序并选择正确的选项。" << endl;
} }
return 0; return 0;
} }
// 检查文件是否存在 // 检查文件是否存在
bool fileExists(const std::string& filename) { bool fileExists(const std::string& filename) {
std::ifstream infile(filename); std::ifstream infile(filename);
return infile.good(); return infile.good();
} }
// 创建默认的config.ini文件 // 创建默认的config.ini文件
bool createDefaultConfig(const std::string& filename) { bool createDefaultConfig(const std::string& filename) {
CSimpleIniA ini; CSimpleIniA ini;
ini.SetUnicode(); ini.SetUnicode();
ini.SetMultiKey(true); ini.SetMultiKey(true);
// 设置默认值 // 设置默认值
ini.SetValue("User", "name", "0"); ini.SetValue("User", "name", "0");
// 保存INI文件 // 保存INI文件
SI_Error rc = ini.SaveFile(filename.c_str()); SI_Error rc = ini.SaveFile(filename.c_str());
return (rc >= 0); return (rc >= 0);
} }
// 使用 MoveFile 重命名文件夹 // 使用 MoveFile 重命名文件夹
bool renameFolder(const std::string& oldName, const std::string& newName) { bool renameFolder(const std::string& oldName, const std::string& newName) {
if (MoveFile(oldName.c_str(), newName.c_str())) { if (MoveFile(oldName.c_str(), newName.c_str())) {
cout << "重命名成功: " << oldName << " -> " << newName << endl; cout << "重命名成功: " << oldName << " -> " << newName << endl;
return true; return true;
} else { } else {
DWORD error = GetLastError(); DWORD error = GetLastError();
cout << "重命名失败: " << oldName << " -> " << newName << " (错误代码: " << error << ")" << endl; cout << "重命名失败: " << oldName << " -> " << newName << " (错误代码: " << error << ")" << endl;
return false; return false;
} }
} }

View File

@ -23,6 +23,9 @@ int main(){
}else if (in==3) }else if (in==3)
{ {
qian(); qian();
}else if (in==4)
{
exit(0);
}else{ }else{
cout <<"输入错误!请重新运行程序并输入正确的编号!"; cout <<"输入错误!请重新运行程序并输入正确的编号!";
Sleep(1250); Sleep(1250);