00001 #pragma warning( disable : 4786 )
00002
00003 #include "Util/DirectoryInfo.h"
00004 #include "Util/FileInfo.h"
00005
00006 namespace Impala
00007 {
00008 namespace Util
00009 {
00010
00011
00012 bool DirectoryInfo::mAutoScanSubDirs = false;
00013
00014 #ifndef unix
00015
00016 #include <windows.h>
00017
00018 void
00019 DirectoryInfo::Scan()
00020 {
00021 Clear();
00022 WIN32_FIND_DATA data;
00023 HANDLE h;
00024 std::string pattern(mName);
00025 if(pattern.size() > 0)
00026 pattern.append("/");
00027 pattern.append(mFilter);
00028
00029 h = FindFirstFile(pattern.c_str(), &data);
00030 if (h != INVALID_HANDLE_VALUE)
00031 {
00032 do
00033 {
00034 std::string filename(data.cFileName);
00035 if(filename == ".")
00036 CopyWinFindData(&mInfo, &data);
00037 if(filename != "." && filename != "..")
00038 {
00039 if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00040 {
00041 DirectoryInfo* child;
00042 if(mName[mName.length()-1] != '/' && mName[mName.length()-1] != '\\')
00043 child = new DirectoryInfo(mName + "/" + filename, filename);
00044 else
00045 child = new DirectoryInfo(mName + filename, filename);
00046 if(mAutoScanSubDirs)
00047 child->Scan();
00048 mSubDirs.push_back(child);
00049 }
00050 else
00051 mFiles.push_back(new Util::FileInfo(filename, this));
00052 }
00053 }
00054 while(FindNextFile(h, &data));
00055 }
00056 FindClose(h);
00057 }
00058
00059 void
00060 DirectoryInfo::CopyWinFindData(WIN32_FIND_DATA* dst, const WIN32_FIND_DATA* src) const
00061 {
00062 dst->dwFileAttributes = src->dwFileAttributes;
00063 dst->ftCreationTime = src->ftCreationTime;
00064 dst->ftLastAccessTime = src->ftLastAccessTime;
00065 dst->ftLastWriteTime = src->ftLastWriteTime;
00066 dst->nFileSizeHigh = src->nFileSizeHigh;
00067 dst->nFileSizeLow = src->nFileSizeLow;
00068
00069 memcpy(dst->cFileName, src->cFileName, MAX_PATH);
00070 memcpy(dst->cAlternateFileName, src->cAlternateFileName, 14);
00071 }
00072
00073 #else //defined unix
00074
00075
00076 void DirectoryInfo::Scan()
00077 {
00078 }
00079
00080 #endif //defined unix
00081
00082 }
00083 }