#include #include #include using namespace std; class Xf_change { public: string line, everything, game, id, temp_s, scriptstring; int mainstart, mainend, substart, subend, prev; void find_game(); void load_script(string); void exec_script(); void merge(); void backup(); void write_results(); } mainchange; void Xf_change::find_game() { ifstream gamefile ("xfire_games.ini"); if(gamefile.is_open()) { while(!gamefile.eof()) { getline(gamefile, line); everything.append(line); } gamefile.close(); } mainstart=everything.find(id); mainend=everything.find("\r\r", mainstart); if(mainend!=-1) { cout << "Found game\n"; game=everything.substr(mainstart, (mainend-mainstart)); } } void Xf_change::load_script(string file) { string temp; int tempi; ifstream script (file.c_str()); if(script.is_open()) { while(!script.eof()){ getline(script, line); if(line!="~~") { scriptstring.append(line); } else break; } } script.close(); tempi=scriptstring.find_first_of("]")+1; id=scriptstring.substr(0, tempi); } void Xf_change::exec_script() { game.erase(prev, -1); game.append(scriptstring); } void Xf_change::merge() { everything.erase(mainstart, (mainend-mainstart)); everything.insert(mainstart, game); } void Xf_change::backup() { ofstream backfile ("xfire_games.ini.cbak"); if(backfile.is_open()) { backfile << everything; } backfile.close(); } void Xf_change::write_results() { ofstream newgamefile("xfire_games.ini"); if(newgamefile.is_open()) { newgamefile << everything; } newgamefile.close(); } int main(int argc, char* argv[]) { if(argc==2) { string file=argv[1]; cout << "wooo" << "\n"; mainchange.load_script(file); mainchange.find_game(); mainchange.backup(); mainchange.exec_script(); mainchange.merge(); mainchange.write_results(); } return 0; }