diff --git a/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail.c b/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail.c index e0cabbd7..5b470d5c 100644 --- a/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail.c +++ b/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail.c @@ -74,6 +74,7 @@ static int32_t ntag_read(vfs_driver_t *p_vfs_driver, const char *path, ntag_t *n memcpy(ntag->notes, meta.notes, strlen(meta.notes)); } + NRF_LOG_INFO("has_flag:%d flag:%d", meta.has_flags, meta.flags); if (meta.has_flags && (meta.flags & VFS_OBJ_FLAG_READONLY)) { ntag->read_only = true; } diff --git a/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail_menu.c b/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail_menu.c index d36e7fa2..a491febb 100644 --- a/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail_menu.c +++ b/fw/application/src/app/amiibo/scene/amiibo_scene_amiibo_detail_menu.c @@ -31,6 +31,8 @@ static ret_code_t amiibo_scene_amiibo_detail_set_readonly(app_amiibo_t *app, boo char path[VFS_MAX_PATH_LEN]; vfs_meta_t meta; vfs_obj_t obj; + uint8_t meta_buf[VFS_MAX_META_LEN]; + cwalk_append_segment(path, string_get_cstr(app->current_folder), string_get_cstr(app->current_file)); @@ -50,7 +52,8 @@ static ret_code_t amiibo_scene_amiibo_detail_set_readonly(app_amiibo_t *app, boo meta.flags &= ~VFS_OBJ_FLAG_READONLY; } - if (p_vfs_driver->update_file_meta(path, obj.meta, sizeof(obj.meta)) == VFS_OK) { + vfs_meta_encode(meta_buf, sizeof(meta_buf), &meta); + if (p_vfs_driver->update_file_meta(path, meta_buf, sizeof(meta_buf)) == VFS_OK) { return NRF_SUCCESS; } else { return -1; @@ -169,6 +172,7 @@ static void amiibo_scene_amiibo_detail_menu_on_selected(mui_list_view_event_t ev ret_code_t err_code = amiibo_scene_amiibo_detail_set_readonly(app, !app->ntag.read_only); if (err_code == NRF_SUCCESS) { app->ntag.read_only = !app->ntag.read_only; + ntag_emu_set_tag(&app->ntag); mui_list_view_item_set_sub_text(p_item, app->ntag.read_only ? getLangString(_L_ON_F) : getLangString(_L_OFF_F)); } diff --git a/fw/application/src/app/amiibo/scene/amiibo_scene_file_browser.c b/fw/application/src/app/amiibo/scene/amiibo_scene_file_browser.c index 1db3982f..a8ba0d1a 100644 --- a/fw/application/src/app/amiibo/scene/amiibo_scene_file_browser.c +++ b/fw/application/src/app/amiibo/scene/amiibo_scene_file_browser.c @@ -54,7 +54,7 @@ static void amiibo_scene_file_browser_reload_folders(app_amiibo_t *app) { vfs_meta_t meta; memset(&meta, 0, sizeof(vfs_meta_t)); vfs_meta_decode(obj.meta, sizeof(obj.meta), &meta); - if (meta.has_flags && (meta.flags && VFS_OBJ_FLAG_HIDDEN)) { + if (meta.has_flags && (meta.flags & VFS_OBJ_FLAG_HIDDEN)) { continue; } uint16_t icon = obj.type == VFS_TYPE_DIR ? ICON_FOLDER : ICON_FILE; diff --git a/fw/application/src/app/amiibo/view/amiibo_detail_view.c b/fw/application/src/app/amiibo/view/amiibo_detail_view.c index c6b0eae7..dbd26638 100644 --- a/fw/application/src/app/amiibo/view/amiibo_detail_view.c +++ b/fw/application/src/app/amiibo/view/amiibo_detail_view.c @@ -1,11 +1,12 @@ #include "amiibo_detail_view.h" -#include "mui_element.h" -#include "i18n/language.h" -#include "db_header.h" #include "amiibo_helper.h" +#include "db_header.h" +#include "i18n/language.h" +#include "mui_element.h" #define ICON_LEFT 0xe1ac #define ICON_RIGHT 0xe1aa +#define ICON_INFO 0xe0ae static void amiibo_detail_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) { char buff[64]; @@ -36,14 +37,22 @@ static void amiibo_detail_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canva y += 12; - mui_canvas_draw_utf8(p_canvas, 0, y += 12, string_get_cstr(p_amiibo_detail_view->file_name)); + if (ntag->read_only) { + mui_canvas_set_font(p_canvas, u8g2_font_siji_t_6x10); + mui_canvas_draw_glyph(p_canvas, 0, y += 12, ICON_INFO); + mui_canvas_set_font(p_canvas, u8g2_font_wqy12_t_gb2312a); + mui_canvas_draw_utf8(p_canvas, 12, y, string_get_cstr(p_amiibo_detail_view->file_name)); + } else { + mui_canvas_draw_utf8(p_canvas, 0, y += 12, string_get_cstr(p_amiibo_detail_view->file_name)); + } uint32_t head = to_little_endian_int32(&ntag->data[84]); uint32_t tail = to_little_endian_int32(&ntag->data[88]); const db_amiibo_t *amd = get_amiibo_by_id(head, tail); if (amd != NULL) { - const char *name =(getLanguage() == LANGUAGE_ZH_TW || getLanguage() == LANGUAGE_ZH_HANS) ? amd->name_cn : amd->name_en; + const char *name = + (getLanguage() == LANGUAGE_ZH_TW || getLanguage() == LANGUAGE_ZH_HANS) ? amd->name_cn : amd->name_en; mui_element_autowrap_text(p_canvas, 0, y += 15, mui_canvas_get_width(p_canvas), 24, name); if (strlen(ntag->notes) > 0) { mui_element_autowrap_text(p_canvas, 0, y += 13, mui_canvas_get_width(p_canvas), 24, ntag->notes); diff --git a/fw/application/src/app/amiidb/api/amiidb_api_slot.c b/fw/application/src/app/amiidb/api/amiidb_api_slot.c index ea283253..cb799c6e 100644 --- a/fw/application/src/app/amiidb/api/amiidb_api_slot.c +++ b/fw/application/src/app/amiidb/api/amiidb_api_slot.c @@ -56,6 +56,12 @@ int32_t amiidb_api_slot_write(uint8_t slot, ntag_t *p_ntag) { meta.amiibo_tail = to_little_endian_int32(&p_ntag->data[88]); // TODO write only flag??? + meta.has_flags = true; + if (p_ntag->read_only) { + meta.flags |= VFS_OBJ_FLAG_READONLY; + } else { + meta.flags &= ~VFS_OBJ_FLAG_READONLY; + } vfs_meta_encode(meta_encoded, sizeof(meta_encoded), &meta); res = p_vfs_driver->update_file_meta(path, meta_encoded, sizeof(meta_encoded)); @@ -135,7 +141,7 @@ int32_t amiidb_api_slot_list(amiibo_slot_info_cb_t cb, void *ctx) { slots[index].amiibo_head = meta.amiibo_head; slots[index].amiibo_tail = meta.amiibo_tail; } - if (meta.has_flags && meta.flags & VFS_OBJ_FLAG_READONLY) { + if (meta.has_flags && (meta.flags & VFS_OBJ_FLAG_READONLY)) { slots[index].is_readonly = true; } } @@ -154,6 +160,7 @@ int32_t amiidb_api_slot_set_readonly(uint8_t slot, bool readonly) { char path[VFS_MAX_PATH_LEN]; vfs_meta_t meta; vfs_obj_t obj; + uint8_t meta_buf[VFS_MAX_META_LEN]; sprintf(path, "/amiibo/data/%02d.bin", slot); vfs_driver_t *p_vfs_driver = vfs_get_driver(VFS_DRIVE_EXT); @@ -172,8 +179,9 @@ int32_t amiidb_api_slot_set_readonly(uint8_t slot, bool readonly) { meta.flags &= ~VFS_OBJ_FLAG_READONLY; } - if (p_vfs_driver->update_file_meta(path, obj.meta, sizeof(obj.meta)) == VFS_OK) { - return 0; + vfs_meta_encode(meta_buf, sizeof(meta_buf), &meta); + if (p_vfs_driver->update_file_meta(path, meta_buf, sizeof(meta_buf)) == VFS_OK) { + return NRF_SUCCESS; } else { return -1; } diff --git a/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail.c b/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail.c index 440c066f..bd1faa5c 100644 --- a/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail.c +++ b/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail.c @@ -182,6 +182,7 @@ static void ntag_generate_timer_handler(void *p_context) { static void amiidb_scene_amiibo_view_on_event(amiibo_view_event_t event, amiibo_view_t *p_view) { app_amiidb_t *app = p_view->user_data; if (event == AMIIBO_VIEW_EVENT_MENU) { + app->cur_slot_index = amiibo_view_get_focus(app->p_amiibo_view); mui_scene_dispatcher_next_scene(app->p_scene_dispatcher, AMIIDB_SCENE_AMIIBO_DETAIL_MENU); } else if (event == AMIIBO_VIEW_EVENT_UPDATE) { if (app->prev_scene_id == AMIIDB_SCENE_GAME_LIST) { diff --git a/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail_menu.c b/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail_menu.c index 89839c01..2d4ebc41 100644 --- a/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail_menu.c +++ b/fw/application/src/app/amiidb/scene/amiidb_scene_amiibo_detail_menu.c @@ -159,9 +159,11 @@ void amiidb_scene_amiibo_detail_menu_on_enter(void *user_data) { mui_list_view_add_item_ext(app->p_list_view, 0xe006, getLangString(_L_SHOW_QRCODE), txt, (void *)AMIIDB_DETAIL_MENU_SHOW_QRCODE); - mui_list_view_add_item_ext(app->p_list_view, 0xe007, getLangString(_L_READ_ONLY), + if (app->prev_scene_id == AMIIDB_SCENE_DATA_LIST){ + mui_list_view_add_item_ext(app->p_list_view, 0xe007, getLangString(_L_READ_ONLY), app->ntag.read_only ? getLangString(_L_ON_F) : getLangString(_L_OFF_F), (void *)AMIIDB_DETAIL_MENU_READ_ONLY); + } mui_list_view_add_item(app->p_list_view, ICON_FAVORITE, getLangString(_L_APP_AMIIDB_DETAIL_FAVORITE), (void *)AMIIDB_DETAIL_MENU_FAVORITE); diff --git a/fw/application/src/app/amiidb/view/amiibo_view.c b/fw/application/src/app/amiidb/view/amiibo_view.c index 9ad258b0..de163a00 100644 --- a/fw/application/src/app/amiidb/view/amiibo_view.c +++ b/fw/application/src/app/amiidb/view/amiibo_view.c @@ -7,6 +7,7 @@ #define ICON_LEFT 0xe1ac #define ICON_RIGHT 0xe1aa +#define ICON_INFO 0xe0ae static void amiibo_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) { char buff[64]; @@ -42,9 +43,17 @@ static void amiibo_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) { const db_amiibo_t *amd = get_amiibo_by_id(head, tail); if (amd != NULL) { - const char *name =(getLanguage() == LANGUAGE_ZH_TW || getLanguage() == LANGUAGE_ZH_HANS) ? amd->name_cn : amd->name_en; - mui_canvas_draw_utf8(p_canvas, 0, y += 13, name); - + const char *name = + (getLanguage() == LANGUAGE_ZH_TW || getLanguage() == LANGUAGE_ZH_HANS) ? amd->name_cn : amd->name_en; + + if (ntag->read_only) { + mui_canvas_set_font(p_canvas, u8g2_font_siji_t_6x10); + mui_canvas_draw_glyph(p_canvas, 0, y += 12, ICON_INFO); + mui_canvas_set_font(p_canvas, u8g2_font_wqy12_t_gb2312a); + mui_canvas_draw_utf8(p_canvas, 12, y, name); + } else { + mui_canvas_draw_utf8(p_canvas, 0, y += 12, name); + } mui_rect_t clip_win_prev; mui_rect_t clip_win_cur; mui_canvas_get_clip_window(p_canvas, &clip_win_prev); @@ -67,17 +76,21 @@ static void amiibo_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) { p_amiibo_view->desc_page_size = clip_win_cur.h; const db_link_t *link = get_link_by_id(p_amiibo_view->game_id, head, tail); if (strlen(ntag->notes) > 0) { - p_amiibo_view->desc_total = mui_element_autowrap_text_box(p_canvas, clip_win_cur.x, clip_win_cur.y, clip_win_cur.w, clip_win_cur.h, p_amiibo_view->desc_offset, square_r, ntag->notes); + p_amiibo_view->desc_total = + mui_element_autowrap_text_box(p_canvas, clip_win_cur.x, clip_win_cur.y, clip_win_cur.w, clip_win_cur.h, + p_amiibo_view->desc_offset, square_r, ntag->notes); } else if (link != NULL) { const char *notes; - if (getLanguage() == LANGUAGE_ZH_HANS) { + if (getLanguage() == LANGUAGE_ZH_HANS) { notes = link->note_cn; - } else if(getLanguage() == LANGUAGE_IT_IT) { + } else if (getLanguage() == LANGUAGE_IT_IT) { notes = link->note_it; } else { notes = link->note_en; } - p_amiibo_view->desc_total = mui_element_autowrap_text_box(p_canvas, clip_win_cur.x, clip_win_cur.y, clip_win_cur.w, clip_win_cur.h, p_amiibo_view->desc_offset, square_r, notes); + p_amiibo_view->desc_total = + mui_element_autowrap_text_box(p_canvas, clip_win_cur.x, clip_win_cur.y, clip_win_cur.w, clip_win_cur.h, + p_amiibo_view->desc_offset, square_r, notes); } mui_canvas_set_clip_window(p_canvas, &clip_win_prev); } else if (head > 0 && tail > 0) { @@ -107,7 +120,11 @@ static void amiibo_view_on_input(mui_view_t *p_view, mui_input_event_t *event) { } break; case INPUT_KEY_RIGHT: - if (p_amiibo_view->desc_total > 0 && p_amiibo_view->desc_offset < p_amiibo_view->desc_page_size * ((p_amiibo_view->desc_total + p_amiibo_view->desc_page_size - 1) / p_amiibo_view->desc_page_size - 1)) { + if (p_amiibo_view->desc_total > 0 && + p_amiibo_view->desc_offset < + p_amiibo_view->desc_page_size * ((p_amiibo_view->desc_total + p_amiibo_view->desc_page_size - 1) / + p_amiibo_view->desc_page_size - + 1)) { p_amiibo_view->desc_offset += p_amiibo_view->desc_step; }