Index: src/ch/CustomCopyDlg.cpp =================================================================== diff -u -r68739164e349c34dcd0bcb36c6eb381f23cb8b77 -r25aab92a9d195154393782ca83cbf5bc41ab9277 --- src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision 68739164e349c34dcd0bcb36c6eb381f23cb8b77) +++ src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision 25aab92a9d195154393782ca83cbf5bc41ab9277) @@ -25,6 +25,7 @@ #include "FilterDlg.h" #include "StringHelpers.h" #include "ch.h" +#include #ifdef _DEBUG #define new DEBUG_NEW @@ -934,32 +935,87 @@ 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)); if (dlg.DoModal() == IDOK) { + const int iMaxLineLength = 4096; 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(); + spBuffer.reset(new BYTE[llSize + 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, llSize + 3); + + ulSize = file.read(spBuffer.get(), (ulong_t)llSize); + file.close(); } - catch(CException* e) + catch(icpf::exception& /*e*/) { - e->Delete(); + AfxMessageBox(GetResManager().LoadString(IDS_IMPORTERROR_STRING)); + return; } + // parse text from buffer (there is no point processing files with size < 3 - i.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)); fmt.SetParam(_t("%count"), uiCount); Index: src/ch/ch.rc =================================================================== diff -u -r11621f18af6a7b1d486a7d6a576b97d4d09e8e96 -r25aab92a9d195154393782ca83cbf5bc41ab9277 --- src/ch/ch.rc (.../ch.rc) (revision 11621f18af6a7b1d486a7d6a576b97d4d09e8e96) +++ src/ch/ch.rc (.../ch.rc) (revision 25aab92a9d195154393782ca83cbf5bc41ab9277) @@ -969,6 +969,7 @@ IDS_EMPTYFILTER_STRING "None of filtering options were selected" IDS_FLTALLFILTER_STRING "All files (*.*)|*.*||" IDS_IMPORTREPORT_STRING "Imported %count path(s)" + IDS_IMPORTERROR_STRING "Cannot import paths from the specified file" END STRINGTABLE Index: src/ch/ch.vc90.vcproj =================================================================== diff -u -r464f72c605017d96d52ec59e916b29f5aff51340 -r25aab92a9d195154393782ca83cbf5bc41ab9277 --- src/ch/ch.vc90.vcproj (.../ch.vc90.vcproj) (revision 464f72c605017d96d52ec59e916b29f5aff51340) +++ src/ch/ch.vc90.vcproj (.../ch.vc90.vcproj) (revision 25aab92a9d195154393782ca83cbf5bc41ab9277) @@ -328,7 +328,7 @@ /> + + + + @@ -509,14 +517,6 @@ > - - - - Index: src/ch/resource.h =================================================================== diff -u -r07a3be49b0c7e5599eb89c2f9da9a9272cc1558a -r25aab92a9d195154393782ca83cbf5bc41ab9277 --- src/ch/resource.h (.../resource.h) (revision 07a3be49b0c7e5599eb89c2f9da9a9272cc1558a) +++ src/ch/resource.h (.../resource.h) (revision 25aab92a9d195154393782ca83cbf5bc41ab9277) @@ -515,6 +515,7 @@ #define IDS_EMPTYFILTER_STRING 15021 #define IDS_FLTALLFILTER_STRING 15022 #define IDS_IMPORTREPORT_STRING 15023 +#define IDS_IMPORTERROR_STRING 15024 #define IDS_NERPATH_STRING 16500 #define IDS_DATECREATED_STRING 18000 #define IDS_DATELASTWRITE_STRING 18001