Index: src/ch/CustomCopyDlg.cpp =================================================================== diff -u -rd5c3edd0d167db9b5d47d04248820fda49499a5e -rc435ab507c8b8280264188b49e9ada56d46c0261 --- src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) +++ src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision c435ab507c8b8280264188b49e9ada56d46c0261) @@ -18,13 +18,15 @@ ***************************************************************************/ #include "stdafx.h" #include "resource.h" +#include "FileInfo.h" #include "CustomCopyDlg.h" #include "structs.h" #include "dialogs.h" #include "BufferSizeDlg.h" #include "FilterDlg.h" #include "StringHelpers.h" #include "ch.h" +#include #ifdef _DEBUG #define new DEBUG_NEW @@ -114,12 +116,60 @@ { CLanguageDialog::OnInitDialog(); + AddResizableControl(IDC_001_STATIC, 0.0, 0.0, 1.0, 0.0); + AddResizableControl(IDC_FILES_LIST, 0.0, 0.0, 1.0, 0.5); + AddResizableControl(IDC_ADDFILE_BUTTON, 1.0, 0.0, 0.0, 0.0); + AddResizableControl(IDC_ADDDIR_BUTTON, 1.0, 0.0, 0.0, 0.0); + AddResizableControl(IDC_REMOVEFILEFOLDER_BUTTON, 1.0, 0.0, 0.0, 0.0); + AddResizableControl(IDC_IMPORT_BUTTON, 1.0, 0.0, 0.0, 0.0); + + AddResizableControl(IDC_002_STATIC, 0.0, 0.5, 1.0, 0.0); + AddResizableControl(IDC_DESTPATH_COMBOBOXEX, 0.0, 0.5, 1.0, 0.0); + AddResizableControl(IDC_DESTBROWSE_BUTTON, 1.0, 0.5, 0.0, 0.0); + + AddResizableControl(IDC_BAR1_STATIC, 0.0, 0.5, 0.5, 0.0); + 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_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_006_STATIC, 0.0, 0.5, 1.0, 0.0); + AddResizableControl(IDC_BUFFERSIZES_LIST, 0.0, 0.5, 1.0, 0.0); + AddResizableControl(IDC_BUFFERSIZES_BUTTON, 1.0, 0.5, 0.0, 0.0); + + AddResizableControl(IDC_FILTERS_CHECK, 0.0, 0.5, 0.0, 0.0); + AddResizableControl(IDC_BAR3_STATIC, 0.0, 0.5, 1.0, 0.0); + AddResizableControl(IDC_FILTERS_LIST, 0.0, 0.5, 1.0, 0.5); + AddResizableControl(IDC_ADDFILTER_BUTTON, 1.0, 0.5, 0.0, 0.0); + AddResizableControl(IDC_REMOVEFILTER_BUTTON, 1.0, 0.5, 0.0, 0.0); + + AddResizableControl(IDC_ADVANCED_CHECK, 0.0, 1.0, 0.0, 0.0); + AddResizableControl(IDC_BAR4_STATIC, 0.0, 1.0, 1.0, 0.0); + + AddResizableControl(IDC_IGNOREFOLDERS_CHECK, 0.0, 1.0, 1.0, 0.0); + AddResizableControl(IDC_ONLYSTRUCTURE_CHECK, 0.0, 1.0, 1.0, 0.0); + AddResizableControl(IDC_FORCEDIRECTORIES_CHECK, 0.0, 1.0, 1.0, 0.0); + + AddResizableControl(IDC_BAR5_STATIC, 0.0, 1.0, 1.0, 0.0); + 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); + + InitializeResizableControls(); + // make this dialog on top SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE /*| SWP_SHOWWINDOW*/); // paths' listbox - init images - system image list - SHFILEINFO sfi; - HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHFILEINFO sfi; + HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); m_ilImages.Attach(hImageList); @@ -153,15 +203,15 @@ CString strText; cbi.mask=CBEIF_IMAGE | CBEIF_TEXT; - for (int i=0;i<(int)m_ccData.m_vRecent.size();i++) + for(size_t stIndex = 0; stIndex < m_ccData.m_vRecent.size(); ++stIndex) { - cbi.iItem=i; - strText=m_ccData.m_vRecent.at(i); - cbi.pszText=strText.GetBuffer(1); - sfi.iIcon=-1; + cbi.iItem = stIndex; + strText=m_ccData.m_vRecent.at(stIndex); + cbi.pszText = strText.GetBuffer(1); + sfi.iIcon = -1; SHGetFileInfo(strText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - cbi.iImage=sfi.iIcon; + cbi.iImage = sfi.iIcon; m_ctlDstPath.InsertItem(&cbi); } @@ -171,16 +221,16 @@ // m_strDest=m_ccData.m_strDestPath; //** // operation type - m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDCOPY_STRING)); - m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDMOVE_STRING)); + m_ctlOperation.AddString(GetResManager().LoadString(IDS_CCDCOPY_STRING)); + m_ctlOperation.AddString(GetResManager().LoadString(IDS_CCDMOVE_STRING)); // copying/moving m_ctlOperation.SetCurSel(m_ccData.m_iOperation); // fill priority combo for (int i=0;i<7;i++) { - m_ctlPriority.AddString(GetResManager()->LoadString(IDS_PRIORITY0_STRING+i)); + m_ctlPriority.AddString(GetResManager().LoadString(IDS_PRIORITY0_STRING+i)); } m_ctlPriority.SetCurSel(PriorityToIndex(m_ccData.m_iPriority)); @@ -202,42 +252,42 @@ // mask lvc.iSubItem=-1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRMASK_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRMASK_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.15*rc.Width()); m_ctlFilters.InsertColumn(1, &lvc); // exclude mask lvc.iSubItem=0; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEMASK_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDREXCLUDEMASK_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.15*rc.Width()); m_ctlFilters.InsertColumn(2, &lvc); // size lvc.iSubItem=1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRSIZE_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRSIZE_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.3*rc.Width()); m_ctlFilters.InsertColumn(3, &lvc); // time lvc.iSubItem=2; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRDATE_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRDATE_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.3*rc.Width()); m_ctlFilters.InsertColumn(4, &lvc); // attributes lvc.iSubItem=3; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRATTRIB_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRATTRIB_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.1*rc.Width()); m_ctlFilters.InsertColumn(5, &lvc); // -attributes lvc.iSubItem=4; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEATTRIB_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDREXCLUDEATTRIB_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.1*rc.Width()); m_ctlFilters.InsertColumn(6, &lvc); @@ -275,16 +325,16 @@ // operation int iPos=m_ctlOperation.GetCurSel(); m_ctlOperation.ResetContent(); - m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDCOPY_STRING)); - m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDMOVE_STRING)); + m_ctlOperation.AddString(GetResManager().LoadString(IDS_CCDCOPY_STRING)); + m_ctlOperation.AddString(GetResManager().LoadString(IDS_CCDMOVE_STRING)); m_ctlOperation.SetCurSel(iPos); // priority combo iPos=m_ctlPriority.GetCurSel(); m_ctlPriority.ResetContent(); for (int i=0;i<7;i++) { - m_ctlPriority.AddString(GetResManager()->LoadString(IDS_PRIORITY0_STRING+i)); + m_ctlPriority.AddString(GetResManager().LoadString(IDS_PRIORITY0_STRING+i)); } m_ctlPriority.SetCurSel(iPos); @@ -299,90 +349,91 @@ // mask lvc.iSubItem=-1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRMASK_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRMASK_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.15*rc.Width()); m_ctlFilters.InsertColumn(1, &lvc); // exclude mask lvc.iSubItem=0; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEMASK_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDREXCLUDEMASK_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.15*rc.Width()); m_ctlFilters.InsertColumn(2, &lvc); // size lvc.iSubItem=1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRSIZE_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRSIZE_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.3*rc.Width()); m_ctlFilters.InsertColumn(3, &lvc); // time lvc.iSubItem=2; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRDATE_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRDATE_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.3*rc.Width()); m_ctlFilters.InsertColumn(4, &lvc); // attributes lvc.iSubItem=3; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRATTRIB_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDRATTRIB_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.1*rc.Width()); m_ctlFilters.InsertColumn(5, &lvc); // -attributes lvc.iSubItem=4; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEATTRIB_STRING); + lvc.pszText=(PTSTR)GetResManager().LoadString(IDS_HDREXCLUDEATTRIB_STRING); lvc.cchTextMax=lstrlen(lvc.pszText); lvc.cx=static_cast(0.1*rc.Width()); m_ctlFilters.InsertColumn(6, &lvc); // refresh the entries in filters' list m_ctlFilters.DeleteAllItems(); - for (size_t i=0;i(stIndex)); } } void CCustomCopyDlg::OnAddDirectoryButton() { CString strPath; - if (BrowseForFolder(GetResManager()->LoadString(IDS_BROWSE_STRING), &strPath)) + if (BrowseForFolder(GetResManager().LoadString(IDS_BROWSE_STRING), &strPath)) AddPath(strPath); } 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, NULL, NULL, 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]; + TCHAR *pszBuffer = new TCHAR[65535]; memset(pszBuffer, 0, 65535*sizeof(TCHAR)); dlg.m_ofn.lpstrFile=pszBuffer; dlg.m_ofn.nMaxFile=65535; - if (dlg.DoModal() == IDOK) + if(dlg.DoModal() == IDOK) { + pszBuffer[65534] = _T('\0'); // first element is the path CString strPath=pszBuffer; - int iOffset=_tcslen(pszBuffer)+1; + size_t stOffset = _tcslen(pszBuffer) + 1; // get filenames - if (pszBuffer[iOffset] == _T('\0')) + if(pszBuffer[stOffset] == _T('\0')) AddPath(strPath); else { - if (strPath.Right(1) != _T("\\")) - strPath+=_T("\\"); - while (pszBuffer[iOffset] != _T('\0')) + if(strPath.Right(1) != _T("\\")) + strPath += _T("\\"); + while(pszBuffer[stOffset] != _T('\0')) { - AddPath(strPath+CString(pszBuffer+iOffset)); - iOffset+=_tcslen(pszBuffer+iOffset)+1; + AddPath(strPath + CString(pszBuffer + stOffset)); + stOffset += _tcslen(pszBuffer + stOffset) + 1; } } } @@ -411,7 +462,7 @@ void CCustomCopyDlg::OnBrowseButton() { CString strPath; - if (BrowseForFolder(GetResManager()->LoadString(IDS_DSTFOLDERBROWSE_STRING), &strPath)) + if (BrowseForFolder(GetResManager().LoadString(IDS_DSTFOLDERBROWSE_STRING), &strPath)) { SetComboPath(strPath); // m_strDest=strPath; //** @@ -470,25 +521,25 @@ TCHAR szSize[64]; ictranslate::CFormat fmt; - fmt.SetFormat(GetResManager()->LoadString(IDS_BSEDEFAULT_STRING)); + fmt.SetFormat(GetResManager().LoadString(IDS_BSEDEFAULT_STRING)); fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiDefaultSize, szSize, 64, true)); m_ctlBufferSizes.AddString(fmt); if (!m_ccData.m_bsSizes.m_bOnlyDefault) { - fmt.SetFormat(GetResManager()->LoadString(IDS_BSEONEDISK_STRING)); + fmt.SetFormat(GetResManager().LoadString(IDS_BSEONEDISK_STRING)); fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiOneDiskSize, szSize, 64, true)); m_ctlBufferSizes.AddString(fmt); - fmt.SetFormat(GetResManager()->LoadString(IDS_BSETWODISKS_STRING)); + fmt.SetFormat(GetResManager().LoadString(IDS_BSETWODISKS_STRING)); fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiTwoDisksSize, szSize, 64, true)); m_ctlBufferSizes.AddString(fmt); - fmt.SetFormat(GetResManager()->LoadString(IDS_BSECD_STRING)); + fmt.SetFormat(GetResManager().LoadString(IDS_BSECD_STRING)); fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiCDSize, szSize, 64, true)); m_ctlBufferSizes.AddString(fmt); - fmt.SetFormat(GetResManager()->LoadString(IDS_BSELAN_STRING)); + fmt.SetFormat(GetResManager().LoadString(IDS_BSELAN_STRING)); fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiLANSize, szSize, 64, true)); m_ctlBufferSizes.AddString(fmt); } @@ -575,7 +626,7 @@ _tcscpy(szLoaded, strData); } else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERMASKEMPTY_STRING)); + _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERMASKEMPTY_STRING)); lvi.pszText=szLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); @@ -591,7 +642,7 @@ _tcscpy(szLoaded, strData); } else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERMASKEMPTY_STRING)); + _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERMASKEMPTY_STRING)); lvi.pszText=szLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); @@ -602,18 +653,18 @@ if (rFilter.m_bUseSize) { - _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iSizeType1), GetSizeString(rFilter.m_ullSize1, szData, 64, true)); + _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) { - _tcscat(szLoaded, GetResManager()->LoadString(IDS_AND_STRING)); + _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)); + strLoaded2.Format(_T("%s %s"), GetResManager().LoadString(IDS_LT_STRING+rFilter.m_iSizeType2), GetSizeString(rFilter.m_ullSize2, szData, 64, true)); _tcscat(szLoaded, strLoaded2); } } else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERSIZE_STRING)); + _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERSIZE_STRING)); lvi.pszText=szLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); @@ -624,7 +675,7 @@ if (rFilter.m_bUseDate) { - _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager()->LoadString(IDS_DATECREATED_STRING+rFilter.m_iDateType), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iDateType1)); + _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"))); @@ -633,16 +684,16 @@ if (rFilter.m_bUseDate2) { - _tcscat(szLoaded, GetResManager()->LoadString(IDS_AND_STRING)); - _tcscat(szLoaded, GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iDateType2)); + _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"))); } } else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERDATE_STRING)); + _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERDATE_STRING)); lvi.pszText=szLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); @@ -666,7 +717,7 @@ } if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('\0')) - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERATTRIB_STRING)); + _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERATTRIB_STRING)); lvi.pszText=szLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); @@ -690,7 +741,7 @@ } if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('0')) - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERATTRIB_STRING)); + _tcscpy(szLoaded, GetResManager().LoadString(IDS_FILTERATTRIB_STRING)); lvi.pszText=szLoaded; lvi.cchTextMax=lstrlen(lvi.pszText); @@ -764,15 +815,15 @@ dlg.m_ffFilter = *pFilter; CString strData; - for (size_t i=0;im_bUseMask && i != iItem) + if(pFilter->m_bUseMask && boost::numeric_cast(stIndex) != iItem) dlg.m_astrAddMask.Add(pFilter->GetCombinedMask(strData)); - if (pFilter->m_bUseExcludeMask && i != iItem) + if (pFilter->m_bUseExcludeMask && boost::numeric_cast(stIndex) != iItem) dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask(strData)); } } @@ -886,34 +937,89 @@ void CCustomCopyDlg::OnImportButton() { - CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager()->LoadString(IDS_FLTALLFILTER_STRING)); - if (dlg.DoModal() == IDOK) + boost::shared_array spBuffer; + ulong_t ulSize = 0; + + CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager().LoadString(IDS_FLTALLFILTER_STRING)); + if(dlg.DoModal() == IDOK) { UINT uiCount=0; - CString strData; try { - CFile file(dlg.GetPathName(), CFile::modeRead); - CArchive ar(&file, CArchive::load); + icpf::file file; + file.open(dlg.GetPathName(), FA_READ); - while (ar.ReadString(strData)) + // load files max 1MB in size; + ll_t llSize = file.get_size(); + if(llSize > 1*1024*1024 || llSize < 2) { - strData.TrimLeft(_T("\" \t")); - strData.TrimRight(_T("\" \t")); - AddPath(strData); - uiCount++; + AfxMessageBox(GetResManager().LoadString(IDS_IMPORTERROR_STRING)); + return; } - ar.Close(); - file.Close(); + ulong_t ulSize = boost::numeric_cast(llSize); + 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(); } - catch(CException* e) + catch(...) { - e->Delete(); + AfxMessageBox(GetResManager().LoadString(IDS_IMPORTERROR_STRING)); + return; } + // parse text from buffer (there is no point processing files with size < 3 - stIndex.e. "c:") + if(!spBuffer || ulSize < 3) + { + AfxMessageBox(GetResManager().LoadString(IDS_IMPORTERROR_STRING)); + return; + } + + // which format? + CString strData; + if(spBuffer[0] == 0xff && spBuffer[1] == 0xfe) + { + // utf-16 (native) + strData = (wchar_t*)(spBuffer.get() + 2); + + } + else if(ulSize >= 3 && spBuffer[0] == 0xef && spBuffer[1] == 0xbb && spBuffer[2] == 0xbf) + { + boost::shared_array spWideBuffer(new wchar_t[ulSize + 1]); + memset(spWideBuffer.get(), 0, (ulSize + 1) * sizeof(wchar_t)); + + // utf-8 - needs conversion + int iRes = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, (char*)(spBuffer.get() + 3), ulSize - 3, spWideBuffer.get(), ulSize); + if(iRes == 0) + return; // failed to convert + + spWideBuffer[iRes] = L'\0'; + strData = spWideBuffer.get(); + } + else + { + // assuming ansi + strData = (char*)spBuffer.get(); + } + + CString strToken; + int iPos = 0; + strToken = strData.Tokenize(_T("\n"), iPos); + while(strToken != _T("")) + { + strToken.TrimLeft(_T("\" \t\r\n")); + strToken.TrimRight(_T("\" \t\r\n")); + + AddPath(strToken); + uiCount++; + + strToken = strData.Tokenize(_T("\n"), iPos); + } + // report - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_IMPORTREPORT_STRING)); + ictranslate::CFormat fmt(GetResManager().LoadString(IDS_IMPORTREPORT_STRING)); fmt.SetParam(_t("%count"), uiCount); AfxMessageBox(fmt); }