M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1 * Header stage complete * Source stage complete * Lint & merge fixes * Includes * Documentation step 1 * FBT: output free size considering BT STACK * Documentation step 2 * py lint * Fix music player plugin * unit test stage 1: string allocator, mem, getters, setters, appends, compare, search. * unit test: string equality * unit test: string replace * unit test: string start_with, end_with * unit test: string trim * unit test: utf-8 * Rename * Revert fw_size changes * Simplify CLI backspace handling * Simplify CLI character insert * Merge fixes * Furi: correct filenaming and spelling * Bt: remove furi string include Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include <core/log.h>
|
||||
#include <core/record.h>
|
||||
#include <m-string.h>
|
||||
#include "storage.h"
|
||||
#include "storage_i.h"
|
||||
#include "storage_message.h"
|
||||
@@ -374,13 +373,13 @@ static FS_Error
|
||||
storage_copy_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error = storage_common_mkdir(storage, new_path);
|
||||
DirWalk* dir_walk = dir_walk_alloc(storage);
|
||||
string_t path;
|
||||
string_t tmp_new_path;
|
||||
string_t tmp_old_path;
|
||||
FuriString* path;
|
||||
FuriString* tmp_new_path;
|
||||
FuriString* tmp_old_path;
|
||||
FileInfo fileinfo;
|
||||
string_init(path);
|
||||
string_init(tmp_new_path);
|
||||
string_init(tmp_old_path);
|
||||
path = furi_string_alloc();
|
||||
tmp_new_path = furi_string_alloc();
|
||||
tmp_old_path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(error != FSE_OK) break;
|
||||
@@ -399,15 +398,17 @@ static FS_Error
|
||||
} else if(res == DirWalkLast) {
|
||||
break;
|
||||
} else {
|
||||
string_set(tmp_old_path, path);
|
||||
string_right(path, strlen(old_path));
|
||||
string_printf(tmp_new_path, "%s%s", new_path, string_get_cstr(path));
|
||||
furi_string_set(tmp_old_path, path);
|
||||
furi_string_right(path, strlen(old_path));
|
||||
furi_string_printf(tmp_new_path, "%s%s", new_path, furi_string_get_cstr(path));
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
|
||||
error = storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
||||
} else {
|
||||
error = storage_common_copy(
|
||||
storage, string_get_cstr(tmp_old_path), string_get_cstr(tmp_new_path));
|
||||
storage,
|
||||
furi_string_get_cstr(tmp_old_path),
|
||||
furi_string_get_cstr(tmp_new_path));
|
||||
}
|
||||
|
||||
if(error != FSE_OK) break;
|
||||
@@ -416,9 +417,9 @@ static FS_Error
|
||||
|
||||
} while(false);
|
||||
|
||||
string_clear(tmp_new_path);
|
||||
string_clear(tmp_old_path);
|
||||
string_clear(path);
|
||||
furi_string_free(tmp_new_path);
|
||||
furi_string_free(tmp_old_path);
|
||||
furi_string_free(path);
|
||||
dir_walk_free(dir_walk);
|
||||
return error;
|
||||
}
|
||||
@@ -459,11 +460,11 @@ static FS_Error
|
||||
storage_merge_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error = storage_common_mkdir(storage, new_path);
|
||||
DirWalk* dir_walk = dir_walk_alloc(storage);
|
||||
string_t path, file_basename, tmp_new_path;
|
||||
FuriString *path, *file_basename, *tmp_new_path;
|
||||
FileInfo fileinfo;
|
||||
string_init(path);
|
||||
string_init(file_basename);
|
||||
string_init(tmp_new_path);
|
||||
path = furi_string_alloc();
|
||||
file_basename = furi_string_alloc();
|
||||
tmp_new_path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if((error != FSE_OK) && (error != FSE_EXIST)) break;
|
||||
@@ -483,14 +484,15 @@ static FS_Error
|
||||
} else if(res == DirWalkLast) {
|
||||
break;
|
||||
} else {
|
||||
path_extract_basename(string_get_cstr(path), file_basename);
|
||||
path_concat(new_path, string_get_cstr(file_basename), tmp_new_path);
|
||||
path_extract_basename(furi_string_get_cstr(path), file_basename);
|
||||
path_concat(new_path, furi_string_get_cstr(file_basename), tmp_new_path);
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(storage_common_stat(storage, string_get_cstr(tmp_new_path), &fileinfo) ==
|
||||
FSE_OK) {
|
||||
if(storage_common_stat(
|
||||
storage, furi_string_get_cstr(tmp_new_path), &fileinfo) == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
|
||||
error =
|
||||
storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
||||
if(error != FSE_OK) {
|
||||
break;
|
||||
}
|
||||
@@ -498,7 +500,7 @@ static FS_Error
|
||||
}
|
||||
}
|
||||
error = storage_common_merge(
|
||||
storage, string_get_cstr(path), string_get_cstr(tmp_new_path));
|
||||
storage, furi_string_get_cstr(path), furi_string_get_cstr(tmp_new_path));
|
||||
|
||||
if(error != FSE_OK) {
|
||||
break;
|
||||
@@ -508,9 +510,9 @@ static FS_Error
|
||||
|
||||
} while(false);
|
||||
|
||||
string_clear(tmp_new_path);
|
||||
string_clear(file_basename);
|
||||
string_clear(path);
|
||||
furi_string_free(tmp_new_path);
|
||||
furi_string_free(file_basename);
|
||||
furi_string_free(path);
|
||||
dir_walk_free(dir_walk);
|
||||
return error;
|
||||
}
|
||||
@@ -518,8 +520,8 @@ static FS_Error
|
||||
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error;
|
||||
const char* new_path_tmp;
|
||||
string_t new_path_next;
|
||||
string_init(new_path_next);
|
||||
FuriString* new_path_next;
|
||||
new_path_next = furi_string_alloc();
|
||||
|
||||
FileInfo fileinfo;
|
||||
error = storage_common_stat(storage, old_path, &fileinfo);
|
||||
@@ -530,13 +532,13 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
||||
} else {
|
||||
error = storage_common_stat(storage, new_path, &fileinfo);
|
||||
if(error == FSE_OK) {
|
||||
string_set_str(new_path_next, new_path);
|
||||
string_t dir_path;
|
||||
string_t filename;
|
||||
furi_string_set(new_path_next, new_path);
|
||||
FuriString* dir_path;
|
||||
FuriString* filename;
|
||||
char extension[MAX_EXT_LEN];
|
||||
|
||||
string_init(dir_path);
|
||||
string_init(filename);
|
||||
dir_path = furi_string_alloc();
|
||||
filename = furi_string_alloc();
|
||||
|
||||
path_extract_filename(new_path_next, filename, true);
|
||||
path_extract_dirname(new_path, dir_path);
|
||||
@@ -544,17 +546,18 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
||||
|
||||
storage_get_next_filename(
|
||||
storage,
|
||||
string_get_cstr(dir_path),
|
||||
string_get_cstr(filename),
|
||||
furi_string_get_cstr(dir_path),
|
||||
furi_string_get_cstr(filename),
|
||||
extension,
|
||||
new_path_next,
|
||||
255);
|
||||
string_cat_printf(dir_path, "/%s%s", string_get_cstr(new_path_next), extension);
|
||||
string_set(new_path_next, dir_path);
|
||||
furi_string_cat_printf(
|
||||
dir_path, "/%s%s", furi_string_get_cstr(new_path_next), extension);
|
||||
furi_string_set(new_path_next, dir_path);
|
||||
|
||||
string_clear(dir_path);
|
||||
string_clear(filename);
|
||||
new_path_tmp = string_get_cstr(new_path_next);
|
||||
furi_string_free(dir_path);
|
||||
furi_string_free(filename);
|
||||
new_path_tmp = furi_string_get_cstr(new_path_next);
|
||||
} else {
|
||||
new_path_tmp = new_path;
|
||||
}
|
||||
@@ -577,7 +580,7 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(new_path_next);
|
||||
furi_string_free(new_path_next);
|
||||
|
||||
return error;
|
||||
}
|
||||
@@ -707,8 +710,8 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
furi_assert(path);
|
||||
FileInfo fileinfo;
|
||||
bool result = false;
|
||||
string_t fullname;
|
||||
string_t cur_dir;
|
||||
FuriString* fullname;
|
||||
FuriString* cur_dir;
|
||||
|
||||
if(storage_simply_remove(storage, path)) {
|
||||
return true;
|
||||
@@ -716,26 +719,26 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
|
||||
char* name = malloc(MAX_NAME_LENGTH + 1);
|
||||
File* dir = storage_file_alloc(storage);
|
||||
string_init_set_str(cur_dir, path);
|
||||
cur_dir = furi_string_alloc_set(path);
|
||||
bool go_deeper = false;
|
||||
|
||||
while(1) {
|
||||
if(!storage_dir_open(dir, string_get_cstr(cur_dir))) {
|
||||
if(!storage_dir_open(dir, furi_string_get_cstr(cur_dir))) {
|
||||
storage_dir_close(dir);
|
||||
break;
|
||||
}
|
||||
|
||||
while(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
string_cat_printf(cur_dir, "/%s", name);
|
||||
furi_string_cat_printf(cur_dir, "/%s", name);
|
||||
go_deeper = true;
|
||||
break;
|
||||
}
|
||||
|
||||
string_init_printf(fullname, "%s/%s", string_get_cstr(cur_dir), name);
|
||||
FS_Error error = storage_common_remove(storage, string_get_cstr(fullname));
|
||||
fullname = furi_string_alloc_printf("%s/%s", furi_string_get_cstr(cur_dir), name);
|
||||
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(fullname));
|
||||
furi_check(error == FSE_OK);
|
||||
string_clear(fullname);
|
||||
furi_string_free(fullname);
|
||||
}
|
||||
storage_dir_close(dir);
|
||||
|
||||
@@ -744,13 +747,13 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FS_Error error = storage_common_remove(storage, string_get_cstr(cur_dir));
|
||||
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(cur_dir));
|
||||
furi_check(error == FSE_OK);
|
||||
|
||||
if(string_cmp(cur_dir, path)) {
|
||||
size_t last_char = string_search_rchar(cur_dir, '/');
|
||||
furi_assert(last_char != STRING_FAILURE);
|
||||
string_left(cur_dir, last_char);
|
||||
if(furi_string_cmp(cur_dir, path)) {
|
||||
size_t last_char = furi_string_search_rchar(cur_dir, '/');
|
||||
furi_assert(last_char != FURI_STRING_FAILURE);
|
||||
furi_string_left(cur_dir, last_char);
|
||||
} else {
|
||||
result = true;
|
||||
break;
|
||||
@@ -758,7 +761,7 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
}
|
||||
|
||||
storage_file_free(dir);
|
||||
string_clear(cur_dir);
|
||||
furi_string_free(cur_dir);
|
||||
free(name);
|
||||
return result;
|
||||
}
|
||||
@@ -780,22 +783,22 @@ void storage_get_next_filename(
|
||||
const char* dirname,
|
||||
const char* filename,
|
||||
const char* fileextension,
|
||||
string_t nextfilename,
|
||||
FuriString* nextfilename,
|
||||
uint8_t max_len) {
|
||||
string_t temp_str;
|
||||
FuriString* temp_str;
|
||||
uint16_t num = 0;
|
||||
|
||||
string_init_printf(temp_str, "%s/%s%s", dirname, filename, fileextension);
|
||||
temp_str = furi_string_alloc_printf("%s/%s%s", dirname, filename, fileextension);
|
||||
|
||||
while(storage_common_stat(storage, string_get_cstr(temp_str), NULL) == FSE_OK) {
|
||||
while(storage_common_stat(storage, furi_string_get_cstr(temp_str), NULL) == FSE_OK) {
|
||||
num++;
|
||||
string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
|
||||
furi_string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
|
||||
}
|
||||
if(num && (max_len > strlen(filename))) {
|
||||
string_printf(nextfilename, "%s%d", filename, num);
|
||||
furi_string_printf(nextfilename, "%s%d", filename, num);
|
||||
} else {
|
||||
string_printf(nextfilename, "%s", filename);
|
||||
furi_string_printf(nextfilename, "%s", filename);
|
||||
}
|
||||
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
Reference in New Issue
Block a user