Skip to content

Commit

Permalink
Refactor file storage location and name
Browse files Browse the repository at this point in the history
  • Loading branch information
fridgepoet committed Dec 5, 2023
1 parent 4b7b8d7 commit b40e161
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions knit_counter.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <furi.h>
#include <gui/gui.h>
/* generated by fbt from .png files in images folder */
#include <knit_counter_icons.h>

#include <input/input.h>
#include <stdlib.h>
#include <storage/storage.h>
#include <flipper_format/flipper_format_i.h>
/* generated by fbt from .png files in images folder */
#include <knit_counter_icons.h>

#define MAX_COUNT 99
#define BOXTIME 2
Expand Down Expand Up @@ -85,18 +84,18 @@ Counter* state_init() {
void save_count(uint32_t count) {
Storage* storage = furi_record_open(RECORD_STORAGE);

FlipperFormat* fff_format = flipper_format_file_alloc(storage);
FlipperFormat* file = flipper_format_file_alloc(storage);

do {
if(storage_file_exists(storage, EXT_PATH("counter_storage"))) {
storage_simply_remove(storage, EXT_PATH("counter_storage"));
if(storage_file_exists(storage, APP_DATA_PATH("counter_storage.txt"))) {
storage_simply_remove(storage, APP_DATA_PATH("counter_storage.txt"));
}

if(!flipper_format_file_open_new(fff_format, EXT_PATH("counter_storage"))) break;
if(!flipper_format_write_uint32(fff_format, "UINT", &count, 1)) break;
if(!flipper_format_file_open_new(file, APP_DATA_PATH("counter_storage.txt"))) break;
if(!flipper_format_write_uint32(file, "UINT", &count, 1)) break;
} while(0);

flipper_format_free(fff_format);
flipper_format_free(file);
}

uint32_t read_count() {
Expand All @@ -106,7 +105,7 @@ uint32_t read_count() {
uint32_t uint32_value = 0;

do {
if(!flipper_format_file_open_existing(file, EXT_PATH("counter_storage"))) break;
if(!flipper_format_file_open_existing(file, APP_DATA_PATH("counter_storage.txt"))) break;
if(!flipper_format_read_uint32(file, "UINT", &uint32_value, 1)) break;
} while(0);

Expand Down

0 comments on commit b40e161

Please sign in to comment.