dolphin backup

This commit is contained in:
RogueMaster
2022-09-17 04:40:36 -04:00
parent e5925543b1
commit c29d2383b1
10 changed files with 133 additions and 133 deletions
@@ -0,0 +1,30 @@
#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,
};
@@ -3,27 +3,27 @@
#include <gui/scene_manager.h>
// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) StorageMoveToSd##id,
#define ADD_SCENE(prefix, name, id) StorageDolphinBackup##id,
typedef enum {
#include "storage_move_to_sd_scene_config.h"
StorageMoveToSdSceneNum,
} StorageMoveToSdScene;
#include "storage_DolphinBackup_scene_config.h"
StorageDolphinBackupSceneNum,
} StorageDolphinBackupScene;
#undef ADD_SCENE
extern const SceneManagerHandlers storage_move_to_sd_scene_handlers;
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_move_to_sd_scene_config.h"
#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_move_to_sd_scene_config.h"
#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_move_to_sd_scene_config.h"
#include "storage_DolphinBackup_scene_config.h"
#undef ADD_SCENE
@@ -0,0 +1,2 @@
ADD_SCENE(storage_DolphinBackup, confirm, Confirm)
ADD_SCENE(storage_DolphinBackup, progress, Progress)
@@ -1,37 +1,37 @@
#include "../storage_move_to_sd.h"
#include "../storage_DolphinBackup.h"
#include "gui/canvas.h"
#include "gui/modules/widget_elements/widget_element_i.h"
#include "storage/storage.h"
static void storage_move_to_sd_scene_confirm_widget_callback(
static void storage_DolphinBackup_scene_confirm_widget_callback(
GuiButtonType result,
InputType type,
void* context) {
StorageMoveToSd* app = context;
StorageDolphinBackup* app = context;
furi_assert(app);
if(type == InputTypeShort) {
if(result == GuiButtonTypeRight) {
view_dispatcher_send_custom_event(app->view_dispatcher, MoveToSdCustomEventConfirm);
view_dispatcher_send_custom_event(app->view_dispatcher, DolphinBackupCustomEventConfirm);
} else if(result == GuiButtonTypeLeft) {
view_dispatcher_send_custom_event(app->view_dispatcher, MoveToSdCustomEventExit);
view_dispatcher_send_custom_event(app->view_dispatcher, DolphinBackupCustomEventExit);
}
}
}
void storage_move_to_sd_scene_confirm_on_enter(void* context) {
StorageMoveToSd* app = context;
void storage_DolphinBackup_scene_confirm_on_enter(void* context) {
StorageDolphinBackup* app = context;
widget_add_button_element(
app->widget,
GuiButtonTypeLeft,
"Cancel",
storage_move_to_sd_scene_confirm_widget_callback,
storage_DolphinBackup_scene_confirm_widget_callback,
app);
widget_add_button_element(
app->widget,
GuiButtonTypeRight,
"Confirm",
storage_move_to_sd_scene_confirm_widget_callback,
storage_DolphinBackup_scene_confirm_widget_callback,
app);
widget_add_string_element(
@@ -45,18 +45,18 @@ void storage_move_to_sd_scene_confirm_on_enter(void* context) {
FontSecondary,
"Copy data from\ninternal storage to SD card?");
view_dispatcher_switch_to_view(app->view_dispatcher, StorageMoveToSdViewWidget);
view_dispatcher_switch_to_view(app->view_dispatcher, StorageDolphinBackupViewWidget);
}
bool storage_move_to_sd_scene_confirm_on_event(void* context, SceneManagerEvent event) {
StorageMoveToSd* app = context;
bool storage_DolphinBackup_scene_confirm_on_event(void* context, SceneManagerEvent event) {
StorageDolphinBackup* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == MoveToSdCustomEventConfirm) {
scene_manager_next_scene(app->scene_manager, StorageMoveToSdProgress);
if(event.event == DolphinBackupCustomEventConfirm) {
scene_manager_next_scene(app->scene_manager, StorageDolphinBackupProgress);
consumed = true;
} else if(event.event == MoveToSdCustomEventExit) {
} else if(event.event == DolphinBackupCustomEventExit) {
view_dispatcher_stop(app->view_dispatcher);
}
}
@@ -64,7 +64,7 @@ bool storage_move_to_sd_scene_confirm_on_event(void* context, SceneManagerEvent
return consumed;
}
void storage_move_to_sd_scene_confirm_on_exit(void* context) {
StorageMoveToSd* app = context;
void storage_DolphinBackup_scene_confirm_on_exit(void* context) {
StorageDolphinBackup* app = context;
widget_reset(app->widget);
}
@@ -0,0 +1,31 @@
#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,30 +0,0 @@
#include "storage_move_to_sd_scene.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const storage_move_to_sd_on_enter_handlers[])(void*) = {
#include "storage_move_to_sd_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_move_to_sd_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "storage_move_to_sd_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_move_to_sd_on_exit_handlers[])(void* context) = {
#include "storage_move_to_sd_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers storage_move_to_sd_scene_handlers = {
.on_enter_handlers = storage_move_to_sd_on_enter_handlers,
.on_event_handlers = storage_move_to_sd_on_event_handlers,
.on_exit_handlers = storage_move_to_sd_on_exit_handlers,
.scene_num = StorageMoveToSdSceneNum,
};
@@ -1,2 +0,0 @@
ADD_SCENE(storage_move_to_sd, confirm, Confirm)
ADD_SCENE(storage_move_to_sd, progress, Progress)
@@ -1,31 +0,0 @@
#include "../storage_move_to_sd.h"
void storage_move_to_sd_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);
storage_move_to_sd_perform();
view_dispatcher_send_custom_event(app->view_dispatcher, MoveToSdCustomEventExit);
}
bool storage_move_to_sd_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 storage_move_to_sd_scene_progress_on_exit(void* context) {
StorageMoveToSd* app = context;
widget_reset(app->widget);
}
@@ -1,16 +1,16 @@
#include "storage_move_to_sd.h"
#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 "MoveToSd"
#define TAG "DolphinBackup"
#define MOVE_SRC "/int"
#define MOVE_DST "/ext"
static const char* app_dirs[] = {
static const char* app_dirsDolphinBackup[] = {
"subghz",
"lfrfid",
"nfc",
@@ -25,7 +25,7 @@ static const char* app_dirs[] = {
".power.settings",
};
bool storage_move_to_sd_perform(void) {
bool storage_DolphinBackup_perform(void) {
Storage* storage = furi_record_open(RECORD_STORAGE);
string_t path_src;
string_t path_dst;
@@ -37,15 +37,15 @@ bool storage_move_to_sd_perform(void) {
string_printf(new_path, "%s/dolphin_restorer", MOVE_DST);
storage_common_mkdir(storage, string_get_cstr(new_path));
string_clear(new_path);
for(uint32_t i = 0; i < COUNT_OF(app_dirs); i++) {
for(uint32_t i = 0; i < COUNT_OF(app_dirsDolphinBackup); i++) {
if(i > 5) {
string_printf(path_src, "%s/%s", MOVE_SRC, app_dirs[i]);
string_printf(path_dst, "%s/dolphin_restorer/%s", MOVE_DST, app_dirs[i]);
string_printf(path_src, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
string_printf(path_dst, "%s/dolphin_restorer/%s", MOVE_DST, app_dirsDolphinBackup[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));
} else {
string_printf(path_src, "%s/%s", MOVE_SRC, app_dirs[i]);
string_printf(path_dst, "%s/%s", MOVE_DST, app_dirs[i]);
string_printf(path_src, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
string_printf(path_dst, "%s/%s", MOVE_DST, app_dirsDolphinBackup[i]);
storage_common_merge(storage, string_get_cstr(path_src), string_get_cstr(path_dst));
storage_simply_remove_recursive(storage, string_get_cstr(path_src));
}
@@ -59,7 +59,7 @@ bool storage_move_to_sd_perform(void) {
return false;
}
static bool storage_move_to_sd_check(void) {
static bool storage_DolphinBackup_check(void) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FileInfo file_info;
@@ -67,8 +67,8 @@ static bool storage_move_to_sd_check(void) {
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]);
for(uint32_t i = 0; i < COUNT_OF(app_dirsDolphinBackup); i++) {
string_printf(path, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
// if((file_info.flags & FSF_DIRECTORY) != 0) {
state = true;
@@ -84,69 +84,69 @@ static bool storage_move_to_sd_check(void) {
return state;
}
static bool storage_move_to_sd_custom_event_callback(void* context, uint32_t event) {
static bool storage_DolphinBackup_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
StorageMoveToSd* app = context;
StorageDolphinBackup* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}
static bool storage_move_to_sd_back_event_callback(void* context) {
static bool storage_DolphinBackup_back_event_callback(void* context) {
furi_assert(context);
StorageMoveToSd* app = context;
StorageDolphinBackup* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}
static void storage_move_to_sd_unmount_callback(const void* message, void* context) {
StorageMoveToSd* app = context;
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, MoveToSdCustomEventExit);
view_dispatcher_send_custom_event(app->view_dispatcher, DolphinBackupCustomEventExit);
}
}
static StorageMoveToSd* storage_move_to_sd_alloc() {
StorageMoveToSd* app = malloc(sizeof(StorageMoveToSd));
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_move_to_sd_scene_handlers, app);
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_move_to_sd_custom_event_callback);
app->view_dispatcher, storage_DolphinBackup_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, storage_move_to_sd_back_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, StorageMoveToSdViewWidget, widget_get_view(app->widget));
app->view_dispatcher, StorageDolphinBackupViewWidget, widget_get_view(app->widget));
scene_manager_next_scene(app->scene_manager, StorageMoveToSdConfirm);
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_move_to_sd_unmount_callback, app);
storage_get_pubsub(storage), storage_DolphinBackup_unmount_callback, app);
furi_record_close(RECORD_STORAGE);
return app;
}
static void storage_move_to_sd_free(StorageMoveToSd* 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, StorageMoveToSdViewWidget);
view_dispatcher_remove_view(app->view_dispatcher, StorageDolphinBackupViewWidget);
widget_free(app->widget);
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
@@ -156,14 +156,14 @@ static void storage_move_to_sd_free(StorageMoveToSd* app) {
free(app);
}
int32_t storage_move_to_sd_app(void* p) {
int32_t storage_DolphinBackup_app(void* p) {
UNUSED(p);
if(storage_move_to_sd_check()) {
StorageMoveToSd* app = storage_move_to_sd_alloc();
if(storage_DolphinBackup_check()) {
StorageDolphinBackup* app = storage_DolphinBackup_alloc();
notification_message(app->notifications, &sequence_display_backlight_on);
view_dispatcher_run(app->view_dispatcher);
storage_move_to_sd_free(app);
storage_DolphinBackup_free(app);
} else {
FURI_LOG_I(TAG, "Nothing to move");
}
@@ -171,23 +171,23 @@ int32_t storage_move_to_sd_app(void* p) {
return 0;
}
static void storage_move_to_sd_mount_callback(const void* message, void* context) {
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, "StorageMoveToSd", NULL);
loader_start(loader, "StorageDolphinBackup", NULL);
furi_record_close("loader");
}
}
int32_t storage_move_to_sd_start(void* p) {
int32_t storage_DolphinBackup_start(void* p) {
UNUSED(p);
Storage* storage = furi_record_open(RECORD_STORAGE);
furi_pubsub_subscribe(storage_get_pubsub(storage), storage_move_to_sd_mount_callback, NULL);
furi_pubsub_subscribe(storage_get_pubsub(storage), storage_DolphinBackup_mount_callback, NULL);
furi_record_close(RECORD_STORAGE);
return 0;
@@ -13,16 +13,16 @@
#include <storage/storage.h>
#include <storage/storage_sd_api.h>
#include "scenes/storage_move_to_sd_scene.h"
#include "scenes/storage_DolphinBackup_scene.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
MoveToSdCustomEventExit,
MoveToSdCustomEventConfirm,
} MoveToSdCustomEvent;
DolphinBackupCustomEventExit,
DolphinBackupCustomEventConfirm,
} DolphinBackupCustomEvent;
typedef struct {
// records
@@ -36,13 +36,13 @@ typedef struct {
FuriPubSubSubscription* sub;
} StorageMoveToSd;
} StorageDolphinBackup;
typedef enum {
StorageMoveToSdViewWidget,
} StorageMoveToSdView;
StorageDolphinBackupViewWidget,
} StorageDolphinBackupView;
bool storage_move_to_sd_perform(void);
bool storage_DolphinBackup_perform(void);
#ifdef __cplusplus
}