Changed filetype var handling to bitwise

... cause files can have more than one filetype
This commit is contained in:
d0k3 2017-01-27 15:29:53 +01:00
parent 0abc6e88ff
commit 3b6932d9ab
7 changed files with 41 additions and 41 deletions

View File

@ -143,9 +143,9 @@ DSTATUS disk_initialize (
if (!nand_type_emu) return STA_NOINIT|STA_NODISK;
} else if (pdrv < 10) {
UINT mount_state = GetMountState();
nand_type_img = (mount_state == IMG_NAND) ? CheckNandType(NAND_IMGNAND) : 0;
nand_type_img = (mount_state & IMG_NAND) ? CheckNandType(NAND_IMGNAND) : 0;
if (!nand_type_img) {
if ((pdrv == 7) && (mount_state != IMG_FAT)) return STA_NOINIT|STA_NODISK;
if ((pdrv == 7) && !(mount_state & IMG_FAT)) return STA_NOINIT|STA_NODISK;
else if (pdrv == 8) return STA_NOINIT|STA_NODISK;
else if (pdrv == 9) InitRamDrive();
}

View File

@ -21,14 +21,14 @@ int DriveType(const char* path) {
} else if ((pdrv >= 0) && (pdrv < NORM_FS)) {
if (pdrv == 0) {
type = DRV_FAT | DRV_SDCARD | DRV_STDFAT;
} else if ((pdrv == 9) && (GetMountState() != IMG_NAND)) {
} else if ((pdrv == 9) && !(GetMountState() & IMG_NAND)) {
type = DRV_FAT | DRV_RAMDRIVE | DRV_STDFAT;
} else if ((pdrv >= 1) && (pdrv <= 3)) {
type = DRV_FAT | DRV_SYSNAND | DRV_STDFAT;
} else if ((pdrv >= 4) && (pdrv <= 6)) {
type = DRV_FAT | DRV_EMUNAND | DRV_STDFAT;
} else if ((pdrv >= 7) && (pdrv <= 9) &&
((GetMountState() == IMG_FAT) || (GetMountState() == IMG_NAND))) {
(GetMountState() & (IMG_FAT|IMG_NAND))) {
type = DRV_FAT | DRV_IMAGE | DRV_STDFAT;
}
} else if (CheckVirtualDrive(path)) {
@ -71,18 +71,18 @@ bool GetRootDirContentsWorker(DirStruct* contents) {
if (!DriveType(drvnum[pdrv])) continue; // drive not available
memset(entry->path, 0x00, 64);
snprintf(entry->path + 0, 4, drvnum[pdrv]);
if ((pdrv == 7) && (GetMountState() == IMG_FAT)) // FAT image handling
if ((pdrv == 7) && (GetMountState() & IMG_FAT)) // FAT image handling
snprintf(entry->path + 4, 32, "[%s] %s", drvnum[pdrv], "FAT IMAGE");
else if ((pdrv == 9) && (GetMountState() != IMG_NAND)) // RAM drive handling
else if ((pdrv == 9) && !(GetMountState() & IMG_NAND)) // RAM drive handling
snprintf(entry->path + 4, 32, "[%s] %s", drvnum[pdrv], "RAMDRIVE");
else if (pdrv == 10) // Game drive special handling
snprintf(entry->path + 4, 32, "[%s] %s %s", drvnum[pdrv],
(GetMountState() == GAME_CIA ) ? "CIA" :
(GetMountState() == GAME_NCSD ) ? "NCSD" :
(GetMountState() == GAME_NCCH ) ? "NCCH" :
(GetMountState() == GAME_EXEFS) ? "EXEFS" :
(GetMountState() == GAME_ROMFS) ? "ROMFS" :
(GetMountState() == SYS_FIRM) ? "FIRM" : "UNK", drvname[pdrv]);
(GetMountState() & GAME_CIA ) ? "CIA" :
(GetMountState() & GAME_NCSD ) ? "NCSD" :
(GetMountState() & GAME_NCCH ) ? "NCCH" :
(GetMountState() & GAME_EXEFS) ? "EXEFS" :
(GetMountState() & GAME_ROMFS) ? "ROMFS" :
(GetMountState() & SYS_FIRM) ? "FIRM" : "UNK", drvname[pdrv]);
else snprintf(entry->path + 4, 32, "[%s] %s", drvnum[pdrv], drvname[pdrv]);
entry->name = entry->path + 4;
entry->size = GetTotalSpace(entry->path);

View File

@ -22,7 +22,7 @@ bool InitExtFS() {
snprintf(fsname, 7, "%lu:", i);
if (fs_mounted[i]) continue;
fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
if (!fs_mounted[i] && (i == NORM_FS - 1) && (GetMountState() != IMG_NAND)) {
if (!fs_mounted[i] && (i == NORM_FS - 1) && !(GetMountState() & IMG_NAND)) {
f_mkfs(fsname, FM_ANY, 0, MAIN_BUFFER, MAIN_BUFFER_SIZE); // format ramdrive if required
f_mount(NULL, fsname, 1);
fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK);
@ -35,7 +35,7 @@ bool InitExtFS() {
bool InitImgFS(const char* path) {
// deinit image filesystem
for (u32 i = (GetMountState() == IMG_NAND) ? NORM_FS - 1 : NORM_FS - IMGN_FS; i >= NORM_FS - IMGN_FS; i--) {
for (u32 i = (GetMountState() & IMG_NAND) ? NORM_FS - 1 : NORM_FS - IMGN_FS; i >= NORM_FS - IMGN_FS; i--) {
char fsname[8];
snprintf(fsname, 7, "%lu:", i);
if (!fs_mounted[i]) continue;

View File

@ -505,15 +505,15 @@ u32 VerifyFirmFile(const char* path) {
u32 VerifyGameFile(const char* path) {
u32 filetype = IdentifyFileType(path);
if (filetype == GAME_CIA)
if (filetype & GAME_CIA)
return VerifyCiaFile(path);
else if (filetype == GAME_NCSD)
else if (filetype & GAME_NCSD)
return VerifyNcsdFile(path);
else if (filetype == GAME_NCCH)
else if (filetype & GAME_NCCH)
return VerifyNcchFile(path, 0, 0);
else if (filetype == GAME_TMD)
else if (filetype & GAME_TMD)
return VerifyTmdFile(path);
else if (filetype == SYS_FIRM)
else if (filetype & SYS_FIRM)
return VerifyFirmFile(path);
else return 1;
}
@ -599,13 +599,13 @@ u32 CheckEncryptedFirmFile(const char* path) {
u32 CheckEncryptedGameFile(const char* path) {
u32 filetype = IdentifyFileType(path);
if (filetype == GAME_CIA)
if (filetype & GAME_CIA)
return CheckEncryptedCiaFile(path);
else if (filetype == GAME_NCSD)
else if (filetype & GAME_NCSD)
return CheckEncryptedNcsdFile(path);
else if (filetype == GAME_NCCH)
else if (filetype & GAME_NCCH)
return CheckEncryptedNcchFile(path, 0);
else if (filetype == SYS_FIRM)
else if (filetype & SYS_FIRM)
return CheckEncryptedFirmFile(path);
else return 1;
}

View File

@ -616,17 +616,17 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur
(int) ++n_opt : -1;
int searchdrv = (DriveType(current_path) & DRV_SEARCH) ? ++n_opt : -1;
if (special > 0) optionstr[special-1] =
(filetype == IMG_NAND ) ? "NAND image options..." :
(filetype == IMG_FAT ) ? "Mount as FAT image" :
(filetype == GAME_CIA ) ? "CIA image options..." :
(filetype == GAME_NCSD ) ? "NCSD image options..." :
(filetype == GAME_NCCH ) ? "NCCH image options..." :
(filetype == GAME_EXEFS) ? "Mount as EXEFS image" :
(filetype == GAME_ROMFS) ? "Mount as ROMFS image" :
(filetype == GAME_TMD) ? "TMD file options..." :
(filetype == SYS_FIRM) ? "FIRM image options..." :
(filetype == BIN_NCCHNFO) ? "NCCHinfo options..." :
(filetype == BIN_LAUNCH) ? "Launch as arm9 payload" : "???";
(filetype & IMG_NAND ) ? "NAND image options..." :
(filetype & IMG_FAT ) ? "Mount as FAT image" :
(filetype & GAME_CIA ) ? "CIA image options..." :
(filetype & GAME_NCSD ) ? "NCSD image options..." :
(filetype & GAME_NCCH ) ? "NCCH image options..." :
(filetype & GAME_EXEFS) ? "Mount as EXEFS image" :
(filetype & GAME_ROMFS) ? "Mount as ROMFS image" :
(filetype & GAME_TMD) ? "TMD file options..." :
(filetype & SYS_FIRM) ? "FIRM image options..." :
(filetype & BIN_NCCHNFO) ? "NCCHinfo options..." :
(filetype & BIN_LAUNCH) ? "Launch as arm9 payload" : "???";
optionstr[hexviewer-1] = "Show in Hexeditor";
optionstr[calcsha-1] = "Calculate SHA-256";
if (copystd > 0) optionstr[copystd-1] = "Copy to " OUTPUT_PATH;

View File

@ -397,7 +397,7 @@ u64 GetNandSizeSectors(u32 nand_src)
u32 emunand_min_sectors = (emunand_base_sector % 0x2000 == 0) ? sysnand_sectors : NAND_MIN_SECTORS;
return (emunand_min_sectors > emunand_max_sectors) ? 0 : emunand_min_sectors;
} else if (nand_src == NAND_IMGNAND) { // for images
u32 img_sectors = (GetMountState() == IMG_NAND) ? GetMountSize() / 0x200 : 0;
u32 img_sectors = (GetMountState() & IMG_NAND) ? GetMountSize() / 0x200 : 0;
return (img_sectors >= sysnand_sectors) ? sysnand_sectors : (img_sectors >= NAND_MIN_SECTORS) ? NAND_MIN_SECTORS : 0;
} else if (nand_src == NAND_SYSNAND) { // for SysNAND
return sysnand_sectors;

View File

@ -455,12 +455,12 @@ u32 InitVGameDrive(void) { // prerequisite: game file mounted as image
offset_lv3fd = (u64) -1;
base_vdir =
(type == SYS_FIRM ) ? VFLAG_FIRM :
(type == GAME_CIA ) ? VFLAG_CIA :
(type == GAME_NCSD ) ? VFLAG_NCSD :
(type == GAME_NCCH ) ? VFLAG_NCCH :
(type == GAME_EXEFS) ? VFLAG_EXEFS :
(type == GAME_ROMFS) ? VFLAG_ROMFS : 0;
(type & SYS_FIRM ) ? VFLAG_FIRM :
(type & GAME_CIA ) ? VFLAG_CIA :
(type & GAME_NCSD ) ? VFLAG_NCSD :
(type & GAME_NCCH ) ? VFLAG_NCCH :
(type & GAME_EXEFS) ? VFLAG_EXEFS :
(type & GAME_ROMFS) ? VFLAG_ROMFS : 0;
if (!base_vdir) return 0;
vgame_type = type;