/* * Winefile * * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include "winefile.h" /* read a directory entry using the WIN32 file system API */ void read_directory_win(Entry* dir, LPCTSTR path) { Entry* first_entry = NULL; Entry* last = NULL; Entry* entry; int level = dir->level + 1; WIN32_FIND_DATA w32fd; HANDLE hFind; #ifndef _NO_EXTENSIONS HANDLE hFile; #endif TCHAR buffer[MAX_PATH], *p; for(p=buffer; *path; ) *p++ = *path++; *p++ = '\\'; p[0] = '*'; p[1] = '\0'; hFind = FindFirstFile(buffer, &w32fd); if (hFind != INVALID_HANDLE_VALUE) { do { #ifdef _NO_EXTENSIONS /* hide directory entry "." */ if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { LPCTSTR name = w32fd.cFileName; if (name[0]=='.' && name[1]=='\0') continue; } #endif entry = alloc_entry(); if (!first_entry) first_entry = entry; if (last) last->next = entry; memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA)); entry->down = NULL; entry->up = dir; entry->expanded = FALSE; entry->scanned = FALSE; entry->level = level; #ifndef _NO_EXTENSIONS entry->etype = ET_WINDOWS; entry->bhfi_valid = FALSE; lstrcpy(p, entry->data.cFileName); hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); if (hFile != INVALID_HANDLE_VALUE) { if (GetFileInformationByHandle(hFile, &entry->bhfi)) entry->bhfi_valid = TRUE; CloseHandle(hFile); } #endif last = entry; } while(FindNextFile(hFind, &w32fd)); if (last) last->next = NULL; FindClose(hFind); } dir->down = first_entry; dir->scanned = TRUE; } /* search a Windows directory entry by name */ static Entry* find_entry_win(Entry* dir, LPCTSTR name) { Entry* entry; for(entry=dir->down; entry; entry=entry->next) { LPCTSTR p = name; LPCTSTR q = entry->data.cFileName; do { if (!*p || *p=='\\' || *p=='/') return entry; } while(tolower(*p++) == tolower(*q++)); p = name; q = entry->data.cAlternateFileName; do { if (!*p || *p=='\\' || *p=='/') return entry; } while(tolower(*p++) == tolower(*q++)); } return 0; } /* read a directory tree for the given path using the WIN32 file system API */ Entry* read_tree_win(Root* root, LPCTSTR path, enum SORT_ORDER sortOrder, HWND hwnd) { TCHAR buffer[MAX_PATH]; Entry* entry = &root->entry; LPCTSTR s = path; PTSTR d = buffer; HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT)); #ifndef _NO_EXTENSIONS entry->etype = ET_WINDOWS; #endif while(entry) { while(*s && *s!='\\' && *s!='/') *d++ = *s++; while(*s=='\\' || *s=='/') s++; *d++ = '\\'; *d = '\0'; read_directory(entry, buffer, sortOrder, hwnd); if (entry->down) entry->expanded = TRUE; if (!*s) break; entry = find_entry_win(entry, s); } SetCursor(old_cursor); return entry; }