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
31 #include "../utility/utility.h"
32 #include "../utility/shellclasses.h"
37 // for UnixDirectory::read_directory()
43 void UnixDirectory::read_directory()
45 Entry* first_entry = NULL;
49 int level = _level + 1;
51 LPCTSTR path = (LPCTSTR)_path;
52 DIR* pdir = opendir(path);
57 TCHAR buffer[MAX_PATH], *p;
59 for(p=buffer; *path; )
62 if (p==buffer || p[-1]!='/')
65 while((ent=readdir(pdir))) {
66 int statres = stat(buffer, &st);
68 if (!statres && S_ISDIR(st.st_mode))
69 entry = new UnixDirectory(this, buffer);
71 entry = new UnixEntry(this);
79 lstrcpy(entry->_data.cFileName, ent->d_name);
80 entry->_data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
82 strcpy(p, ent->d_name);
85 if (S_ISDIR(st.st_mode))
86 entry->_data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
88 entry->_data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
89 entry->_data.nFileSizeHigh = st.st_size >> 32;
91 memset(&entry->_data.ftCreationTime, 0, sizeof(FILETIME));
92 time_to_filetime(&st.st_atime, &entry->_data.ftLastAccessTime);
93 time_to_filetime(&st.st_mtime, &entry->_data.ftLastWriteTime);
95 entry->_bhfi.nFileIndexLow = ent->d_ino;
96 entry->_bhfi.nFileIndexHigh = 0;
98 entry->_bhfi.nNumberOfLinks = st.st_nlink;
100 entry->_bhfi_valid = TRUE;
102 entry->_data.nFileSizeLow = 0;
103 entry->_data.nFileSizeHigh = 0;
104 entry->_bhfi_valid = FALSE;
109 entry->_expanded = FALSE;
110 entry->_scanned = FALSE;
111 entry->_level = level;
126 const void* UnixDirectory::get_next_path_component(const void* p)
128 LPCTSTR s = (LPCTSTR) p;
130 while(*s && *s!=TEXT('/'))
133 while(*s == TEXT('/'))
143 Entry* UnixDirectory::find_entry(const void* p)
145 LPCTSTR name = (LPCTSTR)p;
147 for(Entry*entry=_down; entry; entry=entry->_next) {
149 LPCTSTR q = entry->_data.cFileName;
152 if (!*p || *p==TEXT('/'))
154 } while(*p++ == *q++);
161 // get full path of specified directory entry
162 void UnixEntry::get_path(PTSTR path) const
167 for(const Entry* entry=this; entry; level++) {
168 LPCTSTR name = entry->_data.cFileName;
171 for(LPCTSTR s=name; *s && *s!=TEXT('/'); s++)
176 memmove(path+l+1, path, len*sizeof(TCHAR));
177 memcpy(path+1, name, l*sizeof(TCHAR));
185 memmove(path+l, path, len*sizeof(TCHAR));
186 memcpy(path, name, l*sizeof(TCHAR));
193 path[len++] = TEXT('/');
195 path[len] = TEXT('\0');