2 #include "InstallerUtil.h"
6 CFileList::CFileList(const TCHAR *name) : m_TotalSize(0), m_RecursiveSize(0),
7 m_bGotRecursiveSize(false)
9 UTIL_Format(m_FolderName, sizeof(m_FolderName) / sizeof(TCHAR), _T("%s"), name);
12 CFileList::~CFileList()
14 list<CFileList *>::iterator iter;
16 for (iter = m_folder_list.begin();
17 iter != m_folder_list.end();
24 const TCHAR *CFileList::GetFolderName()
29 void CFileList::AddFolder(CFileList *pFileList)
31 m_folder_list.push_back(pFileList);
34 void CFileList::AddFile(const TCHAR *name, unsigned __int64 size)
38 UTIL_Format(entry.file, sizeof(entry.file) / sizeof(TCHAR), _T("%s"), name);
41 m_file_list.push_back(entry);
45 unsigned __int64 CFileList::GetRecursiveSize()
47 if (m_bGotRecursiveSize)
49 return m_RecursiveSize;
52 m_RecursiveSize = m_TotalSize;
54 list<CFileList *>::iterator iter;
55 for (iter = m_folder_list.begin(); iter != m_folder_list.end(); iter++)
57 m_RecursiveSize += (*iter)->GetRecursiveSize();
60 m_bGotRecursiveSize = true;
62 return m_RecursiveSize;
65 const TCHAR *CFileList::PeekCurrentFile()
67 if (m_file_list.empty())
72 return m_file_list.begin()->file;
75 void CFileList::PopCurrentFile()
77 m_file_list.erase(m_file_list.begin());
80 CFileList *CFileList::PeekCurrentFolder()
82 if (m_folder_list.empty())
87 return *(m_folder_list.begin());
90 void CFileList::PopCurrentFolder()
92 m_folder_list.erase(m_folder_list.begin());
95 void RecursiveBuildFileList(CFileList *file_list, const TCHAR *current_folder)
101 UTIL_PathFormat(path, sizeof(path) / sizeof(TCHAR), _T("%s\\*.*"), current_folder);
103 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
110 if (tstrcasecmp(fd.cFileName, _T(".")) == 0
111 || tstrcasecmp(fd.cFileName, _T("..")) == 0)
116 if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
118 CFileList *pSubList = new CFileList(fd.cFileName);
120 UTIL_PathFormat(path,
121 sizeof(path) / sizeof(TCHAR),
126 RecursiveBuildFileList(pSubList, path);
128 file_list->AddFolder(pSubList);
134 li.LowPart = fd.nFileSizeLow;
135 li.HighPart = fd.nFileSizeHigh;
137 file_list->AddFile(fd.cFileName, li.QuadPart);
139 } while (FindNextFile(hFind, &fd));
144 CFileList *CFileList::BuildFileList(const TCHAR *name, const TCHAR *root_folder)
146 CFileList *pFileList = new CFileList(name);
148 RecursiveBuildFileList(pFileList, root_folder);