From 439ebd181bf0defe44d785a96dd5d56ffc3591bc Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Mon, 3 Feb 2020 17:03:00 -0700 Subject: [PATCH] Add file attribute changing --- arm9/source/fileOperations.cpp | 87 ++++++++++++++++++++++++++++++++++ arm9/source/fileOperations.h | 3 ++ arm9/source/file_browse.cpp | 9 +++- 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/arm9/source/fileOperations.cpp b/arm9/source/fileOperations.cpp index d837da3..74ced23 100644 --- a/arm9/source/fileOperations.cpp +++ b/arm9/source/fileOperations.cpp @@ -1,5 +1,6 @@ #include "fileOperations.h" #include +#include #include #include #include @@ -145,3 +146,89 @@ int fcopy(const char *sourcePath, const char *destinationPath) return -1; } } + +void changeFileAttribs(DirEntry* entry) { + consoleClear(); + int pressed = 0; + uint8_t currentAttribs = FAT_getAttr(entry->name.c_str()); + uint8_t newAttribs = currentAttribs; + + printf ("\x1b[0;0H"); + printf (entry->name.c_str()); + if (!entry->isDirectory) { + printf ("\x1b[3;0H"); + printf ("filesize: "); + printBytes(entry->size); + } + printf ("\x1b[5;0H"); + printf ("[ ] U read-only [ ] D hidden"); + printf ("\x1b[6;0H"); + printf ("[ ] R system [ ] L archive"); + printf ("\x1b[7;0H"); + printf ("[ ] virtual"); + printf ("\x1b[7;1H"); + printf ((newAttribs & ATTR_VOLUME) ? "X" : " "); + printf ("\x1b[9;0H"); + printf ("(UDRL to change attributes)"); + while (1) { + printf ("\x1b[5;1H"); + printf ((newAttribs & ATTR_READONLY) ? "X" : " "); + printf ("\x1b[5;18H"); + printf ((newAttribs & ATTR_HIDDEN) ? "X" : " "); + printf ("\x1b[6;1H"); + printf ((newAttribs & ATTR_SYSTEM) ? "X" : " "); + printf ("\x1b[6;18H"); + printf ((newAttribs & ATTR_ARCHIVE) ? "X" : " "); + printf ("\x1b[11;0H"); + printf ((currentAttribs==newAttribs) ? "( to continue) " : "( to apply, to cancel)"); + + // Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do + do { + scanKeys(); + pressed = keysDown(); + swiWaitForVBlank(); + } while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_RIGHT) && !(pressed & KEY_LEFT) + && !(pressed & KEY_A) && !(pressed & KEY_B)); + + if (pressed & KEY_UP) { + if (newAttribs & ATTR_READONLY) { + newAttribs -= ATTR_READONLY; + } else { + newAttribs += ATTR_READONLY; + } + } + + if (pressed & KEY_DOWN) { + if (newAttribs & ATTR_HIDDEN) { + newAttribs -= ATTR_HIDDEN; + } else { + newAttribs += ATTR_HIDDEN; + } + } + + if (pressed & KEY_RIGHT) { + if (newAttribs & ATTR_SYSTEM) { + newAttribs -= ATTR_SYSTEM; + } else { + newAttribs += ATTR_SYSTEM; + } + } + + if (pressed & KEY_LEFT) { + if (newAttribs & ATTR_ARCHIVE) { + newAttribs -= ATTR_ARCHIVE; + } else { + newAttribs += ATTR_ARCHIVE; + } + } + + if ((pressed & KEY_A) && (currentAttribs!=newAttribs)) { + FAT_setAttr(entry->name.c_str(), newAttribs); + break; + } + + if ((pressed & KEY_A) || (pressed & KEY_B)) { + break; + } + } +} diff --git a/arm9/source/fileOperations.h b/arm9/source/fileOperations.h index 5dfd2be..f253ed4 100644 --- a/arm9/source/fileOperations.h +++ b/arm9/source/fileOperations.h @@ -1,5 +1,7 @@ #include +#include "file_browse.h" + #ifndef FILE_COPY #define FILE_COPY @@ -15,5 +17,6 @@ extern void printBytes(int bytes); extern off_t getFileSize(const char *fileName); extern int fcopy(const char *sourcePath, const char *destinationPath); +void changeFileAttribs(DirEntry* entry); #endif // FILE_COPY \ No newline at end of file diff --git a/arm9/source/file_browse.cpp b/arm9/source/file_browse.cpp index 8947b21..7ac65de 100644 --- a/arm9/source/file_browse.cpp +++ b/arm9/source/file_browse.cpp @@ -181,7 +181,7 @@ void showDirectoryContents (const vector& dirContents, int fileOffset, int fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) { int pressed = 0; - int assignedOp[3] = {0}; + int assignedOp[4] = {0}; int optionOffset = 0; int cursorScreenPos = 0; int maxCursors = -1; @@ -216,6 +216,9 @@ int fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) { assignedOp[maxCursors] = 3; printf(" Mount NitroFS\n"); } + maxCursors++; + assignedOp[maxCursors] = 4; + printf(entry->isDirectory ? " Show directory info\n" : " Show file info\n"); if (sdMounted && (strcmp (path, "sd:/gm9i/out/") != 0)) { maxCursors++; assignedOp[maxCursors] = 1; @@ -295,6 +298,8 @@ int fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) { chdir("nitro:/"); nitroSecondaryDrive = secondaryDrive; } + } else if (assignedOp[optionOffset] == 4) { + changeFileAttribs(entry); } return assignedOp[optionOffset]; } @@ -536,6 +541,8 @@ string browseForFile (void) { screenOffset = 0; fileOffset = 0; } + } else if (getOp == 4) { + for (int i = 0; i < 15; i++) swiWaitForVBlank(); } } }