From a7957f124a2dd1c94cff165e06a18a6a02660fc8 Mon Sep 17 00:00:00 2001 From: Epicpkmn11 <41608708+Epicpkmn11@users.noreply.github.com> Date: Mon, 22 Oct 2018 16:18:04 -0500 Subject: [PATCH] Add ".." to top of the list after sorting (#17) Fixes #15 --- arm9/source/file_browse.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/arm9/source/file_browse.cpp b/arm9/source/file_browse.cpp index 92026de..c47f283 100644 --- a/arm9/source/file_browse.cpp +++ b/arm9/source/file_browse.cpp @@ -73,7 +73,6 @@ bool dirEntryPredicate (const DirEntry& lhs, const DirEntry& rhs) { } void getDirectoryContents (vector& dirContents) { - bool twoDotsMade = false; struct stat st; dirContents.clear(); @@ -91,15 +90,7 @@ void getDirectoryContents (vector& dirContents) { if(pent == NULL) break; stat(pent->d_name, &st); - if (!twoDotsMade) { - if (strcmp(pent->d_name, "..") != 0) { - dirEntry.name = ".."; - dirEntry.isDirectory = true; - dirEntry.isApp = false; - dirContents.push_back (dirEntry); // List ".." - } - twoDotsMade = true; - } else if (strcmp(pent->d_name, "..") != 0) { + if (strcmp(pent->d_name, "..") != 0) { dirEntry.name = pent->d_name; dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false; if (!dirEntry.isDirectory) { @@ -130,6 +121,12 @@ void getDirectoryContents (vector& dirContents) { } sort(dirContents.begin(), dirContents.end(), dirEntryPredicate); + + DirEntry dirEntry; + dirEntry.name = ".."; // ".." entry + dirEntry.isDirectory = true; + dirEntry.isApp = false; + dirContents.insert (dirContents.begin(), dirEntry); // Add ".." to top of list } void showDirectoryContents (const vector& dirContents, int fileOffset, int startRow) {