void workout_delete_by_slot(uint16_t slot_number) { SaveState state = slots_load_state(); uint32_t data_position; switch (slot_number) { case 1: data_position = DATA_WORKOUT_SAVE_1; state.save1_in_use = false; break; case 2: data_position = DATA_WORKOUT_SAVE_2; state.save2_in_use = false; break; case 3: data_position = DATA_WORKOUT_SAVE_3; state.save3_in_use = false; break; default: return; } persist_delete(data_position); for (int i = 0; i < M__COUNT; i++) { persist_delete(data_position + 1 + i); } slots_save_state(state); }
/** * Function that saves the presets into persistent storage. */ void presets_save(void){ int block = 0; uint8_t num_presets = presets_get_count(); if (num_presets == 0){ while (persist_exists(STORAGE_PRESET_START + block)){ persist_delete(STORAGE_PRESET_START + block); block++; } return; } for (int i = 0; i < num_presets; i+= PRESET_BLOCK_SIZE){ PresetBlock *presetBlock = malloc(sizeof(PresetBlock)); presetBlock->count = num_presets; presetBlock->time = time(NULL); for (int j = 0; j < PRESET_BLOCK_SIZE; j++){ if (i+j >= num_presets) break; presetBlock->presets[j] = *presets_get(i+j); } persist_write_data(STORAGE_PRESET_START+block, presetBlock, sizeof(PresetBlock)); free(presetBlock); block++; } return; }
void timers_save(void) { if (timers_count() == 0) { persist_delete(PERSIST_TIMER_START); return; } TimerBlock* block = NULL; uint8_t block_count = 0; for (uint8_t b = 0; b < timers_count(); b += 1) { if (NULL == block) { block = malloc(sizeof(TimerBlock)); block->total_timers = timers_count(); block->save_time = time(NULL); } uint8_t timer_block_pos = b % TIMER_BLOCK_SIZE; block->timers[timer_block_pos] = *timers_get(b); bool is_last_timer_in_block = timer_block_pos == (TIMER_BLOCK_SIZE - 1); if (is_last_timer_in_block) { persist_write_data(PERSIST_TIMER_START + block_count, block, sizeof(TimerBlock)); block_count += 1; free(block); block = NULL; } } if (block) { persist_write_data(PERSIST_TIMER_START + block_count, block, sizeof(TimerBlock)); } persist_write_int(PERSIST_TIMERS_VERSION, TIMERS_VERSION_CURRENT); }
void strap_deinit() { if (!persist_read_bool(STRAP_OPT_OUT)) { persist_delete(STRAP_CRASH_WATCHER); strap_log_action("STRAP_FINISH"); accl_deinit(); } }
void jobs_list_save(uint8_t first_key) { Job_ptr* job_ptr = first_job_ptr; while (job_ptr) { persist_write_data(first_key++, job_ptr->Job, sizeof(Job)); job_ptr=job_ptr->Next_ptr; } // if we've delete a job then need to delete the saved version or it will come back! persist_delete(first_key); }
status_t persist_write_int(const uint32_t key, const int32_t value) { persist_delete(key); Persist* persist = malloc(sizeof(Persist)); persist->key = key; persist->type = NUMBER; persist->number = value; linked_list_append(persistence, persist); return 0; }
int persist_write_data(const uint32_t key, const void *data, const size_t size) { persist_delete(key); Persist* persist = malloc(sizeof(Persist)); persist->key = key; persist->type = DATA; persist->data = malloc(size); memcpy(persist->data, data, size); linked_list_append(persistence, persist); return size; }
int persist_write_string(const uint32_t key, const char *cstring) { persist_delete(key); Persist* persist = malloc(sizeof(Persist)); persist->key = key; persist->type = STRING; persist->str = malloc(strlen(cstring) + 1); strcpy(persist->str, cstring); linked_list_append(persistence, persist); return strlen(cstring); }
void ClearPersistedData(void) { if(persist_exists(PERSISTED_IS_DATA_SAVED)) { int maxKey = persist_read_int(PERSISTED_MAX_KEY_USED); int i; for(i = 0; i <= maxKey; ++i) { persist_delete(i); } } }
void sustenance_storage_update_sustenance(int id, struct Sustenance *sustenance) { int next_id = sustenance_first_pkey + id; if (persist_exists(next_id)) { bool existed = persist_delete(next_id); APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. UPDATE SUSTENANCE. DELETED EXISTING KEY. EXISTED: %d", existed); } int bytesWritten = persist_write_data(next_id, sustenance, sizeof(struct Sustenance)); int expectedBytesWritten = sizeof(struct Sustenance); APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. UPDATE SUSTENANCE. PKEY: %d. Expected bytes written: %d. Bytes written: %d", next_id, expectedBytesWritten, bytesWritten); APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. UPDATE SUSTENANCE. Type: %d. Substance: %d. Amount: %d", sustenance->type, sustenance->substance, sustenance->amount); }
void data_init() { // Nuke previus version settings if(!persist_exists(V_3_1)) { persist_write_bool(V_3_1, true); for(int i = 0; i < DataNumBoolKeys; i++) { persist_delete(i); } persist_delete(DataKeyForegroundColor); persist_delete(DataKeyBackgroundColor); write_defaults(); } else { // Read settings for(int i = 0; i < DataNumBoolKeys; i++) { s_bool_settings[i] = persist_read_bool(i); } s_foreground = (GColor){ .argb = persist_read_int(DataKeyForegroundColor) }; s_background = (GColor){ .argb = persist_read_int(DataKeyBackgroundColor) }; } }
static void upgrade(void) { Version saved_version = { 0, 0 }; persist_read_data(STORAGE_APP_VERSION, &saved_version, sizeof(saved_version)); if (saved_version.major < 3) { for (uint32_t i = 0; i < 5; i++) { persist_delete(i); } } Version current_version = __pbl_app_info.app_version; persist_write_data(STORAGE_APP_VERSION, ¤t_version, sizeof(current_version)); }
void ClearPersistedData(void) { ProfileLogStart("ClearPersistedData"); if(persist_exists(PERSISTED_IS_DATA_SAVED)) { DEBUG_LOG("Clearing persisted data."); int maxKey = persist_read_int(PERSISTED_MAX_KEY_USED); int i; for(i = 0; i <= maxKey; ++i) { persist_delete(i); } } ProfileLogStop("ClearPersistedData"); }
void main_save_data() { data_loaded_from_watch = true; persist_write_int(STORAGE_KEY_VERSION, CURRENT_STORAGE_VERSION); data_timestamp=time(NULL); persist_write_int(STORAGE_KEY_TIMESTAMP, data_timestamp); if (timer.Active) { persist_write_data(STORAGE_KEY_TIMER, &timer, sizeof(Timer)); } else { persist_delete(STORAGE_KEY_TIMER); } persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(Settings)); jobs_list_save(STORAGE_KEY_FIRST_JOB); send_settings_to_phone(); settings_menu_hide(); }
void log_deinit() { if (eventLogSize > 0) { LOG(APP_LOG_LEVEL_DEBUG, "log not clean on exit, persisting remaining events"); uint8_t bufferSize = log_calculate_serialized_size(); uint8_t buffer[bufferSize]; log_serialize(buffer); if (persist_write_data(PERSIST_LOG, buffer, bufferSize) != bufferSize) { LOG(APP_LOG_LEVEL_ERROR, "persist failed"); } else { LOG(APP_LOG_LEVEL_DEBUG, "persisted %i events", (int)eventLogSize); } } else { persist_delete(PERSIST_LOG); } }
void migrate_legacy_data() { // load legacy checklist information from storage s_checklist_length = persist_read_int(PERSIST_KEY_CHECKLIST_LENGTH); s_checklist_num_checked = 0; // load the legacy checklist data from storage for(int i = 0; i < MAX_CHECKLIST_ITEMS; i++) { persist_read_data(PERSIST_KEY_CHECKLIST_ITEM_FIRST + i, &s_checklist_items[i], sizeof(ChecklistItem)); if(s_checklist_items[i].is_checked) { s_checklist_num_checked++; } } // now write the data in the new format save_data_to_storage(); // delete the old data for(int i = 0; i < MAX_CHECKLIST_ITEMS; i++) { persist_delete(PERSIST_KEY_CHECKLIST_ITEM_FIRST + i); } }
status_t timers_save(void) { int block = 0; uint8_t num_timers = timers_get_count(); if (num_timers == 0) { persist_delete(STORAGE_TIMER_START); return 0; } for (int t = 0; t < num_timers; t += TIMER_BLOCK_SIZE) { TimerBlock* timerBlock = malloc(sizeof(TimerBlock)); timerBlock->count = num_timers; timerBlock->time = time(NULL); for (int u = 0; u < TIMER_BLOCK_SIZE; u += 1) { if (t + u >= num_timers) { break; } timerBlock->timers[u] = *timers_get(t + u); } persist_write_data(STORAGE_TIMER_START + block, timerBlock, sizeof(TimerBlock)); free(timerBlock); block += 1; } return 0; }
void SetThreadSubreddit(struct ThreadData* thread, int index, char* str) { #ifdef USE_PERSIST_STRINGS if(str != NULL) { persist_write_string(PERSIST_OFFSET_THREAD_SUBREDDIT + index, str); } else { persist_delete(PERSIST_OFFSET_THREAD_SUBREDDIT + index); } #else if(thread->subreddit != NULL) { nt_Free(thread->subreddit); } if(str != NULL) { thread->subreddit = (char*)nt_Malloc(sizeof(char) * (strlen(str) + 1)); strcpy(thread->subreddit, str); } #endif }
void process_eventsmenu_message(DictionaryIterator *received) { Tuple *tuple; tuple = dict_find(received, KEY_INIT); if (tuple) { if (tuple->value->int8 == 0) { eventsmenu_firstload(); } else { if (!persist_exists(PERSIST_KEY_VERSION)) { if(persist_exists(PERSIST_EVENT_TITLE)) persist_write_int(PERSIST_KEY_VERSION, 21); else persist_write_int(PERSIST_KEY_VERSION, APP_VERSION); } if (persist_read_int(PERSIST_KEY_VERSION) < 22) { ui_messagebox_show("What's new", "Version 2.2: Added event reminders. To enable, visit app settings on phone."); } if (persist_read_int(PERSIST_KEY_VERSION) < 25) { ui_messagebox_show("What's new", "Version 2.5: Added auto refresh. To enable, visit app settings on phone."); } if (persist_read_int(PERSIST_KEY_VERSION) < APP_VERSION) { persist_write_int(PERSIST_KEY_VERSION, APP_VERSION); } } send_client_secret(); wakeup_schedule_sync(); } tuple = dict_find(received, KEY_SHOW_LOADING); if(tuple) { eventsmenu_loading(); } tuple = dict_find(received, KEY_EVENT_ID); if(tuple) { current_event_id = tuple->value->uint8; if (persist_exists((current_event_id + 1) * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE)) persist_delete((current_event_id + 1) * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE); } tuple = dict_find(received, KEY_EVENT_TITLE); if(tuple) { persist_write_string(PERSIST_EVENT_TITLE + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_START_DATE); if(tuple) { persist_write_int(PERSIST_EVENT_START_DATE + current_event_id*PERSIST_EVENT_FIELDCOUNT, tuple->value->uint32); } tuple = dict_find(received, KEY_EVENT_END_DATE); if(tuple) { persist_write_int(PERSIST_EVENT_END_DATE + current_event_id*PERSIST_EVENT_FIELDCOUNT, tuple->value->uint32); } tuple = dict_find(received, KEY_EVENT_LOCATION); if(tuple) { persist_write_string(PERSIST_EVENT_LOCATION + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_ATTENDEES); if(tuple) { persist_write_string(PERSIST_EVENT_ATTENDEES + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_BODY); if(tuple) { persist_write_string(PERSIST_EVENT_BODY + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_REFRESH_UI); if(tuple) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Refreshing events menu"); menu_layer_reload_data(s_menu_layer); text_layer_set_text(s_title_layer, "Events (online)"); wakeup_schedule_event_reminder(); if (layer_get_hidden(menu_layer_get_layer(s_menu_layer))) { layer_set_hidden(text_layer_get_layer(s_message_layer), true); layer_set_hidden(menu_layer_get_layer(s_menu_layer), false); } } }
void log_reset() { eventLogSize = firstEventIdx = 0; persist_delete(PERSIST_LOG); }
void in_received_handler(DictionaryIterator *received, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "in_received_handler"); Tuple *hh_in_bold_tuple = dict_find(received, MESSAGE_KEY_HH_IN_BOLD); if (hh_in_bold_tuple) { app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "hh_in_bold=%s", hh_in_bold_tuple->value->cstring); if (strcmp(hh_in_bold_tuple->value->cstring, "0") == 0) { persist_write_bool(MESSAGE_KEY_HH_IN_BOLD, false); } else { persist_write_bool(MESSAGE_KEY_HH_IN_BOLD, true); } } Tuple *mm_in_bold_tuple = dict_find(received, MESSAGE_KEY_MM_IN_BOLD); if (mm_in_bold_tuple) { app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "mm_in_bold=%s", mm_in_bold_tuple->value->cstring); if (strcmp(mm_in_bold_tuple->value->cstring, "1") == 0) { persist_write_bool(MESSAGE_KEY_MM_IN_BOLD, true); } else { persist_write_bool(MESSAGE_KEY_MM_IN_BOLD, false); } } Tuple *locale_tuple = dict_find(received, MESSAGE_KEY_LOCALE); if (locale_tuple) { app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "locale=%s", locale_tuple->value->cstring); if (strcmp(locale_tuple->value->cstring, "default") == 0) { if (persist_exists(MESSAGE_KEY_LOCALE)) { persist_delete(MESSAGE_KEY_LOCALE); } } else if (strcmp(locale_tuple->value->cstring, "fr") == 0) { persist_write_int(MESSAGE_KEY_LOCALE, locale_fr); } else if (strcmp(locale_tuple->value->cstring, "de") == 0) { persist_write_int(MESSAGE_KEY_LOCALE, locale_de); } else if (strcmp(locale_tuple->value->cstring, "es") == 0) { persist_write_int(MESSAGE_KEY_LOCALE, locale_es); } else if (strcmp(locale_tuple->value->cstring, "it") == 0) { persist_write_int(MESSAGE_KEY_LOCALE, locale_it); } else { persist_write_int(MESSAGE_KEY_LOCALE, locale_en); } } Tuple *hh_strip_zero_tuple = dict_find(received, MESSAGE_KEY_HH_STRIP_ZERO); if (hh_strip_zero_tuple) { app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "hh_strip_zero=%s", hh_strip_zero_tuple->value->cstring); if (strcmp(hh_strip_zero_tuple->value->cstring, "0") == 0) { persist_write_bool(MESSAGE_KEY_HH_STRIP_ZERO, false); } else { persist_write_bool(MESSAGE_KEY_HH_STRIP_ZERO, true); } } Tuple *time_sep_tuple = dict_find(received, MESSAGE_KEY_TIME_SEP); if (time_sep_tuple) { app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "time_sep=%s", time_sep_tuple->value->cstring); if (strcmp(time_sep_tuple->value->cstring, "square") == 0) { persist_write_int(MESSAGE_KEY_TIME_SEP, time_sep_square); } else if (strcmp(time_sep_tuple->value->cstring, "round") == 0) { persist_write_int(MESSAGE_KEY_TIME_SEP, time_sep_round); } else if (strcmp(time_sep_tuple->value->cstring, "squareb") == 0) { persist_write_int(MESSAGE_KEY_TIME_SEP, time_sep_square_bold); } else if (strcmp(time_sep_tuple->value->cstring, "roundb") == 0) { persist_write_int(MESSAGE_KEY_TIME_SEP, time_sep_round_bold); } else { persist_write_int(MESSAGE_KEY_TIME_SEP, time_sep_none); } } Tuple *repeat_vib_tuple = dict_find(received, MESSAGE_KEY_REPEAT_VIB); if (repeat_vib_tuple) { app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "repeat_vib=%s", repeat_vib_tuple->value->cstring); if (strcmp(repeat_vib_tuple->value->cstring, "1") == 0) { persist_write_bool(MESSAGE_KEY_REPEAT_VIB, true); } else { persist_write_bool(MESSAGE_KEY_REPEAT_VIB, false); } } read_configuration(); update_display(); }
void pomClearTimer() { persist_delete(TIMER_STRUCT_KEY); }
static void reset_wakeup() { wakeup_cancel(s_wakeup_id); s_wakeup_id = -1; s_wakeup_timestamp = 0; persist_delete(PERSIST_WAKEUP); }
void persist_safe_delete(const uint32_t key) { if (persist_exists(key)) { persist_delete(key); } }
static void clearData() { persist_delete(STORAGE_WATERCNT_ML); persist_delete(STORAGE_DAY); persist_delete(STORAGE_GOAL_ML); persist_delete(STORAGE_DRINKS); }
void __delete(int key) { persist_delete(key); }