#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <switch.h>
#define SDMC_PATH "/switch" // Directory to scan
void set_archive_bit(const char* path) {
struct stat file_stat;
if (stat(path, &file_stat) == 0) {
if (!(file_stat.st_mode & S_IFDIR)) { // Ensure it's a file, not a directory
FILE* f = fopen(path, "r+");
if (f) {
fclose(f); // Just opening and closing may trigger an update
printf("Set archive bit: %s\n", path);
}
else {
printf("Failed to open: %s\n", path);
}
}
}
}
void scan_directory(const char* directory) {
DIR* dir = opendir(directory);
if (!dir) return;
struct dirent* entry;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] == '.') continue; // Skip hidden files and . / ..
char full_path[PATH_MAX];
snprintf(full_path, sizeof(full_path), "%s/%s", directory, entry->d_name);
struct stat path_stat;
if (stat(full_path, &path_stat) == 0) {
if (S_ISDIR(path_stat.st_mode)) {
scan_directory(full_path); // Recurse into directories
}
else {
set_archive_bit(full_path); // Set archive bit on files
}
}
}
closedir(dir);
}
int main(int argc, char* argv[]) {
consoleInit(NULL);
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
PadState pad;
padInitializeDefault(&pad);
printf("Scanning SD card for files to fix...\n");
scan_directory(SDMC_PATH);
printf("Scan complete. Press A to exit.\n");
while (appletMainLoop()) {
padUpdate(&pad);
u64 kDown = padGetButtonsDown(&pad);
if (kDown & HidNpadButton_A) break;
consoleUpdate(NULL);
}
consoleExit(NULL);
return 0;
}