From 4578cb0b185b6f590505a6cbfcaa884f4576a4db Mon Sep 17 00:00:00 2001 From: Joel16 Date: Sun, 21 Nov 2021 15:31:07 -0500 Subject: [PATCH] fs: Clean-up dir listing impl and fix imgui table sorting column index --- source/fs.cpp | 31 +++++++++++++++++++------------ source/tabs/filebrowser.cpp | 4 ++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/source/fs.cpp b/source/fs.cpp index 84637a0..fbd0b43 100644 --- a/source/fs.cpp +++ b/source/fs.cpp @@ -82,18 +82,25 @@ namespace FS { return ret; } - do { + while (true) { SceIoDirent entry; sceClibMemset(&entry, 0, sizeof(entry)); - ret = sceIoDread(dir, &entry); - - if (ret > 0) { + + if (R_FAILED(ret = sceIoDread(dir, &entry))) { + Log::Error("sceIoDread(%s) failed: %08x\n", path.c_str(), ret); + sceIoDclose(dir); + return ret; + } + + if (ret) { if ((!FS::IsImageType(entry.d_name)) && (!SCE_S_ISDIR(entry.d_stat.st_mode))) continue; - - entries.push_back(entry); } - } while (ret > 0); + else + break; + + entries.push_back(entry); + } sceIoDclose(dir); return 0; @@ -112,11 +119,11 @@ namespace FS { cfg.cwd = path; Config::Save(cfg); entries = new_entries; - return 0;; + return 0; } - static int ChangeDirUp(char path[256]) { - if (cfg.cwd.length() <= 1 && cfg.cwd.c_str()[0] == '/') + static int GetPrevPath(char path[256]) { + if (cfg.cwd.c_str() == "ux0:") return -1; // Remove upmost directory @@ -134,7 +141,7 @@ namespace FS { // remove trailing slash if (len > 1 && path[len - 1] == '/') len--; - + path[len] = '\0'; return 0; } @@ -148,7 +155,7 @@ namespace FS { int ChangeDirPrev(std::vector &entries) { char new_path[256]; - if (FS::ChangeDirUp(new_path) < 0) + if (FS::GetPrevPath(new_path) < 0) return -1; return FS::ChangeDir(std::string(new_path), entries); diff --git a/source/tabs/filebrowser.cpp b/source/tabs/filebrowser.cpp index da80458..7f341eb 100644 --- a/source/tabs/filebrowser.cpp +++ b/source/tabs/filebrowser.cpp @@ -72,12 +72,12 @@ namespace Tabs { return false; else { switch (column_sort_spec->ColumnIndex) { - case 1: // filename + case 0: // filename sort = descending? FS_SORT_ALPHA_DESC : FS_SORT_ALPHA_ASC; return descending? (strcasecmp(entryB.d_name, entryA.d_name) < 0) : (strcasecmp(entryA.d_name, entryB.d_name) < 0); break; - case 2: // Size + case 1: // Size sort = descending? FS_SORT_SIZE_DESC : FS_SORT_SIZE_ASC; return descending? (entryB.d_stat.st_size < entryA.d_stat.st_size) : (entryA.d_stat.st_size < entryB.d_stat.st_size); break;