PlaylistManager: Extracted create_mapping_txt from _save_mapping.

This commit is contained in:
Fabian Schlenz 2019-11-19 20:46:54 +01:00
parent 68ecc05712
commit 4f9174d362
2 changed files with 13 additions and 7 deletions

View File

@ -19,4 +19,5 @@ public:
void scan_files(); void scan_files();
String json(); String json();
bool add_mapping(String id, String folder); bool add_mapping(String id, String folder);
String create_mapping_txt();
}; };

View File

@ -143,13 +143,7 @@ bool PlaylistManager::add_mapping(String id, String folder) {
void PlaylistManager::_save_mapping() { void PlaylistManager::_save_mapping() {
SPIMaster::select_sd(); SPIMaster::select_sd();
File f = SD.open("/_mapping.txt", "w"); File f = SD.open("/_mapping.txt", "w");
String s; String s = create_mapping_txt();
for(std::map<String, String>::iterator it = _map.begin(); it != _map.end(); it++) {
s += it->first;
s += "=";
s += it->second;
s += '\n';
}
unsigned char* buf = new unsigned char[s.length()]; unsigned char* buf = new unsigned char[s.length()];
s.getBytes(buf, s.length()); s.getBytes(buf, s.length());
f.write(buf, s.length()-1); f.write(buf, s.length()-1);
@ -157,3 +151,14 @@ void PlaylistManager::_save_mapping() {
SPIMaster::select_sd(false); SPIMaster::select_sd(false);
delete buf; delete buf;
} }
String PlaylistManager::create_mapping_txt() {
String s;
for(std::map<String, String>::iterator it = _map.begin(); it != _map.end(); it++) {
s += it->first;
s += "=";
s += it->second;
s += '\n';
}
return s;
}