forked from Mirror/GodMode9
Misc cosmetics and coding style improvements
This commit is contained in:
parent
d35e03f1a3
commit
b361db2b7e
@ -2,7 +2,7 @@
|
||||
#include "fatfs/ff.h"
|
||||
|
||||
FIL mount_file;
|
||||
u32 mount_state = IMG_NONE;
|
||||
u32 mount_state = 0;
|
||||
|
||||
int ReadImageSectors(u8* buffer, u32 sector, u32 count) {
|
||||
UINT bytes_read;
|
||||
@ -40,14 +40,14 @@ u32 IdentifyImage(const char* path) {
|
||||
u8 header[0x200];
|
||||
FIL file;
|
||||
if (f_open(&file, path, FA_READ | FA_OPEN_EXISTING) != FR_OK)
|
||||
return IMG_NONE;
|
||||
return 0;
|
||||
f_lseek(&file, 0);
|
||||
f_sync(&file);
|
||||
UINT fsize = f_size(&file);
|
||||
UINT bytes_read;
|
||||
if ((f_read(&file, header, 0x200, &bytes_read) != FR_OK) || (bytes_read != 0x200)) {
|
||||
f_close(&file);
|
||||
return IMG_NONE;
|
||||
return 0;
|
||||
}
|
||||
f_close(&file);
|
||||
if ((getbe32(header + 0x100) == 0x4E435344) && (getbe64(header + 0x110) == (u64) 0x0104030301000000) && (getbe64(header + 0x108) == (u64) 0)) {
|
||||
@ -63,17 +63,17 @@ u32 IdentifyImage(const char* path) {
|
||||
return IMG_FAT; // this might be an MBR -> give it the benefit of doubt
|
||||
}
|
||||
}
|
||||
return IMG_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 MountImage(const char* path) {
|
||||
if (mount_state) {
|
||||
f_close(&mount_file);
|
||||
mount_state = IMG_NONE;
|
||||
mount_state = 0;
|
||||
}
|
||||
if (!path || !IdentifyImage(path)) return IMG_NONE;
|
||||
if (!path || !IdentifyImage(path)) return 0;
|
||||
if (f_open(&mount_file, path, FA_READ | FA_WRITE | FA_OPEN_EXISTING) != FR_OK)
|
||||
return IMG_NONE;
|
||||
return 0;
|
||||
f_lseek(&mount_file, 0);
|
||||
f_sync(&mount_file);
|
||||
return (mount_state = IdentifyImage(path));
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define IMG_NONE 0
|
||||
#define IMG_FAT 1
|
||||
#define IMG_NAND 2
|
||||
|
||||
|
@ -65,7 +65,7 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
|
||||
char numstr[32];
|
||||
char bytestr[32];
|
||||
FormatNumber(numstr, curr_entry->size);
|
||||
snprintf(bytestr, 31, "%s byte", numstr);
|
||||
snprintf(bytestr, 31, "%s Byte", numstr);
|
||||
ResizeString(tempstr, bytestr, 20, 8, false);
|
||||
}
|
||||
DrawStringF(true, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr);
|
||||
@ -95,8 +95,8 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
|
||||
"GodMode9 Explorer v", VERSION, // generic start part
|
||||
(*curr_path) ? ((clipboard->n_entries == 0) ? "L - MARK files (use with \x18\x19\x1A\x1B)\nX - DELETE / [+R] RENAME file(s)\nY - COPY file(s) / [+R] CREATE dir\n" :
|
||||
"L - MARK files (use with \x18\x19\x1A\x1B)\nX - DELETE / [+R] RENAME file(s)\nY - PASTE file(s) / [+R] CREATE dir\n") :
|
||||
((GetWritePermissions() <= 1) ? "X - Unlock EmuNAND/image writing\nY - Unlock SysNAND writing\nR+B - Unmount SD card\n" :
|
||||
(GetWritePermissions() == 2) ? "X - Relock EmuNAND/image writing\nY - Unlock SysNAND writing\nR+B - Unmount SD card\n" :
|
||||
((GetWritePermissions() <= 1) ? "X - Unlock EmuNAND / image writing\nY - Unlock SysNAND writing\nR+B - Unmount SD card\n" :
|
||||
(GetWritePermissions() == 2) ? "X - Relock EmuNAND / image writing\nY - Unlock SysNAND writing\nR+B - Unmount SD card\n" :
|
||||
"X - Relock EmuNAND writing\nY - Relock SysNAND writing\nR+B - Unmount SD card\n"),
|
||||
(GetMountState() && !*curr_path) ? "R+X - Unmount image\n" : "",
|
||||
"R+L - Make a Screenshot\n",
|
||||
@ -130,7 +130,7 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) {
|
||||
FormatBytes(bytestr, curr_entry->size);
|
||||
ResizeString(namestr, curr_entry->name, str_width - 10, str_width - 20, false);
|
||||
snprintf(tempstr, str_width + 1, "%s%10.10s", namestr,
|
||||
(curr_entry->type == T_DIR) ? "(dir)" : (curr_entry->type == T_DOTDOT) ? "(back)" : bytestr);
|
||||
(curr_entry->type == T_DIR) ? "(dir)" : (curr_entry->type == T_DOTDOT) ? "(..)" : bytestr);
|
||||
} else snprintf(tempstr, str_width + 1, "%-*.*s", str_width, str_width, "");
|
||||
DrawStringF(false, pos_x, pos_y, color_font, COLOR_STD_BG, tempstr);
|
||||
pos_y += stp_y;
|
||||
@ -170,8 +170,9 @@ u32 GodMode() {
|
||||
InitNandCrypto();
|
||||
InitExtFS();
|
||||
|
||||
// could also check for a9lh via this: ((*(vu32*) 0x101401C0) == 0)
|
||||
if ((GetUnitPlatform() == PLATFORM_N3DS) && !CheckSlot0x05Crypto()) {
|
||||
if (!ShowPrompt(true, "Warning: slot0x05 crypto fail\nslot0x05keyY.bin is either corrupt\nor does not exist. Continue?")) {
|
||||
if (!ShowPrompt(true, "Warning: slot0x05 crypto fail!\nCould not set up slot0x05keyY.\nContinue?")) {
|
||||
DeinitExtFS();
|
||||
DeinitSDCardFS();
|
||||
return exit_mode;
|
||||
@ -232,7 +233,8 @@ u32 GodMode() {
|
||||
GetDirContents(current_dir, current_path);
|
||||
if (*old_path) {
|
||||
for (cursor = current_dir->n_entries - 1;
|
||||
(cursor > 1) && (strncmp(current_dir->entry[cursor].path, old_path, 256) != 0); cursor--);
|
||||
(cursor > 0) && (strncmp(current_dir->entry[cursor].path, old_path, 256) != 0); cursor--);
|
||||
if (*current_path && !cursor) cursor = 1; // don't set it on the dotdot
|
||||
scroll = 0;
|
||||
}
|
||||
} else if (switched && (pad_state & BUTTON_B)) { // unmount SD card
|
||||
|
@ -253,14 +253,14 @@ int WriteNandSectors(const u8* buffer, u32 sector, u32 count, u32 keyslot, u32 n
|
||||
u8 CheckNandType(u32 nand_src)
|
||||
{
|
||||
if (ReadNandSectors(NAND_BUFFER, 0, 1, 0xFF, nand_src) != 0)
|
||||
return NAND_UNKNOWN;
|
||||
return 0;
|
||||
if (memcmp(NAND_BUFFER + 0x100, nand_magic_n3ds, 0x60) == 0) {
|
||||
return NAND_TYPE_N3DS;
|
||||
} else if (memcmp(NAND_BUFFER + 0x100, nand_magic_o3ds, 0x60) == 0) {
|
||||
return (GetUnitPlatform() == PLATFORM_3DS) ? NAND_TYPE_O3DS : NAND_TYPE_NO3DS;
|
||||
}
|
||||
|
||||
return NAND_UNKNOWN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 GetNandSizeSectors(u32 nand_src)
|
||||
@ -280,11 +280,11 @@ u64 GetNandSizeSectors(u32 nand_src)
|
||||
bool InitEmuNandBase(void)
|
||||
{
|
||||
emunand_base_sector = 0x000000; // GW type EmuNAND
|
||||
if (CheckNandType(NAND_EMUNAND) != NAND_UNKNOWN)
|
||||
if (CheckNandType(NAND_EMUNAND))
|
||||
return true;
|
||||
|
||||
emunand_base_sector = 0x000001; // RedNAND type EmuNAND
|
||||
if (CheckNandType(NAND_EMUNAND) != NAND_UNKNOWN)
|
||||
if (CheckNandType(NAND_EMUNAND))
|
||||
return true;
|
||||
|
||||
if (GetPartitionOffsetSector("0:") > getMMCDevice(0)->total_size)
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define NAND_UNKNOWN 0
|
||||
#define NAND_SYSNAND (1<<0)
|
||||
#define NAND_EMUNAND (1<<1)
|
||||
#define NAND_IMGNAND (1<<2)
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "common.h"
|
||||
#include "nand.h"
|
||||
|
||||
#define VRT_NONE 0
|
||||
#define VRT_SYSNAND NAND_SYSNAND
|
||||
#define VRT_EMUNAND NAND_EMUNAND
|
||||
#define VRT_IMGNAND NAND_IMGNAND
|
||||
|
@ -165,7 +165,7 @@ void FormatNumber(char* str, u64 number) { // str should be 32 byte in size
|
||||
}
|
||||
|
||||
void FormatBytes(char* str, u64 bytes) { // str should be 32 byte in size, just to be safe
|
||||
const char* units[] = {" byte", " kB", " MB", " GB"};
|
||||
const char* units[] = {" Byte", " kB", " MB", " GB"};
|
||||
|
||||
if (bytes == (u64) -1) snprintf(str, 32, "INVALID");
|
||||
else if (bytes < 1024) snprintf(str, 32, "%llu%s", bytes, units[0]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user