From 3533aced8b3fc4d6c1ec22c35f805ae966d8a7cb Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 16 Dec 2024 16:30:06 +1300 Subject: Hide the . and .. directories in file device The file device shows the special directories . and .. in every directory but the root directory. To hide these, in non-root directories, we reduce the reported number of child entries by 2, and when selecting a child entry we increment the pointer by 2. --- arm9/source/devices/file.c | 8 +++++++- arm9/source/devices/file.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'arm9/source') diff --git a/arm9/source/devices/file.c b/arm9/source/devices/file.c index c9b822c..1b10862 100644 --- a/arm9/source/devices/file.c +++ b/arm9/source/devices/file.c @@ -29,6 +29,7 @@ void fs_close(FileDevice *fs) { fs->length = 0; fs->child = NULL; fs->dir_i = 0; + fs->at_root = false; } void fs_clear(FileDevice *fs) { @@ -82,6 +83,8 @@ void fs_open_entry(FileDevice* fs, u8 *path) { while ((fs->child = readdir(fs->dir))) { fs->dir_i++; }; + // If this is not the root directory, reduce len by 2 for . and .. dirs. + if (path[1] == 0) { fs->at_root = true; } else { fs->dir_i -= 2; } fs->length = fs->dir_i; fs_select_child(fs, 0); pb_populate(&fs->path, path); @@ -113,9 +116,12 @@ void fs_open_entry(FileDevice* fs, u8 *path) { } void fs_select_child(FileDevice *fs, u32 pointer) { + // Increment past the . and .. directories. + if (!fs->at_root) { + pointer += 2; + } fs->pointer = pointer; rewinddir(fs->dir); - fs->dir_i = 0; for (fs->dir_i=0; fs->dir_idir_i++) { fs->child = readdir(fs->dir); diff --git a/arm9/source/devices/file.h b/arm9/source/devices/file.h index 86ca039..efff684 100644 --- a/arm9/source/devices/file.h +++ b/arm9/source/devices/file.h @@ -29,6 +29,7 @@ FILE *tmpfile; // to open file and keep existing file open struct dirent *child; // currently-selected directory child information u32 dir_i; // index of next child to read from dir + bool at_root; // current entry is the root directory } FileDevice; void init_filesystem(); -- cgit v1.2.3-70-g09d2