예제 #1
0
파일: Util.cpp 프로젝트: hufuman/filesiconv
    BOOL BrowseForFiles(ATL::CSimpleArray<CString>& listFiles, HWND hWnd)
    {
        listFiles.RemoveAll();
        CFileDialog dlg(TRUE, 0, 0, OFN_NOCHANGEDIR | OFN_ENABLESIZING | OFN_EXPLORER | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT | OFN_NODEREFERENCELINKS);
        if(dlg.DoModal(hWnd) != IDOK)
            return FALSE;

        CString strPath = dlg.m_szFileName;
        CString strFilePath, strFileName;
        size_t nLen = strPath.GetLength();

        TCHAR* pFileName = dlg.m_szFileName + nLen + 1;

        if(pFileName[0] == 0)
        {
            strFileName = pFileName;
            strFilePath = strPath + pFileName;
            listFiles.Add(strFilePath);
            return TRUE;
        }

        strPath += _T("\\");
        while(pFileName != NULL && pFileName[0] != 0)
        {
            strFileName = pFileName;
            strFilePath = strPath + pFileName;
            listFiles.Add(strFilePath);
            nLen += strFileName.GetLength() + 1;
            pFileName = dlg.m_szFileName + nLen + 1;
        }

        return TRUE;
    }
예제 #2
0
template< PSTADE_APPLE_ATL_CSIMPLEARRAY_TEMPLATE_PARAMS, class Value > inline
void pstade_garlic_push_back(
    ATL::CSimpleArray< PSTADE_APPLE_ATL_CSIMPLEARRAY_TEMPLATE_ARGS >& arr,
    Value const& val, pstade::overload<>)
{
#if !defined(PSTADE_APPLE_ATL_HAS_OLD_CSIMPLEARRAY)
    arr.Add(val);
#else
    Value val_(val);
    arr.Add(val_);
#endif
}
예제 #3
0
        void GetAllChildItems(HWND hTreeView, HTREEITEM hParent, HTREEITEM hItem, ATL::CSimpleArray<HTREEITEM>& arrItems, int& nIndex)
        {
            HTREEITEM hTempItem = TreeView_GetChild(hTreeView, hParent);

            while(hTempItem != NULL)
            {
                if(hTempItem == hItem)
                    nIndex = arrItems.GetSize();
                arrItems.Add(hTempItem);

                GetAllChildItems(hTreeView, hTempItem, hItem, arrItems, nIndex);

                hTempItem = TreeView_GetNextSibling(hTreeView, hTempItem);
            }
        }
예제 #4
0
        void GetAllTreeItems(HWND hTreeView, HTREEITEM hItem, ATL::CSimpleArray<HTREEITEM>& arrItems, int& nIndex)
        {
            int nSize = TreeView_GetCount(hTreeView);
            arrItems.RemoveAll();

            GetAllChildItems(hTreeView, TVI_ROOT, hItem, arrItems, nIndex);
        }
예제 #5
0
    HTREEITEM TraversalItemsUp(HWND hTreeView, HTREEITEM hStartItem, std::tr1::function<BOOL (HTREEITEM)> comparer)
    {
        int nIndex = 0;
        ATL::CSimpleArray<HTREEITEM> arrItems;
        details::GetAllTreeItems(hTreeView, hStartItem, arrItems, nIndex);

        int nSize = arrItems.GetSize();
        for(int i=nIndex-1; i >= 0; -- i)
        {
            if(comparer(arrItems[i]))
                return arrItems[i];
        }

        for(int i=nSize-1; i > nIndex; -- i)
        {
            if(comparer(arrItems[i]))
                return arrItems[i];
        }

        return NULL;
    }
예제 #6
0
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
        return 1;
	}

    CString strTestCasePath = GetTestCasesPath();
    if(strTestCasePath.IsEmpty())
    {
        _tprintf(_T("Fatal Error: Not Found testcases directory\n"));
        return 1;
    }

    struct stTestCases
    {
        LPCTSTR szSrcFile;
        LPCTSTR szCorrectFile;
        CodePageValue srcCode;
        CodePageValue dstCode;
    } testcases[] =
    {
        // auto
        /* 00 */ {_T("ansi_enUS.txt"),       _T("unicode_enUS.txt"),     CodeAuto, CodeUnicode},
        /* 01 */ {_T("ansi_enUS.txt"),       _T("utf8_enUS.txt"),        CodeAuto, CodeUtf8},
        /* 02 */ {_T("unicode_enUS.txt"),    _T("ansi_enUS.txt"),        CodeAuto, CodeAnsi},
        /* 03 */ {_T("unicode_enUS.txt"),    _T("utf8_enUS.txt"),        CodeAuto, CodeUtf8},
        /* 04 */ {_T("utf8_enUS.txt"),       _T("ansi_enUS.txt"),        CodeAuto, CodeAnsi},
        /* 05 */ {_T("utf8_enUS.txt"),       _T("unicode_enUS.txt"),     CodeAuto, CodeUnicode},

        /* 06 */ {_T("unicode.txt"),         _T("chinese.txt"),          CodeAuto, CodeChinese},
        /* 07 */ {_T("unicode.txt"),         _T("utf8.txt"),             CodeAuto, CodeUtf8},
        /* 08 */ {_T("utf8.txt"),            _T("chinese.txt"),          CodeAuto, CodeChinese},
        /* 09 */ {_T("utf8.txt"),            _T("unicode.txt"),          CodeAuto, CodeUnicode},

        // multi bytes to wide chars
        /* 10 */ {_T("ansi_enUS.txt"),       _T("unicode_enUS.txt"),     CodeAnsi, CodeUnicode},
        /* 11 */ {_T("utf8_enUS.txt"),       _T("unicode_enUS.txt"),     CodeUtf8, CodeUnicode},
        /* 12 */ {_T("chinese.txt"),         _T("unicode.txt"),          CodeChinese, CodeUnicode},
        /* 13 */ {_T("utf8.txt"),            _T("unicode.txt"),          CodeUtf8, CodeUnicode},

        // wide chars to multi bytes
        /* 14 */ {_T("unicode_enUS.txt"),    _T("ansi_enUS.txt"),        CodeUnicode, CodeAnsi},
        /* 15 */ {_T("unicode_enUS.txt"),    _T("utf8_enUS.txt"),        CodeUnicode, CodeUtf8},
        /* 16 */ {_T("unicode.txt"),         _T("chinese.txt"),          CodeUnicode, CodeChinese},
        /* 17 */ {_T("unicode.txt"),         _T("utf8.txt"),             CodeUnicode, CodeUtf8},

        // multi bytes to multi bytes
        /* 18 */ {_T("chinese.txt"),         _T("utf8.txt"),             CodeChinese, CodeUtf8},
        /* 19 */ {_T("utf8.txt"),            _T("chinese.txt"),          CodeUtf8, CodeChinese},
        /* 20 */ {_T("ansi_enUS.txt"),       _T("utf8_enUS.txt"),        CodeAnsi, CodeUtf8},
        /* 21 */ {_T("utf8_enUS.txt"),       _T("ansi_enUS.txt"),        CodeUtf8, CodeAnsi},

        // auto same to same
        /* 22 */ {_T("ansi_enUS.txt"),       _T("ansi_enUS.txt"),        CodeAuto, CodeAnsi},
        /* 23 */ {_T("unicode.txt"),         _T("unicode.txt"),          CodeAuto, CodeUnicode},
        /* 24 */ {_T("unicode_enUS.txt"),    _T("unicode_enUS.txt"),     CodeAuto, CodeUnicode},
        /* 25 */ {_T("utf8.txt"),            _T("utf8.txt"),             CodeAuto, CodeUtf8},
        /* 26 */ {_T("utf8_enUS.txt"),       _T("utf8_enUS.txt"),        CodeAuto, CodeUtf8},

        // not auto same to same
        /* 27 */ {_T("ansi_enUS.txt"),       _T("ansi_enUS.txt"),        CodeAnsi, CodeAnsi},
        /* 28 */ {_T("chinese.txt"),         _T("chinese.txt"),          CodeChinese, CodeChinese},
        /* 29 */ {_T("unicode.txt"),         _T("unicode.txt"),          CodeUnicode, CodeUnicode},
        /* 30 */ {_T("unicode_enUS.txt"),    _T("unicode_enUS.txt"),     CodeUnicode, CodeUnicode},
        /* 31 */ {_T("utf8.txt"),            _T("utf8.txt"),             CodeUtf8, CodeUtf8},
        /* 32 */ {_T("utf8_enUS.txt"),       _T("utf8_enUS.txt"),        CodeUtf8, CodeUtf8},
    };

    CString strTempFile = CIconvWorker::GetTempFilePath();
    CString strOutputPath = strTestCasePath + _T("tmp\\");

    BOOL bHasError = FALSE;
    for(int i=0; i<_countof(testcases); ++ i)
    {
        const stTestCases& test = testcases[i];
        CString strSrcFile = strTestCasePath + test.szSrcFile;
        CString strCorrectFile = strTestCasePath + test.szCorrectFile;

        CIconvWorker worker;

        ATL::CSimpleArray<CString> arrFiles;
        arrFiles.Add(strSrcFile);
        worker.SetFiles(&arrFiles);
        worker.SetOverwrite(FALSE);
        worker.SetTargetPath(strOutputPath);

        worker.SetCodepage(test.srcCode, test.dstCode);

        ATL::CSimpleArray<CString> failedFiles;
        ATL::CSimpleArray<CString> outFiles;
        if(i == 23)
        {
            int a = 0;
        }
        worker.Convert(&failedFiles, &outFiles);
        int nFailedCount = failedFiles.GetSize();
        if(nFailedCount == 0)
        {
            BOOL bEqual = CompareFile(strCorrectFile, outFiles[0]);
            if(!bEqual)
            {
                bHasError = TRUE;
                _tprintf(_T("TestCase[%d] failed: \r\n"), i);
                _tprintf(_T("\tFiles are not same\r\n"));
            }
            continue;
        }

        bHasError = TRUE;
        _tprintf(_T("TestCase[%d] failed: \r\n"), i);
        for(int j=0; j<nFailedCount; ++ j)
        {
            _tprintf(_T("\tFile[%d] %s\r\n"), j, failedFiles[j]);
        }
        _tprintf(_T("\r\n\r\n"));
    }

    if(!bHasError)
    {
        _tprintf(_T("All Tests Passed\r\n"));
    }

	return nRetCode;
}