Merge branch 'fz-dev' into dev

This commit is contained in:
MX
2023-03-02 21:18:35 +03:00
143 changed files with 4716 additions and 2754 deletions
+1
View File
@@ -27,6 +27,7 @@ env.Append(
File("stream/string_stream.h"),
File("stream/buffered_file_stream.h"),
File("protocols/protocol_dict.h"),
File("pretty_format.h"),
],
)
+1 -1
View File
@@ -83,7 +83,7 @@ static DirWalkResult
end = true;
}
if((info.flags & FSF_DIRECTORY) && dir_walk->recursive) {
if(file_info_is_dir(&info) && dir_walk->recursive) {
// step into
DirIndexList_push_back(dir_walk->index_list, dir_walk->current_index);
dir_walk->current_index = 0;
+60
View File
@@ -0,0 +1,60 @@
#include "pretty_format.h"
#include <core/check.h>
#include <core/core_defines.h>
#define PRETTY_FORMAT_MAX_CANONICAL_DATA_SIZE 256U
void pretty_format_bytes_hex_canonical(
FuriString* result,
size_t num_places,
const char* line_prefix,
const uint8_t* data,
size_t data_size) {
furi_assert(data);
bool is_truncated = false;
if(data_size > PRETTY_FORMAT_MAX_CANONICAL_DATA_SIZE) {
data_size = PRETTY_FORMAT_MAX_CANONICAL_DATA_SIZE;
is_truncated = true;
}
/* Only num_places byte(s) can be on a single line, therefore: */
const size_t line_count =
data_size / num_places + (data_size % num_places != 0 ? 1 : 0) + (is_truncated ? 2 : 0);
/* Line length = Prefix length + 3 * num_places (2 hex digits + space) + 1 * num_places +
+ 1 pipe character + 1 newline character */
const size_t line_length = (line_prefix ? strlen(line_prefix) : 0) + 4 * num_places + 2;
/* Reserve memory in adance in order to avoid unnecessary reallocs */
furi_string_reset(result);
furi_string_reserve(result, line_count * line_length);
for(size_t i = 0; i < data_size; i += num_places) {
if(line_prefix) {
furi_string_cat(result, line_prefix);
}
const size_t begin_idx = i;
const size_t end_idx = MIN(i + num_places, data_size);
for(size_t j = begin_idx; j < end_idx; j++) {
furi_string_cat_printf(result, "%02X ", data[j]);
}
furi_string_push_back(result, '|');
for(size_t j = begin_idx; j < end_idx; j++) {
const char c = data[j];
const char sep = ((j < end_idx - 1) ? ' ' : '\n');
const char* fmt = ((j < data_size - 1) ? "%c%c" : "%c");
furi_string_cat_printf(result, fmt, (c > 0x1f && c < 0x7f) ? c : '.', sep);
}
}
if(is_truncated) {
furi_string_cat_printf(
result, "\n(Data is too big. Showing only the first %zu bytes.)", data_size);
}
}
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include <core/string.h>
#ifdef __cplusplus
extern "C" {
#endif
#define PRETTY_FORMAT_FONT_BOLD "\e#"
#define PRETTY_FORMAT_FONT_MONOSPACE "\e*"
/**
* Format a data buffer as a canonical HEX dump
* @param [out] result pointer to the output string (must be initialised)
* @param [in] num_places the number of bytes on one line (both as HEX and ASCII)
* @param [in] line_prefix if not NULL, prepend this string to each line
* @param [in] data pointer to the input data buffer
* @param [in] data_size input data size
*/
void pretty_format_bytes_hex_canonical(
FuriString* result,
size_t num_places,
const char* line_prefix,
const uint8_t* data,
size_t data_size);
#ifdef __cplusplus
}
#endif
@@ -95,6 +95,7 @@ FS_Error buffered_file_stream_get_error(Stream* _stream) {
static void buffered_file_stream_free(BufferedFileStream* stream) {
furi_assert(stream);
buffered_file_stream_sync((Stream*)stream);
stream_free(stream->file_stream);
stream_cache_free(stream->cache);
free(stream);
+1 -1
View File
@@ -344,7 +344,7 @@ bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const ch
furi_string_set(element_name, name);
}
if(file_info.flags & FSF_DIRECTORY) {
if(file_info_is_dir(&file_info)) {
success =
tar_archive_dir_add_element(archive, furi_string_get_cstr(element_name)) &&
tar_archive_add_dir(