1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-21 22:50:55 +00:00

Converted to normalized littlefs definition

This commit is contained in:
MartinMueller2003 2024-02-12 09:09:51 -05:00
parent 707c2aa3bf
commit da20c8b0a5

View File

@ -76,16 +76,7 @@ void listDir(const char* dirname, uint8_t levels)
} }
#endif #endif
#if defined(ESP32) File root = ESPUI.EspuiLittleFS.open(dirname);
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
File root = LittleFS.open(dirname);
#else
File root = LITTLEFS.open(dirname);
#endif
#else
File root = LittleFS.open(dirname);
#endif
if (!root) if (!root)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
@ -160,7 +151,7 @@ void listDir(const char* dirname, uint8_t levels)
} }
#endif #endif
Dir dir = LittleFS.openDir(dirname); Dir dir = EspuiLittleFS.openDir(dirname);
while (dir.next()) while (dir.next())
{ {
@ -199,63 +190,33 @@ void listDir(const char* dirname, uint8_t levels)
void ESPUIClass::list() void ESPUIClass::list()
{ {
#if defined(ESP32) if (!EspuiLittleFS.begin())
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
if (!LittleFS.begin())
#else
if (!LITTLEFS.begin())
#endif
{ {
Serial.println(F("LITTLEFS Mount Failed")); Serial.println(F("Espui LittleFS Mount Failed"));
return; return;
} }
#else
if (!LittleFS.begin())
{
Serial.println(F("LittleFS Mount Failed"));
return;
}
#endif
listDir("/", 1); listDir("/", 1);
#if defined(ESP32) #if defined(ESP32)
Serial.print(F("Total KB: ")); Serial.print(F("Total KB: "));
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 Serial.println(EspuiLittleFS.totalBytes() / 1024);
Serial.println(LittleFS.totalBytes() / 1024);
#else
Serial.println(LITTLEFS.totalBytes() / 1024);
#endif
Serial.print(F("Used KB: ")); Serial.print(F("Used KB: "));
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 Serial.println(EspuiLittleFS.usedBytes() / 1024);
Serial.println(LittleFS.usedBytes() / 1024);
#else
Serial.println(LITTLEFS.usedBytes() / 1024);
#endif
#else #else
FSInfo fs_info; FSInfo fs_info;
LittleFS.info(fs_info); EspuiLittleFS.info(fs_info);
Serial.print(F("Total KB: ")); Serial.print(F("Total KB: "));
Serial.println(fs_info.totalBytes / 1024); Serial.println(fs_info.totalBytes / 1024);
Serial.print(F("Used KB: ")); Serial.print(F("Used KB: "));
Serial.println(fs_info.usedBytes / 1024); Serial.println(fs_info.usedBytes / 1024);
#endif // !defined(ESP32)
#endif
} }
void deleteFile(const char* path) void deleteFile(const char* path)
{ {
#if defined(ESP32) bool exists = ESPUI.EspuiLittleFS.exists(path);
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
bool exists = LittleFS.exists(path);
#else
bool exists = LITTLEFS.exists(path);
#endif
#else
bool exists = LittleFS.exists(path);
#endif
if (!exists) if (!exists)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
@ -275,15 +236,7 @@ void deleteFile(const char* path)
} }
#endif #endif
#if defined(ESP32) bool didRemove = ESPUI.EspuiLittleFS.remove(path);
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
bool didRemove = LittleFS.remove(path);
#else
bool didRemove = LITTLEFS.remove(path);
#endif
#else
bool didRemove = LittleFS.remove(path);
#endif
if (didRemove) if (didRemove)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
@ -304,7 +257,7 @@ void deleteFile(const char* path)
} }
} }
void writeFile(const char* path, const char* data) void ESPUIClass::writeFile(const char* path, const char* data)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
@ -313,15 +266,7 @@ void writeFile(const char* path, const char* data)
} }
#endif #endif
#if defined(ESP32) File file = EspuiLittleFS.open(path, FILE_WRITE);
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
File file = LittleFS.open(path, FILE_WRITE);
#else
File file = LITTLEFS.open(path, FILE_WRITE);
#endif
#else
File file = LittleFS.open(path, FILE_WRITE);
#endif
if (!file) if (!file)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
@ -335,48 +280,26 @@ void writeFile(const char* path, const char* data)
} }
#if defined(ESP32) #if defined(ESP32)
if (file.print(data)) if (file.print(data))
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(F("File written"));
}
#endif
}
else
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(F("Write failed"));
}
#endif
}
#else #else
if (file.print(FPSTR(data))) if (file.print(FPSTR(data)))
#endif // !defined(ESP32)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
Serial.println(F("File written")); Serial.println(F("File written"));
} }
#endif
} }
else else
{ {
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
Serial.println(F("Write failed")); Serial.println(F("Write failed"));
} }
#endif #endif
} }
#endif
file.close(); file.close();
} }
@ -394,18 +317,17 @@ void ESPUIClass::prepareFileSystem(bool format)
#endif #endif
#if defined(ESP32) #if defined(ESP32)
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 if (!EspuiLittleFS.begin(false)) // Test for an already formatted LittleFS by a mount failure
if (!LittleFS.begin(false)) // Test for an already formatted LittleFS by a mount failure
#else
if (!LITTLEFS.begin(false)) // Test for an already formatted LittleFS by a mount failure
#endif
{ {
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 if (!EspuiLittleFS.begin(true)) // Attempt to format LittleFS
if (!LittleFS.begin(true)) // Attempt to format LittleFS
#else
if (!LITTLEFS.begin(true)) // Attempt to format LittleFS
#endif
{ {
#else
if (!EspuiLittleFS.begin()) // Test for an already formatted LittleFS by a mount failure
{
if (EspuiLittleFS.format()) // Attempt to format LittleFS
{
#endif // !defined(ESP32)
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (verbosity) if (verbosity)
{ {
@ -417,11 +339,8 @@ void ESPUIClass::prepareFileSystem(bool format)
} }
else if (format) else if (format)
{ {
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 EspuiLittleFS.format();
LittleFS.format();
#else
LITTLEFS.format();
#endif
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (verbosity) if (verbosity)
{ {
@ -436,51 +355,6 @@ void ESPUIClass::prepareFileSystem(bool format)
listDir("/", 1); listDir("/", 1);
Serial.println(F("LittleFS Mount ESP32 Done")); Serial.println(F("LittleFS Mount ESP32 Done"));
} }
#endif
#else
if (!LittleFS.begin()) // Test for an already formatted LittleFS by a mount failure
{
if (LittleFS.format()) // Attempt to format LittleFS
{
#if defined(DEBUG_ESPUI)
if (verbosity)
{
Serial.println(F("LittleFS Formatted"));
}
#endif
}
else
{
#if defined(DEBUG_ESPUI)
if (verbosity)
{
Serial.println(F("LittleFS Mount Failed"));
}
#endif
return;
}
}
else if (format)
{
LittleFS.format();
#if defined(DEBUG_ESPUI)
if (verbosity)
{
Serial.println(F("LittleFS Formatted"));
}
#endif
}
#if defined(DEBUG_ESPUI)
if (verbosity)
{
listDir("/", 1);
Serial.println(F("LittleFS Mount ESP8266 Done"));
}
#endif
#endif #endif
deleteFile("/index.htm"); deleteFile("/index.htm");
@ -503,31 +377,18 @@ void ESPUIClass::prepareFileSystem(bool format)
// Now write // Now write
#ifdef ESP32 #ifdef ESP32
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
writeFile("/index.htm", HTML_INDEX); writeFile("/index.htm", HTML_INDEX);
LittleFS.mkdir("/css"); EspuiLittleFS.mkdir("/css");
writeFile("/css/style.css", CSS_STYLE); writeFile("/css/style.css", CSS_STYLE);
writeFile("/css/normalize.css", CSS_NORMALIZE); writeFile("/css/normalize.css", CSS_NORMALIZE);
LittleFS.mkdir("/js"); EspuiLittleFS.mkdir("/js");
writeFile("/js/zepto.min.js", JS_ZEPTO); writeFile("/js/zepto.min.js", JS_ZEPTO);
writeFile("/js/controls.js", JS_CONTROLS); writeFile("/js/controls.js", JS_CONTROLS);
writeFile("/js/slider.js", JS_SLIDER); writeFile("/js/slider.js", JS_SLIDER);
writeFile("/js/graph.js", JS_GRAPH); writeFile("/js/graph.js", JS_GRAPH);
writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT); writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT);
#else
writeFile("/index.htm", HTML_INDEX);
LITTLEFS.mkdir("/css");
writeFile("/css/style.css", CSS_STYLE);
writeFile("/css/normalize.css", CSS_NORMALIZE);
LITTLEFS.mkdir("/js");
writeFile("/js/zepto.min.js", JS_ZEPTO);
writeFile("/js/controls.js", JS_CONTROLS);
writeFile("/js/slider.js", JS_SLIDER);
writeFile("/js/graph.js", JS_GRAPH);
writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT);
#endif
#else #else
writeFile("/index.htm", HTML_INDEX); writeFile("/index.htm", HTML_INDEX);
@ -560,15 +421,7 @@ void ESPUIClass::prepareFileSystem(bool format)
#endif #endif
#if defined(ESP32) EspuiLittleFS.end();
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
LittleFS.end();
#else
LITTLEFS.end();
#endif
#else
LittleFS.end();
#endif
} }
// Handle Websockets Communication // Handle Websockets Communication
@ -1177,15 +1030,7 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c
server = new AsyncWebServer(port); server = new AsyncWebServer(port);
ws = new AsyncWebSocket("/ws"); ws = new AsyncWebSocket("/ws");
#if defined(ESP32) bool fsBegin = EspuiLittleFS.begin();
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
bool fsBegin = LittleFS.begin();
#else
bool fsBegin = LITTLEFS.begin();
#endif
#else
bool fsBegin = LittleFS.begin();
#endif
if (!fsBegin) if (!fsBegin)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
@ -1206,15 +1051,7 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c
} }
#endif #endif
#if defined(ESP32) bool indexExists = EspuiLittleFS.exists("/index.htm");
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
bool indexExists = LittleFS.exists("/index.htm");
#else
bool indexExists = LITTLEFS.exists("/index.htm");
#endif
#else
bool indexExists = LittleFS.exists("/index.htm");
#endif
if (!indexExists) if (!indexExists)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
@ -1238,27 +1075,11 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c
{ {
ws->setAuthentication(basicAuthUsername, basicAuthPassword); ws->setAuthentication(basicAuthUsername, basicAuthPassword);
} }
#if defined(ESP32) server->serveStatic("/", EspuiLittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#else
server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#endif
#else
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#endif
} }
else else
{ {
#if defined(ESP32) server->serveStatic("/", EspuiLittleFS, "/").setDefaultFile("index.htm");
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
#else
server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm");
#endif
#else
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
#endif
} }
// Heap for general Servertest // Heap for general Servertest
@ -1444,6 +1265,7 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas
{ {
request->send(404); request->send(404);
} }
yield();
}); });
server->begin(); server->begin();