 777a4d109d
			
		
	
	
		777a4d109d
		
			
		
	
	
	
	
		
			
			* Threads: application id * Unit tests: appsdata getter test * Unit tests: moar test cases for appsdata getter * Unit tests: remove folders after test * Storage: dir_is_exist, migrate, + unit_tests * Plugins: migration * Storage: common_exists, moar unit_tests 4 "common_migrate", "common_migrate" and "common_merge" bugfixes * Storage: use FuriString for path handling * Storage API: send caller thread id with path * Storage: remove StorageType field in storage file list * Storage: simplify processing * Storage API: send caller thread id with path everywhere * Storage: /app alias, unit tests and path creation * Storage, path helper: remove unused * Examples: app data example * App plugins: use new VFS path * Storage: file_info_is_dir * Services: handle alias if the service accepts a path. * App plugins: fixes * Make PVS happy * Storage: fix storage_merge_recursive * Storage: rename process_aliases to resolve_path. Rename APPS_DATA to APP_DATA. * Apps: use predefined macro instead of raw paths. Example Apps Data: README fixes. * Storage: rename storage_common_resolve_path to storage_common_resolve_path_and_ensure_app_directory * Api: fix version * Storage: rename alias message * Storage: do not create app folders in path resolving process in certain cases. --------- Co-authored-by: Astra <93453568+Astrrra@users.noreply.github.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
		
			
				
	
	
		
			112 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #include "archive_files.h"
 | |
| #include "archive_apps.h"
 | |
| #include "archive_browser.h"
 | |
| 
 | |
| #define TAG "Archive"
 | |
| 
 | |
| #define ASSETS_DIR "assets"
 | |
| 
 | |
| void archive_set_file_type(ArchiveFile_t* file, const char* path, bool is_folder, bool is_app) {
 | |
|     furi_assert(file);
 | |
| 
 | |
|     file->is_app = is_app;
 | |
|     if(is_app) {
 | |
|         file->type = archive_get_app_filetype(archive_get_app_type(path));
 | |
|     } else {
 | |
|         for(size_t i = 0; i < COUNT_OF(known_ext); i++) {
 | |
|             if((known_ext[i][0] == '?') || (known_ext[i][0] == '*')) continue;
 | |
|             if(furi_string_search(file->path, known_ext[i], 0) != FURI_STRING_FAILURE) {
 | |
|                 if(i == ArchiveFileTypeBadUsb) {
 | |
|                     if(furi_string_search(
 | |
|                            file->path, archive_get_default_path(ArchiveTabBadUsb)) == 0) {
 | |
|                         file->type = i;
 | |
|                         return; // *.txt file is a BadUSB script only if it is in BadUSB folder
 | |
|                     }
 | |
|                 } else {
 | |
|                     file->type = i;
 | |
|                     return;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         if(is_folder) {
 | |
|             file->type = ArchiveFileTypeFolder;
 | |
|         } else {
 | |
|             file->type = ArchiveFileTypeUnknown;
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| bool archive_get_items(void* context, const char* path) {
 | |
|     furi_assert(context);
 | |
| 
 | |
|     bool res = false;
 | |
|     ArchiveBrowserView* browser = context;
 | |
| 
 | |
|     if(archive_get_tab(browser) == ArchiveTabFavorites) {
 | |
|         res = archive_favorites_read(browser);
 | |
|     } else if(strncmp(path, "/app:", 5) == 0) {
 | |
|         res = archive_app_read_dir(browser, path);
 | |
|     }
 | |
|     return res;
 | |
| }
 | |
| 
 | |
| void archive_file_append(const char* path, const char* format, ...) {
 | |
|     furi_assert(path);
 | |
| 
 | |
|     FuriString* string;
 | |
|     va_list args;
 | |
|     va_start(args, format);
 | |
|     string = furi_string_alloc_vprintf(format, args);
 | |
|     va_end(args);
 | |
| 
 | |
|     Storage* fs_api = furi_record_open(RECORD_STORAGE);
 | |
|     File* file = storage_file_alloc(fs_api);
 | |
| 
 | |
|     bool res = storage_file_open(file, path, FSAM_WRITE, FSOM_OPEN_APPEND);
 | |
| 
 | |
|     if(res) {
 | |
|         storage_file_write(file, furi_string_get_cstr(string), furi_string_size(string));
 | |
|     }
 | |
| 
 | |
|     storage_file_close(file);
 | |
|     storage_file_free(file);
 | |
|     furi_record_close(RECORD_STORAGE);
 | |
| }
 | |
| 
 | |
| void archive_delete_file(void* context, const char* format, ...) {
 | |
|     furi_assert(context);
 | |
| 
 | |
|     FuriString* filename;
 | |
|     va_list args;
 | |
|     va_start(args, format);
 | |
|     filename = furi_string_alloc_vprintf(format, args);
 | |
|     va_end(args);
 | |
| 
 | |
|     ArchiveBrowserView* browser = context;
 | |
|     Storage* fs_api = furi_record_open(RECORD_STORAGE);
 | |
| 
 | |
|     FileInfo fileinfo;
 | |
|     storage_common_stat(fs_api, furi_string_get_cstr(filename), &fileinfo);
 | |
| 
 | |
|     bool res = false;
 | |
| 
 | |
|     if(file_info_is_dir(&fileinfo)) {
 | |
|         res = storage_simply_remove_recursive(fs_api, furi_string_get_cstr(filename));
 | |
|     } else {
 | |
|         res = (storage_common_remove(fs_api, furi_string_get_cstr(filename)) == FSE_OK);
 | |
|     }
 | |
| 
 | |
|     furi_record_close(RECORD_STORAGE);
 | |
| 
 | |
|     if(archive_is_favorite("%s", furi_string_get_cstr(filename))) {
 | |
|         archive_favorites_delete("%s", furi_string_get_cstr(filename));
 | |
|     }
 | |
| 
 | |
|     if(res) {
 | |
|         archive_file_array_rm_selected(browser);
 | |
|     }
 | |
| 
 | |
|     furi_string_free(filename);
 | |
| }
 |