mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-17 20:19:43 -07:00
Remove dolphin backup and restorer
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
App(
|
||||
appid="DolphinBackup",
|
||||
name="Dolphin Backup",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="storage_DolphinBackup_app",
|
||||
cdefines=["APP_DBACKUP"],
|
||||
requires=["gui", "storage"],
|
||||
stack_size=2 * 1024,
|
||||
order=85,
|
||||
fap_icon="bckupIcon.png",
|
||||
fap_category="Tools",
|
||||
)
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -1,30 +0,0 @@
|
||||
#include "storage_DolphinBackup_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const storage_DolphinBackup_on_enter_handlers[])(void*) = {
|
||||
#include "storage_DolphinBackup_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const storage_DolphinBackup_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "storage_DolphinBackup_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const storage_DolphinBackup_on_exit_handlers[])(void* context) = {
|
||||
#include "storage_DolphinBackup_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers storage_DolphinBackup_scene_handlers = {
|
||||
.on_enter_handlers = storage_DolphinBackup_on_enter_handlers,
|
||||
.on_event_handlers = storage_DolphinBackup_on_event_handlers,
|
||||
.on_exit_handlers = storage_DolphinBackup_on_exit_handlers,
|
||||
.scene_num = StorageDolphinBackupSceneNum,
|
||||
};
|
||||
@@ -1,29 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) StorageDolphinBackup##id,
|
||||
typedef enum {
|
||||
#include "storage_DolphinBackup_scene_config.h"
|
||||
StorageDolphinBackupSceneNum,
|
||||
} StorageDolphinBackupScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers storage_DolphinBackup_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "storage_DolphinBackup_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 "storage_DolphinBackup_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 "storage_DolphinBackup_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
@@ -1,2 +0,0 @@
|
||||
ADD_SCENE(storage_DolphinBackup, confirm, Confirm)
|
||||
ADD_SCENE(storage_DolphinBackup, progress, Progress)
|
||||
@@ -1,71 +0,0 @@
|
||||
#include "../storage_DolphinBackup.h"
|
||||
#include "gui/canvas.h"
|
||||
#include "gui/modules/widget_elements/widget_element_i.h"
|
||||
#include "storage/storage.h"
|
||||
|
||||
static void storage_DolphinBackup_scene_confirm_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
StorageDolphinBackup* app = context;
|
||||
furi_assert(app);
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeRight) {
|
||||
view_dispatcher_send_custom_event(
|
||||
app->view_dispatcher, DolphinBackupCustomEventConfirm);
|
||||
} else if(result == GuiButtonTypeLeft) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, DolphinBackupCustomEventExit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void storage_DolphinBackup_scene_confirm_on_enter(void* context) {
|
||||
StorageDolphinBackup* app = context;
|
||||
|
||||
widget_add_button_element(
|
||||
app->widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
storage_DolphinBackup_scene_confirm_widget_callback,
|
||||
app);
|
||||
widget_add_button_element(
|
||||
app->widget,
|
||||
GuiButtonTypeRight,
|
||||
"Confirm",
|
||||
storage_DolphinBackup_scene_confirm_widget_callback,
|
||||
app);
|
||||
|
||||
widget_add_string_element(
|
||||
app->widget, 64, 10, AlignCenter, AlignCenter, FontPrimary, "SD Card Present");
|
||||
widget_add_string_multiline_element(
|
||||
app->widget,
|
||||
64,
|
||||
32,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
FontSecondary,
|
||||
"Copy data from\ninternal storage to SD card?");
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, StorageDolphinBackupViewWidget);
|
||||
}
|
||||
|
||||
bool storage_DolphinBackup_scene_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
StorageDolphinBackup* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == DolphinBackupCustomEventConfirm) {
|
||||
scene_manager_next_scene(app->scene_manager, StorageDolphinBackupProgress);
|
||||
consumed = true;
|
||||
} else if(event.event == DolphinBackupCustomEventExit) {
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void storage_DolphinBackup_scene_confirm_on_exit(void* context) {
|
||||
StorageDolphinBackup* app = context;
|
||||
widget_reset(app->widget);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "../storage_DolphinBackup.h"
|
||||
|
||||
void storage_DolphinBackup_scene_progress_on_enter(void* context) {
|
||||
StorageDolphinBackup* app = context;
|
||||
|
||||
widget_add_string_element(
|
||||
app->widget, 64, 10, AlignCenter, AlignCenter, FontPrimary, "Moving...");
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, StorageDolphinBackupViewWidget);
|
||||
|
||||
storage_DolphinBackup_perform();
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, DolphinBackupCustomEventExit);
|
||||
}
|
||||
|
||||
bool storage_DolphinBackup_scene_progress_on_event(void* context, SceneManagerEvent event) {
|
||||
StorageDolphinBackup* 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 storage_DolphinBackup_scene_progress_on_exit(void* context) {
|
||||
StorageDolphinBackup* app = context;
|
||||
widget_reset(app->widget);
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
#include "storage_DolphinBackup.h"
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include "loader/loader.h"
|
||||
#include "m-string.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define TAG "DolphinBackup"
|
||||
|
||||
#define MOVE_SRC "/int"
|
||||
#define MOVE_DST "/ext"
|
||||
|
||||
static const char* app_dirsDolphinBackup[] = {
|
||||
"subghz",
|
||||
"lfrfid",
|
||||
"nfc",
|
||||
"infrared",
|
||||
"ibutton",
|
||||
"badkb",
|
||||
".bt.settings",
|
||||
".desktop.settings",
|
||||
".dolphin.state",
|
||||
".notification.settings",
|
||||
".bt.keys",
|
||||
".power.settings",
|
||||
};
|
||||
|
||||
bool storage_DolphinBackup_perform(void) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* path_src;
|
||||
FuriString* path_dst;
|
||||
FuriString* new_path;
|
||||
path_src = furi_string_alloc();
|
||||
path_dst = furi_string_alloc();
|
||||
new_path = furi_string_alloc();
|
||||
|
||||
furi_string_printf(new_path, "%s/dolphin_restorer", MOVE_DST);
|
||||
storage_common_mkdir(storage, furi_string_get_cstr(new_path));
|
||||
furi_string_free(new_path);
|
||||
for(uint32_t i = 0; i < COUNT_OF(app_dirsDolphinBackup); i++) {
|
||||
if(i > 5) {
|
||||
furi_string_printf(path_src, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
|
||||
furi_string_printf(
|
||||
path_dst, "%s/dolphin_restorer/%s", MOVE_DST, app_dirsDolphinBackup[i]);
|
||||
storage_simply_remove_recursive(storage, furi_string_get_cstr(path_dst));
|
||||
storage_common_copy(
|
||||
storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
|
||||
} else {
|
||||
furi_string_printf(path_src, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
|
||||
furi_string_printf(path_dst, "%s/%s", MOVE_DST, app_dirsDolphinBackup[i]);
|
||||
storage_common_merge(
|
||||
storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
|
||||
storage_simply_remove_recursive(storage, furi_string_get_cstr(path_src));
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_free(path_src);
|
||||
furi_string_free(path_dst);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool storage_DolphinBackup_check(void) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
FileInfo file_info;
|
||||
bool state = false;
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
|
||||
for(uint32_t i = 0; i < COUNT_OF(app_dirsDolphinBackup); i++) {
|
||||
furi_string_printf(path, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
// if((file_info.flags & FSF_DIRECTORY) != 0) {
|
||||
state = true;
|
||||
break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_free(path);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
static bool storage_DolphinBackup_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
StorageDolphinBackup* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
static bool storage_DolphinBackup_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
StorageDolphinBackup* app = context;
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static void storage_DolphinBackup_unmount_callback(const void* message, void* context) {
|
||||
StorageDolphinBackup* 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, DolphinBackupCustomEventExit);
|
||||
}
|
||||
}
|
||||
|
||||
static StorageDolphinBackup* storage_DolphinBackup_alloc() {
|
||||
StorageDolphinBackup* app = malloc(sizeof(StorageDolphinBackup));
|
||||
|
||||
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(&storage_DolphinBackup_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, storage_DolphinBackup_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, storage_DolphinBackup_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, StorageDolphinBackupViewWidget, widget_get_view(app->widget));
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, StorageDolphinBackupConfirm);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
app->sub = furi_pubsub_subscribe(
|
||||
storage_get_pubsub(storage), storage_DolphinBackup_unmount_callback, app);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
static void storage_DolphinBackup_free(StorageDolphinBackup* 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, StorageDolphinBackupViewWidget);
|
||||
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 storage_DolphinBackup_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
if(storage_DolphinBackup_check()) {
|
||||
StorageDolphinBackup* app = storage_DolphinBackup_alloc();
|
||||
notification_message(app->notifications, &sequence_display_backlight_on);
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
storage_DolphinBackup_free(app);
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "Nothing to move");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void storage_DolphinBackup_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, "StorageDolphinBackup", NULL);
|
||||
furi_record_close("loader");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t storage_DolphinBackup_start(void* p) {
|
||||
UNUSED(p);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
furi_pubsub_subscribe(storage_get_pubsub(storage), storage_DolphinBackup_mount_callback, NULL);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
#include "gui/modules/widget_elements/widget_element_i.h"
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include <gui/modules/widget.h>
|
||||
#include <gui/modules/popup.h>
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <storage/storage_sd_api.h>
|
||||
|
||||
#include "scenes/storage_DolphinBackup_scene.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
DolphinBackupCustomEventExit,
|
||||
DolphinBackupCustomEventConfirm,
|
||||
} DolphinBackupCustomEvent;
|
||||
|
||||
typedef struct {
|
||||
// records
|
||||
Gui* gui;
|
||||
Widget* widget;
|
||||
NotificationApp* notifications;
|
||||
|
||||
// view managment
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
|
||||
FuriPubSubSubscription* sub;
|
||||
|
||||
} StorageDolphinBackup;
|
||||
|
||||
typedef enum {
|
||||
StorageDolphinBackupViewWidget,
|
||||
} StorageDolphinBackupView;
|
||||
|
||||
bool storage_DolphinBackup_perform(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,12 +0,0 @@
|
||||
App(
|
||||
appid="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="Tools",
|
||||
)
|
||||
@@ -1,176 +0,0 @@
|
||||
#include "drestorer.h"
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include "loader/loader.h"
|
||||
#include "m-string.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#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);
|
||||
FuriString* path_src;
|
||||
FuriString* path_dst;
|
||||
path_src = furi_string_alloc();
|
||||
path_dst = furi_string_alloc();
|
||||
|
||||
for(uint32_t i = 0; i < COUNT_OF(app_dirs); i++) {
|
||||
furi_string_printf(path_src, "%s/%s", MOVE_SRC, app_dirs[i]);
|
||||
furi_string_printf(path_dst, "%s/%s", MOVE_DST, app_dirs[i]);
|
||||
storage_simply_remove_recursive(storage, furi_string_get_cstr(path_dst));
|
||||
storage_common_copy(
|
||||
storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
|
||||
}
|
||||
|
||||
furi_string_free(path_src);
|
||||
furi_string_free(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;
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
|
||||
for(uint32_t i = 0; i < COUNT_OF(app_dirs); i++) {
|
||||
furi_string_printf(path, "%s/%s", MOVE_SRC, app_dirs[i]);
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
// if((file_info.flags & FSF_DIRECTORY) != 0) {
|
||||
state = true;
|
||||
break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_free(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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
#include "gui/modules/widget_elements/widget_element_i.h"
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include <gui/modules/widget.h>
|
||||
#include <gui/modules/popup.h>
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <storage/storage_sd_api.h>
|
||||
|
||||
#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
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -1,30 +0,0 @@
|
||||
#include "drestorer_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const drestorer_on_enter_handlers[])(void*) = {
|
||||
#include "drestorer_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const drestorer_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "drestorer_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const drestorer_on_exit_handlers[])(void* context) = {
|
||||
#include "drestorer_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers drestorer_scene_handlers = {
|
||||
.on_enter_handlers = drestorer_on_enter_handlers,
|
||||
.on_event_handlers = drestorer_on_event_handlers,
|
||||
.on_exit_handlers = drestorer_on_exit_handlers,
|
||||
.scene_num = StorageMoveToSdSceneNum,
|
||||
};
|
||||
@@ -1,29 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.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
|
||||
@@ -1,2 +0,0 @@
|
||||
ADD_SCENE(drestorer, confirm, Confirm)
|
||||
ADD_SCENE(drestorer, progress, Progress)
|
||||
@@ -1,60 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user