|
|
@@ -1,6 +1,5 @@
|
|
|
#include "hex_viewer_storage.h"
|
|
|
|
|
|
-
|
|
|
static Storage* hex_viewer_open_storage() {
|
|
|
return furi_record_open(RECORD_STORAGE);
|
|
|
}
|
|
|
@@ -10,21 +9,21 @@ static void hex_viewer_close_storage() {
|
|
|
}
|
|
|
|
|
|
static void hex_viewer_close_config_file(FlipperFormat* file) {
|
|
|
- if (file == NULL) return;
|
|
|
+ if(file == NULL) return;
|
|
|
flipper_format_file_close(file);
|
|
|
flipper_format_free(file);
|
|
|
}
|
|
|
|
|
|
void hex_viewer_save_settings(void* context) {
|
|
|
HexViewer* app = context;
|
|
|
- if (app->save_settings == 0) {
|
|
|
+ if(app->save_settings == 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
FURI_LOG_D(TAG, "Saving Settings");
|
|
|
Storage* storage = hex_viewer_open_storage();
|
|
|
FlipperFormat* fff_file = flipper_format_file_alloc(storage);
|
|
|
-
|
|
|
+
|
|
|
// Overwrite wont work, so delete first
|
|
|
if(storage_file_exists(storage, HEX_VIEWER_SETTINGS_SAVE_PATH)) {
|
|
|
storage_simply_remove(storage, HEX_VIEWER_SETTINGS_SAVE_PATH);
|
|
|
@@ -32,12 +31,11 @@ void hex_viewer_save_settings(void* context) {
|
|
|
|
|
|
// Open File, create if not exists
|
|
|
if(!storage_common_stat(storage, HEX_VIEWER_SETTINGS_SAVE_PATH, NULL) == FSE_OK) {
|
|
|
- FURI_LOG_D(TAG, "Config file %s is not found. Will create new.", HEX_VIEWER_SETTINGS_SAVE_PATH);
|
|
|
+ FURI_LOG_D(
|
|
|
+ TAG, "Config file %s is not found. Will create new.", HEX_VIEWER_SETTINGS_SAVE_PATH);
|
|
|
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
|
|
|
FURI_LOG_D(
|
|
|
- TAG,
|
|
|
- "Directory %s doesn't exist. Will create new.",
|
|
|
- CONFIG_FILE_DIRECTORY_PATH);
|
|
|
+ TAG, "Directory %s doesn't exist. Will create new.", CONFIG_FILE_DIRECTORY_PATH);
|
|
|
if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
|
|
|
FURI_LOG_E(TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
|
|
|
}
|
|
|
@@ -50,19 +48,16 @@ void hex_viewer_save_settings(void* context) {
|
|
|
hex_viewer_close_storage();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Store Settings
|
|
|
flipper_format_write_header_cstr(
|
|
|
fff_file, HEX_VIEWER_SETTINGS_HEADER, HEX_VIEWER_SETTINGS_FILE_VERSION);
|
|
|
- flipper_format_write_uint32(
|
|
|
- fff_file, HEX_VIEWER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
|
|
|
- flipper_format_write_uint32(
|
|
|
- fff_file, HEX_VIEWER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
|
|
|
- flipper_format_write_uint32(
|
|
|
- fff_file, HEX_VIEWER_SETTINGS_KEY_LED, &app->led, 1);
|
|
|
+ flipper_format_write_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
|
|
|
+ flipper_format_write_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
|
|
|
+ flipper_format_write_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_LED, &app->led, 1);
|
|
|
flipper_format_write_uint32(
|
|
|
fff_file, HEX_VIEWER_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
|
|
|
-
|
|
|
+
|
|
|
if(!flipper_format_rewind(fff_file)) {
|
|
|
hex_viewer_close_config_file(fff_file);
|
|
|
FURI_LOG_E(TAG, "Rewind error");
|
|
|
@@ -87,7 +82,7 @@ void hex_viewer_read_settings(void* context) {
|
|
|
uint32_t file_version;
|
|
|
FuriString* temp_str = furi_string_alloc();
|
|
|
|
|
|
- if (!flipper_format_file_open_existing(fff_file, HEX_VIEWER_SETTINGS_SAVE_PATH)) {
|
|
|
+ if(!flipper_format_file_open_existing(fff_file, HEX_VIEWER_SETTINGS_SAVE_PATH)) {
|
|
|
FURI_LOG_E(TAG, "Cannot open file %s", HEX_VIEWER_SETTINGS_SAVE_PATH);
|
|
|
hex_viewer_close_config_file(fff_file);
|
|
|
hex_viewer_close_storage();
|
|
|
@@ -111,7 +106,8 @@ void hex_viewer_read_settings(void* context) {
|
|
|
flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
|
|
|
flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
|
|
|
flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_LED, &app->led, 1);
|
|
|
- flipper_format_read_uint32(fff_file, HEX_VIEWER_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
|
|
|
+ flipper_format_read_uint32(
|
|
|
+ fff_file, HEX_VIEWER_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
|
|
|
|
|
|
flipper_format_rewind(fff_file);
|
|
|
|
|
|
@@ -119,12 +115,16 @@ void hex_viewer_read_settings(void* context) {
|
|
|
hex_viewer_close_storage();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
bool hex_viewer_open_file(void* context, const char* file_path) {
|
|
|
HexViewer* hex_viewer = context;
|
|
|
furi_assert(hex_viewer);
|
|
|
furi_assert(file_path);
|
|
|
|
|
|
+ if(hex_viewer->model->stream) {
|
|
|
+ buffered_file_stream_close(hex_viewer->model->stream);
|
|
|
+ stream_free(hex_viewer->model->stream); // TODO Check
|
|
|
+ }
|
|
|
+
|
|
|
hex_viewer->model->stream = buffered_file_stream_alloc(hex_viewer->storage);
|
|
|
bool isOk = true;
|
|
|
|