15
File& FileList::Add(const File& file)
17
POSITION pos = m_fileList.AddTail((File&)file);
18
return m_fileList.GetAt(pos);
22
void FileList::RemoveAll()
24
m_fileList.RemoveAll();
25
m_fileArray.RemoveAll();
29
void FileList::BuildArray()
31
// Build the file array.
32
m_fileArray.RemoveAll();
33
m_fileArray.SetSize(m_fileList.GetCount());
36
POSITION listPos = m_fileList.GetHeadPosition();
37
while (listPos != NULL)
41
info.m_file = &m_fileList.GetNext(listPos);
42
m_fileArray[arrayPos++] = info;
47
static int __cdecl CompareArray(const void* elem1, const void* elem2)
49
FileList::Info* info1 = (FileList::Info*)elem1;
50
FileList::Info* info2 = (FileList::Info*)elem2;
51
File* file1 = info1->m_file;
52
File* file2 = info2->m_file;
54
int ret = file1->GetShortName().Compare(file2->GetShortName());
57
// If the names match, compare against the file extensions.
58
ret = file1->GetExt().Compare(file2->GetExt());
61
// If the extensions match, compare against the path.
62
ret = file1->GetPath().CompareNoCase(file2->GetPath());
65
file1->SetDuplicate(true);
66
file2->SetDuplicate(true);
76
// Build the file array.
79
// Sort the file array.
80
qsort(m_fileArray.GetData(), m_fileArray.GetSize(), sizeof(Info), CompareArray);
83
for (int curPos = 0; curPos < m_fileArray.GetSize(); curPos++)
85
File& file = *m_fileArray[curPos].m_file;
87
// Check for duplicates.
88
if (!file.m_duplicate)
91
// Found a duplicate... see how many more match.
92
for (int endPos = curPos + 1; endPos < m_fileArray.GetSize(); endPos++)
94
File& fileCmp = *m_fileArray[endPos].m_file;
95
int ret = file.GetShortName().Compare(fileCmp.GetShortName());
99
// If the names match, compare against the file extensions.
100
ret = file.GetExt().Compare(fileCmp.GetExt());
104
// If the extensions match, compare against the path.
105
ret = file.GetPath().CompareNoCase(fileCmp.GetPath());
110
// [endPos] is now the last one that matched.
111
if (endPos - curPos < 2)
118
for (int i = curPos + 1; i < endPos; i++)
120
m_fileList.RemoveAt(m_fileArray[i].m_pos);
123
m_fileArray.RemoveAt(curPos + 1, endPos - curPos - 1);
127
// Find exact file index.
128
int FileList::FindExact(File& file) const
130
// Scan the file list.
131
for (int i = 0; i < GetCount(); i++)
133
File& fileCmp = (*this)[i];
135
// Compare the extension.
136
if (!file.GetExt().IsEmpty() && file.GetExt() != fileCmp.GetExt())
139
// Compare the short name.
140
if (file.GetShortName() != fileCmp.GetShortName())
144
if (file.GetPath().CompareNoCase(fileCmp.GetPath()) == 0)
154
// Find next file index.
155
int FileList::FindNext(int startPos, File& file) const
157
// Scan the file list.
158
for (int i = startPos + 1; i < GetCount(); i++)
160
File& fileCmp = (*this)[i];
162
// Compare the short name.
163
if (file.GetShortName() == fileCmp.GetShortName())
167
for (i = 0; i < startPos; i++)
169
File& fileCmp = (*this)[i];
171
// Compare the short name.
172
if (file.GetShortName() == fileCmp.GetShortName())
180
// Find next file index.
181
int FileList::FindPrevious(int startPos, File& file) const
183
// Scan the file list.
184
for (int i = startPos - 1; i >= 0; i--)
186
File& fileCmp = (*this)[i];
188
// Compare the short name.
189
if (file.GetShortName() == fileCmp.GetShortName())
193
for (i = GetCount() - 1; i > startPos; i--)
195
File& fileCmp = (*this)[i];
197
// Compare the short name.
198
if (file.GetShortName() == fileCmp.GetShortName())