winfs.c

Go to the documentation of this file.
00001 /*
00002  * Winefile
00003  *
00004  * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "winefile.h"
00022 
00023 
00024 /* read a directory entry using the WIN32 file system API */
00025 
00026 void read_directory_win(Entry* dir, LPCTSTR path)
00027 {
00028     Entry* first_entry = NULL;
00029     Entry* last = NULL;
00030     Entry* entry;
00031 
00032     int level = dir->level + 1;
00033     WIN32_FIND_DATA w32fd;
00034     HANDLE hFind;
00035 #ifndef _NO_EXTENSIONS
00036     HANDLE hFile;
00037 #endif
00038 
00039     TCHAR buffer[MAX_PATH], *p;
00040     for(p=buffer; *path; )
00041         *p++ = *path++;
00042 
00043     *p++ = '\\';
00044     p[0] = '*';
00045     p[1] = '\0';
00046 
00047     hFind = FindFirstFile(buffer, &w32fd);
00048 
00049     if (hFind != INVALID_HANDLE_VALUE) {
00050         do {
00051 #ifdef _NO_EXTENSIONS
00052             /* hide directory entry "." */
00053             if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
00054                 LPCTSTR name = w32fd.cFileName;
00055 
00056                 if (name[0]=='.' && name[1]=='\0')
00057                     continue;
00058             }
00059 #endif
00060             entry = alloc_entry();
00061 
00062             if (!first_entry)
00063                 first_entry = entry;
00064 
00065             if (last)
00066                 last->next = entry;
00067 
00068             memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
00069             entry->down = NULL;
00070             entry->up = dir;
00071             entry->expanded = FALSE;
00072             entry->scanned = FALSE;
00073             entry->level = level;
00074 
00075 #ifndef _NO_EXTENSIONS
00076             entry->etype = ET_WINDOWS;
00077             entry->bhfi_valid = FALSE;
00078 
00079             lstrcpy(p, entry->data.cFileName);
00080 
00081             hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
00082                                 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
00083 
00084             if (hFile != INVALID_HANDLE_VALUE) {
00085                 if (GetFileInformationByHandle(hFile, &entry->bhfi))
00086                     entry->bhfi_valid = TRUE;
00087 
00088                 CloseHandle(hFile);
00089             }
00090 #endif
00091 
00092             last = entry;
00093         } while(FindNextFile(hFind, &w32fd));
00094 
00095         if (last)
00096             last->next = NULL;
00097 
00098         FindClose(hFind);
00099     }
00100 
00101     dir->down = first_entry;
00102     dir->scanned = TRUE;
00103 }
00104 
00105 
00106 /* search a Windows directory entry by name */
00107 
00108 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
00109 {
00110     Entry* entry;
00111 
00112     for(entry=dir->down; entry; entry=entry->next) {
00113         LPCTSTR p = name;
00114         LPCTSTR q = entry->data.cFileName;
00115 
00116         do {
00117             if (!*p || *p=='\\' || *p=='/')
00118                 return entry;
00119         } while(tolower(*p++) == tolower(*q++));
00120 
00121         p = name;
00122         q = entry->data.cAlternateFileName;
00123 
00124         do {
00125             if (!*p || *p=='\\' || *p=='/')
00126                 return entry;
00127         } while(tolower(*p++) == tolower(*q++));
00128     }
00129 
00130     return 0;
00131 }
00132 
00133 
00134 /* read a directory tree for the given path using the WIN32 file system API */
00135 
00136 Entry* read_tree_win(Root* root, LPCTSTR path, enum SORT_ORDER sortOrder, HWND hwnd)
00137 {
00138     TCHAR buffer[MAX_PATH];
00139     Entry* entry = &root->entry;
00140     LPCTSTR s = path;
00141     PTSTR d = buffer;
00142 
00143     HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
00144 
00145 #ifndef _NO_EXTENSIONS
00146     entry->etype = ET_WINDOWS;
00147 #endif
00148 
00149     while(entry) {
00150         while(*s && *s!='\\' && *s!='/')
00151             *d++ = *s++;
00152 
00153         while(*s=='\\' || *s=='/')
00154             s++;
00155 
00156         *d++ = '\\';
00157         *d = '\0';
00158 
00159         read_directory(entry, buffer, sortOrder, hwnd);
00160 
00161         if (entry->down)
00162             entry->expanded = TRUE;
00163 
00164         if (!*s)
00165             break;
00166 
00167         entry = find_entry_win(entry, s);
00168     }
00169 
00170     SetCursor(old_cursor);
00171 
00172     return entry;
00173 }

Winefile Source Code Documentation
generated on 15.09.2008 by doxygen

Winefile Homepage