Skip to content

Commit

Permalink
Added toggle functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
krazynez committed Jul 17, 2023
1 parent d7f04ca commit 6ebfa85
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion extras/menus/xMenu/src/menu.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "menu.h"
#include <systemctrl.h>
#include <systemctrl_se.h>
#include <fstream>
#include <sstream>
#include <string>


#define BOTTOM 260

Expand All @@ -11,6 +14,8 @@ static SEConfig _se_conf;
SEConfig* se_config = &_se_conf;
static string ark_version;

static string r;

Menu::Menu(){

this->readEbootList("ms0:/PSP/GAME/");
Expand Down Expand Up @@ -149,6 +154,8 @@ void Menu::updateScreen(){

common::printText(2, 2, ver.str().c_str());

common::printText(2, BOTTOM-10, r.c_str());

common::printText(2, BOTTOM, "LT - Toggle Speedup");

common::flip();
Expand Down Expand Up @@ -212,7 +219,64 @@ void Menu::control(){
}
else if (control.LT()){
se_config->msspeed = !se_config->msspeed;
sctrlSESetConfig(se_config);
char arkSettingsPath[ARK_PATH_SIZE];
strcpy(arkSettingsPath, ark_config->arkpath);
strcat(arkSettingsPath, "SETTINGS.TXT");
std::stringstream final_str;
std::ifstream fs_in(arkSettingsPath);
if (!fs_in) {
final_str << "Cannot open: " << "SETTINGS.TXT";
r = final_str.str().c_str();
return;
}
// fs.open(arkSettingsPath);

std::string line = "";
std::string replace_str = "";
std::string search_str = "mscache";
std::stringstream updated_content;

while (std::getline(fs_in, line)) {
if (line.find(search_str) != std::string::npos) {
int size = line.find(search_str) + search_str.length() + 2;
std::string status = line.substr(line.find_last_of(" ")+1);

if (status == "on") {
line.replace(size, status.length(), "off");
}
else if (status == "off"){
line.replace(size, status.length(), "on");
}



final_str << "Saved Settings!";

r = final_str.str().c_str();

}
updated_content << line << std::endl;



}

fs_in.close();

std::ofstream fs_out(arkSettingsPath);
if (!fs_out) {
final_str << "Cannot open: " << "SETTINGS.TXT";
r = final_str.str().c_str();
return;
}

fs_out << updated_content.str();

fs_out.close();
/*fs_out.close();
std::remove(arkSettingsPath);
std::rename(tempArkSettingsPath, arkSettingsPath);
*/
}

}
Expand Down

0 comments on commit 6ebfa85

Please sign in to comment.