parent
0ddbc56b94
commit
baf9c73626
|
@ -4836,41 +4836,22 @@ bool FurnaceGUI::exportColors(String path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUI::importKeybinds(String path) {
|
bool FurnaceGUI::importKeybinds(String path) {
|
||||||
FILE* f=ps_fopen(path.c_str(),"rb");
|
DivConfig c;
|
||||||
if (f==NULL) {
|
if (!c.loadFromFile(path.c_str(),false,false)) {
|
||||||
logW("error while opening keybind file for import: %s",strerror(errno));
|
logW("error while opening keybind file for import: %s",strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
resetKeybinds();
|
resetKeybinds();
|
||||||
char line[4096];
|
if (c.has("configVersion")) {
|
||||||
while (!feof(f)) {
|
// new
|
||||||
String key="";
|
readConfig(c,GUI_SETTINGS_KEYBOARD);
|
||||||
String value="";
|
|
||||||
bool keyOrValue=false;
|
|
||||||
if (fgets(line,4095,f)==NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (char* i=line; *i; i++) {
|
|
||||||
if (*i=='\n') continue;
|
|
||||||
if (keyOrValue) {
|
|
||||||
value+=*i;
|
|
||||||
} else {
|
} else {
|
||||||
if (*i=='=') {
|
|
||||||
keyOrValue=true;
|
|
||||||
} else {
|
|
||||||
key+=*i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (keyOrValue) {
|
|
||||||
// unoptimal
|
// unoptimal
|
||||||
const char* cs=key.c_str();
|
for (auto& key: c.configMap()) {
|
||||||
bool found=false;
|
|
||||||
for (int i=0; i<GUI_ACTION_MAX; i++) {
|
for (int i=0; i<GUI_ACTION_MAX; i++) {
|
||||||
try {
|
try {
|
||||||
if (strcmp(cs,guiActions[i].name)==0) {
|
if (key.first==guiActions[i].name) {
|
||||||
actionKeys[i]=std::stoi(value);
|
actionKeys[i]=std::stoi(key.second);
|
||||||
found=true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (std::out_of_range& e) {
|
} catch (std::out_of_range& e) {
|
||||||
|
@ -4879,26 +4860,29 @@ bool FurnaceGUI::importKeybinds(String path) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) logW("line invalid: %s",line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(f);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUI::exportKeybinds(String path) {
|
bool FurnaceGUI::exportKeybinds(String path) {
|
||||||
|
DivConfig c;
|
||||||
|
|
||||||
|
c.set("configVersion",DIV_ENGINE_VERSION);
|
||||||
|
writeConfig(c,GUI_SETTINGS_KEYBOARD);
|
||||||
|
|
||||||
FILE* f=ps_fopen(path.c_str(),"wb");
|
FILE* f=ps_fopen(path.c_str(),"wb");
|
||||||
if (f==NULL) {
|
if (f==NULL) {
|
||||||
logW("error while opening keybind file for export: %s",strerror(errno));
|
logW("error while opening keybind file for export: %s",strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i=0; i<GUI_ACTION_MAX; i++) {
|
|
||||||
if (guiActions[i].defaultBind==-1) continue;
|
String result=c.toString();
|
||||||
if (fprintf(f,"%s=%d\n",guiActions[i].name,actionKeys[i])<0) {
|
|
||||||
logW("error while exporting keybinds: %s",strerror(errno));
|
if (fwrite(result.c_str(),1,result.size(),f)!=result.size()) {
|
||||||
break;
|
logW("couldn't write keybind file entirely.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue