mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Add filsystem_list
This commit is contained in:
parent
0dd8e3dc2b
commit
eaa9d34a1a
@ -1,8 +1,10 @@
|
|||||||
/* MIT License - Copyright (c) 2019-2022 Francis Van Roie
|
/* MIT License - Copyright (c) 2019-2023 Francis Van Roie
|
||||||
For full license information read the LICENSE file in the project folder */
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
|
#include <Arduino.h>
|
||||||
#include "ArduinoLog.h"
|
#include "ArduinoLog.h"
|
||||||
|
#include "FS.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "hasp_conf.h" // include first
|
#include "hasp_conf.h" // include first
|
||||||
@ -10,12 +12,12 @@
|
|||||||
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
|
|
||||||
#ifndef HASP_ONLINE_CMD
|
#ifndef HASP_ONLINE_CMD
|
||||||
#define HASP_ONLINE_CMD "jsonl {\"page\":0,\"id\":239,\"obj\":\"msgbox\",\"text\":\"%ip%\", \"auto_close\":20000}"
|
#define HASP_ONLINE_CMD "jsonl {\"page\":0,\"id\":239,\"obj\":\"msgbox\",\"text\":\"%ip%\",\"auto_close\":20000}"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HASP_OFFLINE_CMD
|
#ifndef HASP_OFFLINE_CMD
|
||||||
#define HASP_OFFLINE_CMD \
|
#define HASP_OFFLINE_CMD \
|
||||||
"jsonl {\"page\":0,\"id\":239,\"obj\":\"msgbox\",\"text\":\"" D_NETWORK_OFFLINE "\", \"auto_close\":20000}"
|
"jsonl {\"page\":0,\"id\":239,\"obj\":\"msgbox\",\"text\":\"" D_NETWORK_OFFLINE "\",\"auto_close\":20000}"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HASP_PAGES_JSONL
|
#ifndef HASP_PAGES_JSONL
|
||||||
@ -194,6 +196,50 @@ void filesystemList()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
String filesystem_list(fs::FS& fs, const char* dirname, uint8_t levels)
|
||||||
|
{
|
||||||
|
LOG_VERBOSE(TAG_FILE, "Listing directory: %s\n", dirname);
|
||||||
|
String data = "[";
|
||||||
|
|
||||||
|
File root = fs.open(dirname);
|
||||||
|
if(!root) {
|
||||||
|
LOG_WARNING(TAG_FILE, "Failed to open directory");
|
||||||
|
} else if(!root.isDirectory()) {
|
||||||
|
LOG_WARNING(TAG_FILE, "Not a directory");
|
||||||
|
} else {
|
||||||
|
File file = root.openNextFile();
|
||||||
|
while(file) {
|
||||||
|
|
||||||
|
if(data != "[") {
|
||||||
|
data += ",";
|
||||||
|
}
|
||||||
|
data += "{\"name\":\"";
|
||||||
|
data += file.name();
|
||||||
|
data += "\"";
|
||||||
|
|
||||||
|
if(file.isDirectory()) {
|
||||||
|
data += ",\"children\":";
|
||||||
|
if(levels) {
|
||||||
|
String dir = dirname;
|
||||||
|
dir += file.name();
|
||||||
|
dir += '/';
|
||||||
|
data += filesystem_list(fs, dir.c_str(), levels - 1);
|
||||||
|
} else {
|
||||||
|
data += "[]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data += "}";
|
||||||
|
file = root.openNextFile();
|
||||||
|
}
|
||||||
|
root.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
data += "]";
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void filesystem_write_file(const char* filename, const char* data)
|
static void filesystem_write_file(const char* filename, const char* data)
|
||||||
{
|
{
|
||||||
if(HASP_FS.exists(filename)) return;
|
if(HASP_FS.exists(filename)) return;
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
/* MIT License - Copyright (c) 2019-2022 Francis Van Roie
|
/* MIT License - Copyright (c) 2019-2023 Francis Van Roie
|
||||||
For full license information read the LICENSE file in the project folder */
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#ifndef HASP_FILESYSTEM_H
|
#ifndef HASP_FILESYSTEM_H
|
||||||
#define HASP_FILESYSTEM_H
|
#define HASP_FILESYSTEM_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <FS.h>
|
||||||
|
|
||||||
bool filesystemSetup(void);
|
bool filesystemSetup(void);
|
||||||
|
|
||||||
@ -12,10 +13,6 @@ void filesystemList();
|
|||||||
void filesystemInfo();
|
void filesystemInfo();
|
||||||
void filesystemSetupFiles();
|
void filesystemSetupFiles();
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
void filesystemUnzip(const char*, const char* filename, uint8_t source);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum { ZIP_NO_COMPRESSION = 0, ZIP_DEFLTATE = 8 };
|
enum { ZIP_NO_COMPRESSION = 0, ZIP_DEFLTATE = 8 };
|
||||||
typedef uint16_t zip_compression_method_t;
|
typedef uint16_t zip_compression_method_t;
|
||||||
|
|
||||||
@ -54,6 +51,7 @@ typedef struct
|
|||||||
#endif // ESP_ARDUINO_VERSION
|
#endif // ESP_ARDUINO_VERSION
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
// included by default
|
// included by default
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
@ -65,4 +63,9 @@ typedef struct
|
|||||||
#include <Esp.h>
|
#include <Esp.h>
|
||||||
#endif // ARDUINO_ARCH
|
#endif // ARDUINO_ARCH
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
void filesystemUnzip(const char*, const char* filename, uint8_t source);
|
||||||
|
String filesystem_list(fs::FS& fs, const char* dirname, uint8_t levels);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // HASP_FILESYSTEM_H
|
#endif // HASP_FILESYSTEM_H
|
Loading…
x
Reference in New Issue
Block a user