- Backup/restore DBI settings file instead of whole DBI folder - Remove Tinfoil folder backup/restore - Adjust deletion_lists_clean.h comments; UI strings in install_clean.c Made-with: Cursor
117 lines
2.9 KiB
C
117 lines
2.9 KiB
C
/*
|
|
* OmniNX Installer - Backup and Restore Operations
|
|
*/
|
|
|
|
#include "backup.h"
|
|
#include "fs.h"
|
|
#include <libs/fatfs/ff.h>
|
|
#include <string.h>
|
|
#include <utils/sprintf.h>
|
|
|
|
// Check if file/directory exists
|
|
static bool path_exists(const char *path) {
|
|
FILINFO fno;
|
|
return (f_stat(path, &fno) == FR_OK);
|
|
}
|
|
|
|
// Backup user data before clean install
|
|
int backup_user_data(void) {
|
|
int res;
|
|
|
|
// Create temp backup directory
|
|
res = f_mkdir(TEMP_BACKUP_PATH);
|
|
if (res != FR_OK && res != FR_EXIST) {
|
|
return res;
|
|
}
|
|
|
|
// Backup DBI settings file only (not .nro installers)
|
|
if (path_exists(DBI_CONFIG_PATH)) {
|
|
res = file_copy(DBI_CONFIG_PATH, TEMP_BACKUP_DBI_CONFIG);
|
|
if (res != FR_OK) {
|
|
return res;
|
|
}
|
|
}
|
|
|
|
// Backup prod.keys if it exists
|
|
if (path_exists("sd:/switch/prod.keys")) {
|
|
res = file_copy("sd:/switch/prod.keys", "sd:/temp_backup/prod.keys");
|
|
if (res != FR_OK) {
|
|
return res;
|
|
}
|
|
}
|
|
|
|
return FR_OK;
|
|
}
|
|
|
|
// Restore user data after clean install
|
|
int restore_user_data(void) {
|
|
int res;
|
|
|
|
// Recreate switch directory (should already exist, but be safe)
|
|
res = f_mkdir("sd:/switch");
|
|
if (res != FR_OK && res != FR_EXIST) {
|
|
return res;
|
|
}
|
|
|
|
// Restore DBI settings if backed up
|
|
if (path_exists(TEMP_BACKUP_DBI_CONFIG)) {
|
|
res = f_mkdir("sd:/switch/DBI");
|
|
if (res != FR_OK && res != FR_EXIST) {
|
|
return res;
|
|
}
|
|
res = file_copy(TEMP_BACKUP_DBI_CONFIG, DBI_CONFIG_PATH);
|
|
if (res != FR_OK) {
|
|
return res;
|
|
}
|
|
}
|
|
|
|
// Restore prod.keys if backup exists
|
|
if (path_exists("sd:/temp_backup/prod.keys")) {
|
|
res = file_copy("sd:/temp_backup/prod.keys", "sd:/switch/prod.keys");
|
|
if (res != FR_OK) {
|
|
return res;
|
|
}
|
|
}
|
|
|
|
return FR_OK;
|
|
}
|
|
|
|
// Clean up temporary backup directory
|
|
int cleanup_backup(void) {
|
|
if (path_exists(TEMP_BACKUP_PATH)) {
|
|
return folder_delete(TEMP_BACKUP_PATH);
|
|
}
|
|
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);
|
|
}
|