1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2014 - TortoiseSVN
4 // Copyright (C) 2008-2017 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "GitStatusListCtrl.h"
24 #include "ColumnManager.h"
26 // sorter utility class
27 CSorter::CSorter ( ColumnManager
* columnManager
30 : columnManager (columnManager
)
31 , sortedColumn (sortedColumn
)
32 , ascending (ascending
)
34 s_bSortLogical
= !CRegDWORD(L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\NoStrCmpLogical", 0, false, HKEY_CURRENT_USER
);
36 s_bSortLogical
= !CRegDWORD(L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\NoStrCmpLogical", 0, false, HKEY_LOCAL_MACHINE
);
39 bool CSorter::operator() (const CTGitPath
* entry1
, const CTGitPath
* entry2
) const
41 #define SGN(x) ((x)==0?0:((x)>0?1:-1))
50 __int64 fileSize1
= entry1
->IsDirectory() ? 0 : entry1
->GetFileSize();
51 __int64 fileSize2
= entry2
->IsDirectory() ? 0 : entry2
->GetFileSize();
53 result
= SGN(fileSize1
- fileSize2
);
57 case 6: //Last Modification Date
61 __int64 writetime1
= entry1
->GetLastWriteTime();
62 __int64 writetime2
= entry2
->GetLastWriteTime();
64 FILETIME
* filetime1
= (FILETIME
*)(__int64
*)&writetime1
;
65 FILETIME
* filetime2
= (FILETIME
*)(__int64
*)&writetime2
;
67 result
= CompareFileTime(filetime1
, filetime2
);
74 result
= SGN(A2L(entry1
->m_StatDel
) - A2L(entry2
->m_StatDel
));
80 result
= SGN(A2L(entry1
->m_StatAdd
) - A2L(entry2
->m_StatAdd
));
87 result
= entry1
->GetActionName(entry1
->m_Action
).CompareNoCase(entry2
->GetActionName(entry2
->m_Action
));
95 result
= StrCmpLogicalW(entry1
->GetFileExtension(), entry2
->GetFileExtension());
97 result
= StrCmpI(entry1
->GetFileExtension(), entry2
->GetFileExtension());
106 result
= StrCmpLogicalW(entry1
->GetFileOrDirectoryName(), entry2
->GetFileOrDirectoryName());
108 result
= StrCmpI(entry1
->GetFileOrDirectoryName(), entry2
->GetFileOrDirectoryName());
112 case 0: // Full path column
117 result
= StrCmpLogicalW(entry1
->GetGitPathString(), entry2
->GetGitPathString());
119 result
= StrCmpI(entry1
->GetGitPathString(), entry2
->GetGitPathString());
123 } // switch (m_nSortedColumn)
124 // sort by path name as second priority
125 if (sortedColumn
> 0 && result
== 0)
128 result
= StrCmpLogicalW(entry1
->GetGitPathString(), entry2
->GetGitPathString());
130 result
= StrCmpI(entry1
->GetGitPathString(), entry2
->GetGitPathString());