mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-11-02 00:11:07 -04:00
Add file attribute changing
This commit is contained in:
parent
19ea9c39a6
commit
439ebd181b
@ -1,5 +1,6 @@
|
||||
#include "fileOperations.h"
|
||||
#include <nds.h>
|
||||
#include <fat.h>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <vector>
|
||||
@ -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) ? "(<A> to continue) " : "(<A> to apply, <B> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include <nds.h>
|
||||
|
||||
#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
|
||||
@ -181,7 +181,7 @@ void showDirectoryContents (const vector<DirEntry>& 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user