Enumify drive number

This commit is contained in:
Pk11 2021-11-22 16:16:48 -06:00
parent b5df5a6971
commit e44678598c
7 changed files with 74 additions and 56 deletions

View File

@ -96,20 +96,20 @@ void dm_drawTopScreen(void) {
break; break;
case DriveMenuOperation::nitroFs: case DriveMenuOperation::nitroFs:
font->print(0, i + 1, true, "[nitro:] NDS GAME IMAGE", Alignment::left, pal); font->print(0, i + 1, true, "[nitro:] NDS GAME IMAGE", Alignment::left, pal);
if (!((sdMounted && nitroCurrentDrive==0) if (!((sdMounted && nitroCurrentDrive == Drive::sdCard)
|| (flashcardMounted && nitroCurrentDrive==1) || (flashcardMounted && nitroCurrentDrive == Drive::flashcard)
|| (ramdrive1Mounted && nitroCurrentDrive==2) || (ramdrive1Mounted && nitroCurrentDrive == Drive::ramDrive1)
|| (ramdrive2Mounted && nitroCurrentDrive==3) || (ramdrive2Mounted && nitroCurrentDrive == Drive::ramDrive2)
|| (nandMounted && nitroCurrentDrive==4) || (nandMounted && nitroCurrentDrive == Drive::nand)
|| (imgMounted && nitroCurrentDrive==6))) || (imgMounted && nitroCurrentDrive == Drive::fatImg)))
font->print(256 - font->width(), i + 1, true, "[x]", Alignment::right, pal); font->print(256 - font->width(), i + 1, true, "[x]", Alignment::right, pal);
break; break;
case DriveMenuOperation::fatImage: case DriveMenuOperation::fatImage:
if ((sdMounted && imgCurrentDrive==0) if ((sdMounted && imgCurrentDrive == Drive::sdCard)
|| (flashcardMounted && imgCurrentDrive==1) || (flashcardMounted && imgCurrentDrive == Drive::flashcard)
|| (ramdrive1Mounted && imgCurrentDrive==2) || (ramdrive1Mounted && imgCurrentDrive == Drive::ramDrive1)
|| (ramdrive2Mounted && imgCurrentDrive==3) || (ramdrive2Mounted && imgCurrentDrive == Drive::ramDrive2)
|| (nandMounted && imgCurrentDrive==4)) { || (nandMounted && imgCurrentDrive == Drive::nand)) {
font->printf(0, i + 1, true, Alignment::left, pal, "[nitro:] FAT IMAGE (%s)", imgLabel[0] == 0 ? "UNTITLED" : imgLabel); font->printf(0, i + 1, true, Alignment::left, pal, "[nitro:] FAT IMAGE (%s)", imgLabel[0] == 0 ? "UNTITLED" : imgLabel);
} else { } else {
font->print(0, i + 1, true, "[nitro:] FAT IMAGE", Alignment::left, pal); font->print(0, i + 1, true, "[nitro:] FAT IMAGE", Alignment::left, pal);
@ -291,26 +291,26 @@ void driveMenu (void) {
if (pressed & KEY_A) { if (pressed & KEY_A) {
if (dmOperations[dmCursorPosition] == DriveMenuOperation::sdCard && sdMounted) { if (dmOperations[dmCursorPosition] == DriveMenuOperation::sdCard && sdMounted) {
currentDrive = 0; currentDrive = Drive::sdCard;
chdir("sd:/"); chdir("sd:/");
screenMode = 1; screenMode = 1;
break; break;
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::flashcard && flashcardMounted) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::flashcard && flashcardMounted) {
currentDrive = 1; currentDrive = Drive::flashcard;
chdir("fat:/"); chdir("fat:/");
screenMode = 1; screenMode = 1;
break; break;
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::gbaCart && isRegularDS && flashcardMounted && gbaFixedValue == 0x96) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::gbaCart && isRegularDS && flashcardMounted && gbaFixedValue == 0x96) {
gbaCartDump(); gbaCartDump();
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::nitroFs && nitroMounted) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::nitroFs && nitroMounted) {
if ((sdMounted && nitroCurrentDrive==0) if ((sdMounted && nitroCurrentDrive == Drive::sdCard)
|| (flashcardMounted && nitroCurrentDrive==1) || (flashcardMounted && nitroCurrentDrive == Drive::flashcard)
|| (ramdrive1Mounted && nitroCurrentDrive==2) || (ramdrive1Mounted && nitroCurrentDrive == Drive::ramDrive1)
|| (ramdrive2Mounted && nitroCurrentDrive==3) || (ramdrive2Mounted && nitroCurrentDrive == Drive::ramDrive2)
|| (nandMounted && nitroCurrentDrive==4) || (nandMounted && nitroCurrentDrive == Drive::nand)
|| (imgMounted && nitroCurrentDrive==6)) || (imgMounted && nitroCurrentDrive == Drive::fatImg))
{ {
currentDrive = 5; currentDrive = Drive::nitroFS;
chdir("nitro:/"); chdir("nitro:/");
screenMode = 1; screenMode = 1;
break; break;
@ -318,28 +318,28 @@ void driveMenu (void) {
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::ndsCard && (sdMounted || flashcardMounted)) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::ndsCard && (sdMounted || flashcardMounted)) {
ndsCardDump(); ndsCardDump();
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::ramDrive1 && isDSiMode() && ramdrive1Mounted) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::ramDrive1 && isDSiMode() && ramdrive1Mounted) {
currentDrive = 2; currentDrive = Drive::ramDrive1;
chdir("ram1:/"); chdir("ram1:/");
screenMode = 1; screenMode = 1;
break; break;
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::ramDrive2 && isDSiMode() && ramdrive2Mounted) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::ramDrive2 && isDSiMode() && ramdrive2Mounted) {
currentDrive = 3; currentDrive = Drive::ramDrive2;
chdir("ram2:/"); chdir("ram2:/");
screenMode = 1; screenMode = 1;
break; break;
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::sysNand && isDSiMode() && nandMounted) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::sysNand && isDSiMode() && nandMounted) {
currentDrive = 4; currentDrive = Drive::nand;
chdir("nand:/"); chdir("nand:/");
screenMode = 1; screenMode = 1;
break; break;
} else if (dmOperations[dmCursorPosition] == DriveMenuOperation::fatImage && imgMounted) { } else if (dmOperations[dmCursorPosition] == DriveMenuOperation::fatImage && imgMounted) {
if ((sdMounted && imgCurrentDrive==0) if ((sdMounted && imgCurrentDrive == Drive::sdCard)
|| (flashcardMounted && imgCurrentDrive==1) || (flashcardMounted && imgCurrentDrive == Drive::flashcard)
|| (ramdrive1Mounted && imgCurrentDrive==2) || (ramdrive1Mounted && imgCurrentDrive == Drive::ramDrive1)
|| (ramdrive2Mounted && imgCurrentDrive==3) || (ramdrive2Mounted && imgCurrentDrive == Drive::ramDrive2)
|| (nandMounted && imgCurrentDrive==4)) || (nandMounted && imgCurrentDrive == Drive::nand))
{ {
currentDrive = 6; currentDrive = Drive::fatImg;
chdir("img:/"); chdir("img:/");
screenMode = 1; screenMode = 1;
break; break;
@ -350,11 +350,11 @@ void driveMenu (void) {
// Unmount/Remount FAT image // Unmount/Remount FAT image
if ((held & KEY_R) && (pressed & KEY_X)) { if ((held & KEY_R) && (pressed & KEY_X)) {
if (nitroMounted) { if (nitroMounted) {
currentDrive = 5; currentDrive = Drive::nitroFS;
chdir("nitro:/"); chdir("nitro:/");
nitroUnmount(); nitroUnmount();
} else if (imgMounted) { } else if (imgMounted) {
currentDrive = 6; currentDrive = Drive::fatImg;
chdir("img:/"); chdir("img:/");
imgUnmount(); imgUnmount();
} }
@ -364,7 +364,7 @@ void driveMenu (void) {
if ((held & KEY_R) && (pressed & KEY_B)) { if ((held & KEY_R) && (pressed & KEY_B)) {
if (isDSiMode() && sdMountedDone) { if (isDSiMode() && sdMountedDone) {
if (sdMounted) { if (sdMounted) {
currentDrive = 0; currentDrive = Drive::sdCard;
chdir("sd:/"); chdir("sd:/");
sdUnmount(); sdUnmount();
} else if (isRegularDS) { } else if (isRegularDS) {
@ -372,7 +372,7 @@ void driveMenu (void) {
} }
} else { } else {
if (flashcardMounted) { if (flashcardMounted) {
currentDrive = 1; currentDrive = Drive::flashcard;
chdir("fat:/"); chdir("fat:/");
flashcardUnmount(); flashcardUnmount();
} else { } else {

View File

@ -1,3 +1,5 @@
#include "driveOperations.h"
#include <nds.h> #include <nds.h>
#include <nds/arm9/dldi.h> #include <nds/arm9/dldi.h>
#include <fat.h> #include <fat.h>
@ -30,9 +32,9 @@ bool ramdrive2Mounted = false;
bool imgMounted = false; bool imgMounted = false;
bool nitroMounted = false; bool nitroMounted = false;
int currentDrive = 0; // 0 == SD card, 1 == Flashcard, 2 == RAMdrive 1, 3 == RAMdrive 2, 4 == NAND, 5 == NitroFS, 6 == FAT IMG Drive currentDrive = Drive::sdCard;
int nitroCurrentDrive = 0; Drive nitroCurrentDrive = Drive::sdCard;
int imgCurrentDrive = 0; Drive imgCurrentDrive = Drive::sdCard;
char sdLabel[12]; char sdLabel[12];
char fatLabel[12]; char fatLabel[12];
@ -79,19 +81,19 @@ std::string getDriveBytes(u64 bytes)
const char* getDrivePath(void) { const char* getDrivePath(void) {
switch (currentDrive) { switch (currentDrive) {
case 0: case Drive::sdCard:
return "sd:/"; return "sd:/";
case 1: case Drive::flashcard:
return "fat:/"; return "fat:/";
case 2: case Drive::ramDrive1:
return "ram1:/"; return "ram1:/";
case 3: case Drive::ramDrive2:
return "ram2:/"; return "ram2:/";
case 4: case Drive::nand:
return "nand:/"; return "nand:/";
case 5: case Drive::nitroFS:
return "nitro:/"; return "nitro:/";
case 6: case Drive::fatImg:
return "img:/"; return "img:/";
} }
return ""; return "";

View File

@ -2,6 +2,19 @@
#define FLASHCARD_H #define FLASHCARD_H
#include <string> #include <string>
#include <nds/ndstypes.h>
enum class Drive : u8 {
sdCard = 0,
flashcard,
ramDrive1,
ramDrive2,
nand,
nitroFS,
fatImg
};
#define DRIVE_WRITABLE(drive) (drive < Drive::nand)
extern u8 stored_SCFG_MC; extern u8 stored_SCFG_MC;
@ -14,9 +27,9 @@ extern bool ramdrive2Mounted;
extern bool imgMounted; extern bool imgMounted;
extern bool nitroMounted; extern bool nitroMounted;
extern int currentDrive; // 0 == SD card, 1 == Flashcard, 2 == RAMdrive 1, 3 == RAMdrive 2, 4 == NAND, 5 == NitroFS, 6 == FAT IMG extern Drive currentDrive;
extern int nitroCurrentDrive; extern Drive nitroCurrentDrive;
extern int imgCurrentDrive; extern Drive imgCurrentDrive;
extern char sdLabel[12]; extern char sdLabel[12];
extern char fatLabel[12]; extern char fatLabel[12];

View File

@ -1,5 +1,6 @@
#include <nds.h> #include <nds.h>
#include "driveOperations.h"
#include "file_browse.h" #include "file_browse.h"
#ifndef FILE_COPY #ifndef FILE_COPY
@ -9,10 +10,10 @@ struct ClipboardFile {
std::string path; std::string path;
std::string name; std::string name;
bool folder; bool folder;
int drive; // 0 == SD card, 1 == Flashcard, 2 == RAMdrive 1, 3 == RAMdrive 2 Drive drive;
bool nitro; bool nitro;
ClipboardFile(std::string path, std::string name, bool folder, int drive, bool nitro) : path(std::move(path)), name(std::move(name)), folder(folder), drive(drive), nitro(nitro) {} ClipboardFile(std::string path, std::string name, bool folder, Drive drive, bool nitro) : path(std::move(path)), name(std::move(name)), folder(folder), drive(drive), nitro(nitro) {}
}; };
extern std::vector<ClipboardFile> clipboard; extern std::vector<ClipboardFile> clipboard;

View File

@ -95,7 +95,7 @@ void getDirectoryContents(std::vector<DirEntry>& dirContents) {
bool isApp = false; bool isApp = false;
if (extension(pent->d_name, {"nds", "argv", "dsi", "ids", "app", "srl"})) { if (extension(pent->d_name, {"nds", "argv", "dsi", "ids", "app", "srl"})) {
isApp = (currentDrive == 0 && sdMounted) || (currentDrive == 1 && flashcardMounted); isApp = (currentDrive == Drive::sdCard && sdMounted) || (currentDrive == Drive::flashcard && flashcardMounted);
} else if (extension(pent->d_name, {"firm"})) { } else if (extension(pent->d_name, {"firm"})) {
isApp = (isDSiMode() && is3DS && sdMounted); isApp = (isDSiMode() && is3DS && sdMounted);
} }
@ -380,7 +380,7 @@ FileOperation fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
if (nitroMounted) { if (nitroMounted) {
chdir("nitro:/"); chdir("nitro:/");
nitroCurrentDrive = currentDrive; nitroCurrentDrive = currentDrive;
currentDrive = 5; currentDrive = Drive::nitroFS;
} }
break; break;
} case FileOperation::ndsInfo: { } case FileOperation::ndsInfo: {
@ -397,7 +397,7 @@ FileOperation fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
if (imgMounted) { if (imgMounted) {
chdir("img:/"); chdir("img:/");
imgCurrentDrive = currentDrive; imgCurrentDrive = currentDrive;
currentDrive = 6; currentDrive = Drive::fatImg;
} }
break; break;
} case FileOperation::hexEdit: { } case FileOperation::hexEdit: {
@ -650,7 +650,7 @@ std::string browseForFile (void) {
} }
} while (!pressed); } while (!pressed);
if (isDSiMode() && !pressed && currentDrive == 1 && REG_SCFG_MC == 0x11 && flashcardMounted) { if (isDSiMode() && !pressed && currentDrive == Drive::flashcard && REG_SCFG_MC == 0x11 && flashcardMounted) {
flashcardUnmount(); flashcardUnmount();
screenMode = 0; screenMode = 0;
return "null"; return "null";

View File

@ -231,8 +231,8 @@ u32 search(u32 offset, FILE *file) {
return offset; return offset;
} }
void hexEditor(const char *path, int drive) { void hexEditor(const char *path, Drive drive) {
FILE *file = fopen(path, drive < 4 ? "rb+" : "rb"); FILE *file = fopen(path, DRIVE_WRITABLE(drive) ? "rb+" : "rb");
if(!file) if(!file)
return; return;
@ -355,7 +355,7 @@ void hexEditor(const char *path, int drive) {
if((int)cursorPosition < bytesPerLine * maxLines - 1) if((int)cursorPosition < bytesPerLine * maxLines - 1)
cursorPosition = std::min(cursorPosition + 1, fileSize - offset - 1); cursorPosition = std::min(cursorPosition + 1, fileSize - offset - 1);
} else if(pressed & KEY_A) { } else if(pressed & KEY_A) {
if(drive < 4) { if(DRIVE_WRITABLE(drive)) {
mode = 2; mode = 2;
} }
} else if(pressed & KEY_B) { } else if(pressed & KEY_B) {

View File

@ -1,6 +1,8 @@
#ifndef HEX_EDITOR_H #ifndef HEX_EDITOR_H
#define HEX_EDITOR_H #define HEX_EDITOR_H
void hexEditor(const char *path, int drive); #include "driveOperations.h"
void hexEditor(const char *path, Drive drive);
#endif #endif