From a2941ae27e73f8ee5c6f03d3eee42d5f348eff30 Mon Sep 17 00:00:00 2001 From: TpaBkaY Date: Fri, 17 May 2024 09:27:26 +0300 Subject: [PATCH] Better ZIP sorting, add suffix (#900) --- file_io.cpp | 11 +++++++++++ file_io.h | 2 ++ menu.cpp | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/file_io.cpp b/file_io.cpp index 9b99e2a..c5ba8be 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -1224,6 +1224,12 @@ struct DirentComp if ((de1.de.d_type == DT_DIR) && (de2.de.d_type != DT_DIR)) return true; if ((de1.de.d_type != DT_DIR) && (de2.de.d_type == DT_DIR)) return false; + if ((de1.de.d_type == DT_DIR) && (de2.de.d_type == DT_DIR)) + { + if (!(de1.flags & DT_EXT_ZIP) && (de2.flags & DT_EXT_ZIP)) return true; + if ((de1.flags & DT_EXT_ZIP) && !(de2.flags & DT_EXT_ZIP)) return false; + } + int len1 = strlen(de1.altname); int len2 = strlen(de2.altname); if ((len1 > 4) && (de1.altname[len1 - 4] == '.')) len1 -= 4; @@ -1465,6 +1471,8 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons } #endif struct dirent64 _de = {}; + int isZip = 0; + if (z) { mz_zip_reader_get_filename(z, i, &_de.d_name[0], sizeof(_de.d_name)); @@ -1634,6 +1642,7 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons { // Fake that zip-file is a directory. de->d_type = DT_DIR; + isZip = 1; found = 1; } if (!found && is_minimig() && !memcmp(extension, "HDF", 3)) @@ -1681,6 +1690,8 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons direntext_t dext; memset(&dext, 0, sizeof(dext)); memcpy(&dext.de, de, sizeof(dext.de)); + if (isZip) + dext.flags |= DT_EXT_ZIP; get_display_name(&dext, extension, options); DirItem.push_back(dext); } diff --git a/file_io.h b/file_io.h index cf9794d..04a724e 100644 --- a/file_io.h +++ b/file_io.h @@ -30,6 +30,8 @@ struct direntext_t { dirent de; int cookie; +#define DT_EXT_ZIP 0x1 + unsigned int flags; char datecode[16]; char altname[256]; }; diff --git a/menu.cpp b/menu.cpp index 6a6e85a..6a2763b 100644 --- a/menu.cpp +++ b/menu.cpp @@ -7120,7 +7120,10 @@ void PrintDirectory(int expand) } else { - strcpy(&s[22], " "); + if (flist_DirItem(k)->flags & DT_EXT_ZIP) // mark ZIP archive with different suffix + strcpy(&s[22], " "); + else + strcpy(&s[22], " "); } len2 = 0; }