From c0741beda3752be9110f3ca7025dd5de34e7221c Mon Sep 17 00:00:00 2001 From: niklascfw Date: Sun, 14 Jun 2026 17:31:46 +0200 Subject: [PATCH] Preserve CyberFoil across clean install backup/restore. Back up cyberfoil.nro, config.json, and remotes/ when sd:/switch/CyberFoil exists, then restore them after the wipe. --- source/backup.c | 58 +++++++++++++++++++++++++++++++++++ source/backup.h | 12 +++++++- source/deletion_lists_clean.h | 2 +- source/install_clean.c | 4 +-- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/source/backup.c b/source/backup.c index 438768e..83948d6 100644 --- a/source/backup.c +++ b/source/backup.c @@ -39,6 +39,35 @@ int backup_user_data(void) { return res; } } + + // Backup CyberFoil (nro, config, remotes) if installed + if (path_exists(CYBERFOIL_DIR)) { + res = f_mkdir(TEMP_BACKUP_CYBERFOIL); + if (res != FR_OK && res != FR_EXIST) { + return res; + } + + if (path_exists(CYBERFOIL_NRO)) { + res = file_copy(CYBERFOIL_NRO, TEMP_BACKUP_CYBERFOIL_NRO); + if (res != FR_OK) { + return res; + } + } + + if (path_exists(CYBERFOIL_CONFIG)) { + res = file_copy(CYBERFOIL_CONFIG, TEMP_BACKUP_CYBERFOIL_CONFIG); + if (res != FR_OK) { + return res; + } + } + + if (path_exists(CYBERFOIL_REMOTES)) { + res = folder_copy(CYBERFOIL_REMOTES, TEMP_BACKUP_CYBERFOIL); + if (res != FR_OK) { + return res; + } + } + } return FR_OK; } @@ -72,6 +101,35 @@ int restore_user_data(void) { return res; } } + + // Restore CyberFoil if backed up + if (path_exists(TEMP_BACKUP_CYBERFOIL)) { + res = f_mkdir(CYBERFOIL_DIR); + if (res != FR_OK && res != FR_EXIST) { + return res; + } + + if (path_exists(TEMP_BACKUP_CYBERFOIL_NRO)) { + res = file_copy(TEMP_BACKUP_CYBERFOIL_NRO, CYBERFOIL_NRO); + if (res != FR_OK) { + return res; + } + } + + if (path_exists(TEMP_BACKUP_CYBERFOIL_CONFIG)) { + res = file_copy(TEMP_BACKUP_CYBERFOIL_CONFIG, CYBERFOIL_CONFIG); + if (res != FR_OK) { + return res; + } + } + + if (path_exists(TEMP_BACKUP_CYBERFOIL_REMOTES)) { + res = folder_copy(TEMP_BACKUP_CYBERFOIL_REMOTES, CYBERFOIL_DIR); + if (res != FR_OK) { + return res; + } + } + } return FR_OK; } diff --git a/source/backup.h b/source/backup.h index fe7113a..f5e295d 100644 --- a/source/backup.h +++ b/source/backup.h @@ -11,13 +11,23 @@ #define DBI_CONFIG_PATH "sd:/switch/DBI/dbi.config" #define TEMP_BACKUP_DBI_CONFIG TEMP_BACKUP_PATH "/dbi.config" +/** CyberFoil homebrew; preserved across clean install (nro, config, remotes only). */ +#define CYBERFOIL_DIR "sd:/switch/CyberFoil" +#define CYBERFOIL_NRO CYBERFOIL_DIR "/cyberfoil.nro" +#define CYBERFOIL_CONFIG CYBERFOIL_DIR "/config.json" +#define CYBERFOIL_REMOTES CYBERFOIL_DIR "/remotes" +#define TEMP_BACKUP_CYBERFOIL TEMP_BACKUP_PATH "/CyberFoil" +#define TEMP_BACKUP_CYBERFOIL_NRO TEMP_BACKUP_CYBERFOIL "/cyberfoil.nro" +#define TEMP_BACKUP_CYBERFOIL_CONFIG TEMP_BACKUP_CYBERFOIL "/config.json" +#define TEMP_BACKUP_CYBERFOIL_REMOTES TEMP_BACKUP_CYBERFOIL "/remotes" + /** Live HorizonOC settings (Overclock tool). */ #define HORIZON_OC_CONFIG_PATH "sd:/config/horizon-oc/config.ini" /** Scratch dir during OC-variant update only; removed after successful restore. */ #define HORIZON_OC_UPDATE_BACKUP_DIR "sd:/.omninx_oc_update" #define HORIZON_OC_UPDATE_BACKUP_INI HORIZON_OC_UPDATE_BACKUP_DIR "/config.ini" -// Backup user data (DBI dbi.config, prod.keys) before clean install +// Backup user data (CyberFoil, DBI dbi.config, prod.keys) before clean install int backup_user_data(void); // Restore user data after clean install diff --git a/source/deletion_lists_clean.h b/source/deletion_lists_clean.h index 3b5df94..4caae8a 100644 --- a/source/deletion_lists_clean.h +++ b/source/deletion_lists_clean.h @@ -2,7 +2,7 @@ * OmniNX Installer - Deletion Lists for Clean Install Mode * Deletion policy aligned with NiklasCFW pack clean install (TegraExplorer script): * full sd:/atmosphere, bootloader/config subsets, sd:/switch, root + misc, then - * post-restore paths (e.g. tinfoil db). DBI/prod.keys backup is in backup.c. + * post-restore paths (e.g. tinfoil db). CyberFoil/DBI/prod.keys backup is in backup.c. */ #pragma once diff --git a/source/install_clean.c b/source/install_clean.c index 30341ce..55a7ea9 100644 --- a/source/install_clean.c +++ b/source/install_clean.c @@ -34,7 +34,7 @@ // Clean mode: Backup user data int clean_mode_backup(void) { set_color(COLOR_CYAN); - gfx_printf(" Sichere: DBI (dbi.config), prod.keys\n"); + gfx_printf(" Sichere: CyberFoil, DBI (dbi.config), prod.keys\n"); set_color(COLOR_WHITE); int res = backup_user_data(); if (res == FR_OK) { @@ -95,7 +95,7 @@ int clean_mode_wipe(void) { // Clean mode: Restore user data int clean_mode_restore(void) { set_color(COLOR_CYAN); - gfx_printf(" Stelle wieder her: DBI (dbi.config), prod.keys\n"); + gfx_printf(" Stelle wieder her: CyberFoil, DBI (dbi.config), prod.keys\n"); set_color(COLOR_WHITE); int res = restore_user_data(); if (res == FR_OK) {