1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-13 05:06:30 +04:00

Archive: Cut/Copy/Past & NewDir

This commit is contained in:
gid9798
2023-07-18 23:46:28 +03:00
parent da919372e2
commit c0eebcb540
11 changed files with 371 additions and 60 deletions

View File

@@ -121,14 +121,19 @@ void archive_delete_file(void* context, const char* format, ...) {
furi_string_free(filename);
}
FS_Error archive_rename_file_or_dir(void* context, const char* src_path, const char* dst_path) {
FS_Error archive_rename_copy_file_or_dir(
void* context,
const char* src_path,
const char* dst_path,
bool copy) {
furi_assert(context);
FURI_LOG_I(TAG, "Rename from %s to %s", src_path, dst_path);
FURI_LOG_I(TAG, "%s from %s to %s", copy ? "Copy" : "Rename/Move", src_path, dst_path);
ArchiveBrowserView* browser = context;
Storage* fs_api = furi_record_open(RECORD_STORAGE);
FuriString* temp_str = furi_string_alloc_set(dst_path);
FileInfo fileinfo;
storage_common_stat(fs_api, src_path, &fileinfo);
@@ -136,22 +141,60 @@ FS_Error archive_rename_file_or_dir(void* context, const char* src_path, const c
if(!path_contains_only_ascii(dst_path)) {
error = FSE_INVALID_NAME;
} else if(!copy && !strcmp(src_path, dst_path)) {
error = FSE_EXIST;
} else {
error = storage_common_rename(fs_api, src_path, dst_path);
if(storage_common_exists(fs_api, dst_path)) {
FuriString* filename = furi_string_alloc();
char* file_ext = malloc(MAX_EXT_LEN + 1);
strncpy(file_ext, "", MAX_EXT_LEN);
path_extract_filename(temp_str, filename, true);
path_extract_extension(temp_str, file_ext, MAX_EXT_LEN);
path_extract_dirname(dst_path, temp_str);
storage_get_next_filename(
fs_api,
furi_string_get_cstr(temp_str),
furi_string_get_cstr(filename),
file_ext,
filename,
255);
furi_string_cat_printf(temp_str, "/%s%s", furi_string_get_cstr(filename), file_ext);
dst_path = furi_string_get_cstr(temp_str);
furi_string_free(filename);
free(file_ext);
}
if(copy) {
error = storage_common_copy(fs_api, src_path, dst_path);
} else {
error = storage_common_rename(fs_api, src_path, dst_path);
}
}
furi_record_close(RECORD_STORAGE);
if(archive_is_favorite("%s", src_path)) {
if(!copy && archive_is_favorite("%s", src_path)) {
archive_favorites_rename(src_path, dst_path);
}
if(error == FSE_OK || error == FSE_EXIST) {
FURI_LOG_I(TAG, "Rename from %s to %s is DONE", src_path, dst_path);
archive_refresh_dir(browser);
if(error == FSE_OK) {
FURI_LOG_I(
TAG, "%s from %s to %s is DONE", copy ? "Copy" : "Rename/Move", src_path, dst_path);
} else {
FURI_LOG_E(
TAG, "Rename failed: %s, Code: %d", filesystem_api_error_get_desc(error), error);
TAG,
"%s failed: %s, Code: %d",
copy ? "Copy" : "Rename/Move",
filesystem_api_error_get_desc(error),
error);
}
furi_string_free(temp_str);
return error;
}