2021-09-21 10:56:33 +00:00
|
|
|
|
2021-09-10 00:57:43 +00:00
|
|
|
#include "archive_favorites.h"
|
2022-02-10 13:01:49 +00:00
|
|
|
#include "archive_files.h"
|
|
|
|
#include "archive_apps.h"
|
2021-09-21 10:56:33 +00:00
|
|
|
#include "archive_browser.h"
|
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
#define ARCHIVE_FAV_FILE_BUF_LEN 32
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
static bool archive_favorites_read_line(File* file, FuriString* str_result) {
|
|
|
|
furi_string_reset(str_result);
|
2022-04-14 11:28:59 +00:00
|
|
|
uint8_t buffer[ARCHIVE_FAV_FILE_BUF_LEN];
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
do {
|
2023-11-15 16:39:27 +00:00
|
|
|
size_t read_count = storage_file_read(file, buffer, ARCHIVE_FAV_FILE_BUF_LEN);
|
2022-04-14 11:28:59 +00:00
|
|
|
if(storage_file_get_error(file) != FSE_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-15 16:39:27 +00:00
|
|
|
for(size_t i = 0; i < read_count; i++) {
|
2022-04-14 11:28:59 +00:00
|
|
|
if(buffer[i] == '\n') {
|
|
|
|
uint32_t position = storage_file_tell(file);
|
|
|
|
if(storage_file_get_error(file) != FSE_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
position = position - read_count + i + 1;
|
|
|
|
|
|
|
|
storage_file_seek(file, position, true);
|
|
|
|
if(storage_file_get_error(file) != FSE_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
} else {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_push_back(str_result, buffer[i]);
|
2022-04-14 11:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result || read_count == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(true);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
uint16_t archive_favorites_count(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
File* file = storage_file_alloc(fs_api);
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* buffer;
|
|
|
|
buffer = furi_string_alloc();
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2021-09-21 10:56:33 +00:00
|
|
|
uint16_t lines = 0;
|
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
2022-04-14 11:28:59 +00:00
|
|
|
if(!archive_favorites_read_line(file, buffer)) {
|
2021-09-21 10:56:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_size(buffer)) {
|
2022-08-11 15:16:47 +00:00
|
|
|
continue; // Skip empty lines
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
++lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_close(file);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(buffer);
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
return lines;
|
|
|
|
}
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-01-29 09:39:10 +00:00
|
|
|
static bool archive_favourites_rescan() {
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* buffer;
|
|
|
|
buffer = furi_string_alloc();
|
[FL-2529][FL-1628] New LF-RFID subsystem (#1601)
* Makefile: unit tests pack
* RFID: pulse joiner and its unit test
* Move pulse protocol helpers to appropriate place
* Drop pulse_joiner tests
* Generic protocol, protocols dictionary, unit test
* Protocol dict unit test
* iButton: protocols dictionary
* Lib: varint
* Lib: profiler
* Unit test: varint
* rfid: worker mockup
* LFRFID: em4100 unit test
* Storage: file_exist function
* rfid: fsk osc
* rfid: generic fsk demodulator
* rfid: protocol em4100
* rfid: protocol h10301
* rfid: protocol io prox xsf
* Unit test: rfid protocols
* rfid: new hal
* rfid: raw worker
* Unit test: fix error output
* rfid: worker
* rfid: plain c cli
* fw: migrate to scons
* lfrfid: full io prox support
* unit test: io prox protocol
* SubGHZ: move bit defines to source
* FSK oscillator: level duration compability
* libs: bit manipulation library
* lfrfid: ioprox protocol, use bit library and new level duration method of FSK ocillator
* bit lib: unit tests
* Bit lib: parity tests, remove every nth bit, copy bits
* Lfrfid: awid protocol
* bit lib: uint16 and uint32 getters, unit tests
* lfrfid: FDX-B read, draft version
* Minunit: better memeq assert
* bit lib: reverse, print, print regions
* Protocol dict: get protocol features, get protocol validate count
* lfrfid worker: improved read
* lfrfid raw worker: psk support
* Cli: rfid plain C cli
* protocol AWID: render
* protocol em4100: render
* protocol h10301: render
* protocol indala26: support every indala 26 scramble
* Protocol IO Prox: render
* Protocol FDX-B: advanced read
* lfrfid: remove unused test function
* lfrfid: fix os primitives
* bit lib: crc16 and unit tests
* FDX-B: save data
* lfrfid worker: increase stream size. Alloc raw worker only when needed.
* lfrfid: indala26 emulation
* lfrfid: prepare to write
* lfrfid: fdx-b emulation
* lfrfid: awid, ioprox write
* lfrfid: write t55xx w\o validation
* lfrfid: better t55xx block0 handling
* lfrfid: use new t5577 functions in worker
* lfrfid: improve protocol description
* lfrfid: write and verify
* lfrfid: delete cpp cli
* lfrfid: improve worker usage
* lfrfid-app: step to new worker
* lfrfid: old indala (I40134) load fallback
* lfrfid: indala26, recover wrong synced data
* lfrfid: remove old worker
* lfrfid app: dummy read screen
* lfrfid app: less dummy read screen
* lfrfid: generic 96-bit HID protocol (covers up to HID 37-bit)
* rename
* lfrfid: improve indala26 read
* lfrfid: generic 192-bit HID protocol (covers all HID extended)
* lfrfid: TODO about HID render
* lfrfid: new protocol FDX-A
* lfrfid-app: correct worker stop on exit
* misc fixes
* lfrfid: FDX-A and HID distinguishability has been fixed.
* lfrfid: decode HID size header and render it (#1612)
* lfrfid: rename HID96 and HID192 to HIDProx and HIDExt
* lfrfid: extra actions scene
* lfrfid: decode generic HID Proximity size lazily (#1618)
* lib: stream of data buffers concept
* lfrfid: raw file helper
* lfrfid: changed raw worker api
* lfrfid: packed varint pair
* lfrfid: read stream speedup
* lfrfid app: show read mode
* Documentation
* lfrfid app: raw read gui
* lfrfid app: storage check for raw read
* memleak fix
* review fixes
* lfrfid app: read blink color
* lfrfid app: reset key name after read
* review fixes
* lfrfid app: fix copypasted text
* review fixes
* lfrfid: disable debug gpio
* lfrfid: card detection events
* lfrfid: change validation color from magenta to green
* Update core_defines.
* lfrfid: prefix fdx-b id by zeroes
* lfrfid: parse up to 43-bit HID Proximity keys (#1640)
* Fbt: downgrade toolchain and fix PS1
* lfrfid: fix unit tests
* lfrfid app: remove printf
* lfrfid: indala26, use bit 55 as data
* lfrfid: indala26, better brief format
* lfrfid: indala26, loading fallback
* lfrfid: read timing tuning
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
2022-08-23 15:57:39 +00:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
File* file = storage_file_alloc(storage);
|
2022-01-29 09:39:10 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2022-01-29 09:39:10 +00:00
|
|
|
if(result) {
|
|
|
|
while(1) {
|
2022-04-14 11:28:59 +00:00
|
|
|
if(!archive_favorites_read_line(file, buffer)) {
|
2022-01-29 09:39:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_size(buffer)) {
|
2022-08-11 15:16:47 +00:00
|
|
|
continue;
|
2022-01-29 09:39:10 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_search(buffer, "/app:") == 0) {
|
|
|
|
if(archive_app_is_available(NULL, furi_string_get_cstr(buffer))) {
|
|
|
|
archive_file_append(
|
|
|
|
ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(buffer));
|
2022-02-10 13:01:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(storage_file_exists(storage, furi_string_get_cstr(buffer))) {
|
|
|
|
archive_file_append(
|
|
|
|
ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(buffer));
|
2022-02-10 13:01:49 +00:00
|
|
|
}
|
2022-01-29 09:39:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(buffer);
|
2022-01-29 09:39:10 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_close(file);
|
[FL-2529][FL-1628] New LF-RFID subsystem (#1601)
* Makefile: unit tests pack
* RFID: pulse joiner and its unit test
* Move pulse protocol helpers to appropriate place
* Drop pulse_joiner tests
* Generic protocol, protocols dictionary, unit test
* Protocol dict unit test
* iButton: protocols dictionary
* Lib: varint
* Lib: profiler
* Unit test: varint
* rfid: worker mockup
* LFRFID: em4100 unit test
* Storage: file_exist function
* rfid: fsk osc
* rfid: generic fsk demodulator
* rfid: protocol em4100
* rfid: protocol h10301
* rfid: protocol io prox xsf
* Unit test: rfid protocols
* rfid: new hal
* rfid: raw worker
* Unit test: fix error output
* rfid: worker
* rfid: plain c cli
* fw: migrate to scons
* lfrfid: full io prox support
* unit test: io prox protocol
* SubGHZ: move bit defines to source
* FSK oscillator: level duration compability
* libs: bit manipulation library
* lfrfid: ioprox protocol, use bit library and new level duration method of FSK ocillator
* bit lib: unit tests
* Bit lib: parity tests, remove every nth bit, copy bits
* Lfrfid: awid protocol
* bit lib: uint16 and uint32 getters, unit tests
* lfrfid: FDX-B read, draft version
* Minunit: better memeq assert
* bit lib: reverse, print, print regions
* Protocol dict: get protocol features, get protocol validate count
* lfrfid worker: improved read
* lfrfid raw worker: psk support
* Cli: rfid plain C cli
* protocol AWID: render
* protocol em4100: render
* protocol h10301: render
* protocol indala26: support every indala 26 scramble
* Protocol IO Prox: render
* Protocol FDX-B: advanced read
* lfrfid: remove unused test function
* lfrfid: fix os primitives
* bit lib: crc16 and unit tests
* FDX-B: save data
* lfrfid worker: increase stream size. Alloc raw worker only when needed.
* lfrfid: indala26 emulation
* lfrfid: prepare to write
* lfrfid: fdx-b emulation
* lfrfid: awid, ioprox write
* lfrfid: write t55xx w\o validation
* lfrfid: better t55xx block0 handling
* lfrfid: use new t5577 functions in worker
* lfrfid: improve protocol description
* lfrfid: write and verify
* lfrfid: delete cpp cli
* lfrfid: improve worker usage
* lfrfid-app: step to new worker
* lfrfid: old indala (I40134) load fallback
* lfrfid: indala26, recover wrong synced data
* lfrfid: remove old worker
* lfrfid app: dummy read screen
* lfrfid app: less dummy read screen
* lfrfid: generic 96-bit HID protocol (covers up to HID 37-bit)
* rename
* lfrfid: improve indala26 read
* lfrfid: generic 192-bit HID protocol (covers all HID extended)
* lfrfid: TODO about HID render
* lfrfid: new protocol FDX-A
* lfrfid-app: correct worker stop on exit
* misc fixes
* lfrfid: FDX-A and HID distinguishability has been fixed.
* lfrfid: decode HID size header and render it (#1612)
* lfrfid: rename HID96 and HID192 to HIDProx and HIDExt
* lfrfid: extra actions scene
* lfrfid: decode generic HID Proximity size lazily (#1618)
* lib: stream of data buffers concept
* lfrfid: raw file helper
* lfrfid: changed raw worker api
* lfrfid: packed varint pair
* lfrfid: read stream speedup
* lfrfid app: show read mode
* Documentation
* lfrfid app: raw read gui
* lfrfid app: storage check for raw read
* memleak fix
* review fixes
* lfrfid app: read blink color
* lfrfid app: reset key name after read
* review fixes
* lfrfid app: fix copypasted text
* review fixes
* lfrfid: disable debug gpio
* lfrfid: card detection events
* lfrfid: change validation color from magenta to green
* Update core_defines.
* lfrfid: prefix fdx-b id by zeroes
* lfrfid: parse up to 43-bit HID Proximity keys (#1640)
* Fbt: downgrade toolchain and fix PS1
* lfrfid: fix unit tests
* lfrfid app: remove printf
* lfrfid: indala26, use bit 55 as data
* lfrfid: indala26, better brief format
* lfrfid: indala26, loading fallback
* lfrfid: read timing tuning
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
2022-08-23 15:57:39 +00:00
|
|
|
storage_common_remove(storage, ARCHIVE_FAV_PATH);
|
|
|
|
storage_common_rename(storage, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
storage_common_remove(storage, ARCHIVE_FAV_TEMP_PATH);
|
2022-01-29 09:39:10 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-01-29 09:39:10 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-10 00:57:43 +00:00
|
|
|
bool archive_favorites_read(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
2021-10-12 13:09:34 +00:00
|
|
|
ArchiveBrowserView* browser = context;
|
[FL-2529][FL-1628] New LF-RFID subsystem (#1601)
* Makefile: unit tests pack
* RFID: pulse joiner and its unit test
* Move pulse protocol helpers to appropriate place
* Drop pulse_joiner tests
* Generic protocol, protocols dictionary, unit test
* Protocol dict unit test
* iButton: protocols dictionary
* Lib: varint
* Lib: profiler
* Unit test: varint
* rfid: worker mockup
* LFRFID: em4100 unit test
* Storage: file_exist function
* rfid: fsk osc
* rfid: generic fsk demodulator
* rfid: protocol em4100
* rfid: protocol h10301
* rfid: protocol io prox xsf
* Unit test: rfid protocols
* rfid: new hal
* rfid: raw worker
* Unit test: fix error output
* rfid: worker
* rfid: plain c cli
* fw: migrate to scons
* lfrfid: full io prox support
* unit test: io prox protocol
* SubGHZ: move bit defines to source
* FSK oscillator: level duration compability
* libs: bit manipulation library
* lfrfid: ioprox protocol, use bit library and new level duration method of FSK ocillator
* bit lib: unit tests
* Bit lib: parity tests, remove every nth bit, copy bits
* Lfrfid: awid protocol
* bit lib: uint16 and uint32 getters, unit tests
* lfrfid: FDX-B read, draft version
* Minunit: better memeq assert
* bit lib: reverse, print, print regions
* Protocol dict: get protocol features, get protocol validate count
* lfrfid worker: improved read
* lfrfid raw worker: psk support
* Cli: rfid plain C cli
* protocol AWID: render
* protocol em4100: render
* protocol h10301: render
* protocol indala26: support every indala 26 scramble
* Protocol IO Prox: render
* Protocol FDX-B: advanced read
* lfrfid: remove unused test function
* lfrfid: fix os primitives
* bit lib: crc16 and unit tests
* FDX-B: save data
* lfrfid worker: increase stream size. Alloc raw worker only when needed.
* lfrfid: indala26 emulation
* lfrfid: prepare to write
* lfrfid: fdx-b emulation
* lfrfid: awid, ioprox write
* lfrfid: write t55xx w\o validation
* lfrfid: better t55xx block0 handling
* lfrfid: use new t5577 functions in worker
* lfrfid: improve protocol description
* lfrfid: write and verify
* lfrfid: delete cpp cli
* lfrfid: improve worker usage
* lfrfid-app: step to new worker
* lfrfid: old indala (I40134) load fallback
* lfrfid: indala26, recover wrong synced data
* lfrfid: remove old worker
* lfrfid app: dummy read screen
* lfrfid app: less dummy read screen
* lfrfid: generic 96-bit HID protocol (covers up to HID 37-bit)
* rename
* lfrfid: improve indala26 read
* lfrfid: generic 192-bit HID protocol (covers all HID extended)
* lfrfid: TODO about HID render
* lfrfid: new protocol FDX-A
* lfrfid-app: correct worker stop on exit
* misc fixes
* lfrfid: FDX-A and HID distinguishability has been fixed.
* lfrfid: decode HID size header and render it (#1612)
* lfrfid: rename HID96 and HID192 to HIDProx and HIDExt
* lfrfid: extra actions scene
* lfrfid: decode generic HID Proximity size lazily (#1618)
* lib: stream of data buffers concept
* lfrfid: raw file helper
* lfrfid: changed raw worker api
* lfrfid: packed varint pair
* lfrfid: read stream speedup
* lfrfid app: show read mode
* Documentation
* lfrfid app: raw read gui
* lfrfid app: storage check for raw read
* memleak fix
* review fixes
* lfrfid app: read blink color
* lfrfid app: reset key name after read
* review fixes
* lfrfid app: fix copypasted text
* review fixes
* lfrfid: disable debug gpio
* lfrfid: card detection events
* lfrfid: change validation color from magenta to green
* Update core_defines.
* lfrfid: prefix fdx-b id by zeroes
* lfrfid: parse up to 43-bit HID Proximity keys (#1640)
* Fbt: downgrade toolchain and fix PS1
* lfrfid: fix unit tests
* lfrfid app: remove printf
* lfrfid: indala26, use bit 55 as data
* lfrfid: indala26, better brief format
* lfrfid: indala26, loading fallback
* lfrfid: read timing tuning
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
2022-08-23 15:57:39 +00:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
File* file = storage_file_alloc(storage);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* buffer;
|
2021-09-10 00:57:43 +00:00
|
|
|
FileInfo file_info;
|
2022-10-05 15:15:23 +00:00
|
|
|
buffer = furi_string_alloc();
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-01-29 09:39:10 +00:00
|
|
|
bool need_refresh = false;
|
2022-04-06 17:44:06 +00:00
|
|
|
uint16_t file_count = 0;
|
|
|
|
|
|
|
|
archive_file_array_rm_all(browser);
|
2022-01-29 09:39:10 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
2022-04-14 11:28:59 +00:00
|
|
|
if(!archive_favorites_read_line(file, buffer)) {
|
2021-09-10 00:57:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_size(buffer)) {
|
2022-08-11 15:16:47 +00:00
|
|
|
continue;
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_search(buffer, "/app:") == 0) {
|
|
|
|
if(archive_app_is_available(browser, furi_string_get_cstr(buffer))) {
|
|
|
|
archive_add_app_item(browser, furi_string_get_cstr(buffer));
|
2022-04-06 17:44:06 +00:00
|
|
|
file_count++;
|
2022-02-10 13:01:49 +00:00
|
|
|
} else {
|
|
|
|
need_refresh = true;
|
|
|
|
}
|
|
|
|
} else {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(storage_file_exists(storage, furi_string_get_cstr(buffer))) {
|
|
|
|
storage_common_stat(storage, furi_string_get_cstr(buffer), &file_info);
|
2022-06-09 07:09:52 +00:00
|
|
|
archive_add_file_item(
|
2023-03-01 17:57:27 +00:00
|
|
|
browser, file_info_is_dir(&file_info), furi_string_get_cstr(buffer));
|
2022-04-06 17:44:06 +00:00
|
|
|
file_count++;
|
|
|
|
} else {
|
2022-02-10 13:01:49 +00:00
|
|
|
need_refresh = true;
|
2022-04-06 17:44:06 +00:00
|
|
|
}
|
2022-02-10 13:01:49 +00:00
|
|
|
}
|
2022-01-29 09:39:10 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_reset(buffer);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_close(file);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(buffer);
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-01-29 09:39:10 +00:00
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
archive_set_item_count(browser, file_count);
|
|
|
|
|
2022-12-26 12:13:30 +00:00
|
|
|
if(need_refresh) { //-V547
|
2022-01-29 09:39:10 +00:00
|
|
|
archive_favourites_rescan();
|
|
|
|
}
|
|
|
|
|
2021-09-10 00:57:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
bool archive_favorites_delete(const char* format, ...) {
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* buffer;
|
|
|
|
FuriString* filename;
|
2021-09-21 10:56:33 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2022-10-05 15:15:23 +00:00
|
|
|
filename = furi_string_alloc_vprintf(format, args);
|
2021-09-21 10:56:33 +00:00
|
|
|
va_end(args);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
buffer = furi_string_alloc();
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
File* file = storage_file_alloc(fs_api);
|
|
|
|
|
|
|
|
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
2022-04-14 11:28:59 +00:00
|
|
|
if(!archive_favorites_read_line(file, buffer)) {
|
2021-09-10 00:57:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_size(buffer)) {
|
2022-08-11 15:16:47 +00:00
|
|
|
continue;
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_search(buffer, filename)) {
|
|
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(buffer));
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(buffer);
|
|
|
|
furi_string_free(filename);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_close(file);
|
|
|
|
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
|
|
|
storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
2022-04-14 17:02:16 +00:00
|
|
|
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
bool archive_is_favorite(const char* format, ...) {
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* buffer;
|
|
|
|
FuriString* filename;
|
2021-09-21 10:56:33 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2022-10-05 15:15:23 +00:00
|
|
|
filename = furi_string_alloc_vprintf(format, args);
|
2021-09-21 10:56:33 +00:00
|
|
|
va_end(args);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
buffer = furi_string_alloc();
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
File* file = storage_file_alloc(fs_api);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
bool found = false;
|
2022-04-14 11:28:59 +00:00
|
|
|
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
2022-04-14 11:28:59 +00:00
|
|
|
if(!archive_favorites_read_line(file, buffer)) {
|
2021-09-10 00:57:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_size(buffer)) {
|
2022-08-11 15:16:47 +00:00
|
|
|
continue;
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_search(buffer, filename)) {
|
2021-09-10 00:57:43 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_close(file);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(buffer);
|
|
|
|
furi_string_free(filename);
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2022-02-10 13:01:49 +00:00
|
|
|
bool archive_favorites_rename(const char* src, const char* dst) {
|
2021-09-10 00:57:43 +00:00
|
|
|
furi_assert(src);
|
|
|
|
furi_assert(dst);
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
File* file = storage_file_alloc(fs_api);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* path;
|
|
|
|
FuriString* buffer;
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
buffer = furi_string_alloc();
|
|
|
|
path = furi_string_alloc();
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(path, "%s", src);
|
2022-04-14 11:28:59 +00:00
|
|
|
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
2022-04-14 11:28:59 +00:00
|
|
|
if(!archive_favorites_read_line(file, buffer)) {
|
2021-09-10 00:57:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_size(buffer)) {
|
2022-08-11 15:16:47 +00:00
|
|
|
continue;
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
2021-09-21 10:56:33 +00:00
|
|
|
|
|
|
|
archive_file_append(
|
|
|
|
ARCHIVE_FAV_TEMP_PATH,
|
2021-10-12 13:09:34 +00:00
|
|
|
"%s\n",
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_search(buffer, path) ? furi_string_get_cstr(buffer) : dst);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(buffer);
|
|
|
|
furi_string_free(path);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_close(file);
|
|
|
|
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
|
|
|
storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
2022-04-14 17:02:16 +00:00
|
|
|
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
void archive_add_to_favorites(const char* file_path) {
|
2021-09-10 00:57:43 +00:00
|
|
|
furi_assert(file_path);
|
|
|
|
|
2021-10-12 13:09:34 +00:00
|
|
|
archive_file_append(ARCHIVE_FAV_PATH, "%s\n", file_path);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
2021-10-12 13:09:34 +00:00
|
|
|
|
|
|
|
void archive_favorites_save(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
ArchiveBrowserView* browser = context;
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
File* file = storage_file_alloc(fs_api);
|
2021-10-12 13:09:34 +00:00
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
for(size_t i = 0; i < archive_file_get_array_size(browser); i++) {
|
2021-10-12 13:09:34 +00:00
|
|
|
ArchiveFile_t* item = archive_get_file_at(browser, i);
|
2022-10-05 15:15:23 +00:00
|
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(item->path));
|
2021-10-12 13:09:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
|
|
|
storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
2022-04-14 17:02:16 +00:00
|
|
|
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);
|
2021-10-12 13:09:34 +00:00
|
|
|
|
2022-04-14 11:28:59 +00:00
|
|
|
storage_file_free(file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-04-14 11:28:59 +00:00
|
|
|
}
|