From 9e0e6dbf19250305276a4bf12848a1c314739b73 Mon Sep 17 00:00:00 2001 From: RogueMaster Date: Sat, 17 Sep 2022 03:03:20 -0400 Subject: [PATCH] restorer --- ReadMe.md | 7 +- .../plugins/drestorer/application.fam | 12 ++ applications/plugins/drestorer/drestorer.c | 175 ++++++++++++++++++ applications/plugins/drestorer/drestorer.h | 49 +++++ .../plugins/drestorer/restoreIcon.png | Bin 0 -> 1960 bytes .../drestorer/scenes/drestorer_scene.c | 30 +++ .../drestorer/scenes/drestorer_scene.h | 29 +++ .../drestorer/scenes/drestorer_scene_config.h | 2 + .../scenes/drestorer_scene_confirm.c | 60 ++++++ .../scenes/drestorer_scene_progress.c | 31 ++++ 10 files changed, 389 insertions(+), 6 deletions(-) create mode 100644 applications/plugins/drestorer/application.fam create mode 100644 applications/plugins/drestorer/drestorer.c create mode 100644 applications/plugins/drestorer/drestorer.h create mode 100644 applications/plugins/drestorer/restoreIcon.png create mode 100644 applications/plugins/drestorer/scenes/drestorer_scene.c create mode 100644 applications/plugins/drestorer/scenes/drestorer_scene.h create mode 100644 applications/plugins/drestorer/scenes/drestorer_scene_config.h create mode 100644 applications/plugins/drestorer/scenes/drestorer_scene_confirm.c create mode 100644 applications/plugins/drestorer/scenes/drestorer_scene_progress.c diff --git a/ReadMe.md b/ReadMe.md index aec10482c..ee746d890 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -11,10 +11,6 @@
TO DO
-- [Calculator (By n-o-T-I-n-s-a-n-e)](https://github.com/n-o-T-I-n-s-a-n-e) -- [Mouse Jiggler (By Jacob-Tate)](https://github.com/Jacob-Tate/flipperzero-firmware/blob/dev/applications/mouse_jiggler/mouse_jiggler.c) (Original By MuddleBox) -- [Paint (By n-o-T-I-n-s-a-n-e)](https://github.com/n-o-T-I-n-s-a-n-e) -- [Dolphin Restorer (By nminaylov)](https://github.com/flipperdevices/flipperzero-firmware/pull/1384) Cloned by RogueMaster - [Dolphin Backup (By nminaylov)](https://github.com/flipperdevices/flipperzero-firmware/pull/1384) Modified by RogueMaster - Assets: Running DolphinRestorer.fap on new install will auto-level to the end of Level 2. - GPIO: Feature to read EEPROM of SFP Modules using I2C [(By marcusju)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/198) @@ -24,8 +20,6 @@ - Settings: Rename from SD `dolphin/name.txt` [(Thanks to E_Surge)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/259) - Settings: Scan names will have timestamp instead of random name assigned for [NFC](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/lib/toolbox/random_name.c) and [SubGHz](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/applications/subghz/scenes/subghz_scene_read_raw.c) (By RogueMaster) - SubGHz: [Add settings to subghz read functionality to allow setting RSSI threshold (raw only) (By PolymerPrints)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/184) -- [Chess (By Okalachev)](https://github.com/okalachev/flipperzero-firmware/tree/chess) Crashes 1st load if FW <~750KB or every load on larger FW `HIDDEN "INTAPP_chess_game"` -- [Chip8 Emulator (By mega8bit)](https://github.com/mega8bit/flipperzero-firmware) Updated by ESurge. Add SD folder `chip8`, [Get GAMES HERE](https://johnearnest.github.io/chip8Archive/) `HIDDEN "INTAPP_Chip8"` (Needs Controls Programmed) - [NFC: Display UL PWD_AUTH payload / ntag-pwd-capture (Thanks to GMMan)](https://github.com/flipperdevices/flipperzero-firmware/pull/1471) - [I²C-Scanner #1431 (By GitChris3004)](https://github.com/flipperdevices/flipperzero-firmware/pull/1431) - [Decode RAW recordings #1667 (By qistoph)](https://github.com/flipperdevices/flipperzero-firmware/pull/1667) @@ -34,6 +28,7 @@ - [SubGhz: fix display information in the file if the frequenc… #1724 (By Skorpionm)](https://github.com/flipperdevices/flipperzero-firmware/pull/1724) - [Show error popup when NFC chip is not init/disconnected #1722 (By Astrrra)](https://github.com/flipperdevices/flipperzero-firmware/pull/1722) - Fix Passport Pic Lvls Documentation +
diff --git a/applications/plugins/drestorer/application.fam b/applications/plugins/drestorer/application.fam new file mode 100644 index 000000000..2236073ac --- /dev/null +++ b/applications/plugins/drestorer/application.fam @@ -0,0 +1,12 @@ +App( + appid="APPS_DolphinRestorer", + name="Dolphin Restorer", + apptype=FlipperAppType.EXTERNAL, + entry_point="drestorer_app", + cdefines=["APP_DRESTORER"], + requires=["gui","storage"], + stack_size= 2 * 1024, + order=90, + fap_icon="restoreIcon.png", + fap_category="Misc", +) \ No newline at end of file diff --git a/applications/plugins/drestorer/drestorer.c b/applications/plugins/drestorer/drestorer.c new file mode 100644 index 000000000..4fbcc07fc --- /dev/null +++ b/applications/plugins/drestorer/drestorer.c @@ -0,0 +1,175 @@ +#include "drestorer.h" +#include +#include +#include "loader/loader.h" +#include "m-string.h" +#include + +#define TAG "MoveToInt" + +#define MOVE_SRC "/ext/dolphin_restorer" +#define MOVE_DST "/int" + +static const char* app_dirs[] = { + ".bt.settings", + ".desktop.settings", + ".dolphin.state", + ".notification.settings", + ".bt.keys", + ".power.settings", +}; + +bool drestorer_perform(void) { + Storage* storage = furi_record_open(RECORD_STORAGE); + string_t path_src; + string_t path_dst; + string_init(path_src); + string_init(path_dst); + + for(uint32_t i = 0; i < COUNT_OF(app_dirs); i++) { + string_printf(path_src, "%s/%s", MOVE_SRC, app_dirs[i]); + string_printf(path_dst, "%s/%s", MOVE_DST, app_dirs[i]); + storage_simply_remove_recursive(storage, string_get_cstr(path_dst)); + storage_common_copy(storage, string_get_cstr(path_src), string_get_cstr(path_dst)); + } + + string_clear(path_src); + string_clear(path_dst); + + furi_record_close(RECORD_STORAGE); + + return false; +} + +static bool drestorer_check(void) { + Storage* storage = furi_record_open(RECORD_STORAGE); + + FileInfo file_info; + bool state = false; + string_t path; + string_init(path); + + for(uint32_t i = 0; i < COUNT_OF(app_dirs); i++) { + string_printf(path, "%s/%s", MOVE_SRC, app_dirs[i]); + if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) { + // if((file_info.flags & FSF_DIRECTORY) != 0) { + state = true; + break; + // } + } + } + + string_clear(path); + + furi_record_close(RECORD_STORAGE); + + return state; +} + +static bool drestorer_custom_event_callback(void* context, uint32_t event) { + furi_assert(context); + StorageMoveToSd* app = context; + return scene_manager_handle_custom_event(app->scene_manager, event); +} + +static bool drestorer_back_event_callback(void* context) { + furi_assert(context); + StorageMoveToSd* app = context; + return scene_manager_handle_back_event(app->scene_manager); +} + +static void drestorer_unmount_callback(const void* message, void* context) { + StorageMoveToSd* app = context; + furi_assert(app); + const StorageEvent* storage_event = message; + + if((storage_event->type == StorageEventTypeCardUnmount) || + (storage_event->type == StorageEventTypeCardMountError)) { + view_dispatcher_send_custom_event(app->view_dispatcher, MoveToSdCustomEventExit); + } +} + +static StorageMoveToSd* drestorer_alloc() { + StorageMoveToSd* app = malloc(sizeof(StorageMoveToSd)); + + app->gui = furi_record_open(RECORD_GUI); + app->notifications = furi_record_open(RECORD_NOTIFICATION); + + app->view_dispatcher = view_dispatcher_alloc(); + app->scene_manager = scene_manager_alloc(&drestorer_scene_handlers, app); + + view_dispatcher_enable_queue(app->view_dispatcher); + view_dispatcher_set_event_callback_context(app->view_dispatcher, app); + + view_dispatcher_set_custom_event_callback( + app->view_dispatcher, drestorer_custom_event_callback); + view_dispatcher_set_navigation_event_callback( + app->view_dispatcher, drestorer_back_event_callback); + + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + + app->widget = widget_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, StorageMoveToSdViewWidget, widget_get_view(app->widget)); + + scene_manager_next_scene(app->scene_manager, StorageMoveToSdConfirm); + + Storage* storage = furi_record_open(RECORD_STORAGE); + app->sub = furi_pubsub_subscribe(storage_get_pubsub(storage), drestorer_unmount_callback, app); + furi_record_close(RECORD_STORAGE); + + return app; +} + +static void drestorer_free(StorageMoveToSd* app) { + Storage* storage = furi_record_open(RECORD_STORAGE); + furi_pubsub_unsubscribe(storage_get_pubsub(storage), app->sub); + furi_record_close(RECORD_STORAGE); + furi_record_close(RECORD_NOTIFICATION); + + view_dispatcher_remove_view(app->view_dispatcher, StorageMoveToSdViewWidget); + widget_free(app->widget); + view_dispatcher_free(app->view_dispatcher); + scene_manager_free(app->scene_manager); + + furi_record_close(RECORD_GUI); + + free(app); +} + +int32_t drestorer_app(void* p) { + UNUSED(p); + + if(drestorer_check()) { + StorageMoveToSd* app = drestorer_alloc(); + notification_message(app->notifications, &sequence_display_backlight_on); + view_dispatcher_run(app->view_dispatcher); + drestorer_free(app); + } else { + FURI_LOG_I(TAG, "Nothing to move"); + } + + return 0; +} + +static void drestorer_mount_callback(const void* message, void* context) { + UNUSED(context); + + const StorageEvent* storage_event = message; + + if(storage_event->type == StorageEventTypeCardMount) { + Loader* loader = furi_record_open("loader"); + loader_start(loader, "StorageMoveToSd", NULL); + furi_record_close("loader"); + } +} + +int32_t drestorer_start(void* p) { + UNUSED(p); + Storage* storage = furi_record_open(RECORD_STORAGE); + + furi_pubsub_subscribe(storage_get_pubsub(storage), drestorer_mount_callback, NULL); + + furi_record_close(RECORD_STORAGE); + return 0; +} diff --git a/applications/plugins/drestorer/drestorer.h b/applications/plugins/drestorer/drestorer.h new file mode 100644 index 000000000..c62adab37 --- /dev/null +++ b/applications/plugins/drestorer/drestorer.h @@ -0,0 +1,49 @@ +#pragma once +#include "gui/modules/widget_elements/widget_element_i.h" +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "scenes/drestorer_scene.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + MoveToSdCustomEventExit, + MoveToSdCustomEventConfirm, +} MoveToSdCustomEvent; + +typedef struct { + // records + Gui* gui; + Widget* widget; + NotificationApp* notifications; + + // view managment + SceneManager* scene_manager; + ViewDispatcher* view_dispatcher; + + FuriPubSubSubscription* sub; + +} StorageMoveToSd; + +typedef enum { + StorageMoveToSdViewWidget, +} StorageMoveToSdView; + +bool drestorer_perform(void); + +#ifdef __cplusplus +} +#endif diff --git a/applications/plugins/drestorer/restoreIcon.png b/applications/plugins/drestorer/restoreIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..752be3bced431bf6c780962040fc57d6855df315 GIT binary patch literal 1960 zcmcIl&1)n@6z}-OZZvyQ!F8A2w)e7&*7V0re=@USlF4oY+c9QG5)s7es_L00GhLnT zPG%DD;!P0uswe*dA+QJ@6j9WZ2NwiEJ$UjG6vRUaB-hO)?(S}HZ@+*2;?MB;d^Gz;A_xUB zd&YjceC3iLJoO-`FQ?1y9f$CC0aNa=Lbn}(wIGxyyAdWUEEPT02*Qf=*B4(&Vn8d> zlI|*QG|ig9>}JgFZqC=q<_fW?G?$2kgK)Q_GUrGf7t} zQZ@4^F1rijG>@5R7BoZ@MG;NApn8UmP5Tv5Q#4Ih3|TEA)pSaRqn5<}PXd3USdOXh zEY@!I{ee`GnrRw2vfSx(3Y}ts#|>GvZCh3}SXV$?>Kj;&Illn%) zgbWauzji(9=KQ6jSzYXf!ywrVfF$eE5A zPI+ACyfx_9!oZ`b6$`p}eJKbj?<6;}i255?4X3OkW!*!Hja0p^8jhknMeSv!=qO5V z>H;AsPVw1{ISu@cvzWTBGZ!W)4hfs9RU`aApk9 zUX25oA>0~8&7z`!$TZ6|RECkF8Yc2tNkO(}`N;4U%Qj4vs#KH2hkmDdi^ndfP~D;= zQsVeLZe!q2(8diWM`2??X&^N?fn;Wb1Uk6U8<%``dP8%Ut&XVrBhU)O9v>Y{vN5Pg zBT6UpRbu)^9$70G0m@aQ;AQ#IQRTZvj^Q3+u7xumBuII1!(`I% zmSQ0kEQUMi+fOdd!u@5<)vEOumMY)BdEsm2na8T9kN^H? + +// Generate scene id and total number +#define ADD_SCENE(prefix, name, id) StorageMoveToSd##id, +typedef enum { +#include "drestorer_scene_config.h" + StorageMoveToSdSceneNum, +} StorageMoveToSdScene; +#undef ADD_SCENE + +extern const SceneManagerHandlers drestorer_scene_handlers; + +// Generate scene on_enter handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*); +#include "drestorer_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_event handlers declaration +#define ADD_SCENE(prefix, name, id) \ + bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event); +#include "drestorer_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_exit handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context); +#include "drestorer_scene_config.h" +#undef ADD_SCENE diff --git a/applications/plugins/drestorer/scenes/drestorer_scene_config.h b/applications/plugins/drestorer/scenes/drestorer_scene_config.h new file mode 100644 index 000000000..80a07e22e --- /dev/null +++ b/applications/plugins/drestorer/scenes/drestorer_scene_config.h @@ -0,0 +1,2 @@ +ADD_SCENE(drestorer, confirm, Confirm) +ADD_SCENE(drestorer, progress, Progress) diff --git a/applications/plugins/drestorer/scenes/drestorer_scene_confirm.c b/applications/plugins/drestorer/scenes/drestorer_scene_confirm.c new file mode 100644 index 000000000..f9de4bccd --- /dev/null +++ b/applications/plugins/drestorer/scenes/drestorer_scene_confirm.c @@ -0,0 +1,60 @@ +#include "../drestorer.h" +#include "gui/canvas.h" +#include "gui/modules/widget_elements/widget_element_i.h" +#include "storage/storage.h" + +static void + drestorer_scene_confirm_widget_callback(GuiButtonType result, InputType type, void* context) { + StorageMoveToSd* app = context; + furi_assert(app); + if(type == InputTypeShort) { + if(result == GuiButtonTypeRight) { + view_dispatcher_send_custom_event(app->view_dispatcher, MoveToSdCustomEventConfirm); + } else if(result == GuiButtonTypeLeft) { + view_dispatcher_send_custom_event(app->view_dispatcher, MoveToSdCustomEventExit); + } + } +} + +void drestorer_scene_confirm_on_enter(void* context) { + StorageMoveToSd* app = context; + + widget_add_button_element( + app->widget, GuiButtonTypeLeft, "Cancel", drestorer_scene_confirm_widget_callback, app); + widget_add_button_element( + app->widget, GuiButtonTypeRight, "Confirm", drestorer_scene_confirm_widget_callback, app); + + widget_add_string_element( + app->widget, 64, 10, AlignCenter, AlignCenter, FontPrimary, "Backup Found"); + widget_add_string_multiline_element( + app->widget, + 64, + 32, + AlignCenter, + AlignCenter, + FontSecondary, + "Copy backup from\nSD card to internal storage?"); + + view_dispatcher_switch_to_view(app->view_dispatcher, StorageMoveToSdViewWidget); +} + +bool drestorer_scene_confirm_on_event(void* context, SceneManagerEvent event) { + StorageMoveToSd* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == MoveToSdCustomEventConfirm) { + scene_manager_next_scene(app->scene_manager, StorageMoveToSdProgress); + consumed = true; + } else if(event.event == MoveToSdCustomEventExit) { + view_dispatcher_stop(app->view_dispatcher); + } + } + + return consumed; +} + +void drestorer_scene_confirm_on_exit(void* context) { + StorageMoveToSd* app = context; + widget_reset(app->widget); +} diff --git a/applications/plugins/drestorer/scenes/drestorer_scene_progress.c b/applications/plugins/drestorer/scenes/drestorer_scene_progress.c new file mode 100644 index 000000000..7c65afb4c --- /dev/null +++ b/applications/plugins/drestorer/scenes/drestorer_scene_progress.c @@ -0,0 +1,31 @@ +#include "../drestorer.h" + +void drestorer_scene_progress_on_enter(void* context) { + StorageMoveToSd* app = context; + + widget_add_string_element( + app->widget, 64, 10, AlignCenter, AlignCenter, FontPrimary, "Moving..."); + + view_dispatcher_switch_to_view(app->view_dispatcher, StorageMoveToSdViewWidget); + + drestorer_perform(); + view_dispatcher_send_custom_event(app->view_dispatcher, MoveToSdCustomEventExit); +} + +bool drestorer_scene_progress_on_event(void* context, SceneManagerEvent event) { + StorageMoveToSd* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + view_dispatcher_stop(app->view_dispatcher); + } else if(event.type == SceneManagerEventTypeBack) { + consumed = true; + } + + return consumed; +} + +void drestorer_scene_progress_on_exit(void* context) { + StorageMoveToSd* app = context; + widget_reset(app->widget); +}