diff --git a/src/configServer.cpp b/src/configServer.cpp
index ab2b6071..3c2812de 100644
--- a/src/configServer.cpp
+++ b/src/configServer.cpp
@@ -392,9 +392,11 @@ static const char* const deleteIndex =
""
""
"
SD Card
"
- ""
- ""
- "";
+ ""
+ ""
+ "";
static const char* const settingsSecurityIndex =
"Http
"
@@ -1600,7 +1602,7 @@ static void handleDeleteFiles(HTTPRequest *req, HTTPResponse * res) {
log_w("Failed to moved '%s' to /", fullName.c_str());
html += HTML_ENTITY_FAILED_CROSS;
}
- } else if (path != "trash") {
+ } else if (path != "/trash") {
if (SD.rename(fullName, "/trash/" + file)) {
log_i("Moved '%s'.", fullName.c_str());
html += HTML_ENTITY_WASTEBASKET;
@@ -2065,6 +2067,62 @@ static void handleDelete(HTTPRequest *, HTTPResponse * res) {
sendHtml(res, html);
}
+static void deleteFilesFromDirectory(File dir) {
+ File entry = dir.openNextFile();
+ while (entry) {
+ if (!entry.isDirectory()) {
+ String fileName = entry.name();
+ entry.close();
+ log_i("Will delete %s", fileName.c_str());
+ SD.remove(fileName);
+ }
+ entry = dir.openNextFile();
+ }
+}
+
+static void deleteFilesFromDirectory(String dirName) {
+ File dir = SD.open(dirName);
+ if (dir.isDirectory()) {
+ deleteFilesFromDirectory(dir);
+ }
+ dir.close();
+}
+
+static void deleteObsdataFiles() {
+ File dir = SD.open("/");
+ if (dir.isDirectory()) {
+ File entry = dir.openNextFile();
+ while (entry) {
+ if (!entry.isDirectory()) {
+ String fileName = entry.name();
+ entry.close();
+ if (fileName.endsWith("obsdata.csv")) {
+ log_d("Will delete %s", fileName.c_str());
+ SD.remove(fileName);
+ }
+ }
+ entry = dir.openNextFile();
+ }
+ }
+ dir.close();
+}
+
+static void deleteAllFromSd() {
+ // ald_ini.ubx, tracknumber.txt, current_14d.*, *.obsdata.csv, sdflash/*, trash/*, uploaded/*
+ deleteFilesFromDirectory("/trash");
+ SD.rmdir("/trash");
+ deleteFilesFromDirectory("/uploaded");
+ SD.rmdir("/uploaded");
+ deleteFilesFromDirectory("/sdflash");
+ SD.rmdir("/sdflash");
+ SD.remove("/tracknumber.txt");
+ SD.remove("/aid_ini.ubx");
+ SD.remove(LAST_MODIFIED_HEADER_FILE_NAME);
+ SD.remove(ALP_DATA_FILE_NAME);
+ SD.remove(ALP_NEW_DATA_FILE_NAME);
+ deleteObsdataFiles();
+}
+
static void handleDeleteAction(HTTPRequest *req, HTTPResponse * res) {
// TODO: Result page with status!
const auto params = extractParameters(req);
@@ -2080,9 +2138,16 @@ static void handleDeleteAction(HTTPRequest *req, HTTPResponse * res) {
}
}
if (getParameter(params, "config") == "on") {
+#ifdef CUSTOM_OBS_DEFAULT_CONFIG
+ theObsConfig->parseJson(CUSTOM_OBS_DEFAULT_CONFIG);
+#else
theObsConfig->parseJson("{}");
+#endif
theObsConfig->fill(config);
}
+ if (getParameter(params, "sdcard") == "on") {
+ deleteAllFromSd();
+ }
sendRedirect(res, "/");
}