mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Improved hex viewer navigation
This commit is contained in:
parent
655d56c7bd
commit
25c346e0d7
16
source/fs.c
16
source/fs.c
@ -188,6 +188,22 @@ size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t FileGetSize(const char* path) {
|
||||||
|
if (PathToNumFS(path) >= 0) {
|
||||||
|
FILINFO fno;
|
||||||
|
fno.lfname = NULL;
|
||||||
|
if (f_stat(path, &fno) != FR_OK)
|
||||||
|
return 0;
|
||||||
|
return fno.fsize;
|
||||||
|
} else if (GetVirtualSource(path)) {
|
||||||
|
VirtualFile vfile;
|
||||||
|
if (!FindVirtualFile(&vfile, path, 0))
|
||||||
|
return 0;
|
||||||
|
return vfile.size;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool PathCopyVirtual(const char* destdir, const char* orig) {
|
bool PathCopyVirtual(const char* destdir, const char* orig) {
|
||||||
char dest[256]; // maximum path name length in FAT
|
char dest[256]; // maximum path name length in FAT
|
||||||
char* oname = strrchr(orig, '/');
|
char* oname = strrchr(orig, '/');
|
||||||
|
@ -44,6 +44,9 @@ bool FileCreateData(const char* path, u8* data, size_t size);
|
|||||||
/** Read data from file@offset **/
|
/** Read data from file@offset **/
|
||||||
size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset);
|
size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset);
|
||||||
|
|
||||||
|
/** Get size of file **/
|
||||||
|
size_t FileGetSize(const char* path);
|
||||||
|
|
||||||
/** Recursively copy a file or directory **/
|
/** Recursively copy a file or directory **/
|
||||||
bool PathCopy(const char* destdir, const char* orig);
|
bool PathCopy(const char* destdir, const char* orig);
|
||||||
|
|
||||||
|
@ -161,6 +161,7 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) {
|
|||||||
u32 HexViewer(const char* path) {
|
u32 HexViewer(const char* path) {
|
||||||
static u32 mode = 0;
|
static u32 mode = 0;
|
||||||
u8 data[(SCREEN_HEIGHT / 8) * 16]; // this is the maximum size
|
u8 data[(SCREEN_HEIGHT / 8) * 16]; // this is the maximum size
|
||||||
|
u32 fsize = FileGetSize(path);
|
||||||
|
|
||||||
int x_off, x_hex, x_ascii;
|
int x_off, x_hex, x_ascii;
|
||||||
u32 vpad, hlpad, hrpad;
|
u32 vpad, hlpad, hrpad;
|
||||||
@ -211,6 +212,9 @@ u32 HexViewer(const char* path) {
|
|||||||
last_mode = mode;
|
last_mode = mode;
|
||||||
ClearScreenF(true, false, COLOR_STD_BG);
|
ClearScreenF(true, false, COLOR_STD_BG);
|
||||||
}
|
}
|
||||||
|
// fix offset (if required)
|
||||||
|
if (offset + total_shown > fsize + cols)
|
||||||
|
offset = (total_shown > fsize) ? 0 : (fsize + cols - total_shown - (fsize % cols));
|
||||||
total_data = FileGetData(path, data, total_shown, offset); // get data
|
total_data = FileGetData(path, data, total_shown, offset); // get data
|
||||||
|
|
||||||
// display data on screen
|
// display data on screen
|
||||||
@ -243,8 +247,8 @@ u32 HexViewer(const char* path) {
|
|||||||
|
|
||||||
// handle user input
|
// handle user input
|
||||||
u32 pad_state = InputWait();
|
u32 pad_state = InputWait();
|
||||||
u32 step_ud = (pad_state & BUTTON_R1) ? total_shown * 16 : cols;
|
u32 step_ud = (pad_state & BUTTON_R1) ? (0x1000 - (0x1000 % cols)) : cols;
|
||||||
u32 step_lr = (pad_state & BUTTON_R1) ? total_shown * 256 : total_shown;
|
u32 step_lr = (pad_state & BUTTON_R1) ? (0x10000 - (0x10000 % cols)) : total_shown;
|
||||||
if (pad_state & BUTTON_DOWN) offset += step_ud;
|
if (pad_state & BUTTON_DOWN) offset += step_ud;
|
||||||
else if (pad_state & BUTTON_RIGHT) offset += step_lr;
|
else if (pad_state & BUTTON_RIGHT) offset += step_lr;
|
||||||
else if (pad_state & BUTTON_UP) offset = (offset > step_ud) ? offset - step_ud : 0;
|
else if (pad_state & BUTTON_UP) offset = (offset > step_ud) ? offset - step_ud : 0;
|
||||||
@ -349,7 +353,8 @@ u32 GodMode() {
|
|||||||
}
|
}
|
||||||
if (clipboard->n_entries && (strcspn(clipboard->entry[0].path, IMG_DRV) == 0))
|
if (clipboard->n_entries && (strcspn(clipboard->entry[0].path, IMG_DRV) == 0))
|
||||||
clipboard->n_entries = 0; // remove invalid clipboard stuff
|
clipboard->n_entries = 0; // remove invalid clipboard stuff
|
||||||
} else if (ShowPrompt(true, "Show HexViewer?\n \nControls:\n\x18\x19\x1A\x1B(+R) - Scroll\nR+Y - Switch view\nB - Exit\n")) {
|
} else if (FileGetSize(curr_entry->path) &&
|
||||||
|
ShowPrompt(true, "Show HexViewer?\n \nControls:\n\x18\x19\x1A\x1B(+R) - Scroll\nR+Y - Switch view\nB - Exit\n")) {
|
||||||
HexViewer(curr_entry->path);
|
HexViewer(curr_entry->path);
|
||||||
}
|
}
|
||||||
} else if (*current_path && ((pad_state & BUTTON_B) || // one level down
|
} else if (*current_path && ((pad_state & BUTTON_B) || // one level down
|
||||||
|
Loading…
x
Reference in New Issue
Block a user