From 7e1fcb5c07eddbd8a1cd3247bb4e6f25c0efb84f Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Mon, 3 Jan 2005 14:17:33 +0000 Subject: [PATCH] Bug fix 2047 FileWindow didnt sort the dirs "." and ".." correctly. Now these two are always first. --- source/blender/blenlib/intern/storage.c | 6 ++++++ source/blender/src/filesel.c | 21 +++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 4982ffa5899..8a4db10c843 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -152,6 +152,12 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2) } if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); + + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + return (strcasecmp(entry1->relname,entry2->relname)); } diff --git a/source/blender/src/filesel.c b/source/blender/src/filesel.c index 4440ecaa86d..cb4e1681dc5 100644 --- a/source/blender/src/filesel.c +++ b/source/blender/src/filesel.c @@ -312,6 +312,12 @@ static int compare_name(const void *a1, const void *a2) } if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); + + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + return (strcasecmp(entry1->relname,entry2->relname)); } @@ -334,12 +340,14 @@ static int compare_date(const void *a1, const void *a2) if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); -/* - if ( entry1->s.st_ctime < entry2->s.st_ctime) return 1; - if ( entry1->s.st_ctime > entry2->s.st_ctime) return -1; -*/ + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + if ( entry1->s.st_mtime < entry2->s.st_mtime) return 1; if ( entry1->s.st_mtime > entry2->s.st_mtime) return -1; + else return strcasecmp(entry1->relname,entry2->relname); } @@ -362,6 +370,11 @@ static int compare_size(const void *a1, const void *a2) if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + if ( entry1->s.st_size < entry2->s.st_size) return 1; if ( entry1->s.st_size > entry2->s.st_size) return -1; else return strcasecmp(entry1->relname,entry2->relname);