Rearrangement

This commit is contained in:
Niklas080208
2026-02-02 12:18:40 +01:00
parent 5825581127
commit 1a44154287
8 changed files with 1215 additions and 762 deletions

View File

@@ -3,8 +3,6 @@
*/
#include "install.h"
#include "backup.h"
#include "deletion_lists.h"
#include "fs.h"
#include "version.h"
#include "gfx.h"
@@ -16,8 +14,6 @@
#define VERSION "1.0.0"
#endif
// Forward declaration
static void combine_path(char *result, size_t size, const char *base, const char *add);
// Color definitions (some already defined in types.h, but we override for consistency)
#undef COLOR_CYAN
@@ -33,12 +29,12 @@ static void combine_path(char *result, size_t size, const char *base, const char
#define COLOR_ORANGE 0xFF00A5FF
#define COLOR_RED 0xFFFF0000
static void set_color(u32 color) {
void install_set_color(u32 color) {
gfx_con_setcol(color, gfx_con.fillbg, gfx_con.bgcol);
}
// Check if we need to clear screen (when getting close to bottom)
static void check_and_clear_screen_if_needed(void) {
void install_check_and_clear_screen_if_needed(void) {
// In the gfx system:
// - gfx_con.x is the vertical position (line number, increments by 16 per line)
// - gfx_con.y is the horizontal position (pixels from left)
@@ -53,22 +49,22 @@ static void check_and_clear_screen_if_needed(void) {
gfx_con_setpos(0, 0);
// Reprint same header as initial launch
set_color(COLOR_CYAN);
gfx_printf("========================================\n");
install_set_color(COLOR_CYAN);
gfx_printf("===================================\n");
gfx_printf(" OmniNX Installer Payload v%s\n", VERSION);
gfx_printf("========================================\n\n");
set_color(COLOR_WHITE);
gfx_printf("===================================\n\n");
install_set_color(COLOR_WHITE);
}
}
// Check if file/directory exists
static bool path_exists(const char *path) {
bool install_path_exists(const char *path) {
FILINFO fno;
return (f_stat(path, &fno) == FR_OK);
}
// Count total items (files + directories) in a directory tree recursively
static int count_directory_items(const char *path) {
int install_count_directory_items(const char *path) {
DIR dir;
FILINFO fno;
int res;
@@ -94,7 +90,7 @@ static int count_directory_items(const char *path) {
if (fno.fattrib & AM_DIR) {
char sub_path[256];
s_printf(sub_path, "%s/%s", path, fno.fname);
count += count_directory_items(sub_path);
count += install_count_directory_items(sub_path);
}
}
@@ -103,7 +99,7 @@ static int count_directory_items(const char *path) {
}
// Helper to combine paths (handles trailing slashes properly)
static void combine_path(char *result, size_t size, const char *base, const char *add) {
void install_combine_path(char *result, size_t size, const char *base, const char *add) {
size_t base_len = strlen(base);
if (base_len > 0 && base[base_len - 1] == '/') {
// Base has trailing slash, just append
@@ -137,7 +133,7 @@ static int folder_copy_progress_recursive(const char *src, const char *dst, int
}
// Create destination folder path (handle trailing slash in dst)
combine_path(dst_dir, sizeof(dst_dir), dst, folder_name);
install_combine_path(dst_dir, sizeof(dst_dir), dst, folder_name);
// Try to create the directory (ignore if it already exists)
res = f_mkdir(dst_dir);
@@ -171,8 +167,8 @@ static int folder_copy_progress_recursive(const char *src, const char *dst, int
}
// Build source and destination paths
combine_path(src_full, sizeof(src_full), src, fno.fname);
combine_path(dst_full, sizeof(dst_full), dst_dir, fno.fname);
install_combine_path(src_full, sizeof(src_full), src, fno.fname);
install_combine_path(dst_full, sizeof(dst_full), dst_dir, fno.fname);
if (fno.fattrib & AM_DIR) {
res = folder_copy_progress_recursive(src_full, dst_dir, copied, total, start_x, start_y, display_name, last_percent);
@@ -188,9 +184,9 @@ static int folder_copy_progress_recursive(const char *src, const char *dst, int
int percent = total > 0 ? (*copied * 100) / total : 0;
if (percent != *last_percent || *copied % 50 == 0) {
gfx_con_setpos(start_x, start_y);
set_color(COLOR_CYAN);
install_set_color(COLOR_CYAN);
gfx_printf(" Kopiere: %s [%3d%%] (%d/%d)", display_name, percent, *copied, total);
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
*last_percent = percent;
}
}
@@ -203,7 +199,7 @@ static int folder_copy_progress_recursive(const char *src, const char *dst, int
}
// Progress-aware folder copy (improved version)
static int folder_copy_with_progress_v2(const char *src, const char *dst, const char *display_name) {
int folder_copy_with_progress_v2(const char *src, const char *dst, const char *display_name) {
int copied = 0;
int total = 0;
int last_percent = -1;
@@ -211,15 +207,15 @@ static int folder_copy_with_progress_v2(const char *src, const char *dst, const
int res;
// Check if source exists
if (!path_exists(src)) {
set_color(COLOR_ORANGE);
if (!install_path_exists(src)) {
install_set_color(COLOR_ORANGE);
gfx_printf(" Ueberspringe: %s (nicht gefunden)\n", display_name);
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
return FR_NO_FILE;
}
// Count total items first
total = count_directory_items(src);
total = install_count_directory_items(src);
if (total == 0) {
// Empty directory, just create destination
@@ -227,7 +223,7 @@ static int folder_copy_with_progress_v2(const char *src, const char *dst, const
if (folder_name) folder_name++;
else folder_name = src;
char dst_path[256];
combine_path(dst_path, sizeof(dst_path), dst, folder_name);
install_combine_path(dst_path, sizeof(dst_path), dst, folder_name);
res = f_mkdir(dst_path);
if (res == FR_OK || res == FR_EXIST) {
return FR_OK;
@@ -239,9 +235,9 @@ static int folder_copy_with_progress_v2(const char *src, const char *dst, const
gfx_con_getpos(&start_x, &start_y);
// Show initial status
set_color(COLOR_CYAN);
install_set_color(COLOR_CYAN);
gfx_printf(" Kopiere: %s [ 0%%] (0/%d)", display_name, total);
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
// Perform the copy with progress updates
res = folder_copy_progress_recursive(src, dst, &copied, total, start_x, start_y, display_name, &last_percent);
@@ -249,26 +245,26 @@ static int folder_copy_with_progress_v2(const char *src, const char *dst, const
// Final update - overwrite the same line
gfx_con_setpos(start_x, start_y);
if (res == FR_OK) {
set_color(COLOR_GREEN);
install_set_color(COLOR_GREEN);
gfx_printf(" Kopiere: %s [100%%] (%d/%d) - Fertig!\n", display_name, copied, total);
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
} else {
set_color(COLOR_RED);
install_set_color(COLOR_RED);
gfx_printf(" Kopiere: %s - Fehlgeschlagen!\n", display_name);
gfx_printf(" Fehler: %s (Code=%d)\n", fs_error_str(res), res);
gfx_printf(" Quelle: %s\n", src);
gfx_printf(" Ziel: %s\n", dst);
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
// Fallback: try using the original folder_copy function
set_color(COLOR_ORANGE);
install_set_color(COLOR_ORANGE);
gfx_printf(" Versuche alternative Kopiermethode...\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
int fallback_res = folder_copy(src, dst);
if (fallback_res == FR_OK) {
set_color(COLOR_GREEN);
install_set_color(COLOR_GREEN);
gfx_printf(" Alternative Kopie erfolgreich!\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
return FR_OK;
}
}
@@ -276,20 +272,186 @@ static int folder_copy_with_progress_v2(const char *src, const char *dst, const
return res;
}
// Delete a list of paths
// Recursive folder delete with progress tracking (shared implementation)
int folder_delete_progress_recursive(const char *path, int *deleted, int total, u32 start_x, u32 start_y, const char *display_name, int *last_percent) {
DIR dir;
FILINFO fno;
int res;
res = f_opendir(&dir, path);
if (res != FR_OK) {
// Maybe it's a file, try to delete it
res = f_unlink(path);
if (res == FR_OK || res == FR_NO_FILE) {
(*deleted)++;
}
return res;
}
while (1) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) break;
// Skip . and ..
if (fno.fname[0] == '.' && (fno.fname[1] == '\0' || (fno.fname[1] == '.' && fno.fname[2] == '\0'))) {
continue;
}
char full_path[256];
install_combine_path(full_path, sizeof(full_path), path, fno.fname);
if (fno.fattrib & AM_DIR) {
res = folder_delete_progress_recursive(full_path, deleted, total, start_x, start_y, display_name, last_percent);
(*deleted)++;
} else {
// Clear read-only attribute if set
if (fno.fattrib & AM_RDO) {
f_chmod(full_path, fno.fattrib & ~AM_RDO, AM_RDO);
}
res = f_unlink(full_path);
if (res == FR_OK || res == FR_NO_FILE) {
(*deleted)++;
}
}
// Update progress every 10 items or when percentage changes
if ((*deleted % 10 == 0 || total == 0) && (res == FR_OK || res == FR_NO_FILE)) {
int percent = total > 0 ? (*deleted * 100) / total : 0;
if (percent != *last_percent || *deleted % 50 == 0) {
gfx_con_setpos(start_x, start_y);
install_set_color(COLOR_CYAN);
gfx_printf(" Loesche: %s [%3d%%] (%d/%d)", display_name, percent, *deleted, total);
install_set_color(COLOR_WHITE);
*last_percent = percent;
}
}
if (res != FR_OK && res != FR_NO_FILE) break;
}
f_closedir(&dir);
if (res == FR_OK || res == FR_NO_FILE) {
// Check and clear read-only attribute on directory if set
FILINFO dir_info;
if (f_stat(path, &dir_info) == FR_OK && (dir_info.fattrib & AM_RDO)) {
f_chmod(path, dir_info.fattrib & ~AM_RDO, AM_RDO);
}
res = f_unlink(path);
}
return res;
}
// Progress-aware delete for a single directory (used for large directories)
int folder_delete_single_with_progress(const char *path, const char *display_name) {
int deleted = 0;
int total = 0;
int last_percent = -1;
u32 start_x, start_y;
int res;
// Count total items first
total = install_count_directory_items(path);
if (total == 0) {
// Empty directory, just delete it
FILINFO fno;
if (f_stat(path, &fno) == FR_OK) {
if (fno.fattrib & AM_RDO) {
f_chmod(path, fno.fattrib & ~AM_RDO, AM_RDO);
}
res = f_unlink(path);
} else {
res = FR_NO_FILE;
}
return res;
}
// Save cursor position
gfx_con_getpos(&start_x, &start_y);
// Show initial status
install_set_color(COLOR_CYAN);
gfx_printf(" Loesche: %s [ 0%%] (0/%d)", display_name, total);
install_set_color(COLOR_WHITE);
// Use the shared recursive progress function
res = folder_delete_progress_recursive(path, &deleted, total, start_x, start_y, display_name, &last_percent);
// Final update
gfx_con_setpos(start_x, start_y);
if (res == FR_OK || res == FR_NO_FILE) {
install_set_color(COLOR_GREEN);
gfx_printf(" Loesche: %s [100%%] (%d/%d) - Fertig!\n", display_name, deleted, total);
install_set_color(COLOR_WHITE);
} else {
install_set_color(COLOR_RED);
gfx_printf(" Loesche: %s - Fehlgeschlagen!\n", display_name);
install_set_color(COLOR_WHITE);
}
return res;
}
// Delete a list of paths with progress tracking
int delete_path_list(const char* paths[], const char* description) {
int res;
int deleted = 0;
int failed = 0;
int total_paths = 0;
u32 start_x, start_y;
int last_percent = -1;
// Count total paths first
for (int i = 0; paths[i] != NULL; i++) {
if (install_path_exists(paths[i])) {
total_paths++;
}
}
if (total_paths == 0) {
return FR_OK; // Nothing to delete
}
// Save cursor position
gfx_con_getpos(&start_x, &start_y);
// Show initial status
install_set_color(COLOR_CYAN);
gfx_printf(" Loesche: %s [ 0%%] (0/%d)", description, total_paths);
install_set_color(COLOR_WHITE);
for (int i = 0; paths[i] != NULL; i++) {
if (path_exists(paths[i])) {
if (install_path_exists(paths[i])) {
FILINFO fno;
f_stat(paths[i], &fno);
if (fno.fattrib & AM_DIR) {
res = folder_delete(paths[i]);
// Extract just the folder/file name for display
const char *item_name = strrchr(paths[i], '/');
if (item_name) {
item_name++; // Skip the '/'
} else {
item_name = paths[i];
}
if (fno.fattrib & AM_DIR) {
// Check if directory has many items - if so, show detailed progress
int item_count = install_count_directory_items(paths[i]);
if (item_count > 50) {
// Large directory - show individual progress
// Move to new line for the detailed progress
gfx_printf("\n");
res = folder_delete_single_with_progress(paths[i], item_name);
} else {
// Small directory - use regular delete
res = folder_delete(paths[i]);
}
} else {
// Clear read-only attribute if set
if (fno.fattrib & AM_RDO) {
f_chmod(paths[i], fno.fattrib & ~AM_RDO, AM_RDO);
}
res = f_unlink(paths[i]);
}
@@ -298,420 +460,103 @@ int delete_path_list(const char* paths[], const char* description) {
} else {
failed++;
}
// Update list-level progress (only if not showing detailed progress)
if (fno.fattrib & AM_DIR && install_count_directory_items(paths[i]) <= 50) {
int percent = (deleted * 100) / total_paths;
if (percent != last_percent || deleted % 5 == 0) {
gfx_con_setpos(start_x, start_y);
install_set_color(COLOR_CYAN);
gfx_printf(" Loesche: %s [%3d%%] (%d/%d)", description, percent, deleted, total_paths);
install_set_color(COLOR_WHITE);
last_percent = percent;
}
} else if (!(fno.fattrib & AM_DIR)) {
// Update for files
int percent = (deleted * 100) / total_paths;
if (percent != last_percent || deleted % 5 == 0) {
gfx_con_setpos(start_x, start_y);
install_set_color(COLOR_CYAN);
gfx_printf(" Loesche: %s [%3d%%] (%d/%d)", description, percent, deleted, total_paths);
install_set_color(COLOR_WHITE);
last_percent = percent;
}
}
}
}
// Final update
gfx_con_setpos(start_x, start_y);
if (failed == 0) {
install_set_color(COLOR_GREEN);
gfx_printf(" Loesche: %s [100%%] (%d/%d) - Fertig!\n", description, deleted, total_paths);
install_set_color(COLOR_WHITE);
} else {
install_set_color(COLOR_ORANGE);
gfx_printf(" Loesche: %s [%3d%%] (%d/%d) - %d Fehler\n", description, last_percent, deleted, total_paths, failed);
install_set_color(COLOR_WHITE);
}
return (failed == 0) ? FR_OK : FR_DISK_ERR;
}
// Delete old version markers (legacy files from old system)
int cleanup_old_version_markers(omninx_variant_t current_variant) {
// Delete all old version files (they're no longer used)
for (int i = 0; old_version_files_to_delete[i] != NULL; i++) {
const char* path = old_version_files_to_delete[i];
if (path_exists(path)) {
f_unlink(path);
}
}
return FR_OK;
}
// Update mode: Cleanup specific directories/files
int update_mode_cleanup(omninx_variant_t variant) {
check_and_clear_screen_if_needed();
set_color(COLOR_CYAN);
gfx_printf(" Bereinige: atmosphere/\n");
set_color(COLOR_WHITE);
// Delete atmosphere subdirectories
delete_path_list(atmosphere_dirs_to_delete, "atmosphere subdirs");
// Delete atmosphere root directories (title IDs)
delete_path_list(atmosphere_root_dirs_to_delete, "atmosphere root dirs");
// Delete atmosphere contents directories (title IDs)
delete_path_list(atmosphere_contents_dirs_to_delete, "atmosphere contents dirs");
// Delete atmosphere files
delete_path_list(atmosphere_files_to_delete, "atmosphere files");
set_color(COLOR_CYAN);
gfx_printf(" Bereinige: bootloader/\n");
set_color(COLOR_WHITE);
// Delete bootloader directories
delete_path_list(bootloader_dirs_to_delete, "bootloader dirs");
// Delete bootloader files
delete_path_list(bootloader_files_to_delete, "bootloader files");
set_color(COLOR_CYAN);
gfx_printf(" Bereinige: config/\n");
set_color(COLOR_WHITE);
// Delete config directories
delete_path_list(config_dirs_to_delete, "config dirs");
set_color(COLOR_CYAN);
gfx_printf(" Bereinige: switch/\n");
set_color(COLOR_WHITE);
// Delete switch directories
delete_path_list(switch_dirs_to_delete, "switch dirs");
// Delete switch files
delete_path_list(switch_files_to_delete, "switch files");
set_color(COLOR_CYAN);
gfx_printf(" Bereinige: Root-Dateien\n");
set_color(COLOR_WHITE);
// Delete root files
delete_path_list(root_files_to_delete, "root files");
// Delete miscellaneous directories
delete_path_list(misc_dirs_to_delete, "misc dirs");
// Delete miscellaneous files
delete_path_list(misc_files_to_delete, "misc files");
set_color(COLOR_GREEN);
gfx_printf(" Bereinigung abgeschlossen!\n");
set_color(COLOR_WHITE);
return FR_OK;
}
// Update mode: Copy files from staging
int update_mode_install(omninx_variant_t variant) {
int res;
const char* staging = get_staging_path(variant);
char src_path[256];
char dst_path[256];
if (!staging) {
return FR_INVALID_PARAMETER;
}
check_and_clear_screen_if_needed();
set_color(COLOR_YELLOW);
gfx_printf("Dateien werden kopiert...\n");
set_color(COLOR_WHITE);
// Copy directories (use progress-aware copy for large directories)
s_printf(src_path, "%s/atmosphere", staging);
res = folder_copy_with_progress_v2(src_path, "sd:/", "atmosphere/");
if (res != FR_OK && res != FR_NO_FILE) return res;
s_printf(src_path, "%s/bootloader", staging);
res = folder_copy_with_progress_v2(src_path, "sd:/", "bootloader/");
if (res != FR_OK && res != FR_NO_FILE) return res;
s_printf(src_path, "%s/config", staging);
res = folder_copy_with_progress_v2(src_path, "sd:/", "config/");
if (res != FR_OK && res != FR_NO_FILE) return res;
s_printf(src_path, "%s/switch", staging);
res = folder_copy_with_progress_v2(src_path, "sd:/", "switch/");
if (res != FR_OK && res != FR_NO_FILE) return res;
s_printf(src_path, "%s/warmboot_mariko", staging);
res = folder_copy_with_progress_v2(src_path, "sd:/", "warmboot_mariko/");
if (res != FR_OK && res != FR_NO_FILE) return res;
// OC variant includes SaltySD (this is the large one with ~2500 files)
if (variant == VARIANT_OC) {
s_printf(src_path, "%s/SaltySD", staging);
res = folder_copy_with_progress_v2(src_path, "sd:/", "SaltySD/");
if (res != FR_OK && res != FR_NO_FILE) return res;
}
// Copy root files
set_color(COLOR_CYAN);
gfx_printf(" Kopiere Root-Dateien...\n");
set_color(COLOR_WHITE);
s_printf(src_path, "%s/boot.dat", staging);
s_printf(dst_path, "sd:/boot.dat");
if (path_exists(src_path)) {
file_copy(src_path, dst_path);
}
s_printf(src_path, "%s/boot.ini", staging);
s_printf(dst_path, "sd:/boot.ini");
if (path_exists(src_path)) {
file_copy(src_path, dst_path);
}
s_printf(src_path, "%s/exosphere.ini", staging);
s_printf(dst_path, "sd:/exosphere.ini");
if (path_exists(src_path)) {
file_copy(src_path, dst_path);
}
s_printf(src_path, "%s/hbmenu.nro", staging);
s_printf(dst_path, "sd:/hbmenu.nro");
if (path_exists(src_path)) {
file_copy(src_path, dst_path);
}
s_printf(src_path, "%s/loader.bin", staging);
s_printf(dst_path, "sd:/loader.bin");
if (path_exists(src_path)) {
file_copy(src_path, dst_path);
}
s_printf(src_path, "%s/payload.bin", staging);
s_printf(dst_path, "sd:/payload.bin");
if (path_exists(src_path)) {
file_copy(src_path, dst_path);
}
// Create manifest.ini file
set_color(COLOR_CYAN);
gfx_printf(" Erstelle manifest.ini...\n");
set_color(COLOR_WHITE);
// Ensure config/omninx directory exists
s_printf(dst_path, "sd:/config/omninx");
f_mkdir(dst_path);
// Determine pack name and update channel
const char* pack_name;
int update_channel;
switch (variant) {
case VARIANT_STANDARD:
pack_name = "standard";
update_channel = 2;
break;
case VARIANT_LIGHT:
pack_name = "light";
update_channel = 0;
break;
case VARIANT_OC:
pack_name = "oc";
update_channel = 1;
break;
default:
pack_name = "unknown";
update_channel = 0;
break;
}
// Create manifest.ini
s_printf(dst_path, "sd:/config/omninx/manifest.ini");
FIL fp;
if (f_open(&fp, dst_path, FA_WRITE | FA_CREATE_ALWAYS) == FR_OK) {
f_printf(&fp, "[OmniNX]\n");
f_printf(&fp, "current_pack=%s\n", pack_name);
f_printf(&fp, "version=%s\n", VERSION);
f_printf(&fp, "update_channel=%d\n", update_channel);
f_printf(&fp, "channel_pack=%s\n", pack_name);
f_close(&fp);
set_color(COLOR_GREEN);
gfx_printf(" [OK] manifest.ini erstellt\n");
set_color(COLOR_WHITE);
} else {
set_color(COLOR_ORANGE);
gfx_printf(" [WARN] manifest.ini konnte nicht erstellt werden\n");
set_color(COLOR_WHITE);
}
// Cleanup old version markers (legacy files)
cleanup_old_version_markers(variant);
set_color(COLOR_GREEN);
gfx_printf(" Kopie abgeschlossen!\n");
set_color(COLOR_WHITE);
return FR_OK;
}
// Clean mode: Backup user data
int clean_mode_backup(void) {
set_color(COLOR_CYAN);
gfx_printf(" Sichere: DBI, Tinfoil, 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 directories
int clean_mode_wipe(void) {
int res;
// Delete entire directories
if (path_exists("sd:/atmosphere")) {
set_color(COLOR_CYAN);
gfx_printf(" Loesche: atmosphere/\n");
set_color(COLOR_WHITE);
res = folder_delete("sd:/atmosphere");
if (res != FR_OK && res != FR_NO_FILE) return res;
}
if (path_exists("sd:/bootloader")) {
set_color(COLOR_CYAN);
gfx_printf(" Loesche: bootloader/\n");
set_color(COLOR_WHITE);
res = folder_delete("sd:/bootloader");
if (res != FR_OK && res != FR_NO_FILE) return res;
}
if (path_exists("sd:/config")) {
set_color(COLOR_CYAN);
gfx_printf(" Loesche: config/\n");
set_color(COLOR_WHITE);
res = folder_delete("sd:/config");
if (res != FR_OK && res != FR_NO_FILE) return res;
}
if (path_exists("sd:/switch")) {
set_color(COLOR_CYAN);
gfx_printf(" Loesche: switch/\n");
set_color(COLOR_WHITE);
res = folder_delete("sd:/switch");
if (res != FR_OK && res != FR_NO_FILE) return res;
}
// Delete root files
set_color(COLOR_CYAN);
gfx_printf(" Bereinige: Root-Dateien\n");
set_color(COLOR_WHITE);
delete_path_list(root_files_to_delete, "root files");
// Delete miscellaneous directories
delete_path_list(misc_dirs_to_delete, "misc dirs");
// Delete miscellaneous files
delete_path_list(misc_files_to_delete, "misc files");
// Recreate switch directory
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: DBI, Tinfoil, 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);
}
cleanup_backup(); // Clean up temp backup
return res;
}
// Clean mode: Install files
int clean_mode_install(omninx_variant_t variant) {
// Same as update mode install
return update_mode_install(variant);
}
// Remove staging directory after installation
int cleanup_staging_directory(omninx_variant_t pack_variant) {
const char* staging = get_staging_path(pack_variant);
if (!staging) {
return FR_INVALID_PARAMETER;
}
check_and_clear_screen_if_needed();
if (path_exists(staging)) {
set_color(COLOR_YELLOW);
gfx_printf("\nEntferne Installationsordner...\n");
set_color(COLOR_WHITE);
set_color(COLOR_CYAN);
gfx_printf(" Loesche: %s\n", staging);
set_color(COLOR_WHITE);
int res = folder_delete(staging);
if (res == FR_OK) {
set_color(COLOR_GREEN);
gfx_printf(" [OK] Installationsordner entfernt\n");
set_color(COLOR_WHITE);
} else {
set_color(COLOR_ORANGE);
gfx_printf(" [WARN] Ordner konnte nicht entfernt werden (err=%d)\n", res);
set_color(COLOR_WHITE);
}
return res;
}
return FR_OK;
}
// Main installation function
int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) {
int res;
if (mode == INSTALL_MODE_UPDATE) {
// Update mode: selective cleanup then install
set_color(COLOR_YELLOW);
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 1: Bereinigung...\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
res = update_mode_cleanup(pack_variant);
if (res != FR_OK) return res;
check_and_clear_screen_if_needed();
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
set_color(COLOR_YELLOW);
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 2: Dateien kopieren...\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
res = update_mode_install(pack_variant);
if (res != FR_OK) return res;
check_and_clear_screen_if_needed();
install_check_and_clear_screen_if_needed();
// Remove staging directory
res = cleanup_staging_directory(pack_variant);
return res;
} else {
// Clean mode: backup, wipe, restore, install
set_color(COLOR_YELLOW);
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 1: Sichere Benutzerdaten...\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
res = clean_mode_backup();
if (res != FR_OK) return res;
check_and_clear_screen_if_needed();
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
set_color(COLOR_YELLOW);
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 2: Bereinige alte Installation...\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
res = clean_mode_wipe();
if (res != FR_OK) return res;
check_and_clear_screen_if_needed();
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
set_color(COLOR_YELLOW);
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 3: Stelle Benutzerdaten wieder her...\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
res = clean_mode_restore();
if (res != FR_OK) return res;
check_and_clear_screen_if_needed();
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
set_color(COLOR_YELLOW);
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 4: Dateien kopieren...\n");
set_color(COLOR_WHITE);
install_set_color(COLOR_WHITE);
res = clean_mode_install(pack_variant);
if (res != FR_OK) return res;
check_and_clear_screen_if_needed();
install_check_and_clear_screen_if_needed();
// Remove staging directory
res = cleanup_staging_directory(pack_variant);
return res;