00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "ZipPreviewDlg.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 using namespace fsArchive;
00017
00018 CZipPreviewDlg::CZipPreviewDlg(CWnd* pParent )
00019 : CDialog(CZipPreviewDlg::IDD, pParent)
00020 {
00021 m_ar = NULL;
00022 }
00023
00024 void CZipPreviewDlg::DoDataExchange(CDataExchange* pDX)
00025 {
00026 CDialog::DoDataExchange(pDX);
00027
00028 DDX_Control(pDX, IDC_FILES, m_wndFiles);
00029
00030 }
00031
00032 BEGIN_MESSAGE_MAP(CZipPreviewDlg, CDialog)
00033
00034 ON_BN_CLICKED(IDC_CHECKUNCHECKALL, OnCheckuncheckall)
00035
00036 END_MESSAGE_MAP()
00037
00038 void CZipPreviewDlg::OnOK()
00039 {
00040 if (FALSE == ApplyTreeChecks ())
00041 {
00042 MessageBox (LS (L_SELECTATLEAST1FILE), LS (L_INPERR), MB_ICONEXCLAMATION);
00043 return;
00044 }
00045
00046 CDialog::OnOK();
00047 }
00048
00049 BOOL CZipPreviewDlg::OnInitDialog()
00050 {
00051 CDialog::OnInitDialog();
00052
00053 CBitmap bmp; bmp.Attach (SBMP (IDB_CHECKS));
00054 BITMAP bm; bmp.GetBitmap (&bm);
00055 m_checks.Create (15, bm.bmHeight, ILC_COLOR24|ILC_MASK, 3, 1);
00056 m_checks.Add (&bmp, RGB (255, 0, 255));
00057 m_wndFiles.SetImageList (&m_checks, TVSIL_STATE);
00058
00059 BuildTreeOfFiles ();
00060 TreeToDlg (TVI_ROOT, &m_tFiles);
00061
00062 ApplyLanguage ();
00063
00064 return TRUE;
00065
00066 }
00067
00068 void CZipPreviewDlg::BuildTreeOfFiles()
00069 {
00070 for (int i = 0; i < m_ar->GetFileCount (); i++)
00071 AddToTree (m_ar->GetFileName (i), i, &m_tFiles);
00072 }
00073
00074 void CZipPreviewDlg::AddToTree(LPCSTR pszFile, int iIndex, fs::ListTree <fsFile>* root)
00075 {
00076 LPCSTR pszNextDir = strpbrk (pszFile, "/\\");
00077
00078 if (pszNextDir)
00079 pszNextDir++;
00080
00081 fsString strFileToAdd;
00082
00083 fsFile file;
00084
00085 if (pszNextDir == NULL || *pszNextDir == 0)
00086 {
00087 strFileToAdd = pszFile;
00088 if (pszNextDir)
00089 strFileToAdd [strFileToAdd.Length ()-1] = 0;
00090
00091 for (int i = 0; i < root->GetLeafCount (); i++)
00092 {
00093 if (root->GetLeaf (i)->GetData ().strName == strFileToAdd)
00094 {
00095 root->GetLeaf (i)->GetData ().iIndex = iIndex;
00096 return;
00097 }
00098 }
00099
00100 file.strName = strFileToAdd;
00101 file.iIndex = iIndex;
00102 root->AddLeaf (file);
00103
00104 return;
00105 }
00106
00107 fsString str1stDir;
00108 str1stDir.ncpy (pszFile, pszNextDir-pszFile-1);
00109
00110
00111 for (int i = 0; i < root->GetLeafCount (); i++)
00112 {
00113 if (root->GetLeaf (i)->GetData ().strName == str1stDir)
00114 {
00115
00116 AddToTree (pszNextDir, iIndex, root->GetLeaf (i));
00117 return;
00118 }
00119 }
00120
00121 file.iIndex = -1;
00122 file.strName = str1stDir;
00123 fs::ListTree <fsFile>* t = root->AddLeaf (file);
00124
00125 AddToTree (pszNextDir, iIndex, t);
00126 }
00127
00128 void CZipPreviewDlg::TreeToDlg(HTREEITEM hRoot, fs::ListTree <fsFile>* root)
00129 {
00130 for (int i = 0; i < root->GetLeafCount (); i++)
00131 {
00132 fs::ListTree <fsFile>* t = root->GetLeaf (i);
00133
00134 HTREEITEM ht = m_wndFiles.InsertItem (t->GetData ().strName, hRoot, TVI_LAST);
00135 m_wndFiles.SetItemData (ht, t->GetData ().iIndex);
00136 m_wndFiles.SetCheck (ht, TRUE);
00137
00138 TreeToDlg (ht, t);
00139 }
00140 }
00141
00142 BOOL CZipPreviewDlg::ApplyTreeChecks()
00143 {
00144 fs::list <int> vFiles;
00145 ApplyTreeChecks (TVI_ROOT, vFiles);
00146
00147 if (vFiles.size () == 0)
00148 return FALSE;
00149
00150 fs::list <fsString> vstrFiles;
00151
00152 for (int i = 0; i < vFiles.size (); i++)
00153 vstrFiles.add (m_ar->GetFileName (vFiles [i]));
00154
00155 m_ar->RebuildArchive (vstrFiles);
00156
00157 return TRUE;
00158 }
00159
00160 void CZipPreviewDlg::ApplyTreeChecks(HTREEITEM hRoot, fs::list <int> &vFiles)
00161 {
00162 if (hRoot != TVI_ROOT)
00163 {
00164 if (m_wndFiles.IsChecked (hRoot) == FALSE)
00165 return;
00166
00167 int iIndex = m_wndFiles.GetItemData (hRoot);
00168 if (iIndex != -1)
00169 vFiles.add (iIndex);
00170 }
00171
00172 HTREEITEM hChild = m_wndFiles.GetChildItem (hRoot);
00173
00174 while (hChild)
00175 {
00176 ApplyTreeChecks (hChild, vFiles);
00177 hChild = m_wndFiles.GetNextItem (hChild, TVGN_NEXT);
00178 }
00179 }
00180
00181 void CZipPreviewDlg::ApplyLanguage()
00182 {
00183 fsDlgLngInfo lnginfo [] = {
00184 fsDlgLngInfo (IDC__MSG, L_CHECKFILESTODL),
00185 fsDlgLngInfo (IDC_CHECKUNCHECKALL, L_CHECKUNCHECKALL),
00186 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00187 };
00188
00189 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_ZIPPREVIEW);
00190 }
00191
00192 void CZipPreviewDlg::OnCheckuncheckall()
00193 {
00194 BOOL bChecked = m_wndFiles.IsChecked (m_wndFiles.GetChildItem (TVI_ROOT));
00195 CheckAllItems (TVI_ROOT, !bChecked);
00196 }
00197
00198 void CZipPreviewDlg::CheckAllItems(HTREEITEM hRoot, BOOL bCheck)
00199 {
00200 if (hRoot != TVI_ROOT)
00201 m_wndFiles.SetCheck (hRoot, bCheck);
00202
00203 HTREEITEM hChild = m_wndFiles.GetChildItem (hRoot);
00204
00205 while (hChild)
00206 {
00207 CheckAllItems (hChild, bCheck);
00208 hChild = m_wndFiles.GetNextItem (hChild, TVGN_NEXT);
00209 }
00210 }
00211