2 * Copyright 2003 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Martin Fuchs, 23.07.2003
29 #include "../utility/utility.h"
30 #include "../utility/shellclasses.h"
36 void WinDirectory::read_directory()
38 Entry* first_entry = NULL;
42 int level = _level + 1;
44 LPCTSTR path = (LPCTSTR)_path;
45 TCHAR buffer[MAX_PATH], *p;
46 for(p=buffer; *path; )
49 lstrcpy(p, TEXT("\\*"));
51 WIN32_FIND_DATA w32fd;
52 HANDLE hFind = FindFirstFile(buffer, &w32fd);
54 if (hFind != INVALID_HANDLE_VALUE) {
56 lstrcpy(p+1, w32fd.cFileName);
58 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
59 entry = new WinDirectory(this, buffer);
61 entry = new WinEntry(this);
69 memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA));
71 entry->_expanded = false;
72 entry->_scanned = false;
73 entry->_level = level;
74 entry->_bhfi_valid = false;
76 HANDLE hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
77 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
79 if (hFile != INVALID_HANDLE_VALUE) {
80 if (GetFileInformationByHandle(hFile, &entry->_bhfi))
81 entry->_bhfi_valid = true;
87 } while(FindNextFile(hFind, &w32fd));
99 const void* WinDirectory::get_next_path_component(const void* p)
101 LPCTSTR s = (LPCTSTR) p;
103 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
106 while(*s==TEXT('\\') || *s==TEXT('/'))
116 Entry* WinDirectory::find_entry(const void* p)
118 LPCTSTR name = (LPCTSTR)p;
120 for(Entry*entry=_down; entry; entry=entry->_next) {
122 LPCTSTR q = entry->_data.cFileName;
125 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
127 } while(tolower(*p++) == tolower(*q++));
130 q = entry->_data.cAlternateFileName;
133 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
135 } while(tolower(*p++) == tolower(*q++));
142 // get full path of specified directory entry
143 void WinEntry::get_path(PTSTR path) const
148 for(const Entry* entry=this; entry; level++) {
149 LPCTSTR name = entry->_data.cFileName;
152 for(LPCTSTR s=name; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
157 memmove(path+l+1, path, len*sizeof(TCHAR));
158 memcpy(path+1, name, l*sizeof(TCHAR));
161 path[0] = TEXT('\\');
166 memmove(path+l, path, len*sizeof(TCHAR));
167 memcpy(path, name, l*sizeof(TCHAR));
174 path[len++] = TEXT('\\');
176 path[len] = TEXT('\0');