mirror of https://github.com/arendst/Tasmota.git
Berry add `path.last_modified()`
This commit is contained in:
parent
6b48d9949b
commit
9fa3cb4544
|
@ -16,6 +16,7 @@
|
|||
#include "be_strlib.h"
|
||||
#include "be_mem.h"
|
||||
#include "be_sys.h"
|
||||
#include <time.h>
|
||||
|
||||
static int m_path_exists(bvm *vm)
|
||||
{
|
||||
|
@ -26,10 +27,25 @@ static int m_path_exists(bvm *vm)
|
|||
be_pushbool(vm, be_isexist(path));
|
||||
be_return(vm);
|
||||
}
|
||||
extern time_t be_last_modified(void *hfile);
|
||||
|
||||
static int m_path_last_modified(bvm *vm)
|
||||
{
|
||||
if (be_top(vm) >= 1 && be_isstring(vm, 1)) {
|
||||
const char *path = be_tostring(vm, 1);
|
||||
void * f = be_fopen(path, "r");
|
||||
if (f) {
|
||||
be_pushint(vm, be_last_modified(f));
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
/* @const_object_info_begin
|
||||
module path (scope: global, file: tasmota_path) {
|
||||
exists, func(m_path_exists)
|
||||
last_modified, func(m_path_last_modified)
|
||||
}
|
||||
@const_object_info_end */
|
||||
#include "../generate/be_fixed_tasmota_path.h"
|
||||
|
|
|
@ -248,6 +248,17 @@ size_t be_fsize(void *hfile)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" time_t be_last_modified(void *hfile)
|
||||
{
|
||||
#ifdef USE_UFILESYS
|
||||
if (ufsp != nullptr && hfile != nullptr) {
|
||||
File * f_ptr = (File*) hfile;
|
||||
return f_ptr->getLastWrite();
|
||||
}
|
||||
#endif // USE_UFILESYS
|
||||
return 0;
|
||||
}
|
||||
|
||||
int be_isexist(const char *filename)
|
||||
{
|
||||
#ifdef USE_UFILESYS
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extern const bcstring be_const_str_PZEM0XX_TX;
|
||||
extern const bcstring be_const_str__begin_transmission;
|
||||
extern const bcstring be_const_str_MHZ_TXD;
|
||||
extern const bcstring be_const_str_last_modified;
|
||||
extern const bcstring be_const_str_list;
|
||||
extern const bcstring be_const_str_lv_draw_mask_line_param_cfg;
|
||||
extern const bcstring be_const_str_screenshot;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
be_define_const_str(PZEM0XX_TX, "PZEM0XX_TX", 944775704u, 0, 10, &be_const_str__begin_transmission);
|
||||
be_define_const_str(_begin_transmission, "_begin_transmission", 2779461176u, 0, 19, NULL);
|
||||
be_define_const_str(MHZ_TXD, "MHZ_TXD", 3310158233u, 0, 7, &be_const_str_list);
|
||||
be_define_const_str(MHZ_TXD, "MHZ_TXD", 3310158233u, 0, 7, &be_const_str_last_modified);
|
||||
be_define_const_str(last_modified, "last_modified", 772177145u, 0, 13, &be_const_str_list);
|
||||
be_define_const_str(list, "list", 217798785u, 0, 4, &be_const_str_lv_draw_mask_line_param_cfg);
|
||||
be_define_const_str(lv_draw_mask_line_param_cfg, "lv_draw_mask_line_param_cfg", 2154874825u, 0, 27, &be_const_str_screenshot);
|
||||
be_define_const_str(screenshot, "screenshot", 3894592561u, 0, 10, NULL);
|
||||
|
@ -1058,6 +1059,6 @@ static const bstring* const m_string_table[] = {
|
|||
|
||||
static const struct bconststrtab m_const_string_table = {
|
||||
.size = 344,
|
||||
.count = 688,
|
||||
.count = 689,
|
||||
.table = m_string_table
|
||||
};
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
static be_define_const_map_slots(m_libpath_map) {
|
||||
{ be_const_key(exists, -1), be_const_func(m_path_exists) },
|
||||
{ be_const_key(last_modified, 0), be_const_func(m_path_last_modified) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
m_libpath_map,
|
||||
1
|
||||
2
|
||||
);
|
||||
|
||||
static be_define_const_module(
|
||||
|
|
Loading…
Reference in New Issue