update
This commit is contained in:
parent
0420ff9f94
commit
913b75f8bc
110
change.cpp
Normal file
110
change.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class IniFile {
|
||||
public:
|
||||
void load(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "无法打开文件: " << filename << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::string currentSection;
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
// 去掉注释
|
||||
size_t commentPos = line.find(';');
|
||||
if (commentPos != std::string::npos) {
|
||||
line = line.substr(0, commentPos);
|
||||
}
|
||||
// 去掉前后空格
|
||||
line.erase(remove_if(line.begin(), line.end(), isspace), line.end());
|
||||
|
||||
// 处理节
|
||||
if (line.empty()) continue;
|
||||
if (line[0] == '[' && line[line.size() - 1] == ']') {
|
||||
currentSection = line.substr(1, line.size() - 2);
|
||||
continue;
|
||||
}
|
||||
// 处理键值对
|
||||
size_t pos = line.find('=');
|
||||
if (pos != std::string::npos) {
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1);
|
||||
data[currentSection][key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void save(const std::string& filename) {
|
||||
std::ofstream file(filename);
|
||||
for (const auto& section : data) {
|
||||
file << "[" << section.first << "]\n";
|
||||
for (const auto& kv : section.second) {
|
||||
file << kv.first << "=" << kv.second << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string get(const std::string& section, const std::string& key, const std::string& defaultValue) {
|
||||
return data[section][key].empty() ? defaultValue : data[section][key];
|
||||
}
|
||||
|
||||
void set(const std::string& section, const std::string& key, const std::string& value) {
|
||||
data[section][key] = value;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::map<std::string, std::string>> data;
|
||||
};
|
||||
|
||||
void handleUserInput() {
|
||||
std::cout << "欢迎使用CSSO与CS起源切换程序" << std::endl;
|
||||
std::cout << "1.CSSO 2.CS起源 3.exit" << std::endl;
|
||||
int in;
|
||||
std::cin >> in;
|
||||
|
||||
//CSSO为1,CS起源为2
|
||||
if (in == 1) {
|
||||
ini.load("config.ini");
|
||||
string bin_name = ini.get("User","name","0");
|
||||
int result = system("ren bin bin2");
|
||||
int result2 = system('ren bin1 bin');
|
||||
if (result==0 and result2==0)
|
||||
{
|
||||
cout <<"命令执行成功!"<<endl;
|
||||
}else{
|
||||
cout <<"执行失败!"<<endl;
|
||||
}
|
||||
|
||||
|
||||
} else if (in == 2) {
|
||||
ini.load("config.ini");
|
||||
std::string name = ini.get("User", "name", "unknown");
|
||||
std::string age = ini.get("User", "age", "0");
|
||||
std::string fullscreen = ini.get("Settings", "fullscreen", "false");
|
||||
|
||||
std::cout << "Name: " << name << std::endl;
|
||||
std::cout << "Age: " << age << std::endl;
|
||||
std::cout << "Fullscreen: " << fullscreen << std::endl;
|
||||
|
||||
} else if (in == 3) {
|
||||
std::cout << "退出中" << std::endl;
|
||||
Sleep(1000); // 暂停 1 秒
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
handleUserInput();
|
||||
return 0;
|
||||
}
|
BIN
change.exe
Normal file
BIN
change.exe
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user