Compare commits

..

2 Commits

Author SHA1 Message Date
Niklas080208
31aeeaabbb Disabled build on push 2026-02-15 16:34:38 +01:00
89994995af Add pre-update/clean backup feature
All checks were successful
Build / Build (push) Successful in 12s
- Backup deletion paths before update to sd:/backup/OmniNX/{version}
- Backup deletion paths before clean install to sd:/backup/OmniNX/pre-omninx
- Best-effort backup: continue install even if some copies fail
- Fix directory creation: ensure parent dirs exist before folder_copy
- Step 1 for update: Backup; Step 1-2 for clean: user data + pre-omninx backup

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 16:05:57 +01:00
9 changed files with 178 additions and 230 deletions

View File

@@ -1,7 +1,7 @@
name: Build
on:
push:
#push:
workflow_dispatch:
jobs:

View File

@@ -6,14 +6,97 @@
#include "fs.h"
#include <libs/fatfs/ff.h>
#include <string.h>
#include <stdarg.h>
#include <utils/sprintf.h>
#define BACKUP_PATH_MAX 270
// Check if file/directory exists
static bool path_exists(const char *path) {
FILINFO fno;
return (f_stat(path, &fno) == FR_OK);
}
// Create all parent directories for a path (mkdir -p style)
static void ensure_parent_dirs(const char *full_path) {
char buf[BACKUP_PATH_MAX];
int n = (int)strlen(full_path);
if (n >= BACKUP_PATH_MAX) return;
memcpy(buf, full_path, n + 1);
for (int i = 4; i < n; i++) {
if (buf[i] == '/') {
buf[i] = '\0';
f_mkdir(buf);
buf[i] = '/';
}
}
}
// Copy a single path (file or dir) to backup base, preserving SD structure
static int backup_single_path(const char *src_path, const char *backup_base) {
FILINFO fno;
if (f_stat(src_path, &fno) != FR_OK)
return FR_OK;
const char *relative = src_path;
if (strncmp(relative, "sd:/", 4) == 0)
relative += 4;
if (fno.fattrib & AM_DIR) {
const char *last_slash = strrchr(relative, '/');
char parent[BACKUP_PATH_MAX];
if (last_slash && last_slash > relative) {
s_printf(parent, "%s/%.*s", backup_base, (int)(last_slash - relative), relative);
/* Create full parent hierarchy (e.g. atmosphere, atmosphere/contents) */
ensure_parent_dirs(parent);
f_mkdir(parent); /* Ensure parent exists; FR_EXIST is fine */
return folder_copy(src_path, parent);
} else {
ensure_parent_dirs(backup_base);
return folder_copy(src_path, backup_base);
}
} else {
char dst_path[BACKUP_PATH_MAX];
s_printf(dst_path, "%s/%s", backup_base, relative);
ensure_parent_dirs(dst_path);
return file_copy(src_path, dst_path);
}
}
// Backup all paths from varargs lists (same structure as delete_path_lists_grouped)
int backup_deletion_lists(const char *backup_base, ...) {
va_list ap;
const char **list;
int res = FR_OK;
/* FatFS f_mkdir only creates the last component; parent must exist first */
ensure_parent_dirs(BACKUP_BASE_PATH);
res = f_mkdir(BACKUP_BASE_PATH);
if (res != FR_OK && res != FR_EXIST)
return res;
ensure_parent_dirs(backup_base);
res = f_mkdir(backup_base);
if (res != FR_OK && res != FR_EXIST)
return res;
va_start(ap, backup_base);
while ((list = va_arg(ap, const char **)) != NULL) {
for (int i = 0; list[i] != NULL; i++) {
if (path_exists(list[i])) {
int copy_res = backup_single_path(list[i], backup_base);
if (copy_res != FR_OK && res == FR_OK)
res = copy_res; // Remember first error but keep going
}
}
}
va_end(ap);
/* Best-effort: return FR_OK so install continues even if some copies failed */
return FR_OK;
}
// Backup user data before clean install
int backup_user_data(void) {
int res;

View File

@@ -7,6 +7,8 @@
#include <utils/types.h>
#define TEMP_BACKUP_PATH "sd:/temp_backup"
#define BACKUP_BASE_PATH "sd:/backup/OmniNX"
#define PRE_OMNINX_LABEL "pre-omninx"
// Backup user data (DBI, Tinfoil, prod.keys) before clean install
int backup_user_data(void);
@@ -16,3 +18,6 @@ int restore_user_data(void);
// Clean up temporary backup directory
int cleanup_backup(void);
// Backup paths from varargs lists to backup_base (pass path arrays, terminate with NULL)
int backup_deletion_lists(const char *backup_base, ...);

View File

@@ -122,8 +122,9 @@ static const char* config_dirs_to_delete[] = {
};
// Switch directories to delete
// NOTE: .overlays and .packages excluded - preserve UltraHand .offload hide state during updates
// NOTE: .packages is intentionally excluded - UltraHand package cache, preserve during updates
static const char* switch_dirs_to_delete[] = {
"sd:/switch/.overlays",
"sd:/switch/90DNS_tester",
"sd:/switch/aio-switch-updater",
"sd:/switch/amsPLUS-downloader",

View File

@@ -275,167 +275,6 @@ int folder_copy_with_progress_v2(const char *src, const char *dst, const char *d
return res;
}
// Copy one directory (e.g. .overlays or .packages) with .offload awareness: if the same
// name exists in dst_offload, copy pack's version into dst_offload (update in place);
// otherwise copy to dst_parent. Used only for update mode to preserve UltraHand hide state.
static int copy_dir_offload_aware(const char *src_parent, const char *dst_parent, const char *dst_offload,
const char *display_name, int *copied, int total, u32 start_x, u32 start_y, int *last_percent)
{
DIR dir;
FILINFO fno;
int res;
char src_full[256];
char dst_main[256];
char dst_off[256];
res = f_opendir(&dir, src_parent);
if (res != FR_OK)
return res;
while (1) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) break;
if (fno.fname[0] == '.' && (fno.fname[1] == '\0' || (fno.fname[1] == '.' && fno.fname[2] == '\0')))
continue;
if (strcmp(fno.fname, ".offload") == 0)
continue;
install_combine_path(src_full, sizeof(src_full), src_parent, fno.fname);
install_combine_path(dst_off, sizeof(dst_off), dst_offload, fno.fname);
if (install_path_exists(dst_off)) {
res = (fno.fattrib & AM_DIR) ? folder_copy(src_full, dst_offload) : file_copy(src_full, dst_off);
} else {
install_combine_path(dst_main, sizeof(dst_main), dst_parent, fno.fname);
res = (fno.fattrib & AM_DIR) ? folder_copy(src_full, dst_parent) : file_copy(src_full, dst_main);
}
(*copied)++;
if (total > 0) {
int percent = (*copied * 100) / total;
if (percent != *last_percent || *copied % 20 == 0) {
gfx_con_setpos(start_x, start_y);
install_set_color(COLOR_CYAN);
gfx_printf(" Kopiere: %s [%3d%%] (%d/%d)", display_name, percent, *copied, total);
install_set_color(COLOR_WHITE);
*last_percent = percent;
}
}
if (res != FR_OK) {
f_closedir(&dir);
return res;
}
}
f_closedir(&dir);
return FR_OK;
}
// Copy switch/ folder for update mode only: preserve SD's .overlays/.offload and
// .packages/.offload; for items that exist there, update in place instead of main area.
int folder_copy_switch_update_offload_aware(const char *src_switch, const char *dst_base, const char *display_name) {
char dst_switch[256];
char src_overlays[256], src_packages[256];
char dst_overlays[256], dst_offload_ovl[256], dst_packages[256], dst_offload_pkg[256];
DIR dir;
FILINFO fno;
int res;
int copied = 0;
int total;
int last_percent = -1;
u32 start_x, start_y;
install_combine_path(dst_switch, sizeof(dst_switch), dst_base, "switch");
if (!install_path_exists(src_switch)) {
install_set_color(COLOR_ORANGE);
gfx_printf(" Ueberspringe: %s (nicht gefunden)\n", display_name);
install_set_color(COLOR_WHITE);
return FR_NO_FILE;
}
total = install_count_directory_items(src_switch);
if (total == 0) {
f_mkdir(dst_switch);
return FR_OK;
}
gfx_con_getpos(&start_x, &start_y);
install_set_color(COLOR_CYAN);
gfx_printf(" Kopiere: %s [ 0%%] (0/%d)", display_name, total);
install_set_color(COLOR_WHITE);
res = f_mkdir(dst_switch);
if (res != FR_OK && res != FR_EXIST) return res;
res = f_opendir(&dir, src_switch);
if (res != FR_OK) return res;
while (1) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) break;
if (fno.fname[0] == '.' && (fno.fname[1] == '\0' || (fno.fname[1] == '.' && fno.fname[2] == '\0')))
continue;
if (strcmp(fno.fname, ".overlays") == 0) {
install_combine_path(src_overlays, sizeof(src_overlays), src_switch, ".overlays");
install_combine_path(dst_overlays, sizeof(dst_overlays), dst_switch, ".overlays");
install_combine_path(dst_offload_ovl, sizeof(dst_offload_ovl), dst_overlays, ".offload");
if (!install_path_exists(src_overlays)) { f_closedir(&dir); continue; }
f_mkdir(dst_overlays);
f_mkdir(dst_offload_ovl);
res = copy_dir_offload_aware(src_overlays, dst_overlays, dst_offload_ovl, display_name,
&copied, total, start_x, start_y, &last_percent);
} else if (strcmp(fno.fname, ".packages") == 0) {
install_combine_path(src_packages, sizeof(src_packages), src_switch, ".packages");
install_combine_path(dst_packages, sizeof(dst_packages), dst_switch, ".packages");
install_combine_path(dst_offload_pkg, sizeof(dst_offload_pkg), dst_packages, ".offload");
if (!install_path_exists(src_packages)) { f_closedir(&dir); continue; }
f_mkdir(dst_packages);
f_mkdir(dst_offload_pkg);
{ /* package.ini into main area */
char src_ini[256], dst_ini[256];
s_printf(src_ini, "%s/package.ini", src_packages);
s_printf(dst_ini, "%s/package.ini", dst_packages);
if (install_path_exists(src_ini)) {
res = file_copy(src_ini, dst_ini);
if (res == FR_OK) copied++;
}
}
res = copy_dir_offload_aware(src_packages, dst_packages, dst_offload_pkg, display_name,
&copied, total, start_x, start_y, &last_percent);
} else {
char src_full[256], dst_full[256];
install_combine_path(src_full, sizeof(src_full), src_switch, fno.fname);
install_combine_path(dst_full, sizeof(dst_full), dst_switch, fno.fname);
if (fno.fattrib & AM_DIR)
res = folder_copy(src_full, dst_switch);
else
res = file_copy(src_full, dst_full);
copied++;
}
if (res != FR_OK) break;
if (total > 0 && (copied % 20 == 0 || copied == total)) {
int percent = (copied * 100) / total;
gfx_con_setpos(start_x, start_y);
install_set_color(COLOR_CYAN);
gfx_printf(" Kopiere: %s [%3d%%] (%d/%d)", display_name, percent, copied, total);
install_set_color(COLOR_WHITE);
}
}
f_closedir(&dir);
gfx_con_setpos(start_x, start_y);
if (res == FR_OK) {
install_set_color(COLOR_GREEN);
gfx_printf(" Kopiere: %s [100%%] (%d/%d) - Fertig!\n", display_name, copied, total);
install_set_color(COLOR_WHITE);
} else {
install_set_color(COLOR_RED);
gfx_printf(" Kopiere: %s - Fehlgeschlagen!\n", display_name);
install_set_color(COLOR_WHITE);
}
return res;
}
// 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;
@@ -752,9 +591,29 @@ 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
// Update mode: backup, selective cleanup, then install
omninx_status_t status = detect_omninx_installation();
const char *version = (status.version_file[0] != '\0') ? status.version_file : "unknown";
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 1: Bereinigung...\n");
gfx_printf("Schritt 1: Backup vor Update (%s)...\n", version);
install_set_color(COLOR_WHITE);
res = backup_before_update(version);
/* Backup is best-effort; continue install even on failure */
if (res == FR_OK) {
install_set_color(COLOR_GREEN);
gfx_printf(" [OK] Sicherung nach sd:/backup/OmniNX/%s/\n", version);
install_set_color(COLOR_WHITE);
} else {
install_set_color(COLOR_ORANGE);
gfx_printf(" [WARN] Backup fehlgeschlagen, fahre trotzdem fort...\n");
install_set_color(COLOR_WHITE);
}
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 2: Bereinigung...\n");
install_set_color(COLOR_WHITE);
res = update_mode_cleanup(pack_variant);
if (res != FR_OK) return res;
@@ -762,7 +621,7 @@ int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) {
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 2: Dateien kopieren...\n");
gfx_printf("Schritt 3: Dateien kopieren...\n");
install_set_color(COLOR_WHITE);
res = update_mode_install(pack_variant);
if (res != FR_OK) return res;
@@ -775,7 +634,7 @@ int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) {
res = cleanup_other_staging_directories(pack_variant);
return res;
} else {
// Clean mode: backup, wipe, restore, install
// Clean mode: backup user data, backup pre-omninx, wipe, restore, install
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 1: Sichere Benutzerdaten...\n");
install_set_color(COLOR_WHITE);
@@ -785,7 +644,23 @@ int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) {
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 2: Bereinige alte Installation...\n");
gfx_printf("Schritt 2: Backup alter CFW-Dateien (pre-omninx)...\n");
install_set_color(COLOR_WHITE);
res = backup_before_clean();
if (res == FR_OK) {
install_set_color(COLOR_GREEN);
gfx_printf(" [OK] Sicherung nach sd:/backup/OmniNX/pre-omninx/\n");
install_set_color(COLOR_WHITE);
} else {
install_set_color(COLOR_ORANGE);
gfx_printf(" [WARN] Backup fehlgeschlagen, fahre trotzdem fort...\n");
install_set_color(COLOR_WHITE);
}
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 3: Bereinige alte Installation...\n");
install_set_color(COLOR_WHITE);
res = clean_mode_wipe();
if (res != FR_OK) return res;
@@ -793,7 +668,7 @@ int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) {
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 3: Stelle Benutzerdaten wieder her...\n");
gfx_printf("Schritt 4: Stelle Benutzerdaten wieder her...\n");
install_set_color(COLOR_WHITE);
res = clean_mode_restore();
if (res != FR_OK) return res;
@@ -801,7 +676,7 @@ int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) {
install_check_and_clear_screen_if_needed();
gfx_printf("\n");
install_set_color(COLOR_YELLOW);
gfx_printf("Schritt 4: Dateien kopieren...\n");
gfx_printf("Schritt 5: Dateien kopieren...\n");
install_set_color(COLOR_WHITE);
res = clean_mode_install(pack_variant);
if (res != FR_OK) return res;

View File

@@ -17,6 +17,7 @@ typedef enum {
int perform_installation(omninx_variant_t pack_variant, install_mode_t mode);
// Update mode operations (install_update.c)
int backup_before_update(const char *version);
int update_mode_cleanup(omninx_variant_t variant);
int update_mode_install(omninx_variant_t variant);
int cleanup_staging_directory(omninx_variant_t pack_variant);
@@ -24,6 +25,7 @@ int cleanup_staging_directory(omninx_variant_t pack_variant);
int cleanup_other_staging_directories(omninx_variant_t installed_variant);
// Clean install operations (install_clean.c)
int backup_before_clean(void);
int clean_mode_backup(void);
int clean_mode_wipe(void);
int clean_mode_restore(void);
@@ -40,5 +42,3 @@ int delete_path_lists_grouped(const char *folder_display_name, ...);
int folder_delete_single_with_progress(const char *path, const char *display_name);
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);
int folder_copy_with_progress_v2(const char *src, const char *dst, const char *display_name);
// Update-only: copy switch/ preserving .overlays/.offload and .packages/.offload (UltraHand hide state)
int folder_copy_switch_update_offload_aware(const char *src_switch, const char *dst_base, const char *display_name);

View File

@@ -11,6 +11,7 @@
#include "gfx.h"
#include "version.h"
#include <libs/fatfs/ff.h>
#include <utils/sprintf.h>
#include <string.h>
#undef COLOR_CYAN
@@ -31,6 +32,26 @@
#define path_exists install_path_exists
#define count_directory_items install_count_directory_items
// Backup paths before clean install (sd:/backup/OmniNX/pre-omninx)
int backup_before_clean(void) {
char backup_base[270];
s_printf(backup_base, "%s/%s", BACKUP_BASE_PATH, PRE_OMNINX_LABEL);
return backup_deletion_lists(backup_base,
clean_atmosphere_dirs_to_delete,
clean_atmosphere_contents_dirs_to_delete,
clean_atmosphere_files_to_delete,
clean_bootloader_dirs_to_delete,
clean_bootloader_files_to_delete,
clean_config_dirs_to_delete,
clean_switch_dirs_to_delete,
clean_switch_files_to_delete,
clean_root_files_to_delete,
clean_misc_dirs_to_delete,
clean_misc_files_to_delete,
old_version_files_to_delete,
NULL);
}
// Clean mode: Backup user data
int clean_mode_backup(void) {
set_color(COLOR_CYAN);

View File

@@ -4,6 +4,7 @@
*/
#include "install.h"
#include "backup.h"
#include "deletion_lists_update.h"
#include "fs.h"
#include "version.h"
@@ -34,6 +35,25 @@
#define path_exists install_path_exists
#define count_directory_items install_count_directory_items
// Backup paths before update (sd:/backup/OmniNX/{version})
int backup_before_update(const char *version) {
char backup_base[270];
s_printf(backup_base, "%s/%s", BACKUP_BASE_PATH, version);
return backup_deletion_lists(backup_base,
atmosphere_dirs_to_delete,
atmosphere_contents_dirs_to_delete,
atmosphere_files_to_delete,
bootloader_dirs_to_delete,
bootloader_files_to_delete,
config_dirs_to_delete,
switch_dirs_to_delete,
switch_files_to_delete,
root_files_to_delete,
misc_dirs_to_delete,
misc_files_to_delete,
NULL);
}
// Update mode: Cleanup specific directories/files
int update_mode_cleanup(omninx_variant_t variant) {
(void)variant;
@@ -103,7 +123,7 @@ int update_mode_install(omninx_variant_t variant) {
if (res != FR_OK && res != FR_NO_FILE) return res;
s_printf(src_path, "%s/switch", staging);
res = folder_copy_switch_update_offload_aware(src_path, "sd:/", "switch/");
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);

View File

@@ -428,63 +428,6 @@ void ipl_main(void) {
gfx_con_setpos(0, 0);
print_header();
// UHS class check: recommend U2 / V30 / A2 for emuMMC (speed and reliability)
#define UHS_U2_MIN 2
#define UHS_V30_MIN 30
#define UHS_A2_MIN 2
bool uhs_ok = (sd_storage.ssr.uhs_grade >= UHS_U2_MIN &&
sd_storage.ssr.video_class >= UHS_V30_MIN &&
sd_storage.ssr.app_class >= UHS_A2_MIN);
if (!uhs_ok) {
jc_init_hw();
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
set_color(COLOR_RED);
gfx_printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
gfx_printf("!! WARNUNG - SD-KARTEN-KLASSE !!\n");
gfx_printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n");
set_color(COLOR_WHITE);
gfx_printf("Diese SD-Karte erfuellt NICHT die empfohlenen\n");
gfx_printf("Mindestanforderungen (U2 | V30 | A2).\n\n");
set_color(COLOR_YELLOW);
gfx_printf("Aktuelle Werte: UHS%d | V%d | A%d\n\n",
(u32)sd_storage.ssr.uhs_grade,
(u32)sd_storage.ssr.video_class,
(u32)sd_storage.ssr.app_class);
set_color(COLOR_WHITE);
gfx_printf("Moegliche Folgen bei schwachen Karten:\n");
gfx_printf(" - Langsamere emuMMC / Spiel-Ladezeiten\n");
gfx_printf(" - Hoheres Risiko von Korruption oder Abstuerzen\n");
gfx_printf(" - Instabilitaet beim Schreiben groesserer Daten\n\n");
set_color(COLOR_CYAN);
gfx_printf("Empfohlen: U2 | V30 | A2 oder besser.\n");
gfx_printf("Empfohlene Karten: Samsung EVO Plus, EVO Select und PRO Plus.\n\n");
set_color(COLOR_GREEN);
gfx_printf("Druecke A (oder Power), um trotzdem fortzufahren.\n");
set_color(COLOR_WHITE);
while (btn_read() & BTN_POWER) { msleep(50); }
bool acknowledged = false;
while (!acknowledged) {
u8 btn_state = btn_read();
if (btn_state & BTN_POWER) acknowledged = true;
jc_gamepad_rpt_t *jc = joycon_poll();
if (jc && jc->a) acknowledged = true;
msleep(50);
}
// Wait for A and Power to be released so the same press doesn't start the install
while (btn_read() & BTN_POWER) { msleep(50); }
bool released = false;
while (!released) {
jc_gamepad_rpt_t *jc = joycon_poll();
released = (!jc || !jc->a) && !(btn_read() & BTN_POWER);
if (!released) msleep(50);
}
msleep(300); // Short delay so the next screen is visible before accepting input
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
print_header();
}
// Show information
set_color(COLOR_CYAN);
gfx_printf("Installationsmodus: %s\n", mode == INSTALL_MODE_UPDATE ? "Update" : "Saubere Installation");