From 5c5468b154da94ce595064f8decfe1a8e08b7224 Mon Sep 17 00:00:00 2001 From: elwray Date: Tue, 7 Feb 2023 14:05:12 +0100 Subject: [PATCH 1/2] - Don't show double dots for root directory. --- fileLister.cpp | 9 +++++++-- fileutils.cpp | 5 +++++ fileutils.h | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fileLister.cpp b/fileLister.cpp index b6fe91f..27080ff 100755 --- a/fileLister.cpp +++ b/fileLister.cpp @@ -67,8 +67,13 @@ const bool CFileLister::list(const std::string &p_path) // Sort lists sort(m_listFiles.begin(), m_listFiles.end(), compareNoCase); sort(m_listDirs.begin(), m_listDirs.end(), compareNoCase); - // Add "..", always at the first place - m_listDirs.insert(m_listDirs.begin(), T_FILE("..", 0)); + + // Add "..", always at the first place except root directory + if (!File_utils::pathIsRoot(p_path)) + { + m_listDirs.insert(m_listDirs.begin(), T_FILE("..", 0)); + } + return true; } diff --git a/fileutils.cpp b/fileutils.cpp index 5f974a5..e61648c 100755 --- a/fileutils.cpp +++ b/fileutils.cpp @@ -348,6 +348,11 @@ const unsigned long int File_utils::getFileSize(const std::string &p_file) return l_ret; } +const bool File_utils::pathIsRoot(const std::string& path) +{ + return path == "/"; +} + void File_utils::diskInfo(void) { std::string l_line(""); diff --git a/fileutils.h b/fileutils.h index bf2bb32..e7a7ded 100755 --- a/fileutils.h +++ b/fileutils.h @@ -40,6 +40,8 @@ namespace File_utils void stringReplace(std::string &p_string, const std::string &p_search, const std::string &p_replace); + const bool pathIsRoot(const std::string& path); + // Dialogs void diskInfo(void); From 7a7dba6126eb7e398d85364ba8a054f3997bf6ea Mon Sep 17 00:00:00 2001 From: elwray Date: Wed, 8 Feb 2023 10:41:52 +0100 Subject: [PATCH 2/2] - pathIsRoot function inlined. --- fileutils.cpp | 5 ----- fileutils.h | 9 +++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fileutils.cpp b/fileutils.cpp index e61648c..5f974a5 100755 --- a/fileutils.cpp +++ b/fileutils.cpp @@ -348,11 +348,6 @@ const unsigned long int File_utils::getFileSize(const std::string &p_file) return l_ret; } -const bool File_utils::pathIsRoot(const std::string& path) -{ - return path == "/"; -} - void File_utils::diskInfo(void) { std::string l_line(""); diff --git a/fileutils.h b/fileutils.h index e7a7ded..312cab6 100755 --- a/fileutils.h +++ b/fileutils.h @@ -40,13 +40,18 @@ namespace File_utils void stringReplace(std::string &p_string, const std::string &p_search, const std::string &p_replace); - const bool pathIsRoot(const std::string& path); - // Dialogs void diskInfo(void); void diskUsed(const std::vector &p_files); + + // Inline functions. + + inline const bool pathIsRoot(const std::string& path) + { + return path == "/"; + } } #endif