From a168b92948a2f062c22d32a7aad5b352cab8684a Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Mon, 3 Feb 2020 19:45:24 -0700 Subject: [PATCH] Don't delete files/folders with read-only attribute --- arm9/source/file_browse.cpp | 45 +++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/arm9/source/file_browse.cpp b/arm9/source/file_browse.cpp index eb5de63..991eff7 100644 --- a/arm9/source/file_browse.cpp +++ b/arm9/source/file_browse.cpp @@ -29,6 +29,7 @@ #include #include +#include #include "main.h" #include "date.h" @@ -388,7 +389,9 @@ void recRemove(DirEntry* entry, std::vector dirContents) { for (int i = 1; i < ((int)dirContents.size()); i++) { entry = &dirContents.at(i); if (entry->isDirectory) recRemove(entry, dirContents); - remove(entry->name.c_str()); + if (!(FAT_getAttr(entry->name.c_str()) & ATTR_READONLY)) { + remove(entry->name.c_str()); + } } chdir (".."); remove(startEntry->name.c_str()); @@ -634,21 +637,35 @@ string browseForFile (void) { swiWaitForVBlank(); if (pressed & KEY_A) { consoleClear(); - if (entry->isDirectory) { - printf ("Deleting folder, please wait..."); - recRemove(entry, dirContents); + if (FAT_getAttr(entry->name.c_str()) & ATTR_READONLY) { + printf ("Failed deleting:\n"); + printf (entry->name.c_str()); + printf ("\n"); + printf ("\n"); + printf ("( to continue)"); + pressed = 0; + while (!(pressed & KEY_A)) { + scanKeys(); + pressed = keysDown(); + swiWaitForVBlank(); + } } else { - printf ("Deleting file, please wait..."); - remove(entry->name.c_str()); + if (entry->isDirectory) { + printf ("Deleting folder, please wait..."); + recRemove(entry, dirContents); + } else { + printf ("Deleting file, please wait..."); + remove(entry->name.c_str()); + } + char filePath[256]; + snprintf(filePath, sizeof(filePath), "%s%s", path, entry->name.c_str()); + if (strcmp(filePath, clipboard) == 0) { + clipboardUsed = false; // Disable clipboard restore + clipboardOn = false; + } + getDirectoryContents (dirContents); + fileOffset--; } - char filePath[256]; - snprintf(filePath, sizeof(filePath), "%s%s", path, entry->name.c_str()); - if (strcmp(filePath, clipboard) == 0) { - clipboardUsed = false; // Disable clipboard restore - clipboardOn = false; - } - getDirectoryContents (dirContents); - fileOffset--; pressed = 0; break; }