Index: src/ch/CustomCopyDlg.cpp =================================================================== diff -u -rc435ab507c8b8280264188b49e9ada56d46c0261 -r8068e0c351055554340ac9755d1bc846893bf2b8 --- src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision c435ab507c8b8280264188b49e9ada56d46c0261) +++ src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) @@ -17,16 +17,18 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "stdafx.h" +#include #include "resource.h" -#include "FileInfo.h" +#include "../libchcore/TFileInfo.h" #include "CustomCopyDlg.h" #include "structs.h" #include "dialogs.h" #include "BufferSizeDlg.h" #include "FilterDlg.h" #include "StringHelpers.h" #include "ch.h" -#include +#include "../libchcore/TTaskConfigBufferSizes.h" +#include "CfgProperties.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -38,47 +40,28 @@ // CCustomCopyDlg dialog -CCustomCopyDlg::CCustomCopyDlg() :ictranslate::CLanguageDialog(CCustomCopyDlg::IDD) +CCustomCopyDlg::CCustomCopyDlg() : + ictranslate::CLanguageDialog(IDD_CUSTOM_COPY_DIALOG) { - //{{AFX_DATA_INIT(CCustomCopyDlg) - m_ucCount = 1; - m_bOnlyCreate = FALSE; - m_bIgnoreFolders = FALSE; - m_bFilters = FALSE; - m_bAdvanced = FALSE; - m_bForceDirectories = FALSE; - //}}AFX_DATA_INIT - -// m_ccData.m_astrPaths.RemoveAll(); // unneeded -// m_ccData.m_strDestPath.Empty(); - - m_ccData.m_iOperation=0; - m_ccData.m_iPriority=THREAD_PRIORITY_NORMAL; - m_ccData.m_ucCount=1; + GetConfig().ExtractSubConfig(BRANCH_TASK_SETTINGS, m_tTaskDefinition.GetConfiguration()); +} - // m_ccData.m_bsSizes stays uninitialized - // m_ccData.m_afFilters - this too - - m_ccData.m_bIgnoreFolders=false; - m_ccData.m_bForceDirectories=false; - m_ccData.m_bCreateStructure=false; - - m_bActualisation=false; +CCustomCopyDlg::CCustomCopyDlg(const chcore::TTaskDefinition& rTaskDefinition) : + ictranslate::CLanguageDialog(IDD_CUSTOM_COPY_DIALOG), + m_tTaskDefinition(rTaskDefinition) +{ } void CCustomCopyDlg::DoDataExchange(CDataExchange* pDX) { CLanguageDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCustomCopyDlg) DDX_Control(pDX, IDC_DESTPATH_COMBOBOXEX, m_ctlDstPath); - DDX_Control(pDX, IDC_COUNT_SPIN, m_ctlCountSpin); DDX_Control(pDX, IDC_FILTERS_LIST, m_ctlFilters); DDX_Control(pDX, IDC_BUFFERSIZES_LIST, m_ctlBufferSizes); DDX_Control(pDX, IDC_OPERATION_COMBO, m_ctlOperation); DDX_Control(pDX, IDC_PRIORITY_COMBO, m_ctlPriority); DDX_Control(pDX, IDC_FILES_LIST, m_ctlFiles); - DDX_Text(pDX, IDC_COUNT_EDIT, m_ucCount); - DDV_MinMaxByte(pDX, m_ucCount, 1, 255); DDX_Check(pDX, IDC_ONLYSTRUCTURE_CHECK, m_bOnlyCreate); DDX_Check(pDX, IDC_IGNOREFOLDERS_CHECK, m_bIgnoreFolders); DDX_Check(pDX, IDC_FORCEDIRECTORIES_CHECK, m_bForceDirectories); @@ -87,7 +70,6 @@ //}}AFX_DATA_MAP } - BEGIN_MESSAGE_MAP(CCustomCopyDlg,ictranslate::CLanguageDialog) //{{AFX_MSG_MAP(CCustomCopyDlg) ON_BN_CLICKED(IDC_ADDDIR_BUTTON, OnAddDirectoryButton) @@ -107,6 +89,8 @@ ON_BN_CLICKED(IDC_IMPORT_BUTTON, OnImportButton) ON_BN_CLICKED(IDC_IGNOREFOLDERS_CHECK, OnIgnorefoldersCheck) ON_BN_CLICKED(IDC_FORCEDIRECTORIES_CHECK, OnForcedirectoriesCheck) + ON_BN_CLICKED(IDC_EXPORT_BUTTON, OnExportButtonClicked) + ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -131,14 +115,11 @@ AddResizableControl(IDC_007_STATIC, 0.5, 0.5, 0.0, 0.0); AddResizableControl(IDC_BAR2_STATIC, 0.5, 0.5, 0.5, 0.0); - AddResizableControl(IDC_003_STATIC, 0.0, 0.5, 0.33, 0.0); - AddResizableControl(IDC_004_STATIC, 0.33, 0.5, 0.33, 0.0); - AddResizableControl(IDC_005_STATIC, 0.66, 0.5, 0.33, 0.0); + AddResizableControl(IDC_003_STATIC, 0.0, 0.5, 0.5, 0.0); + AddResizableControl(IDC_004_STATIC, 0.5, 0.5, 0.5, 0.0); - AddResizableControl(IDC_OPERATION_COMBO, 0.0, 0.5, 0.33, 0.0); - AddResizableControl(IDC_PRIORITY_COMBO, 0.33, 0.5, 0.33, 0.0); - AddResizableControl(IDC_COUNT_SPIN, 1.0, 0.5, 0.0, 0.0); - AddResizableControl(IDC_COUNT_EDIT, 0.66, 0.5, 0.33, 0.0); + AddResizableControl(IDC_OPERATION_COMBO, 0.0, 0.5, 0.5, 0.0); + AddResizableControl(IDC_PRIORITY_COMBO, 0.5, 0.5, 0.5, 0.0); AddResizableControl(IDC_006_STATIC, 0.0, 0.5, 1.0, 0.0); AddResizableControl(IDC_BUFFERSIZES_LIST, 0.0, 0.5, 1.0, 0.0); @@ -161,6 +142,7 @@ AddResizableControl(IDOK, 1.0, 1.0, 0.0, 0.0); AddResizableControl(IDCANCEL, 1.0, 1.0, 0.0, 0.0); AddResizableControl(IDC_HELP_BUTTON, 1.0, 1.0, 0.0, 0.0); + AddResizableControl(IDC_EXPORT_BUTTON, 0.0, 1.0, 0.0, 0.0); InitializeResizableControls(); @@ -169,7 +151,7 @@ // paths' listbox - init images - system image list SHFILEINFO sfi; - HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); m_ilImages.Attach(hImageList); @@ -181,8 +163,7 @@ rc.right-=GetSystemMetrics(SM_CXEDGE)*2; // some styles - m_ctlFiles.SetExtendedStyle(m_ctlFiles.GetExtendedStyle() | LVS_EX_FULLROWSELECT); - m_ctlFilters.SetExtendedStyle(m_ctlFiles.GetExtendedStyle() | LVS_EX_FULLROWSELECT); + m_ctlFilters.SetExtendedStyle(m_ctlFilters.GetExtendedStyle() | LVS_EX_FULLROWSELECT); // paths' listbox - add one column LVCOLUMN lvc; @@ -192,8 +173,10 @@ m_ctlFiles.InsertColumn(1, &lvc); // fill paths' listbox - for (int i=0;i(m_tTaskDefinition.GetConfiguration()))); - // count of copies - m_ucCount=m_ccData.m_ucCount; - m_ctlCountSpin.SetRange(1, 255); - // fill buffer sizes listbox SetBuffersizesString(); // list width m_ctlFilters.GetWindowRect(&rc); - rc.right-=GetSystemMetrics(SM_CXEDGE)*2; + rc.right -= GetSystemMetrics(SM_CXEDGE)*2; // filter - some columns in a header lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; @@ -291,14 +269,14 @@ lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.1*rc.Width()); m_ctlFilters.InsertColumn(6, &lvc); - - m_bFilters = !m_ccData.m_afFilters.IsEmpty(); + m_bFilters = !m_tTaskDefinition.GetFilters().IsEmpty(); + // other custom flags - m_bAdvanced=(m_ccData.m_bIgnoreFolders | m_ccData.m_bCreateStructure); - m_bIgnoreFolders=m_ccData.m_bIgnoreFolders; - m_bForceDirectories=m_ccData.m_bForceDirectories; - m_bOnlyCreate=m_ccData.m_bCreateStructure; + m_bIgnoreFolders = chcore::GetTaskPropValue(m_tTaskDefinition.GetConfiguration()); + m_bForceDirectories = chcore::GetTaskPropValue(m_tTaskDefinition.GetConfiguration()); + m_bOnlyCreate = chcore::GetTaskPropValue(m_tTaskDefinition.GetConfiguration()); + m_bAdvanced = (m_bIgnoreFolders | m_bForceDirectories | m_bOnlyCreate); UpdateData(FALSE); @@ -312,16 +290,8 @@ UpdateData(TRUE); // count the width of a list - CRect rc; - m_ctlFiles.GetWindowRect(&rc); - rc.right-=GetSystemMetrics(SM_CXEDGE)*2; + UpdateFilesListCtrlHeaderWidth(); - // change the width of a column - LVCOLUMN lvc; - lvc.mask=LVCF_WIDTH; - lvc.cx=rc.Width(); - m_ctlFiles.SetColumn(0, &lvc); - // operation int iPos=m_ctlOperation.GetCurSel(); m_ctlOperation.ResetContent(); @@ -344,6 +314,11 @@ // filter section (filter, size, date, attributes) while(m_ctlFilters.DeleteColumn(0)); // delete all columns + CRect rc; + m_ctlFilters.GetWindowRect(&rc); + rc.right -= GetSystemMetrics(SM_CXEDGE) * 2; + + LVCOLUMN lvc; lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; lvc.fmt=LVCFMT_LEFT; @@ -390,10 +365,11 @@ m_ctlFilters.InsertColumn(6, &lvc); // refresh the entries in filters' list + const chcore::TFileFiltersArray& afFilters = m_tTaskDefinition.GetFilters(); m_ctlFilters.DeleteAllItems(); - for (size_t stIndex = 0; stIndex < m_ccData.m_afFilters.GetSize(); ++stIndex) + for(size_t stIndex = 0; stIndex < afFilters.GetSize(); ++stIndex) { - const CFileFilter* pFilter = m_ccData.m_afFilters.GetAt(stIndex); + const chcore::TFileFilter* pFilter = afFilters.GetAt(stIndex); if(pFilter) AddFilter(*pFilter, boost::numeric_cast(stIndex)); } @@ -408,7 +384,7 @@ void CCustomCopyDlg::OnAddFilesButton() { - CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager().LoadString(IDS_FILEDLGALLFILTER_STRING), this); + CFileDialog dlg(TRUE, nullptr, nullptr, OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager().LoadString(IDS_FILEDLGALLFILTER_STRING), this); TCHAR *pszBuffer = new TCHAR[65535]; memset(pszBuffer, 0, 65535*sizeof(TCHAR)); @@ -449,7 +425,7 @@ while (true) { pos = m_ctlFiles.GetFirstSelectedItemPosition(); - if (pos == NULL) + if (pos == nullptr) break; else { @@ -464,46 +440,23 @@ CString strPath; if (BrowseForFolder(GetResManager().LoadString(IDS_DSTFOLDERBROWSE_STRING), &strPath)) { - SetComboPath(strPath); -// m_strDest=strPath; //** + m_ctlDstPath.SetPath(strPath); } } void CCustomCopyDlg::OnOK() { UpdateData(TRUE); - // copy files from listctrl to an array - m_ccData.m_astrPaths.RemoveAll(); - CString strPath; + if(!HasBasicTaskData()) + { + MsgBox(IDS_MISSINGDATA_STRING); + return; + } - for (int i=0;im_bUseMask) - dlg.m_astrAddMask.Add(pFilter->GetCombinedMask(strData)); - if(pFilter->m_bUseExcludeMask) - dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask(strData)); + if(pFilter->GetUseMask()) + dlg.m_astrAddMask.Add(pFilter->GetCombinedMask().c_str()); + if(pFilter->GetUseExcludeMask()) + dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask().c_str()); } } - if (dlg.DoModal() == IDOK) + if(dlg.DoModal() == IDOK) { - if (dlg.m_ffFilter.m_bUseMask || dlg.m_ffFilter.m_bUseExcludeMask || dlg.m_ffFilter.m_bUseSize - || dlg.m_ffFilter.m_bUseDate || dlg.m_ffFilter.m_bUseAttributes) + if(dlg.m_ffFilter.GetUseMask() || dlg.m_ffFilter.GetUseExcludeMask() || dlg.m_ffFilter.GetUseSize1() || dlg.m_ffFilter.GetUseDateTime1() || dlg.m_ffFilter.GetUseAttributes()) { - m_ccData.m_afFilters.Add(dlg.m_ffFilter); + afFilters.Add(dlg.m_ffFilter); AddFilter(dlg.m_ffFilter); } else MsgBox(IDS_EMPTYFILTER_STRING, MB_OK | MB_ICONINFORMATION); } } -void CCustomCopyDlg::AddFilter(const CFileFilter &rFilter, int iPos) +void CCustomCopyDlg::AddFilter(const chcore::TFileFilter &rFilter, int iPos) { LVITEM lvi; - TCHAR szLoaded[1024]; - TCHAR szData[64]; + CString strLoaded; lvi.mask=LVIF_TEXT; lvi.iItem=(iPos == -1) ? m_ctlFilters.GetItemCount() : iPos; ///////////////////// lvi.iSubItem=0; - if (rFilter.m_bUseMask) + if (rFilter.GetUseMask()) { - CString strData; - rFilter.GetCombinedMask(strData); - _tcscpy(szLoaded, strData); + chcore::TString strData = rFilter.GetCombinedMask(); + strLoaded = strData.c_str(); } else - _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERMASKEMPTY_STRING)); + strLoaded = GetResManager().LoadString(IDS_FILTERMASKEMPTY_STRING); - lvi.pszText=szLoaded; + lvi.pszText = (PTSTR)(PCTSTR)strLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); m_ctlFilters.InsertItem(&lvi); ///////////////////// lvi.iSubItem=1; - if (rFilter.m_bUseExcludeMask) + if(rFilter.GetUseExcludeMask()) { - CString strData; - rFilter.GetCombinedExcludeMask(strData); - _tcscpy(szLoaded, strData); + chcore::TString strData = rFilter.GetCombinedExcludeMask(); + strLoaded = strData.c_str(); } else - _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERMASKEMPTY_STRING)); + strLoaded = GetResManager().LoadString(IDS_FILTERMASKEMPTY_STRING); - lvi.pszText=szLoaded; + lvi.pszText = (PTSTR)(PCTSTR)strLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); m_ctlFilters.SetItem(&lvi); ///////////////// lvi.iSubItem=2; - if (rFilter.m_bUseSize) + if (rFilter.GetUseSize1()) { - _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager().LoadString(IDS_LT_STRING+rFilter.m_iSizeType1), GetSizeString(rFilter.m_ullSize1, szData, 64, true)); - szLoaded[1023] = _T('\0'); - if (rFilter.m_bUseSize2) + strLoaded.Format(_T("%s %s"), GetResManager().LoadString(IDS_LT_STRING+rFilter.GetSizeType1()), (PCTSTR)GetSizeString(rFilter.GetSize1(), true)); + if (rFilter.GetUseSize2()) { - _tcscat(szLoaded, GetResManager().LoadString(IDS_AND_STRING)); - CString strLoaded2; - strLoaded2.Format(_T("%s %s"), GetResManager().LoadString(IDS_LT_STRING+rFilter.m_iSizeType2), GetSizeString(rFilter.m_ullSize2, szData, 64, true)); - _tcscat(szLoaded, strLoaded2); + strLoaded += GetResManager().LoadString(IDS_AND_STRING); + strLoaded.AppendFormat(_T("%s %s"), GetResManager().LoadString(IDS_LT_STRING+rFilter.GetSizeType2()), (PCTSTR)GetSizeString(rFilter.GetSize2(), true)); } } else - _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERSIZE_STRING)); + strLoaded = GetResManager().LoadString(IDS_FILTERSIZE_STRING); - lvi.pszText=szLoaded; + lvi.pszText = (PTSTR)(PCTSTR)strLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); m_ctlFilters.SetItem(&lvi); /////////////////// lvi.iSubItem=3; - if (rFilter.m_bUseDate) + if (rFilter.GetUseDateTime1()) { - _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager().LoadString(IDS_DATECREATED_STRING+rFilter.m_iDateType), GetResManager().LoadString(IDS_LT_STRING+rFilter.m_iDateType1)); - szLoaded[1023] = _T('\0'); - if (rFilter.m_bDate1) - _tcscat(szLoaded, rFilter.m_tDate1.Format(_T(" %x"))); - if (rFilter.m_bTime1) - _tcscat(szLoaded, rFilter.m_tTime1.Format(_T(" %X"))); + strLoaded.Format(_T("%s %s"), GetResManager().LoadString(IDS_DATECREATED_STRING+rFilter.GetDateType()), GetResManager().LoadString(IDS_LT_STRING+rFilter.GetDateCmpType1())); - if (rFilter.m_bUseDate2) + chcore::TString strFmtDateTime = rFilter.GetDateTime1().Format(rFilter.GetUseDate1(), rFilter.GetUseTime1()); + strLoaded += strFmtDateTime.c_str(); + + if (rFilter.GetUseDateTime2()) { - _tcscat(szLoaded, GetResManager().LoadString(IDS_AND_STRING)); - _tcscat(szLoaded, GetResManager().LoadString(IDS_LT_STRING+rFilter.m_iDateType2)); - if (rFilter.m_bDate2) - _tcscat(szLoaded, rFilter.m_tDate2.Format(_T(" %x"))); - if (rFilter.m_bTime2) - _tcscat(szLoaded, rFilter.m_tTime2.Format(_T(" %X"))); + strLoaded += GetResManager().LoadString(IDS_AND_STRING); + strLoaded += GetResManager().LoadString(IDS_LT_STRING + rFilter.GetDateCmpType2()); + + strFmtDateTime = rFilter.GetDateTime2().Format(rFilter.GetUseDate2(), rFilter.GetUseTime2()); + strLoaded += strFmtDateTime.c_str(); } } else - _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERDATE_STRING)); + strLoaded = GetResManager().LoadString(IDS_FILTERDATE_STRING); - lvi.pszText=szLoaded; + lvi.pszText = (PTSTR)(PCTSTR)strLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); m_ctlFilters.SetItem(&lvi); ///////////////////// lvi.iSubItem=4; - szLoaded[0]=_T('\0'); - if (rFilter.m_bUseAttributes) + strLoaded.Empty(); + if(rFilter.GetUseAttributes()) { - if (rFilter.m_iArchive == 1) - _tcscat(szLoaded, _T("A")); - if (rFilter.m_iReadOnly == 1) - _tcscat(szLoaded, _T("R")); - if (rFilter.m_iHidden == 1) - _tcscat(szLoaded, _T("H")); - if (rFilter.m_iSystem == 1) - _tcscat(szLoaded, _T("S")); - if (rFilter.m_iDirectory == 1) - _tcscat(szLoaded, _T("D")); + if(rFilter.GetArchive() == 1) + strLoaded += L"A"; + if(rFilter.GetReadOnly() == 1) + strLoaded += _T("R"); + if(rFilter.GetHidden() == 1) + strLoaded += _T("H"); + if(rFilter.GetSystem() == 1) + strLoaded += _T("S"); + if(rFilter.GetDirectory() == 1) + strLoaded += _T("D"); } - if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('\0')) - _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERATTRIB_STRING)); + if (!rFilter.GetUseAttributes() || strLoaded.IsEmpty()) + strLoaded = GetResManager().LoadString(IDS_FILTERATTRIB_STRING); - lvi.pszText=szLoaded; + lvi.pszText = (PTSTR)(PCTSTR)strLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); m_ctlFilters.SetItem(&lvi); ///////////////////// lvi.iSubItem=5; - szLoaded[0]=_T('\0'); - if (rFilter.m_bUseAttributes) + strLoaded.Empty(); + if(rFilter.GetUseAttributes()) { - if (rFilter.m_iArchive == 0) - _tcscat(szLoaded, _T("A")); - if (rFilter.m_iReadOnly == 0) - _tcscat(szLoaded, _T("R")); - if (rFilter.m_iHidden == 0) - _tcscat(szLoaded, _T("H")); - if (rFilter.m_iSystem == 0) - _tcscat(szLoaded, _T("S")); - if (rFilter.m_iDirectory == 0) - _tcscat(szLoaded, _T("D")); + if(rFilter.GetArchive() == 0) + strLoaded += _T("A"); + if(rFilter.GetReadOnly() == 0) + strLoaded += _T("R"); + if(rFilter.GetHidden() == 0) + strLoaded += _T("H"); + if(rFilter.GetSystem() == 0) + strLoaded += _T("S"); + if(rFilter.GetDirectory() == 0) + strLoaded += _T("D"); } - if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('0')) - _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERATTRIB_STRING)); + if(!rFilter.GetUseAttributes() || strLoaded.IsEmpty()) + strLoaded = GetResManager().LoadString(IDS_FILTERATTRIB_STRING); - lvi.pszText=szLoaded; + lvi.pszText = (PTSTR)(PCTSTR)strLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); m_ctlFilters.SetItem(&lvi); } void CCustomCopyDlg::OnRemovefilterButton() { + chcore::TFileFiltersArray& afFilters = m_tTaskDefinition.GetFilters(); + POSITION pos; int iItem; - while (true) + while(true) { pos=m_ctlFilters.GetFirstSelectedItemPosition(); - if (pos == NULL) + if (pos == nullptr) break; else { iItem=m_ctlFilters.GetNextSelectedItem(pos); m_ctlFilters.DeleteItem(iItem); - m_ccData.m_afFilters.RemoveAt(iItem); + afFilters.RemoveAt(iItem); } } } void CCustomCopyDlg::OnDestroy() { - m_ctlFiles.SetImageList(NULL, LVSIL_SMALL); + m_ctlFiles.SetImageList(nullptr, LVSIL_SMALL); m_ilImages.Detach(); CLanguageDialog::OnDestroy(); @@ -804,27 +752,28 @@ void CCustomCopyDlg::OnDblclkFiltersList(NMHDR* /*pNMHDR*/, LRESULT* pResult) { - POSITION pos=m_ctlFilters.GetFirstSelectedItemPosition(); - if (pos != NULL) + POSITION pos = m_ctlFilters.GetFirstSelectedItemPosition(); + if(pos != nullptr) { - int iItem=m_ctlFilters.GetNextSelectedItem(pos); + chcore::TFileFiltersArray& afFilters = m_tTaskDefinition.GetFilters(); + + int iItem = m_ctlFilters.GetNextSelectedItem(pos); CFilterDlg dlg; - const CFileFilter* pFilter = m_ccData.m_afFilters.GetAt(iItem); + const chcore::TFileFilter* pFilter = afFilters.GetAt(iItem); BOOST_ASSERT(pFilter); if(pFilter) - dlg.m_ffFilter = *pFilter; + dlg.m_ffFilter = *pFilter; - CString strData; - for (size_t stIndex = 0; stIndex < m_ccData.m_afFilters.GetSize(); ++stIndex) + for(size_t stIndex = 0; stIndex < afFilters.GetSize(); ++stIndex) { - pFilter = m_ccData.m_afFilters.GetAt(stIndex); + pFilter = afFilters.GetAt(stIndex); BOOST_ASSERT(pFilter); if(pFilter) { - if(pFilter->m_bUseMask && boost::numeric_cast(stIndex) != iItem) - dlg.m_astrAddMask.Add(pFilter->GetCombinedMask(strData)); - if (pFilter->m_bUseExcludeMask && boost::numeric_cast(stIndex) != iItem) - dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask(strData)); + if(pFilter->GetUseMask() && boost::numeric_cast(stIndex) != iItem) + dlg.m_astrAddMask.Add(pFilter->GetCombinedMask().c_str()); + if (pFilter->GetUseExcludeMask() && boost::numeric_cast(stIndex) != iItem) + dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask().c_str()); } } @@ -835,10 +784,10 @@ //m_ccData.m_afFilters.RemoveAt(iItem); // insert new if needed - if (dlg.m_ffFilter.m_bUseMask || dlg.m_ffFilter.m_bUseExcludeMask || dlg.m_ffFilter.m_bUseSize - || dlg.m_ffFilter.m_bUseDate || dlg.m_ffFilter.m_bUseAttributes) + if (dlg.m_ffFilter.GetUseMask() || dlg.m_ffFilter.GetUseExcludeMask() || dlg.m_ffFilter.GetUseSize1() + || dlg.m_ffFilter.GetUseDateTime1() || dlg.m_ffFilter.GetUseAttributes()) { - m_ccData.m_afFilters.SetAt(iItem, dlg.m_ffFilter); + afFilters.SetAt(iItem, dlg.m_ffFilter); AddFilter(dlg.m_ffFilter, iItem); } } @@ -849,44 +798,20 @@ void CCustomCopyDlg::OnDblclkBuffersizesList() { - int iItem=m_ctlBufferSizes.GetCurSel(); - if (iItem != LB_ERR) + int iItem = m_ctlBufferSizes.GetCurSel(); + if(iItem != LB_ERR) { - CBufferSizeDlg dlg; - dlg.m_bsSizes=m_ccData.m_bsSizes; - dlg.m_iActiveIndex=iItem; - if (dlg.DoModal() == IDOK) + chcore::TBufferSizes tBufferSizes = GetTaskPropBufferSizes(m_tTaskDefinition.GetConfiguration()); + CBufferSizeDlg dlg(&tBufferSizes, (chcore::TBufferSizes::EBufferType)iItem); + + if(dlg.DoModal() == IDOK) { - m_ccData.m_bsSizes=dlg.m_bsSizes; + SetTaskPropBufferSizes(m_tTaskDefinition.GetConfiguration(), dlg.GetBufferSizes()); SetBuffersizesString(); } } } -void CCustomCopyDlg::SetComboPath(LPCTSTR lpszText) -{ - _ASSERTE(lpszText); - if(!lpszText) - return; - - // set current select to -1 - m_ctlDstPath.SetCurSel(-1); - - SHFILEINFO sfi; - sfi.iIcon=-1; - - COMBOBOXEXITEM cbi; - TCHAR szPath[_MAX_PATH]; - - cbi.mask=CBEIF_TEXT | CBEIF_IMAGE; - cbi.iItem=-1; - _tcscpy(szPath, lpszText); - cbi.pszText=szPath; - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - cbi.iImage=sfi.iIcon; - m_ctlDstPath.SetItem(&cbi); -} - void CCustomCopyDlg::UpdateComboIcon() { // get text from combo @@ -938,31 +863,30 @@ void CCustomCopyDlg::OnImportButton() { boost::shared_array spBuffer; - ulong_t ulSize = 0; - CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager().LoadString(IDS_FLTALLFILTER_STRING)); + CFileDialog dlg(TRUE, nullptr, nullptr, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager().LoadString(IDS_FLTALLFILTER_STRING)); if(dlg.DoModal() == IDOK) { + unsigned long ulSize = 0; UINT uiCount=0; try { - icpf::file file; - file.open(dlg.GetPathName(), FA_READ); + CFile file(dlg.GetPathName(), CFile::modeRead); // load files max 1MB in size; - ll_t llSize = file.get_size(); - if(llSize > 1*1024*1024 || llSize < 2) + unsigned long long ullSize = file.GetLength(); + if(ullSize > 1*1024*1024 || ullSize < 2) { AfxMessageBox(GetResManager().LoadString(IDS_IMPORTERROR_STRING)); return; } - ulong_t ulSize = boost::numeric_cast(llSize); + ulSize = boost::numeric_cast(ullSize); spBuffer.reset(new BYTE[ulSize + 3]); // guarantee that we have null at the end of the string (3 bytes to compensate for possible odd number of bytes and for unicode) memset(spBuffer.get(), 0, ulSize + 3); - ulSize = file.read(spBuffer.get(), ulSize); - file.close(); + ulSize = file.Read(spBuffer.get(), ulSize); + file.Close(); } catch(...) { @@ -1020,7 +944,7 @@ // report ictranslate::CFormat fmt(GetResManager().LoadString(IDS_IMPORTREPORT_STRING)); - fmt.SetParam(_t("%count"), uiCount); + fmt.SetParam(_T("%count"), uiCount); AfxMessageBox(fmt); } } @@ -1038,3 +962,100 @@ GetDlgItem(IDC_FORCEDIRECTORIES_CHECK)->EnableWindow(!m_bIgnoreFolders); } + +void CCustomCopyDlg::OnExportButtonClicked() +{ + UpdateData(TRUE); + + if (!HasBasicTaskData()) + { + MsgBox(IDS_MISSINGDATA_STRING); + return; + } + + UpdateInternalTaskDefinition(); + + CFileDialog dlg(FALSE, _T("xml"), _T("Task"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager().LoadString(IDS_FLTALLFILTER_STRING)); + if (dlg.DoModal() == IDOK) + { + CString strError; + try + { + m_tTaskDefinition.Store(chcore::PathFromString(dlg.GetPathName())); + } + catch (const std::exception& e) + { + strError = e.what(); + } + + if (!strError.IsEmpty()) + { + ictranslate::CFormat fmt; + fmt.SetFormat(GetResManager().LoadString(IDS_EXPORTING_TASK_FAILED)); + fmt.SetParam(_T("%reason"), strError); + + AfxMessageBox(fmt, MB_OK | MB_ICONERROR); + } + } +} + +void CCustomCopyDlg::UpdateInternalTaskDefinition() +{ + CString strDstPath; + m_ctlDstPath.GetWindowText(strDstPath); + + // copy files from listctrl to an array + m_tTaskDefinition.ClearSourcePaths(); + + // dest path + m_tTaskDefinition.SetDestinationPath(chcore::PathFromString(strDstPath)); + + for (int i = 0; i < m_ctlFiles.GetItemCount(); i++) + { + m_tTaskDefinition.AddSourcePath(chcore::PathFromString(m_ctlFiles.GetItemText(i, 0))); + } + + // operation type + m_tTaskDefinition.SetOperationType(m_ctlOperation.GetCurSel() == 0 ? chcore::eOperation_Copy : chcore::eOperation_Move); + + // priority + chcore::SetTaskPropValue(m_tTaskDefinition.GetConfiguration(), IndexToPriority(m_ctlPriority.GetCurSel())); + + chcore::SetTaskPropValue(m_tTaskDefinition.GetConfiguration(), (m_bIgnoreFolders != 0)); + chcore::SetTaskPropValue(m_tTaskDefinition.GetConfiguration(), (m_bForceDirectories != 0)); + chcore::SetTaskPropValue(m_tTaskDefinition.GetConfiguration(), (m_bOnlyCreate != 0)); +} + +bool CCustomCopyDlg::HasBasicTaskData() +{ + CString strDstPath; + m_ctlDstPath.GetWindowText(strDstPath); + + if (strDstPath.IsEmpty() || m_ctlFiles.GetItemCount() == 0) + return false; + + return true; +} + +void CCustomCopyDlg::UpdateFilesListCtrlHeaderWidth() +{ + CRect rc; + m_ctlFiles.GetWindowRect(&rc); + rc.right -= GetSystemMetrics(SM_CXEDGE) * 2; + + // change the width of a column + LVCOLUMN lvc; + lvc.mask = LVCF_WIDTH; + lvc.cx = rc.Width(); + m_ctlFiles.SetColumn(0, &lvc); +} + +void CCustomCopyDlg::OnSize(UINT nType, int /*cx*/, int /*cy*/) +{ + if(nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED) + { + CWnd* pWnd = GetDlgItem(IDC_FILES_LIST); + if(pWnd) + UpdateFilesListCtrlHeaderWidth(); + } +}