Files
OmniNX-Installer-Payload/source/install_clean.c
T
niklascfw 664216fa11 Move pack files instead of copying; one file-op core for all modes
Install: staging and sd:/ are on the same card, so pack folders are now
moved with f_rename (a missing target folder moves in one step, existing
ones are merged file by file). Copying is only a per-entry fallback.
The staging cleanup afterwards only removes empty folders.

Deletion: one f_stat per list entry, no full recursive count before
deleting; large folders are detected with a probe that stops after 51
entries. Progress lines count processed entries instead of needing an
extra pass for a total.

Six copy/delete walkers (fs.c + install.c) are replaced by fs_delete_tree,
fs_move_tree and fs_move_file sharing one path buffer and one copy buffer
per run; the 'alternative copy method' retry is gone. extras/hekate-ams-pro
is moved too. Backups keep copy semantics.
2026-11-12 22:57:26 +01:00

145 lines
4.2 KiB
C

/*
* OmniNX Installer - Clean Install Mode
* Backup, selective cleanup from list, restore, then install when no OmniNX found.
* Does not wipe whole card; only paths in deletion_lists_clean.h are removed.
*/
#include "install.h"
#include "backup.h"
#include "deletion_lists_clean.h"
#include "fs.h"
#include "gfx.h"
#include "version.h"
#include <libs/fatfs/ff.h>
#include <string.h>
#undef COLOR_CYAN
#undef COLOR_WHITE
#undef COLOR_GREEN
#undef COLOR_RED
#undef COLOR_YELLOW
#undef COLOR_ORANGE
#define COLOR_CYAN 0xFF00FFFF
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_GREEN 0xFF00FF00
#define COLOR_RED 0xFFFF0000
#define COLOR_YELLOW 0xFFFFDD00
#define COLOR_ORANGE 0xFF00A5FF
#define set_color install_set_color
#define check_and_clear_screen_if_needed install_check_and_clear_screen_if_needed
#define path_exists install_path_exists
// Clean mode: Backup user data
int clean_mode_backup(void) {
set_color(COLOR_CYAN);
gfx_printf(" Sichere: CyberFoil, Checkpoint, DBI (dbi.config), prod.keys\n");
set_color(COLOR_WHITE);
int res = backup_user_data();
if (res == FR_OK) {
set_color(COLOR_GREEN);
gfx_printf(" [OK] Sicherung abgeschlossen\n");
set_color(COLOR_WHITE);
}
return res;
}
// Clean mode: Wipe using selective deletion list (does not wipe whole card)
int clean_mode_wipe(void) {
check_and_clear_screen_if_needed();
set_color(COLOR_WHITE);
delete_path_lists_grouped("atmosphere/",
clean_atmosphere_dirs_to_delete,
clean_atmosphere_contents_dirs_to_delete,
clean_atmosphere_files_to_delete,
NULL);
delete_path_lists_grouped("bootloader/",
clean_bootloader_dirs_to_delete,
clean_bootloader_files_to_delete,
NULL);
delete_path_lists_grouped("config/",
clean_config_dirs_to_delete,
NULL);
delete_path_lists_grouped("switch/",
clean_switch_dirs_to_delete,
clean_switch_files_to_delete,
NULL);
delete_path_lists_grouped("Root-Dateien",
clean_root_files_to_delete,
clean_misc_dirs_to_delete,
clean_misc_files_to_delete,
NULL);
delete_path_lists_grouped("Alte Versionsmarker",
old_version_files_to_delete,
NULL);
set_color(COLOR_CYAN);
gfx_printf(" Erstelle: switch/\n");
set_color(COLOR_WHITE);
f_mkdir("sd:/switch");
set_color(COLOR_GREEN);
gfx_printf(" Bereinigung abgeschlossen!\n");
set_color(COLOR_WHITE);
return FR_OK;
}
// Clean mode: Restore user data
int clean_mode_restore(void) {
set_color(COLOR_CYAN);
gfx_printf(" Stelle wieder her: CyberFoil, Checkpoint, DBI (dbi.config), prod.keys\n");
set_color(COLOR_WHITE);
int res = restore_user_data();
if (res == FR_OK) {
set_color(COLOR_GREEN);
gfx_printf(" [OK] Wiederherstellung abgeschlossen\n");
set_color(COLOR_WHITE);
delete_path_lists_grouped("switch/ (nach Restore)", clean_post_restore_dirs_to_delete, NULL);
}
cleanup_backup();
return res;
}
// Clean mode: Install files (reuse update mode install)
int clean_mode_install(omninx_variant_t variant) {
return update_mode_install(variant);
}
// Remove other staging directories (OmniNX Standard/Light/OC) that exist on SD
int cleanup_other_staging_directories(omninx_variant_t installed_variant) {
static const omninx_variant_t all_variants[] = { VARIANT_STANDARD, VARIANT_LIGHT, VARIANT_OC };
const int n = sizeof(all_variants) / sizeof(all_variants[0]);
int last_res = FR_OK;
for (int i = 0; i < n; i++) {
omninx_variant_t v = all_variants[i];
if (v == installed_variant)
continue;
const char *staging = get_staging_path(v);
if (!staging || !path_exists(staging))
continue;
check_and_clear_screen_if_needed();
set_color(COLOR_YELLOW);
gfx_printf("\nEntferne weiteren Installationsordner...\n");
set_color(COLOR_WHITE);
int res = install_delete_tree(staging);
if (res != FR_OK) {
set_color(COLOR_ORANGE);
gfx_printf(" [WARN] Ordner konnte nicht entfernt werden (err=%d)\n", res);
set_color(COLOR_WHITE);
}
last_res = res;
}
return last_res;
}