From 195f74bae15df18e4eb0b6b08fb61d58925d4b20 Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Sat, 8 Apr 2023 21:08:16 +0200 Subject: [PATCH] fix #38 --- CHANGELOG.TXT | 1 + tobkit/include/tobkit/fileselector.h | 1 + tobkit/source/fileselector.cpp | 16 ++++++---------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 1db8c19..891882a 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -15,6 +15,7 @@ Improvements: Fixes: - fixed sample tune value not displaying correctly for values below -99 +- fixed some directories being above ".." in file selector - general minor visual glitch fixes -- v0.4.4-unofficial (2023-04-07) diff --git a/tobkit/include/tobkit/fileselector.h b/tobkit/include/tobkit/fileselector.h index f42fb72..2b0199a 100644 --- a/tobkit/include/tobkit/fileselector.h +++ b/tobkit/include/tobkit/fileselector.h @@ -30,6 +30,7 @@ class File { public: std::string name; std::string name_with_path; + u8 order; bool is_dir; u32 size; }; diff --git a/tobkit/source/fileselector.cpp b/tobkit/source/fileselector.cpp index 5c48ce1..e9aa65f 100644 --- a/tobkit/source/fileselector.cpp +++ b/tobkit/source/fileselector.cpp @@ -193,19 +193,13 @@ std::string stringtolowercase(std::string str) inline bool compare_filenames(File f1, File f2) { - bool res; - - if((f1.is_dir)&&(!f2.is_dir)) { - res = true; - } else if ((!f1.is_dir)&&(f2.is_dir)) { - res = false; + if(f1.order != f2.order) { + return f1.order < f2.order; } else if(strcasecmp(f1.name.c_str(),f2.name.c_str())<0) { - res = true; + return true; } else { - res = false; + return false; } - - return res; } // Reads the current directory @@ -242,6 +236,7 @@ void FileSelector::read_directory(void) newfile.name = direntry->d_name; newfile.name_with_path = current_directory + direntry->d_name; newfile.is_dir = (direntry->d_type == DT_DIR); + newfile.order = newfile.is_dir ? 1 : 2; if(!newfile.is_dir) { int stat_res = stat(newfile.name_with_path.c_str(), &filestats); @@ -288,6 +283,7 @@ void FileSelector::read_directory(void) File dotdot; dotdot.name = ".."; dotdot.is_dir = true; + dotdot.order = 0; dotdot.size = 0; filelist.push_back(dotdot); }