コード例 #1
0
ファイル: SoftUninstall.cpp プロジェクト: dreamsxin/PcManager
BOOL CSoftUninstall::LoadPinYin()
{
	CDataFileLoader	loader;
	BkDatLibContent content;

	if(!loader.GetLibDatContent((_ksafePath + SOFT_PINYIN_DAT).c_str(), content))
		return FALSE;

	TiXmlDocument plugins;
	if(plugins.Parse((char*)content.pBuffer) == NULL)
		return FALSE;

	TiXmlHandle hRoot(plugins.FirstChildElement("fonts"));
	for(TiXmlElement *pElem = hRoot.FirstChildElement("font").Element(); pElem != NULL; pElem = pElem->NextSiblingElement())
	{
		LPCSTR pHan = pElem->Attribute("c");
		if(pHan == NULL) continue;

		PinYin pinyin;
		pinyin._whole = pElem->Attribute("p");
		pinyin._acronym = pElem->Attribute("s");

		_hashPinYin.insert(make_pair(pHan, pinyin));
	}

	return TRUE;
}
コード例 #2
0
HRESULT STDMETHODCALLTYPE CSoftMgrUpdateHelper::Combine( LPCWSTR lpwszDifflib )
{
#if OPEN_VCDIFF
	// 加载Delta
	BkDatLibContent delta;
	CDataFileLoader	loader;
	if(!loader.GetLibDatContent(lpwszDifflib, delta)) return ::HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);

	// 目标文件路径
	wchar_t szDstPath[MAX_PATH] = {0};
	{
		::GetModuleFileNameW(NULL, szDstPath, MAX_PATH);

		::PathRemoveFileSpecW(szDstPath);
		wcscat_s(szDstPath, MAX_PATH, L"\\KSoft\\Data\\");
		wcscat_s(szDstPath, MAX_PATH, ::PathFindFileNameW(lpwszDifflib));

		//
		//@Issue
		// 根据名称来判断库类型
		//
		//@Note
		// 命名规则为:libname_old_new.dat
		//
		LPWSTR pSep = wcschr(::PathFindFileNameW(szDstPath), L'_');
		if(pSep == NULL) return ::HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);

		pSep[0] = L'\0';
		wcscat_s(szDstPath, MAX_PATH,  L".dat");
	}

	// 加载字典文件
	CAtlFile dictFile;
	HRESULT hr = dictFile.Create(szDstPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
	if(!SUCCEEDED(hr)) return hr;

	ULONGLONG dictSize;
	hr = dictFile.GetSize(dictSize);
	if(!SUCCEEDED(hr)) return hr;

	auto_buffer<char> dict(static_cast<size_t>(dictSize));
	if(dict.empty()) return ::HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);

	DWORD bytesRead;
	hr = dictFile.Read(dict.data(), static_cast<DWORD>(dict.size()), bytesRead);
	if(!SUCCEEDED(hr)) return hr;

	dictFile.Close();

	// 创建目标临时文件
	CAtlTemporaryFile tempTarget;
	hr = tempTarget.Create();
	if(!SUCCEEDED(hr)) return hr;

	//
	// 开始合并
	//
	//@Note
	// Dict(Source) + Delta => Target
	//
	Output2File output2File(tempTarget);
	{
		VCDiffStreamingDecoder decoder;
		decoder.StartDecoding(&dict[0], dict.size());

		size_t beg = 0;
		size_t end = static_cast<size_t>(delta.nLen);
		LPCSTR pDelta = reinterpret_cast<LPCSTR>(delta.pBuffer);

		while(beg < end)
		{
			static const size_t MAX_THUNK_SIZE = 16*1024;

			size_t size = end - beg;
			if(size > MAX_THUNK_SIZE) size = MAX_THUNK_SIZE;

			if(!decoder.DecodeChunkToInterface(pDelta + beg, size, &output2File))
				return ::HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);

			beg += size;
		}

		if(!decoder.FinishDecoding())
			return ::HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
	}

	// 根据写入文件大小与期望大小来判断是否合并成功
	ULONGLONG dstSize;
	hr = tempTarget.GetPosition(dstSize);
	if(!SUCCEEDED(hr) || dstSize != output2File.GetTotalBytes()) return ::HRESULT_FROM_WIN32(ERROR_WRITE_FAULT);

	// 移动到目标路径
	return tempTarget.Close(szDstPath);
#else
	return S_OK;
#endif
}
コード例 #3
0
ファイル: stubbornfiles.cpp プロジェクト: dudor/pcmanager
BOOL CStubbornFiles::_LoadFromFile()
{
    BOOL retval = FALSE;
    CDataFileLoader dataLoader;
    TiXmlDocument xmlDoc;
    const TiXmlElement* pXmlItems = NULL;
    const TiXmlElement* pXmlItem = NULL;
    const TiXmlElement* pXmlTime = NULL;
    TCHAR szConfPath[MAX_PATH] = { 0 };
    CStringA strXmlAnsi;
    CStringW strPathUtf16;
    CStringA strPathAnsi;
    SYSTEMTIME sysTime = { 0 };
    CStringA strTime;

    GetLocalTime(&sysTime);
    strTime.Format("%d.%d.%d", sysTime.wYear, sysTime.wMonth, sysTime.wDay);

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


    if (!dataLoader.LoadFile(szConfPath, strXmlAnsi))
        goto clean0;

    if (!xmlDoc.LoadBuffer((LPSTR)(LPCSTR)strXmlAnsi, strXmlAnsi.GetLength(), TIXML_ENCODING_UTF8))
        goto clean0;

    pXmlTime = xmlDoc.FirstChildElement("time");
    if (!pXmlTime)
        goto clean0;

    if (strTime.Compare(pXmlTime->GetText()))
        goto clean0;

    pXmlItems = xmlDoc.FirstChildElement("items");
    if (!pXmlItems)
        goto clean0;

    pXmlItem = pXmlItems->FirstChildElement("item");
    while (pXmlItem)
    {
        strPathAnsi = pXmlItem->GetText();
        if (strPathAnsi.GetLength())
        {
            strPathUtf16 = KUTF8_To_UTF16(strPathAnsi);

            if (GetFileAttributes(strPathUtf16) != INVALID_FILE_ATTRIBUTES)
            {
                m_fileList.AddTail(strPathUtf16);
                m_fileMap[strPathUtf16] = TRUE;
            }
        }

        pXmlItem = pXmlItem->NextSiblingElement("item");
    }

    retval = TRUE;

clean0:
    return retval;
}
コード例 #4
0
ファイル: stubbornfiles.cpp プロジェクト: dudor/pcmanager
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;
}
コード例 #5
0
ファイル: slimdata.cpp プロジェクト: 6520874/pcmanager
BOOL SlimData::LoadDataSync()
{
    BOOL retval = FALSE;
    KAutoLock lock(m_lock);
    CStringA  strXml;
    TCHAR szModule[MAX_PATH] = { 0 };
    TiXmlDocument xmlDoc;
    TiXmlElement* pXmlSlims = NULL;
    TiXmlElement* pXmlItem = NULL;
    CDataFileLoader datloader;
    
    GetModuleFileName(NULL, szModule, MAX_PATH);
    PathRemoveFileSpec(szModule);
    PathAppend(szModule, _T("data\\slimdata.dat"));

    if (!datloader.LoadFile(szModule, strXml))
        goto clean0;

    xmlDoc.Parse(strXml);

    pXmlSlims = xmlDoc.FirstChildElement("slims");
    if (!pXmlSlims)
        goto clean0;

    pXmlItem = pXmlSlims->FirstChildElement("slim");
    while (pXmlItem)
    {
        TiXmlElement* pXmlId = pXmlItem->FirstChildElement("id");
        TiXmlElement* pXmlName = pXmlItem->FirstChildElement("name");
        TiXmlElement* pXmlDescription = pXmlItem->FirstChildElement("description");
        TiXmlElement* pXmlWarning = pXmlItem->FirstChildElement("warning");
        TiXmlElement* pXmlMethod = pXmlItem->FirstChildElement("method");

        if (pXmlId && pXmlName && pXmlDescription && pXmlWarning && pXmlMethod)
        {
            SlimItem item;
            TiXmlElement* pXmlPath = NULL;

            item.SetLock(m_sharedLock);
            item.SetId(::StrToIntA(pXmlId->GetText()));
            item.SetName(KUTF8_To_UTF16(pXmlName->GetText()));
            item.SetDescription(KUTF8_To_UTF16(pXmlDescription->GetText()));
            item.SetWarning(KUTF8_To_UTF16(pXmlWarning->GetText()));
            if (!stricmp(pXmlMethod->GetText(), "delete"))
            {
                item.SetMethod(SLIM_DELETE_FILE);
            }
            else if (!stricmp(pXmlMethod->GetText(), "compress"))
            {
                item.SetMethod(SLIM_COMPRESS_FILE);
            }

            pXmlPath = pXmlItem->FirstChildElement("path");
            while (pXmlPath)
            {
                CStringA strOsFlag = pXmlPath->Attribute("os");
                item.InsertPath(KUTF8_To_UTF16(pXmlPath->GetText()), strOsFlag);
                pXmlPath = pXmlPath->NextSiblingElement("path");
            }

            if (item.Valid() || (KGetWinVersion() < WINVERSION_VISTA && item.Id() == 10))
            {
                m_slimItems.Add(item);
            }
        }

        pXmlItem = pXmlItem->NextSiblingElement("slim");
    }

    retval = TRUE;

clean0:
    if (m_hNotifyWnd)
    {
        ::PostMessage(m_hNotifyWnd, SLIM_WM_LOADCOMPLETE, 0, 0);
    }

    return retval;
}