Exemple #1
0
std::wstring AnsiToUnicode(const std::string& strAnsi) 
{
	std::wstring retval;

	if (strAnsi.size())
		retval = KANSI_TO_UTF16(strAnsi.c_str());

	return retval;
}
Exemple #2
0
BOOL CStubbornFiles::_SaveToFile()
{
    BOOL retval = FALSE;
    CDataFileLoader dataLoader;
    TiXmlDocument xmlDoc;
    TiXmlElement* pXmlItem = NULL;
    TiXmlElement* pXmlTime = NULL;
    TiXmlElement* pXmlItems = NULL;
    TiXmlText* pXmlText = NULL;
    TCHAR szConfPathTemp[MAX_PATH] = { 0 };
    TCHAR szConfPath[MAX_PATH] = { 0 };
    TiXmlDeclaration *pXmlDecl = new TiXmlDeclaration("1.0", "utf-8", "yes");
    POSITION pos = NULL;
    CStringW strPathUtf16;
    CStringA strPathUtf8;
    CString strXmlUtf16;
    CStringA strXmlAnsi;
    LARGE_INTEGER ver;
    BOOL fRetCode;
    FILE* pFile = NULL;
    SYSTEMTIME sysTime = { 0 };
    CStringA strTime;

    GetModuleFileName(NULL, szConfPath, MAX_PATH);
    PathRemoveFileSpec(szConfPath);
    _tcscpy_s(szConfPathTemp, MAX_PATH, szConfPath);
    PathAppend(szConfPathTemp, _T("data\\~strash.dat"));
    PathAppend(szConfPath, _T("data\\strash.dat"));

    xmlDoc.LinkEndChild(pXmlDecl);

    pXmlItems = new TiXmlElement("items");
    if (!pXmlItems)
        goto clean0;

    pos = m_fileList.GetHeadPosition();
    while (pos)
    {
        strPathUtf16 = m_fileList.GetNext(pos);
        strPathUtf8 = KUTF16_To_UTF8(strPathUtf16);

        pXmlText = new TiXmlText(strPathUtf8);
        if (!pXmlText)
            goto clean0;

        pXmlItem = new TiXmlElement("item");
        if (!pXmlItem)
            goto clean0;

        pXmlItem->LinkEndChild(pXmlText);
        pXmlItems->LinkEndChild(pXmlItem);
    }
    xmlDoc.LinkEndChild(pXmlItems);

    GetLocalTime(&sysTime);
    strTime.Format("%d.%d.%d", sysTime.wYear, sysTime.wMonth, sysTime.wDay);
    pXmlTime = new TiXmlElement("time");
    if (!pXmlTime)
        goto clean0;

    pXmlText = new TiXmlText(strTime);
    if (!pXmlText)
        goto clean0;

    pXmlTime->LinkEndChild(pXmlText);

    xmlDoc.LinkEndChild(pXmlTime);

    if (!xmlDoc.SaveFile(KUTF16_To_ANSI(szConfPathTemp)))
        goto clean0;

    pFile = _wfopen(szConfPathTemp, L"r");
    if (!pFile)
        goto clean0;

    {
        fseek(pFile, 0, SEEK_END);
        int nSize = ftell(pFile);
        fseek(pFile, 0, SEEK_SET);
        char* pXml = strXmlAnsi.GetBuffer(nSize + 1);
        memset(pXml, 0, nSize + 1);
        fread(pXml, 1, nSize, pFile);
        fclose(pFile);
        pFile = NULL;
        strXmlAnsi.ReleaseBuffer();
        strXmlUtf16 = KANSI_TO_UTF16(strXmlAnsi);
    }

    {
        ver.QuadPart = 1;
        fRetCode = dataLoader.Save(
                       szConfPath, BkDatLibEncodeParam2(enumLibTypePlugine, ver, strXmlUtf16, 1).GetEncodeParam()
                   );
    }

    if (!fRetCode)
        goto clean0;

    retval = TRUE;

clean0:
    if (pFile)
    {
        fclose(pFile);
        pFile = NULL;
    }

    if (GetFileAttributes(szConfPathTemp) != INVALID_FILE_ATTRIBUTES)
    {
        ::DeleteFile(szConfPathTemp);
    }

    return retval;
}
Exemple #3
0
bool KTrashOnekeyTask::StartClean(int nTask,const char* szTask)
{
    CConfigData::DirWorkArray::iterator iter ;
    bool bResult = TRUE;

    if(m_pCallBack != NULL)
        m_pCallBack->OnBegin();

    Initialize();

    TaskMap[L"IE_TEMP"] = false;
    TaskMap[L"BROWER_SOGO"] = false;
    TaskMap[L"BROWER_MATHRON"] = false;
    TaskMap[L"BROWER_FIREFOX"] = false;
    TaskMap[L"BROWER_CHROME"] = false;
    TaskMap[L"BROWER_OPERA"] = false;
    TaskMap[L"WIN_TEMP"] = false;
    TaskMap[L"WIN_HUISHOUZHAN"] = false;
    TaskMap[L"WIN_LOG"] = false;
    TaskMap[L"WIN_UPDATE"] = false;
    TaskMap[L"OFFICE_CACHE"] = false;
    TaskMap[L"WIN_PRE"] = false;
    TaskMap[L"WIN_DOWNLOAD"] = false;
    TaskMap[L"U_TEMP"] = false;
    TaskMap[L"SYS_DRIVE"] = false;
    TaskMap[L"WIN_ERRPORT"] = false;
    TaskMap[L"WIN_LOG"] = false;
    TaskMap[L"WIN_SUOLIETU"] = false;

    if (szTask == NULL)
        goto Exit0;

    {
        std::wstring strTmp(KANSI_TO_UTF16(szTask));
        std::vector<std::wstring> TaskVector;
        SplitStrTask(strTmp, TaskVector);

        for(std::vector<std::wstring>::iterator iter_str = TaskVector.begin(); iter_str!=TaskVector.end(); iter_str++)
        {
            std::map<std::wstring,bool>::iterator mapiter = TaskMap.find(*iter_str);
            if (mapiter != TaskMap.end())
            {
                mapiter->second = true;
            }

        }
    }

    if (IsCleaning())
    {
        bResult = FALSE;
        goto Exit0;
    }

    m_ulTotalJunkFileSize = 0; 
	m_FileListData.m_nTotalsize = 0;
    for (size_t nIndex = 0; nIndex < m_FileListData.m_itemArray.size(); nIndex++)
    {
        m_FileListData.m_itemArray.at(nIndex).ulAllFileSize = 0;
        m_FileListData.m_itemArray.at(nIndex).itemArray.clear();
		m_FileListData.m_itemArray.at(nIndex).strfileList = L"";
    }

    m_DirWorks.resize(m_config.GetConfigData().size());
    m_DirWorks.clear();
    std::copy(m_config.GetConfigData().begin(), m_config.GetConfigData().end(), back_inserter(m_DirWorks));
    size_t i = 0;
    iter = m_DirWorks.begin();
    while (iter != m_DirWorks.end() && i < m_DirWorks.size())
    {
        if(TaskMap[TaskVector.at(i)])
            iter->bDefaultSelect = TRUE;
        else iter->bDefaultSelect = FALSE;

        iter++;
        i++;
    }

    g_bStop[1] = FALSE;

    m_hThread = CreateThread(
        NULL, 
        0, 
        CleanFileThread, 
        (LPVOID)this,
        NULL,
        &m_dwThreadID
        );

    if (m_hThread == NULL)   
        bResult = FALSE;

Exit0:
    return bResult;
}