diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-12-16 16:30:06 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-12-16 16:30:06 +1300 |
commit | 3533aced8b3fc4d6c1ec22c35f805ae966d8a7cb (patch) | |
tree | 4f0fa249c121446c49066fb9cc027286300f0e65 /arm9/source/devices/file.c | |
parent | 38c0a4993265c7c945edd672ed1a5804f2c8b572 (diff) | |
download | bedrock-nds-3533aced8b3fc4d6c1ec22c35f805ae966d8a7cb.zip |
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.
Diffstat (limited to 'arm9/source/devices/file.c')
-rw-r--r-- | arm9/source/devices/file.c | 8 |
1 files changed, 7 insertions, 1 deletions
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_i<pointer+1; fs->dir_i++) { fs->child = readdir(fs->dir); |