Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteda82dd

Browse files
Add directory support to fs_driver
Support directory operations (dir_open_cb, dir_read_cb, dir_close_cb) in fs_driver.pyso that the file_explorer widget, when using fs_driver, is able to browse the filesystem.
1 parent49f63a7 commiteda82dd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎api_drivers/py_api_drivers/fs_driver.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,41 @@ def _fs_write_cb(drv, fs_file, buf, btw, bw):
7474

7575
returnlv.FS_RES.OK
7676

77+
def_fs_dir_open_cb(drv,path):
78+
#print(f"_fs_dir_open_cb for path '{path}'")
79+
try:
80+
importos# for ilistdir()
81+
return {'iterator' :os.ilistdir(path)}
82+
exceptExceptionase:
83+
print(f"_fs_dir_open_cb exception:{e}")
84+
returnNone
85+
86+
def_fs_dir_read_cb(drv,lv_fs_dir_t,buf,btr):
87+
try:
88+
iterator=lv_fs_dir_t.__cast__()['iterator']
89+
nextfile=iterator.__next__()
90+
#print(f"nextfile: {nextfile}")
91+
filename=nextfile[0]
92+
entry_type=nextfile[1]# Type field
93+
ifentry_type==0x4000:
94+
#print(f"{filename} is a directory")
95+
filename=f"/{filename}"
96+
# Convert filename to bytes with null terminator
97+
tmp_data_bytes=filename.encode()+b'\x00'
98+
buf.__dereference__(btr)[0:len(tmp_data_bytes)]=tmp_data_bytes
99+
returnlv.FS_RES.OK
100+
exceptStopIteration:
101+
# Clear buffer and return FS_ERR when iteration ends
102+
buf.__dereference__(btr)[0:1]=b'\x00'# Empty string (null byte)
103+
returnlv.FS_RES.NOT_EX# Next entry "does not exist"
104+
exceptExceptionase:
105+
print(f"_fs_dir_read_cb exception:{e}")
106+
returnlv.FS_RES.UNKNOWN
107+
108+
def_fs_dir_close_cb(drv,lv_fs_dir_t):
109+
#print(f"_fs_dir_close_cb called")
110+
# No need to cleanup the iterator so nothing to do
111+
returnlv.FS_RES.OK
77112

78113
deffs_register(fs_drv,letter,cache_size=500):
79114

@@ -85,6 +120,9 @@ def fs_register(fs_drv, letter, cache_size=500):
85120
fs_drv.seek_cb=_fs_seek_cb
86121
fs_drv.tell_cb=_fs_tell_cb
87122
fs_drv.close_cb=_fs_close_cb
123+
fs_drv.dir_open_cb=_fs_dir_open_cb
124+
fs_drv.dir_read_cb=_fs_dir_read_cb
125+
#fs_drv.dir_close_cb = _fs_dir_close_cb
88126

89127
ifcache_size>=0:
90128
fs_drv.cache_size=cache_size

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp