[FL-2212] File validators and archive fixes #972
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -272,7 +272,6 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t name) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->last_idx = model->idx;
|
||||
model->last_offset = model->list_offset;
|
||||
model->idx = 0;
|
||||
model->depth = CLAMP(model->depth + 1, MAX_DEPTH, 0);
|
||||
return false;
|
||||
|
@@ -31,6 +31,40 @@ uint16_t archive_favorites_count(void* context) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
static bool archive_favourites_rescan() {
|
||||
string_t buffer;
|
||||
string_init(buffer);
|
||||
FileWorker* file_worker = file_worker_alloc(true);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool file_exists = false;
|
||||
file_worker_is_file_exist(file_worker, string_get_cstr(buffer), &file_exists);
|
||||
if(file_exists) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(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);
|
||||
|
||||
file_worker_free(file_worker);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool archive_favorites_read(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
@@ -41,6 +75,8 @@ bool archive_favorites_read(void* context) {
|
||||
FileInfo file_info;
|
||||
string_init(buffer);
|
||||
|
||||
bool need_refresh = false;
|
||||
|
||||
bool result = file_worker_open(file_worker, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
|
||||
if(result) {
|
||||
@@ -52,13 +88,24 @@ bool archive_favorites_read(void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
archive_add_item(browser, &file_info, string_get_cstr(buffer));
|
||||
bool file_exists = false;
|
||||
file_worker_is_file_exist(file_worker, string_get_cstr(buffer), &file_exists);
|
||||
|
||||
if(file_exists)
|
||||
archive_add_item(browser, &file_info, string_get_cstr(buffer));
|
||||
else
|
||||
need_refresh = true;
|
||||
string_reset(buffer);
|
||||
}
|
||||
}
|
||||
string_clear(buffer);
|
||||
file_worker_close(file_worker);
|
||||
file_worker_free(file_worker);
|
||||
|
||||
if(need_refresh) {
|
||||
archive_favourites_rescan();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,14 @@ void archive_trim_file_path(char* name, bool ext) {
|
||||
}
|
||||
}
|
||||
|
||||
void archive_get_file_extension(char* name, char* ext) {
|
||||
char* dot = strrchr(name, '.');
|
||||
if(dot == NULL)
|
||||
*ext = '\0';
|
||||
else
|
||||
strncpy(ext, dot, MAX_EXT_LEN);
|
||||
}
|
||||
|
||||
void set_file_type(ArchiveFile_t* file, FileInfo* file_info) {
|
||||
furi_assert(file);
|
||||
furi_assert(file_info);
|
||||
|
@@ -50,6 +50,7 @@ ARRAY_DEF(
|
||||
bool filter_by_extension(FileInfo* file_info, const char* tab_ext, const char* name);
|
||||
void set_file_type(ArchiveFile_t* file, FileInfo* file_info);
|
||||
void archive_trim_file_path(char* name, bool ext);
|
||||
void archive_get_file_extension(char* name, char* ext);
|
||||
bool archive_get_filenames(void* context, const char* path);
|
||||
bool archive_dir_empty(void* context, const char* path);
|
||||
bool archive_read_dir(void* context, const char* path);
|
||||
|
Reference in New Issue
Block a user