|
@@ -4,20 +4,63 @@
|
|
|
#include "archive_apps.h"
|
|
#include "archive_apps.h"
|
|
|
#include "archive_browser.h"
|
|
#include "archive_browser.h"
|
|
|
|
|
|
|
|
|
|
+#define ARCHIVE_FAV_FILE_BUF_LEN 32
|
|
|
|
|
+
|
|
|
|
|
+static bool archive_favorites_read_line(File* file, string_t str_result) {
|
|
|
|
|
+ string_reset(str_result);
|
|
|
|
|
+ uint8_t buffer[ARCHIVE_FAV_FILE_BUF_LEN];
|
|
|
|
|
+ bool result = false;
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+ uint16_t read_count = storage_file_read(file, buffer, ARCHIVE_FAV_FILE_BUF_LEN);
|
|
|
|
|
+ if(storage_file_get_error(file) != FSE_OK) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for(uint16_t i = 0; i < read_count; i++) {
|
|
|
|
|
+ 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 {
|
|
|
|
|
+ string_push_back(str_result, buffer[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(result || read_count == 0) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ } while(true);
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
uint16_t archive_favorites_count(void* context) {
|
|
uint16_t archive_favorites_count(void* context) {
|
|
|
furi_assert(context);
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
- FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
+ Storage* fs_api = furi_record_open("storage");
|
|
|
|
|
+ File* file = storage_file_alloc(fs_api);
|
|
|
|
|
|
|
|
string_t buffer;
|
|
string_t buffer;
|
|
|
string_init(buffer);
|
|
string_init(buffer);
|
|
|
|
|
|
|
|
- bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
+ bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
uint16_t lines = 0;
|
|
uint16_t lines = 0;
|
|
|
|
|
|
|
|
if(result) {
|
|
if(result) {
|
|
|
while(1) {
|
|
while(1) {
|
|
|
- if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
|
|
|
+ if(!archive_favorites_read_line(file, buffer)) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if(!string_size(buffer)) {
|
|
if(!string_size(buffer)) {
|
|
@@ -27,21 +70,26 @@ uint16_t archive_favorites_count(void* context) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ storage_file_close(file);
|
|
|
|
|
+
|
|
|
string_clear(buffer);
|
|
string_clear(buffer);
|
|
|
- file_worker_close(file_worker);
|
|
|
|
|
- file_worker_free(file_worker);
|
|
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ furi_record_close("storage");
|
|
|
|
|
+
|
|
|
return lines;
|
|
return lines;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static bool archive_favourites_rescan() {
|
|
static bool archive_favourites_rescan() {
|
|
|
string_t buffer;
|
|
string_t buffer;
|
|
|
string_init(buffer);
|
|
string_init(buffer);
|
|
|
- FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
+ Storage* fs_api = furi_record_open("storage");
|
|
|
|
|
+ File* file = storage_file_alloc(fs_api);
|
|
|
|
|
+ File* fav_item_file = storage_file_alloc(fs_api);
|
|
|
|
|
|
|
|
- bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
+ bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
if(result) {
|
|
if(result) {
|
|
|
while(1) {
|
|
while(1) {
|
|
|
- if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
|
|
|
+ if(!archive_favorites_read_line(file, buffer)) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if(!string_size(buffer)) {
|
|
if(!string_size(buffer)) {
|
|
@@ -53,9 +101,10 @@ static bool archive_favourites_rescan() {
|
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- bool file_exists = false;
|
|
|
|
|
- file_worker_is_file_exist(file_worker, string_get_cstr(buffer), &file_exists);
|
|
|
|
|
|
|
+ bool file_exists = storage_file_open(
|
|
|
|
|
+ fav_item_file, string_get_cstr(buffer), FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
if(file_exists) {
|
|
if(file_exists) {
|
|
|
|
|
+ storage_file_close(fav_item_file);
|
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -64,11 +113,13 @@ static bool archive_favourites_rescan() {
|
|
|
|
|
|
|
|
string_clear(buffer);
|
|
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);
|
|
|
|
|
|
|
+ storage_file_close(file);
|
|
|
|
|
+ storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
|
|
|
|
+ storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
|
|
|
|
- file_worker_free(file_worker);
|
|
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ storage_file_free(fav_item_file);
|
|
|
|
|
+ furi_record_close("storage");
|
|
|
|
|
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -77,7 +128,9 @@ bool archive_favorites_read(void* context) {
|
|
|
furi_assert(context);
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
ArchiveBrowserView* browser = context;
|
|
ArchiveBrowserView* browser = context;
|
|
|
- FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
+ Storage* fs_api = furi_record_open("storage");
|
|
|
|
|
+ File* file = storage_file_alloc(fs_api);
|
|
|
|
|
+ File* fav_item_file = storage_file_alloc(fs_api);
|
|
|
|
|
|
|
|
string_t buffer;
|
|
string_t buffer;
|
|
|
FileInfo file_info;
|
|
FileInfo file_info;
|
|
@@ -88,11 +141,11 @@ bool archive_favorites_read(void* context) {
|
|
|
|
|
|
|
|
archive_file_array_rm_all(browser);
|
|
archive_file_array_rm_all(browser);
|
|
|
|
|
|
|
|
- bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
+ bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
|
if(result) {
|
|
if(result) {
|
|
|
while(1) {
|
|
while(1) {
|
|
|
- if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
|
|
|
+ if(!archive_favorites_read_line(file, buffer)) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if(!string_size(buffer)) {
|
|
if(!string_size(buffer)) {
|
|
@@ -107,10 +160,10 @@ bool archive_favorites_read(void* context) {
|
|
|
need_refresh = true;
|
|
need_refresh = true;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- bool file_exists = false;
|
|
|
|
|
- file_worker_is_file_exist(file_worker, string_get_cstr(buffer), &file_exists);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ bool file_exists = storage_file_open(
|
|
|
|
|
+ fav_item_file, string_get_cstr(buffer), FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
if(file_exists) {
|
|
if(file_exists) {
|
|
|
|
|
+ storage_file_close(fav_item_file);
|
|
|
archive_add_file_item(browser, &file_info, string_get_cstr(buffer));
|
|
archive_add_file_item(browser, &file_info, string_get_cstr(buffer));
|
|
|
file_count++;
|
|
file_count++;
|
|
|
} else {
|
|
} else {
|
|
@@ -121,9 +174,11 @@ bool archive_favorites_read(void* context) {
|
|
|
string_reset(buffer);
|
|
string_reset(buffer);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ storage_file_close(file);
|
|
|
string_clear(buffer);
|
|
string_clear(buffer);
|
|
|
- file_worker_close(file_worker);
|
|
|
|
|
- file_worker_free(file_worker);
|
|
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ storage_file_free(fav_item_file);
|
|
|
|
|
+ furi_record_close("storage");
|
|
|
|
|
|
|
|
archive_set_item_count(browser, file_count);
|
|
archive_set_item_count(browser, file_count);
|
|
|
|
|
|
|
@@ -143,12 +198,14 @@ bool archive_favorites_delete(const char* format, ...) {
|
|
|
va_end(args);
|
|
va_end(args);
|
|
|
|
|
|
|
|
string_init(buffer);
|
|
string_init(buffer);
|
|
|
- FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
+ Storage* fs_api = furi_record_open("storage");
|
|
|
|
|
+ File* file = storage_file_alloc(fs_api);
|
|
|
|
|
+
|
|
|
|
|
+ bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
|
- bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
if(result) {
|
|
if(result) {
|
|
|
while(1) {
|
|
while(1) {
|
|
|
- if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
|
|
|
+ if(!archive_favorites_read_line(file, buffer)) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if(!string_size(buffer)) {
|
|
if(!string_size(buffer)) {
|
|
@@ -164,11 +221,12 @@ bool archive_favorites_delete(const char* format, ...) {
|
|
|
string_clear(buffer);
|
|
string_clear(buffer);
|
|
|
string_clear(filename);
|
|
string_clear(filename);
|
|
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
|
+ storage_file_close(file);
|
|
|
|
|
+ storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
|
|
|
|
+ storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
|
|
|
|
- file_worker_free(file_worker);
|
|
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ furi_record_close("storage");
|
|
|
|
|
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -182,14 +240,15 @@ bool archive_is_favorite(const char* format, ...) {
|
|
|
va_end(args);
|
|
va_end(args);
|
|
|
|
|
|
|
|
string_init(buffer);
|
|
string_init(buffer);
|
|
|
- FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
+ Storage* fs_api = furi_record_open("storage");
|
|
|
|
|
+ File* file = storage_file_alloc(fs_api);
|
|
|
|
|
|
|
|
bool found = false;
|
|
bool found = false;
|
|
|
- bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
+ bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
|
if(result) {
|
|
if(result) {
|
|
|
while(1) {
|
|
while(1) {
|
|
|
- if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
|
|
|
+ if(!archive_favorites_read_line(file, buffer)) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if(!string_size(buffer)) {
|
|
if(!string_size(buffer)) {
|
|
@@ -202,10 +261,11 @@ bool archive_is_favorite(const char* format, ...) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ storage_file_close(file);
|
|
|
string_clear(buffer);
|
|
string_clear(buffer);
|
|
|
string_clear(filename);
|
|
string_clear(filename);
|
|
|
- file_worker_close(file_worker);
|
|
|
|
|
- file_worker_free(file_worker);
|
|
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ furi_record_close("storage");
|
|
|
|
|
|
|
|
return found;
|
|
return found;
|
|
|
}
|
|
}
|
|
@@ -214,7 +274,8 @@ bool archive_favorites_rename(const char* src, const char* dst) {
|
|
|
furi_assert(src);
|
|
furi_assert(src);
|
|
|
furi_assert(dst);
|
|
furi_assert(dst);
|
|
|
|
|
|
|
|
- FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
+ Storage* fs_api = furi_record_open("storage");
|
|
|
|
|
+ File* file = storage_file_alloc(fs_api);
|
|
|
|
|
|
|
|
string_t path;
|
|
string_t path;
|
|
|
string_t buffer;
|
|
string_t buffer;
|
|
@@ -223,11 +284,11 @@ bool archive_favorites_rename(const char* src, const char* dst) {
|
|
|
string_init(path);
|
|
string_init(path);
|
|
|
|
|
|
|
|
string_printf(path, "%s", src);
|
|
string_printf(path, "%s", src);
|
|
|
- bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
+ bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
|
if(result) {
|
|
if(result) {
|
|
|
while(1) {
|
|
while(1) {
|
|
|
- if(!file_worker_read_until(file_worker, buffer, '\n')) {
|
|
|
|
|
|
|
+ if(!archive_favorites_read_line(file, buffer)) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if(!string_size(buffer)) {
|
|
if(!string_size(buffer)) {
|
|
@@ -244,11 +305,12 @@ bool archive_favorites_rename(const char* src, const char* dst) {
|
|
|
string_clear(buffer);
|
|
string_clear(buffer);
|
|
|
string_clear(path);
|
|
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);
|
|
|
|
|
|
|
+ storage_file_close(file);
|
|
|
|
|
+ storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
|
|
|
|
+ storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
|
|
|
|
- file_worker_free(file_worker);
|
|
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ furi_record_close("storage");
|
|
|
|
|
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -263,15 +325,17 @@ void archive_favorites_save(void* context) {
|
|
|
furi_assert(context);
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
ArchiveBrowserView* browser = context;
|
|
ArchiveBrowserView* browser = context;
|
|
|
- FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
|
|
|
+ Storage* fs_api = furi_record_open("storage");
|
|
|
|
|
+ File* file = storage_file_alloc(fs_api);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < archive_file_get_array_size(browser); i++) {
|
|
for(size_t i = 0; i < archive_file_get_array_size(browser); i++) {
|
|
|
ArchiveFile_t* item = archive_get_file_at(browser, i);
|
|
ArchiveFile_t* item = archive_get_file_at(browser, i);
|
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(item->name));
|
|
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(item->name));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- file_worker_remove(file_worker, ARCHIVE_FAV_PATH);
|
|
|
|
|
- file_worker_rename(file_worker, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
|
|
|
+ storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
|
|
|
|
+ storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
|
|
|
|
|
|
|
- file_worker_free(file_worker);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ furi_record_close("storage");
|
|
|
|
|
+}
|