ds@1952: #include "CFileList.h" ds@1952: #include "InstallerUtil.h" ds@1952: ds@1952: using namespace std; ds@1952: ds@1952: CFileList::CFileList(const TCHAR *name) : m_TotalSize(0), m_RecursiveSize(0), ds@1952: m_bGotRecursiveSize(false) ds@1952: { ds@1952: UTIL_Format(m_FolderName, sizeof(m_FolderName) / sizeof(TCHAR), _T("%s"), name); ds@1952: } ds@1952: ds@1952: CFileList::~CFileList() ds@1952: { ds@1952: list::iterator iter; ds@1952: ds@1952: for (iter = m_folder_list.begin(); ds@1952: iter != m_folder_list.end(); ds@1952: iter++) ds@1952: { ds@1952: delete (*iter); ds@1952: } ds@1952: } ds@1952: ds@1952: const TCHAR *CFileList::GetFolderName() ds@1952: { ds@1952: return m_FolderName; ds@1952: } ds@1952: ds@1952: void CFileList::AddFolder(CFileList *pFileList) ds@1952: { ds@1952: m_folder_list.push_back(pFileList); ds@1952: } ds@1952: ds@1952: void CFileList::AddFile(const TCHAR *name, unsigned __int64 size) ds@1952: { ds@1952: CFileListEntry entry; ds@1952: ds@1952: UTIL_Format(entry.file, sizeof(entry.file) / sizeof(TCHAR), _T("%s"), name); ds@1952: entry.size = size; ds@1952: ds@1952: m_file_list.push_back(entry); ds@1952: m_TotalSize += size; ds@1952: } ds@1952: ds@1952: unsigned __int64 CFileList::GetRecursiveSize() ds@1952: { ds@1952: if (m_bGotRecursiveSize) ds@1952: { ds@1952: return m_RecursiveSize; ds@1952: } ds@1952: ds@1952: m_RecursiveSize = m_TotalSize; ds@1952: ds@1952: list::iterator iter; ds@1952: for (iter = m_folder_list.begin(); iter != m_folder_list.end(); iter++) ds@1952: { ds@1952: m_RecursiveSize += (*iter)->GetRecursiveSize(); ds@1952: } ds@1952: ds@1952: m_bGotRecursiveSize = true; ds@1952: ds@1952: return m_RecursiveSize; ds@1952: } ds@1952: ds@1952: const TCHAR *CFileList::PeekCurrentFile() ds@1952: { ds@1952: if (m_file_list.empty()) ds@1952: { ds@1952: return NULL; ds@1952: } ds@1952: ds@1952: return m_file_list.begin()->file; ds@1952: } ds@1952: ds@1952: void CFileList::PopCurrentFile() ds@1952: { ds@1952: m_file_list.erase(m_file_list.begin()); ds@1952: } ds@1952: ds@1952: CFileList *CFileList::PeekCurrentFolder() ds@1952: { ds@1952: if (m_folder_list.empty()) ds@1952: { ds@1952: return NULL; ds@1952: } ds@1952: ds@1952: return *(m_folder_list.begin()); ds@1952: } ds@1952: ds@1952: void CFileList::PopCurrentFolder() ds@1952: { ds@1952: m_folder_list.erase(m_folder_list.begin()); ds@1952: } ds@1952: ds@1952: void RecursiveBuildFileList(CFileList *file_list, const TCHAR *current_folder) ds@1952: { ds@1952: HANDLE hFind; ds@1952: WIN32_FIND_DATA fd; ds@1952: TCHAR path[MAX_PATH]; ds@1952: ds@1952: UTIL_PathFormat(path, sizeof(path) / sizeof(TCHAR), _T("%s\\*.*"), current_folder); ds@1952: ds@1952: if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE) ds@1952: { ds@1952: return; ds@1952: } ds@1952: ds@1952: do ds@1952: { ds@1952: if (tstrcasecmp(fd.cFileName, _T(".")) == 0 ds@1952: || tstrcasecmp(fd.cFileName, _T("..")) == 0) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: ds@1952: if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) ds@1952: { ds@1952: CFileList *pSubList = new CFileList(fd.cFileName); ds@1952: ds@1952: UTIL_PathFormat(path, ds@1952: sizeof(path) / sizeof(TCHAR), ds@1952: _T("%s\\%s"), ds@1952: current_folder, ds@1952: fd.cFileName); ds@1952: ds@1952: RecursiveBuildFileList(pSubList, path); ds@1952: ds@1952: file_list->AddFolder(pSubList); ds@1952: } ds@1952: else ds@1952: { ds@1952: LARGE_INTEGER li; ds@1952: ds@1952: li.LowPart = fd.nFileSizeLow; ds@1952: li.HighPart = fd.nFileSizeHigh; ds@1952: ds@1952: file_list->AddFile(fd.cFileName, li.QuadPart); ds@1952: } ds@1952: } while (FindNextFile(hFind, &fd)); ds@1952: ds@1952: FindClose(hFind); ds@1952: } ds@1952: ds@1952: CFileList *CFileList::BuildFileList(const TCHAR *name, const TCHAR *root_folder) ds@1952: { ds@1952: CFileList *pFileList = new CFileList(name); ds@1952: ds@1952: RecursiveBuildFileList(pFileList, root_folder); ds@1952: ds@1952: return pFileList; ds@1952: }