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();
String json();
bool add_mapping(String id, String folder);
String create_mapping_txt();
};

View File

@ -143,6 +143,16 @@ bool PlaylistManager::add_mapping(String id, String folder) {
void PlaylistManager::_save_mapping() {
SPIMaster::select_sd();
File f = SD.open("/_mapping.txt", "w");
String s = create_mapping_txt();
unsigned char* buf = new unsigned char[s.length()];
s.getBytes(buf, s.length());
f.write(buf, s.length()-1);
f.close();
SPIMaster::select_sd(false);
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;
@ -150,10 +160,5 @@ void PlaylistManager::_save_mapping() {
s += it->second;
s += '\n';
}
unsigned char* buf = new unsigned char[s.length()];
s.getBytes(buf, s.length());
f.write(buf, s.length()-1);
f.close();
SPIMaster::select_sd(false);
delete buf;
}
return s;
}