config storage
This commit is contained in:
parent
0f7e1a50c9
commit
03fd518e9b
7 changed files with 74 additions and 3 deletions
|
|
@ -87,3 +87,7 @@ std::string taDecodeBase64(const char* buf) {
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string taDecodeBase64(const std::string& str) {
|
||||
return taDecodeBase64(str.c_str());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@
|
|||
|
||||
std::string taEncodeBase64(const std::string& data);
|
||||
std::string taDecodeBase64(const char* str);
|
||||
std::string taDecodeBase64(const std::string& str);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -340,6 +340,34 @@ std::vector<int> DivConfig::getIntList(String key, std::initializer_list<int> fa
|
|||
return fallback;
|
||||
}
|
||||
|
||||
std::vector<String> DivConfig::getStringList(String key, std::initializer_list<String> fallback) const {
|
||||
String next;
|
||||
std::vector<String> ret;
|
||||
auto val=conf.find(key);
|
||||
if (val!=conf.cend()) {
|
||||
try {
|
||||
for (char i: val->second) {
|
||||
if (i==',') {
|
||||
String result=taDecodeBase64(next);
|
||||
ret.push_back(result);
|
||||
next="";
|
||||
} else {
|
||||
next+=i;
|
||||
}
|
||||
}
|
||||
if (!next.empty()) {
|
||||
String result=taDecodeBase64(next);
|
||||
ret.push_back(result);
|
||||
}
|
||||
|
||||
return ret;
|
||||
} catch (std::out_of_range& e) {
|
||||
} catch (std::invalid_argument& e) {
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
bool DivConfig::has(String key) const {
|
||||
auto val=conf.find(key);
|
||||
return (val!=conf.cend());
|
||||
|
|
@ -384,6 +412,17 @@ void DivConfig::set(String key, const std::vector<int>& value) {
|
|||
conf[key]=val;
|
||||
}
|
||||
|
||||
void DivConfig::set(String key, const std::vector<String>& value) {
|
||||
String val;
|
||||
bool comma=false;
|
||||
for (const String& i: value) {
|
||||
if (comma) val+=',';
|
||||
val+=taEncodeBase64(i);
|
||||
comma=true;
|
||||
}
|
||||
conf[key]=val;
|
||||
}
|
||||
|
||||
bool DivConfig::remove(String key) {
|
||||
return conf.erase(key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class DivConfig {
|
|||
double getDouble(String key, double fallback) const;
|
||||
String getString(String key, String fallback) const;
|
||||
std::vector<int> getIntList(String key, std::initializer_list<int> fallback) const;
|
||||
std::vector<String> getStringList(String key, std::initializer_list<String> fallback) const;
|
||||
|
||||
// check for existence
|
||||
bool has(String key) const;
|
||||
|
|
@ -57,6 +58,7 @@ class DivConfig {
|
|||
void set(String key, const char* value);
|
||||
void set(String key, String value);
|
||||
void set(String key, const std::vector<int>& value);
|
||||
void set(String key, const std::vector<String>& value);
|
||||
|
||||
// remove a config value
|
||||
bool remove(String key);
|
||||
|
|
|
|||
|
|
@ -7516,6 +7516,9 @@ bool FurnaceGUI::loop() {
|
|||
bool FurnaceGUI::init() {
|
||||
logI("initializing GUI.");
|
||||
|
||||
newFilePicker=new FurnaceFilePicker;
|
||||
newFilePicker->setConfigPrefix("fp_");
|
||||
|
||||
opTouched=new bool[DIV_MAX_PATTERNS*DIV_MAX_ROWS];
|
||||
|
||||
syncState();
|
||||
|
|
@ -7831,8 +7834,6 @@ bool FurnaceGUI::init() {
|
|||
}
|
||||
}
|
||||
|
||||
newFilePicker=new FurnaceFilePicker;
|
||||
|
||||
updateWindowTitle();
|
||||
updateROMExportAvail();
|
||||
|
||||
|
|
@ -8250,6 +8251,8 @@ void FurnaceGUI::syncState() {
|
|||
xyOscThickness=e->getConfFloat("xyOscThickness",2.0f);
|
||||
|
||||
cvHiScore=e->getConfInt("cvHiScore",25000);
|
||||
|
||||
newFilePicker->loadSettings(e->getConfObject());
|
||||
}
|
||||
|
||||
void FurnaceGUI::commitState(DivConfig& conf) {
|
||||
|
|
@ -8414,6 +8417,8 @@ void FurnaceGUI::commitState(DivConfig& conf) {
|
|||
}
|
||||
|
||||
conf.set("cvHiScore",cvHiScore);
|
||||
|
||||
newFilePicker->saveSettings(e->getConfObject());
|
||||
}
|
||||
|
||||
bool FurnaceGUI::finish(bool saveConfig) {
|
||||
|
|
|
|||
|
|
@ -1326,11 +1326,29 @@ FilePickerStatus FurnaceFilePicker::getStatus() {
|
|||
}
|
||||
|
||||
void FurnaceFilePicker::loadSettings(DivConfig& conf) {
|
||||
|
||||
showHiddenFiles=conf.getBool(configPrefix+"showHiddenFiles",true);
|
||||
singleClickSelect=conf.getBool(configPrefix+"singleClickSelect",false);
|
||||
clearSearchOnDirChange=conf.getBool(configPrefix+"clearSearchOnDirChange",false);
|
||||
sortDirsFirst=conf.getBool(configPrefix+"sortDirsFirst",true);
|
||||
displayType=conf.getBool(configPrefix+"displayType",true);
|
||||
displaySize=conf.getBool(configPrefix+"displaySize",true);
|
||||
displayDate=conf.getBool(configPrefix+"displayDate",true);
|
||||
bookmarks=conf.getStringList(configPrefix+"bookmarks",{});
|
||||
}
|
||||
|
||||
void FurnaceFilePicker::saveSettings(DivConfig& conf) {
|
||||
conf.set(configPrefix+"showHiddenFiles",showHiddenFiles);
|
||||
conf.set(configPrefix+"singleClickSelect",singleClickSelect);
|
||||
conf.set(configPrefix+"clearSearchOnDirChange",clearSearchOnDirChange);
|
||||
conf.set(configPrefix+"sortDirsFirst",sortDirsFirst);
|
||||
conf.set(configPrefix+"displayType",displayType);
|
||||
conf.set(configPrefix+"displaySize",displaySize);
|
||||
conf.set(configPrefix+"displayDate",displayDate);
|
||||
conf.set(configPrefix+"bookmarks",bookmarks);
|
||||
}
|
||||
|
||||
void FurnaceFilePicker::setConfigPrefix(String prefix) {
|
||||
configPrefix=prefix;
|
||||
}
|
||||
|
||||
const String& FurnaceFilePicker::getPath() {
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ class FurnaceFilePicker {
|
|||
bool editingPath;
|
||||
|
||||
// configuration
|
||||
String configPrefix;
|
||||
std::vector<String> bookmarks;
|
||||
bool showHiddenFiles;
|
||||
bool singleClickSelect;
|
||||
|
|
@ -162,6 +163,7 @@ class FurnaceFilePicker {
|
|||
void setTypeStyle(FileType type, ImVec4 color, String icon);
|
||||
void registerType(String ext, ImVec4 color, String icon);
|
||||
void clearTypes();
|
||||
void setConfigPrefix(String prefix);
|
||||
FurnaceFilePicker();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue