rejetto forum

Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Mars on February 02, 2010, 10:21:34 PM

Title: SB_EXT
Post by: Mars on February 02, 2010, 10:21:34 PM
Another aberration concerns the sorting by extension of files, at present the names of directories are considered as names of classic files with an extension, while they should be considered names without extension.

you have to unselect 'folder before' in the menu

solution:
Quote
 case sortby of
    SB_SIZE: result:=compare_(f1.size, f2.size);
    SB_TIME: result:=-compare_(f1.mtime, f2.mtime);
    SB_DL: result:=-compare_(f1.DLcount, f2.DLcount);
    SB_EXT: begin
            if not (f1.isfolder or f2.isfolder) then result:=compareExt(f1.name, f2.name)             // two files or links  --> sort by ext
            else if (f1.isfolder and f2.isfolder) then result:=ansiCompareText(f1.name, f2.name)   // two folders  --> sort by name
            else if f2.isfolder then result:=1    // sort as without extension
            else result:=-1;
            end;
    SB_COMMENT: result:=ansiCompareText(f1.comment, f2.comment);
    else result:=0;
    end;
Title: Re: SB_EXT
Post by: rejetto on February 09, 2010, 11:59:14 PM
you are right.
but i opted for a different solution

Code: [Select]
  result:=0;
  case sortby of
    SB_SIZE: result:=compare_(f1.size, f2.size);
    SB_TIME: result:=-compare_(f1.mtime, f2.mtime);
    SB_DL: result:=-compare_(f1.DLcount, f2.DLcount);
    SB_EXT:
      if not f1.isFolder() and not f2.isFolder() then
        result:=compareExt(f1.name, f2.name);
    SB_COMMENT: result:=ansiCompareText(f1.comment, f2.comment);
    end;

because compareText is already done below when result is 0, and we should not mess with folders-before because it's already handled few lines above.