2 * Copyright 2003, 2004 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
35 // for UnixDirectory::read_directory()
41 void UnixDirectory::read_directory()
43 Entry
* first_entry
= NULL
;
47 int level
= _level
+ 1;
49 LPCTSTR path
= (LPCTSTR
)_path
;
50 DIR* pdir
= opendir(path
);
55 TCHAR buffer
[MAX_PATH
], *p
;
57 for(p
=buffer
; *path
; )
60 if (p
==buffer
|| p
[-1]!='/')
63 while((ent
=readdir(pdir
))) {
64 int statres
= stat(buffer
, &st
);
66 if (!statres
&& S_ISDIR(st
.st_mode
))
67 entry
= new UnixDirectory(this, buffer
);
69 entry
= new UnixEntry(this);
77 lstrcpy(entry
->_data
.cFileName
, ent
->d_name
);
78 entry
->_data
.dwFileAttributes
= ent
->d_name
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
80 strcpy(p
, ent
->d_name
);
83 if (S_ISDIR(st
.st_mode
))
84 entry
->_data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
86 entry
->_data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
87 entry
->_data
.nFileSizeHigh
= st
.st_size
>> 32;
89 memset(&entry
->_data
.ftCreationTime
, 0, sizeof(FILETIME
));
90 time_to_filetime(&st
.st_atime
, &entry
->_data
.ftLastAccessTime
);
91 time_to_filetime(&st
.st_mtime
, &entry
->_data
.ftLastWriteTime
);
93 entry
->_bhfi
.nFileIndexLow
= ent
->d_ino
;
94 entry
->_bhfi
.nFileIndexHigh
= 0;
96 entry
->_bhfi
.nNumberOfLinks
= st
.st_nlink
;
98 entry
->_bhfi_valid
= TRUE
;
100 entry
->_data
.nFileSizeLow
= 0;
101 entry
->_data
.nFileSizeHigh
= 0;
102 entry
->_bhfi_valid
= FALSE
;
106 entry
->_expanded
= FALSE
;
107 entry
->_scanned
= FALSE
;
108 entry
->_level
= level
;
123 const void* UnixDirectory::get_next_path_component(const void* p
)
125 LPCTSTR s
= (LPCTSTR
) p
;
127 while(*s
&& *s
!=TEXT('/'))
130 while(*s
== TEXT('/'))
140 Entry
* UnixDirectory::find_entry(const void* p
)
142 LPCTSTR name
= (LPCTSTR
)p
;
144 for(Entry
*entry
=_down
; entry
; entry
=entry
->_next
) {
146 LPCTSTR q
= entry
->_data
.cFileName
;
149 if (!*p
|| *p
==TEXT('/'))
151 } while(*p
++ == *q
++);
158 // get full path of specified directory entry
159 bool UnixEntry::get_path(PTSTR path
, size_t path_count
) const
164 if (!path
|| path_count
==0)
167 if ( path_count
> 1 )
169 for(const Entry
* entry
=this; entry
; level
++) {
170 LPCTSTR name
= entry
->_data
.cFileName
;
173 for(LPCTSTR s
=name
; *s
&& *s
!=TEXT('/'); s
++)
178 if ( len
+l
+1 >= path_count
)
180 /* compare to 2 here because of terminator plus the '\\' we prepend */
181 if ( l
+ 2 > path_count
)
184 len
= path_count
- l
- 2;
186 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
187 /* compare to 2 here because of terminator plus the '\\' we prepend */
188 if ( l
+2 >= path_count
)
190 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
198 if ( len
+l
>= path_count
)
200 if ( l
+ 1 > path_count
)
203 len
= path_count
- l
- 1;
205 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
206 if ( l
+1 >= path_count
)
208 memcpy(path
, name
, l
*sizeof(TCHAR
));
214 if ( !level
&& (len
+1 < path_count
) )
215 path
[len
++] = TEXT('/');
218 path
[len
] = TEXT('\0');