-
Notifications
You must be signed in to change notification settings - Fork 29
/
sortfcts.cpp
235 lines (194 loc) · 7.81 KB
/
sortfcts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/***************************************************************************
Copyright 2004 Sebastian Ewert
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
#include "resource.h"
#include "globals.h"
/*****************************************************************************
int CALLBACK SortFilename(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
lParam1 : (IN) lparam of the first list view item to be compared
lParam2 : (IN) lparam of the second list view item to be compared
lParamSort : (IN) lParamSort. Application depending value
Return Value:
returns a value comparing the two items
Notes:
- lParamSort is from DlgProc and stores info if we have to sort ascending or
descending
- uses lstrcmpi to compare filenames
*****************************************************************************/
int CALLBACK SortFilename(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
int iResult = QuickCompFunction( &lParam1, &lParam2);
if( (*((DWORD *)lParamSort)) & SORT_FLAG_ASCENDING)
return iResult;
else
return iResult * (-1);
}
/*****************************************************************************
int CALLBACK SortInfo(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
lParam1 : (IN) lparam of the first list view item to be compared
lParam2 : (IN) lparam of the second list view item to be compared
lParamSort : (IN) lParamSort. Application depending value
Return Value:
returns a value comparing the two items
Notes:
- lParamSort is from DlgProc and stores info if we have to sort ascending or
descending
*****************************************************************************/
int CALLBACK SortInfo(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// File OK < File not OK < No CRC/MD5 found < Error
int iResult1, iResult2;
iResult1 = ((FILEINFO *)lParam1)->status;
iResult2 = ((FILEINFO *)lParam2)->status;
if( (*((DWORD *)lParamSort)) & SORT_FLAG_ASCENDING)
return iResult1 - iResult2;
else
return iResult2 - iResult1;
}
/*****************************************************************************
int CALLBACK SortHash(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
lParam1 : (IN) lparam of the first list view item to be compared
lParam2 : (IN) lparam of the second list view item to be compared
lParamSort : (IN) lParamSort. Application dependend value
Return Value:
returns a value comparing the two items
Notes:
- lParamSort is from DlgProc and stores info if we have to sort ascending or
descending
*****************************************************************************/
int CALLBACK SortHash(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
int iResult;
int hash_num = *((DWORD *)lParamSort) >> 8;
if(hash_num == HASH_TYPE_CRC32) {
iResult = CRCI((FILEINFO *)lParam1).r.dwCrc32Result > CRCI((FILEINFO *)lParam2).r.dwCrc32Result;
if(iResult == 0)
iResult = -1;
} else
iResult = memcmp( &((FILEINFO *)lParam1)->hashInfo[hash_num].r, &((FILEINFO *)lParam2)->hashInfo[hash_num].r, g_hash_lengths[hash_num]);
if( (*((DWORD *)lParamSort)) & SORT_FLAG_ASCENDING)
return iResult;
else
return iResult * (-1);
return 0;
}
/*****************************************************************************
FILEINFO_STATUS InfoToIntValue(FILEINFO * pFileinfo)
Fileinfo : (IN) item with the needed info
Return Value:
returns a generated integer value
Notes:
- generated integer is used in MySortInfo to compare items
*****************************************************************************/
FILEINFO_STATUS InfoToIntValue(FILEINFO * pFileinfo)
{
// File OK < File not OK < No CRC/MD5 found < Error
FILEINFO_STATUS iResult;
UINT uiOkCount = 0, uiNotOkCount = 0, uiFilename = 0, uiStream = 0;
if(pFileinfo->dwError != NO_ERROR)
iResult = STATUS_ERROR;
else {
for(int i=0; i < NUM_HASH_TYPES; i++) {
if(pFileinfo->hashInfo.count(i) > 0 && pFileinfo->hashInfo[i].dwFound) {
if( (pFileinfo->parentList->bCalculated[i]) ){
bool bOk = (memcmp( &pFileinfo->hashInfo[i].r,
&pFileinfo->hashInfo[i].f,
g_hash_lengths[i] ) == 0);
if(bOk)
uiOkCount++;
else
uiNotOkCount++;
} else {
if(pFileinfo->hashInfo[i].dwFound == HASH_FOUND_FILENAME)
uiFilename++;
else
uiStream++;
}
}
}
if(uiNotOkCount)
iResult = STATUS_NOT_OK;
else if(uiOkCount)
iResult = STATUS_OK;
else if(uiFilename)
iResult = STATUS_HASH_FILENAME;
else if(uiStream)
iResult = STATUS_HASH_STREAM;
else
iResult = STATUS_NO_CRC;
}
return iResult;
}
bool ListCompFunction(const FILEINFO& pFileinfo1, const FILEINFO& pFileinfo2)
{
TCHAR szFilenameTemp1[MAX_PATH_EX];
TCHAR szFilenameTemp2[MAX_PATH_EX];
INT iDiff;
StringCchCopy(szFilenameTemp1, MAX_PATH_EX, pFileinfo1.szFilename);
StringCchCopy(szFilenameTemp2, MAX_PATH_EX, pFileinfo2.szFilename);
ReduceToPath(szFilenameTemp1);
ReduceToPath(szFilenameTemp2);
iDiff = StrCmpLogicalW( szFilenameTemp1, szFilenameTemp2);
if(iDiff==0)
iDiff = StrCmpLogicalW( pFileinfo1.szFilenameShort, pFileinfo2.szFilenameShort);
if(iDiff < 0)
return true;
else
return false;
}
bool ListPointerCompFunction(const FILEINFO *pFileinfo1, const FILEINFO *pFileinfo2)
{
return ListCompFunction(*pFileinfo1,*pFileinfo2);
}
bool ListPointerUniqFunction(const FILEINFO *pFileinfo1, const FILEINFO *pFileinfo2)
{
return (lstrcmp(pFileinfo1->szFilename,pFileinfo2->szFilename)==0);
}
/*****************************************************************************
VOID QuickSortList()
Return Value:
- returns nothing
*****************************************************************************/
VOID QuickSortList(lFILEINFO *fileList)
{
fileList->fInfos.sort(ListCompFunction);
return;
}
/*****************************************************************************
INT QuickCompFunction(const void * pElem1, const void * pElem2)
Return Value:
- returns a comparison value to signal which element is smaller
Notes:
- compare function for MS qsort
- if you have an array 'int test[5]' then test has the type int * . If qsort sorts
this array both elements that are to be to compared are to of type int *, too.
That means qsort references the items as test + i
*****************************************************************************/
INT QuickCompFunction(const void * pElem1, const void * pElem2)
{
CONST FILEINFO * CONST pFileinfo1 = *(FILEINFO **)pElem1;
CONST FILEINFO * CONST pFileinfo2 = *(FILEINFO **)pElem2;
TCHAR szFilenameTemp1[MAX_PATH_EX];
TCHAR szFilenameTemp2[MAX_PATH_EX];
INT iDiff;
StringCchCopy(szFilenameTemp1, MAX_PATH_EX, pFileinfo1->szFilenameShort);
StringCchCopy(szFilenameTemp2, MAX_PATH_EX, pFileinfo2->szFilenameShort);
ReduceToPath(szFilenameTemp1);
ReduceToPath(szFilenameTemp2);
iDiff = StrCmpLogicalW(szFilenameTemp1, szFilenameTemp2);
if(iDiff != 0)
return iDiff;
else
return StrCmpLogicalW(pFileinfo1->szFilenameShort, pFileinfo2->szFilenameShort);
}