Fixed advent mode and persistence stuff.
This commit is contained in:
@@ -109,7 +109,6 @@ Playlist* PlaylistManager::get_playlist_for_folder(String folder) {
|
||||
p = new Playlist(folder);
|
||||
_playlists[folder] = p;
|
||||
if (p->persistence == PERSIST_PERMANENTLY) {
|
||||
// TODO Load persistence from file
|
||||
String search = folder;
|
||||
search += "=";
|
||||
SPIMaster::select_sd();
|
||||
@@ -197,38 +196,44 @@ String PlaylistManager::create_mapping_txt() {
|
||||
}
|
||||
|
||||
void PlaylistManager::persist(Playlist* p) {
|
||||
if (p->persistence != PERSIST_PERMANENTLY) return;
|
||||
if (p->persistence == PERSIST_NONE) {
|
||||
_playlists.erase(p->path());
|
||||
return;
|
||||
} else if (p->persistence == PERSIST_PERMANENTLY) {
|
||||
|
||||
String search = p->path();
|
||||
search += '=';
|
||||
|
||||
bool old_file_existed = false;
|
||||
|
||||
SPIMaster::select_sd();
|
||||
if (SD.exists("_positions.txt")) {
|
||||
SD.rename("/_positions.txt", "/_positions.temp.txt");
|
||||
old_file_existed = true;
|
||||
}
|
||||
File dst = SD.open("/_positions.txt", "w");
|
||||
|
||||
if (old_file_existed) {
|
||||
File src = SD.open("/_positions.temp.txt", "r");
|
||||
|
||||
while (true) {
|
||||
String line = src.readStringUntil('\n');
|
||||
line.trim();
|
||||
if (line.startsWith(search)) continue;
|
||||
dst.println(line);
|
||||
String search = p->path();
|
||||
search += '=';
|
||||
|
||||
bool old_file_existed = false;
|
||||
|
||||
SPIMaster::select_sd();
|
||||
if (SD.exists("_positions.txt")) {
|
||||
SD.rename("/_positions.txt", "/_positions.temp.txt");
|
||||
old_file_existed = true;
|
||||
}
|
||||
File dst = SD.open("/_positions.txt", "w");
|
||||
|
||||
if (old_file_existed) {
|
||||
File src = SD.open("/_positions.temp.txt", "r");
|
||||
|
||||
while (true) {
|
||||
String line = src.readStringUntil('\n');
|
||||
line.trim();
|
||||
if (line.startsWith(search)) continue;
|
||||
dst.println(line);
|
||||
}
|
||||
|
||||
src.close();
|
||||
SD.remove("/_positions.temp.txt");
|
||||
}
|
||||
|
||||
src.close();
|
||||
SD.remove("/_positions.temp.txt");
|
||||
dst.print(search);
|
||||
dst.print(p->get_current_track_id());
|
||||
dst.print(',');
|
||||
dst.println(p->get_position());
|
||||
dst.close();
|
||||
SPIMaster::select_sd(false);
|
||||
|
||||
_playlists.erase(p->path());
|
||||
}
|
||||
|
||||
dst.print(search);
|
||||
dst.print(p->get_current_track_id());
|
||||
dst.print(',');
|
||||
dst.println(p->get_position());
|
||||
dst.close();
|
||||
SPIMaster::select_sd(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user