From 13c35400a187e8c33af5ac8ef6c63199e33d1e48 Mon Sep 17 00:00:00 2001 From: niklascfw Date: Thu, 9 Apr 2026 22:11:30 +0200 Subject: [PATCH] install: backup and restore HorizonOC config.ini on OC pack update - Copy sd:/config/horizon-oc/config.ini to sd:/.omninx_oc_update before update cleanup/copy; restore after Hekate step, then remove the scratch dir. - Only when INSTALL_MODE_UPDATE and VARIANT_OC. Made-with: Cursor --- source/backup.c | 31 +++++++++++++++++++++++++++++++ source/backup.h | 13 +++++++++++++ source/install.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/source/backup.c b/source/backup.c index d4ca5ad..c53a1b2 100644 --- a/source/backup.c +++ b/source/backup.c @@ -101,3 +101,34 @@ int cleanup_backup(void) { } return FR_OK; } + +int backup_horizon_oc_config_for_oc_update(void) { + if (!path_exists(HORIZON_OC_CONFIG_PATH)) + return FR_OK; + + int res = f_mkdir(HORIZON_OC_UPDATE_BACKUP_DIR); + if (res != FR_OK && res != FR_EXIST) + return res; + + return file_copy(HORIZON_OC_CONFIG_PATH, HORIZON_OC_UPDATE_BACKUP_INI); +} + +int restore_horizon_oc_config_after_oc_update(void) { + if (!path_exists(HORIZON_OC_UPDATE_BACKUP_INI)) + return FR_OK; + + int res = f_mkdir("sd:/config"); + if (res != FR_OK && res != FR_EXIST) + return res; + res = f_mkdir("sd:/config/horizon-oc"); + if (res != FR_OK && res != FR_EXIST) + return res; + + return file_copy(HORIZON_OC_UPDATE_BACKUP_INI, HORIZON_OC_CONFIG_PATH); +} + +int cleanup_horizon_oc_update_backup(void) { + if (!path_exists(HORIZON_OC_UPDATE_BACKUP_DIR)) + return FR_OK; + return folder_delete(HORIZON_OC_UPDATE_BACKUP_DIR); +} diff --git a/source/backup.h b/source/backup.h index f5ad447..c8ec35a 100644 --- a/source/backup.h +++ b/source/backup.h @@ -8,6 +8,12 @@ #define TEMP_BACKUP_PATH "sd:/temp_backup" +/** 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, Tinfoil, prod.keys) before clean install int backup_user_data(void); @@ -16,3 +22,10 @@ int restore_user_data(void); // Clean up temporary backup directory int cleanup_backup(void); + +// HorizonOC: backup config.ini before OC pack update (update mode only); no-op if missing +int backup_horizon_oc_config_for_oc_update(void); +// Restore after file copy; no-op if no backup from this run +int restore_horizon_oc_config_after_oc_update(void); +// Delete sd:/.omninx_oc_update after successful restore +int cleanup_horizon_oc_update_backup(void); diff --git a/source/install.c b/source/install.c index ce26d48..21bbf2a 100644 --- a/source/install.c +++ b/source/install.c @@ -3,6 +3,7 @@ */ #include "install.h" +#include "backup.h" #include "fs.h" #include "screenshot.h" #include "version.h" @@ -872,6 +873,21 @@ int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) { int res; if (mode == INSTALL_MODE_UPDATE) { + if (pack_variant == VARIANT_OC) { + bool had_horizon_cfg = install_path_exists(HORIZON_OC_CONFIG_PATH); + install_set_color(COLOR_YELLOW); + gfx_printf("HorizonOC: Sichere config.ini...\n"); + install_set_color(COLOR_WHITE); + res = backup_horizon_oc_config_for_oc_update(); + if (res != FR_OK) + return res; + if (had_horizon_cfg) { + install_set_color(COLOR_GREEN); + gfx_printf(" [OK] Bestehende config.ini gesichert.\n"); + install_set_color(COLOR_WHITE); + } + } + // Update mode: selective cleanup then install install_set_color(COLOR_YELLOW); gfx_printf("Schritt 1: Bereinigung...\n"); @@ -889,6 +905,26 @@ int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) { install_hekate_8gb_post_copy(); + if (pack_variant == VARIANT_OC) { + bool had_horizon_bak = install_path_exists(HORIZON_OC_UPDATE_BACKUP_INI); + install_check_and_clear_screen_if_needed(); + install_set_color(COLOR_YELLOW); + gfx_printf("HorizonOC: Stelle config.ini wieder her...\n"); + install_set_color(COLOR_WHITE); + res = restore_horizon_oc_config_after_oc_update(); + if (res != FR_OK) + return res; + install_set_color(COLOR_GREEN); + if (had_horizon_bak) + gfx_printf(" [OK] Deine HorizonOC-Einstellungen wurden wiederhergestellt.\n"); + else + gfx_printf(" [OK] Keine fruehere config.ini — Standard aus dem Paket bleibt.\n"); + install_set_color(COLOR_WHITE); + res = cleanup_horizon_oc_update_backup(); + if (res != FR_OK) + return res; + } + install_check_and_clear_screen_if_needed(); // Remove staging directory (installed pack) res = cleanup_staging_directory(pack_variant);