mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 04:53:08 +00:00
parent
75b1eadd74
commit
db430214e2
3 changed files with 65 additions and 47 deletions
|
@ -305,21 +305,27 @@ static void rpc_system_storage_read_process(const PB_Main* request, void* contex
|
|||
response->command_id = request->command_id;
|
||||
response->which_content = PB_Main_storage_read_response_tag;
|
||||
response->command_status = PB_CommandStatus_OK;
|
||||
|
||||
size_t read_size = MIN(size_left, MAX_DATA_SIZE);
|
||||
if(read_size) {
|
||||
response->content.storage_read_response.has_file = true;
|
||||
response->content.storage_read_response.file.data =
|
||||
malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(MIN(size_left, MAX_DATA_SIZE)));
|
||||
malloc(PB_BYTES_ARRAY_T_ALLOCSIZE());
|
||||
uint8_t* buffer = response->content.storage_read_response.file.data->bytes;
|
||||
uint16_t* read_size_msg = &response->content.storage_read_response.file.data->size;
|
||||
|
||||
size_t read_size = MIN(size_left, MAX_DATA_SIZE);
|
||||
*read_size_msg = storage_file_read(file, buffer, read_size);
|
||||
size_left -= read_size;
|
||||
result = (*read_size_msg == read_size);
|
||||
|
||||
if(result) {
|
||||
response->has_next = (size_left > 0);
|
||||
rpc_send_and_release(session, response);
|
||||
response->has_next = result && (size_left > 0);
|
||||
} else {
|
||||
response->content.storage_read_response.has_file = false;
|
||||
response->has_next = false;
|
||||
result = true;
|
||||
}
|
||||
|
||||
rpc_send_and_release(session, response);
|
||||
} while((size_left != 0) && result);
|
||||
|
||||
if(!result) {
|
||||
|
@ -349,7 +355,7 @@ static void rpc_system_storage_write_process(const PB_Main* request, void* conte
|
|||
RpcSession* session = rpc_storage->session;
|
||||
furi_assert(session);
|
||||
|
||||
bool result = true;
|
||||
bool fs_operation_success = true;
|
||||
|
||||
if(!path_contains_only_ascii(request->content.storage_write_request.path)) {
|
||||
rpc_storage->current_command_id = request->command_id;
|
||||
|
@ -370,28 +376,32 @@ static void rpc_system_storage_write_process(const PB_Main* request, void* conte
|
|||
rpc_storage->current_command_id = request->command_id;
|
||||
rpc_storage->state = RpcStorageStateWriting;
|
||||
const char* path = request->content.storage_write_request.path;
|
||||
result = storage_file_open(rpc_storage->file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
||||
fs_operation_success =
|
||||
storage_file_open(rpc_storage->file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
||||
}
|
||||
|
||||
File* file = rpc_storage->file;
|
||||
bool send_response = false;
|
||||
|
||||
if(result) {
|
||||
if(fs_operation_success) {
|
||||
if(request->content.storage_write_request.has_file) {
|
||||
uint8_t* buffer = request->content.storage_write_request.file.data->bytes;
|
||||
size_t buffer_size = request->content.storage_write_request.file.data->size;
|
||||
|
||||
uint16_t written_size = storage_file_write(file, buffer, buffer_size);
|
||||
result = (written_size == buffer_size);
|
||||
|
||||
if(result && !request->has_next) {
|
||||
rpc_send_and_release_empty(
|
||||
session, rpc_storage->current_command_id, PB_CommandStatus_OK);
|
||||
rpc_system_storage_reset_state(rpc_storage, session, false);
|
||||
}
|
||||
fs_operation_success = (written_size == buffer_size);
|
||||
}
|
||||
|
||||
if(!result) {
|
||||
rpc_send_and_release_empty(
|
||||
session, rpc_storage->current_command_id, rpc_system_storage_get_file_error(file));
|
||||
send_response = !request->has_next;
|
||||
}
|
||||
|
||||
PB_CommandStatus command_status = PB_CommandStatus_OK;
|
||||
if(!fs_operation_success) {
|
||||
send_response = true;
|
||||
command_status = rpc_system_storage_get_file_error(file);
|
||||
}
|
||||
|
||||
if(send_response) {
|
||||
rpc_send_and_release_empty(session, rpc_storage->current_command_id, command_status);
|
||||
rpc_system_storage_reset_state(rpc_storage, session, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -274,11 +274,12 @@ static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
|
|||
if(parsed_count == EOF || parsed_count != 1) {
|
||||
storage_cli_print_usage();
|
||||
} else if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
uint8_t* data = malloc(buffer_size);
|
||||
uint64_t file_size = storage_file_size(file);
|
||||
|
||||
printf("Size: %lu\r\n", (uint32_t)file_size);
|
||||
|
||||
if(buffer_size) {
|
||||
uint8_t* data = malloc(buffer_size);
|
||||
while(file_size > 0) {
|
||||
printf("\r\nReady?\r\n");
|
||||
cli_getc(cli);
|
||||
|
@ -289,9 +290,10 @@ static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
|
|||
}
|
||||
file_size -= read_size;
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
free(data);
|
||||
} else {
|
||||
storage_cli_print_error(storage_file_get_error(file));
|
||||
}
|
||||
|
@ -315,6 +317,7 @@ static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
|
|||
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
printf("Ready\r\n");
|
||||
|
||||
if(buffer_size) {
|
||||
uint8_t* buffer = malloc(buffer_size);
|
||||
|
||||
for(uint32_t i = 0; i < buffer_size; i++) {
|
||||
|
@ -328,6 +331,7 @@ static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
|
|||
}
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
} else {
|
||||
storage_cli_print_error(storage_file_get_error(file));
|
||||
}
|
||||
|
|
|
@ -85,6 +85,10 @@ void path_concat(const char* path, const char* suffix, string_t out_path) {
|
|||
}
|
||||
|
||||
bool path_contains_only_ascii(const char* path) {
|
||||
if(!path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* name_pos = strrchr(path, '/');
|
||||
if(name_pos == NULL) {
|
||||
name_pos = path;
|
||||
|
|
Loading…
Reference in a new issue