portapack-mayhem / mayhem-firmware

Custom firmware for the HackRF+PortaPack H1/H2/H4
https://hackrf.app
GNU General Public License v3.0
3.46k stars 561 forks source link

Fileman: paginate instead of keeping a list of all elements in directory #2071

Closed gullradriel closed 7 months ago

gullradriel commented 7 months ago

Description of the feature you're suggesting.

I want a fileman caching system to allow low memory print navigation/file choosing and custom saved directory sorting. It would be based on storing/updating/using hidden .fileman.db files at the root of each directory on the sdcard to quickly open and read the current displayed 8 lines

Overview of the how fileman cache update should work (will be edited as the conversations are giving feedback)

Each directory modification / deletion / creation should call update_fileman_path_db on:

Each file modification / deletion / creation should call update_fileman_path_db on:

Menu list process:

refresh_menu:

Additionally:

NotherNgineer commented 7 months ago

Another thing I'd like to see in Fileman is the ability to sort files by name or time stamp (this is probably even more unlikely if we only load a partial list into memory, but I thought perhaps the design could take that into consideration)

NotherNgineer commented 7 months ago

Just a thought: I think we set aside about 70KB of RAM space for baseband, and I wonder if we could either allocate space for the file list from that, and/or move part of the File Manager code to baseband. I can imagine messages to baseband to "add this file to list", "sort file list by name (or date)", or "return info on file index 15" so I can display it.

Of course this assumes baseband doesn't need to be running when selecting files, and there would still be a maximum file count (perhaps 1000 vs 100).

NotherNgineer commented 7 months ago

Using DFU, it also appears to me that File Manager isn't completely deallocating space for previously-opened folders until File Manager is exited.

Example: When I start File Manager from the utilities menu, there's about 25KB free (M0 core + M0 heap) when looking at the root directory. But if I open and close my SCREENSHOTS folder with 95 files in it, available memory has dropped to <18KB while viewing the root directory. The missing >7KB seems to be deallocated when File Manager is exited, but perhaps we could look into deallocating this space when the view of the large folder is exited. Otherwise it seems that I can get intermittent Guru "out of memory" faults when navigating between folders.

gullradriel commented 7 months ago

Yes, it's also causing 'out of memory' on 'random' or after a few apps launch. That thing need to be rewritten, even if we loose the sorting. The only way I see for us to keep the sorts and keep speed is to have a procedure that would list sdcard content and put a hidden .fileman.dat at the root of each dir, containing the list of files with size/dirs sorted. That procedure should rely on a single procedure 'update_fileman_path_db(path)' that we can call in some other parts. Then the fileman would just open the .fileman.dat at given path, read it, and just seek on the file. Any procedure that is modifying/adding/deleting folder/files may call update_fileman_path_db on the path itself or the path of the file.

gullradriel commented 7 months ago

@NotherNgineer I'm editing the OP to reflect what I think we need now, and how it should be done

gullradriel commented 7 months ago

Solved by #2077