2021-09-21 10:56:33 +00:00
|
|
|
|
2021-09-10 00:57:43 +00:00
|
|
|
#include "archive_favorites.h"
|
2021-09-21 10:56:33 +00:00
|
|
|
#include "archive_browser.h"
|
|
|
|
|
|
|
|
uint16_t archive_favorites_count(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
|
string_t buffer;
|
|
|
|
string_init(buffer);
|
|
|
|
|
|
|
|
bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
uint16_t lines = 0;
|
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
|
|
|
if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!string_size(buffer)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_clear(buffer);
|
|
|
|
file_worker_close(file_worker);
|
|
|
|
file_worker_free(file_worker);
|
|
|
|
return lines;
|
|
|
|
}
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
bool archive_favorites_read(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
ArchiveBrowserView* archive_view = context;
|
2021-09-10 00:57:43 +00:00
|
|
|
FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
|
string_t buffer;
|
|
|
|
FileInfo file_info;
|
|
|
|
string_init(buffer);
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
|
|
|
if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!string_size(buffer)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
archive_add_item(archive_view, &file_info, string_get_cstr(buffer));
|
2021-09-10 00:57:43 +00:00
|
|
|
string_clean(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string_clear(buffer);
|
|
|
|
file_worker_close(file_worker);
|
|
|
|
file_worker_free(file_worker);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
bool archive_favorites_delete(const char* format, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
uint8_t len = vsnprintf(NULL, 0, format, args);
|
|
|
|
char filename[len + 1];
|
|
|
|
vsnprintf(filename, len + 1, format, args);
|
|
|
|
va_end(args);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
|
string_t buffer;
|
|
|
|
string_init(buffer);
|
|
|
|
|
|
|
|
bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
|
|
|
if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!string_size(buffer)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
if(string_search_str(buffer, filename)) {
|
|
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\r\n", string_get_cstr(buffer));
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_clear(buffer);
|
|
|
|
|
|
|
|
file_worker_close(file_worker);
|
|
|
|
file_worker_remove(file_worker, ARCHIVE_FAV_PATH);
|
|
|
|
file_worker_rename(file_worker, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
|
|
|
|
file_worker_free(file_worker);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
bool archive_is_favorite(const char* format, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
uint8_t len = vsnprintf(NULL, 0, format, args);
|
|
|
|
char filename[len + 1];
|
|
|
|
vsnprintf(filename, len + 1, format, args);
|
|
|
|
va_end(args);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
string_t buffer;
|
|
|
|
string_init(buffer);
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
bool found = false;
|
|
|
|
bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
2021-09-10 00:57:43 +00:00
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
|
|
|
if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!string_size(buffer)) {
|
|
|
|
break;
|
|
|
|
}
|
2021-09-21 10:56:33 +00:00
|
|
|
if(!string_search_str(buffer, filename)) {
|
2021-09-10 00:57:43 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_clear(buffer);
|
|
|
|
file_worker_close(file_worker);
|
|
|
|
file_worker_free(file_worker);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool archive_favorites_rename(const char* file_path, const char* src, const char* dst) {
|
|
|
|
furi_assert(file_path);
|
|
|
|
furi_assert(src);
|
|
|
|
furi_assert(dst);
|
|
|
|
|
|
|
|
FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
|
string_t path;
|
|
|
|
string_t buffer;
|
|
|
|
|
|
|
|
string_init(buffer);
|
|
|
|
string_init(path);
|
|
|
|
|
|
|
|
string_printf(path, "%s/%s", file_path, src);
|
|
|
|
bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
|
if(result) {
|
|
|
|
while(1) {
|
|
|
|
if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!string_size(buffer)) {
|
|
|
|
break;
|
|
|
|
}
|
2021-09-21 10:56:33 +00:00
|
|
|
|
|
|
|
archive_file_append(
|
|
|
|
ARCHIVE_FAV_TEMP_PATH,
|
|
|
|
"%s\r\n",
|
|
|
|
string_search(buffer, path) ? string_get_cstr(buffer) : dst);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_clear(buffer);
|
|
|
|
string_clear(path);
|
|
|
|
|
|
|
|
file_worker_close(file_worker);
|
|
|
|
file_worker_remove(file_worker, ARCHIVE_FAV_PATH);
|
|
|
|
file_worker_rename(file_worker, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
|
|
|
|
file_worker_free(file_worker);
|
|
|
|
|
|
|
|
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-09-21 10:56:33 +00:00
|
|
|
archive_file_append(ARCHIVE_FAV_PATH, "%s\r\n", file_path);
|
2021-09-10 00:57:43 +00:00
|
|
|
}
|