BOOL CSpecialApp::CleanXunleiSearch(LPCTSTR lpcszAppPath) { BYTE* pBuf = NULL; FILE* pFile = NULL; FILE* pfile = NULL; HRESULT hrRet = E_FAIL; DWORD dwRealReadSize = 0; CString strInPath; CString strFileName; CString strSection; CString strTemp; string szFileName; string szSection; std::vector<std::wstring> vLogCache; std::vector<std::wstring> vLogCacheNew; std::vector<std::wstring>::iterator itor; CString szTarget; int nPos = -1; strInPath = lpcszAppPath; nPos = strInPath.Find(L'|'); if (nPos == -1) { // bRet = FALSE; // goto clean0; return FALSE; } strFileName = strInPath.Left(nPos); strSection = strInPath.Right(strInPath.GetLength() - nPos - 1); DWORD dwFileSize = _DoGetFileSizeByFileName(strFileName); if (dwFileSize <= 0) { hrRet = E_FAIL; goto clean0; } pBuf = new BYTE[dwFileSize * 2 + 2]; if (!pBuf) { hrRet = E_OUTOFMEMORY; goto clean0; } ::ZeroMemory(pBuf, dwFileSize * 2 + 2); pFile = ::_wfopen(strFileName, L"rt,ccs=UTF-8"); if (!pFile) { hrRet = E_FAIL; goto clean0; } dwRealReadSize = (DWORD)::fread(pBuf, sizeof(WCHAR), dwFileSize, pFile); if (dwRealReadSize == 0) { hrRet = E_FAIL; goto clean0; } WCHAR* pszInfo = (WCHAR*)pBuf; BOOL bStart = FALSE; DWORD dwLineCount = _DoGetLineByBuf(pszInfo, (DWORD)::wcslen(pszInfo), vLogCache); for (itor = vLogCache.begin(); itor != vLogCache.end(); itor++) { szTarget = (*itor).c_str(); nPos = szTarget.Find(strSection.GetBuffer()); if (nPos != -1) { continue; } vLogCacheNew.push_back(szTarget.GetBuffer()); } { pfile = ::_wfopen(strFileName, L"wt,ccs=UTF-8"); } if (!pfile) { hrRet = S_OK; goto clean0; } for (itor = vLogCacheNew.begin(); itor != vLogCacheNew.end(); itor++) { wstring szTargetEx; szTargetEx = (*itor); DWORD dwSize = (DWORD)::fwrite(szTargetEx.c_str(), sizeof(WCHAR), ::wcslen(szTargetEx.c_str()), pfile); ::fwrite(L"\n", sizeof(WCHAR), ::wcslen(L"\n"), pfile); } clean0: if (pBuf) { delete []pBuf; pBuf = NULL; } if (pFile) { fclose(pFile); pFile = NULL; } if (pfile) { fclose(pfile); pFile = NULL; } return TRUE; }
BOOL CSpecialApp::ModifyTxtData(int nType, const CString strFileName) { BOOL bRet = FALSE; CString strFileNameEx = strFileName; BYTE* pBuf = NULL; HRESULT hrRet = E_FAIL; FILE* pFile = NULL; DWORD dwRealReadSize = 0; std::vector<std::wstring> vLogCache; std::vector<std::wstring>::iterator itor; CString szTarget; int nPos = -1; DWORD dwFileSize = _DoGetFileSizeByFileName(strFileNameEx); if (dwFileSize <= 0 || dwFileSize > 1*1024*1024) { hrRet = E_FAIL; goto clean0; } pBuf = new BYTE[dwFileSize * 2 + 2]; if (!pBuf) { hrRet = E_OUTOFMEMORY; goto clean0; } ::ZeroMemory(pBuf, dwFileSize * 2 + 2); pFile = ::_wfopen(strFileNameEx, L"rt,ccs=UTF-8"); if (!pFile) { hrRet = E_FAIL; goto clean0; } dwRealReadSize = (DWORD)::fread(pBuf, sizeof(WCHAR), dwFileSize, pFile); if (dwRealReadSize == 0) { hrRet = E_FAIL; goto clean0; } WCHAR* pszInfo = (WCHAR*)pBuf; DWORD dwLineCount = _DoGetLineByBuf(pszInfo, (DWORD)::wcslen(pszInfo), vLogCache); for (itor = vLogCache.begin(); itor != vLogCache.end(); itor++) { szTarget = (*itor).c_str(); CString strOutPut = strFileName; strOutPut += L"|"; strOutPut += szTarget; g_fnScanFile(g_pMain, nType,strOutPut, 0, 0); } clean0: if (pBuf) { delete []pBuf; pBuf = NULL; } if (pFile) { fclose(pFile); pFile = NULL; } return bRet; }
BOOL bigfilehelper::GetChromeDownloadDirs(std::vector<CString>& vDirs) { WCHAR szPath[MAX_PATH] = {0}; BOOL bRet = FALSE; CString szPathFull; CString szPathFullEx; CString szTarget; int nPos = -1; CString strPath = L""; WCHAR szAppDataPath[MAX_PATH] = { 0 }; bRet = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_PERSONAL, FALSE); if(bRet) { wcscat(szAppDataPath,L"\\Downloads"); if(szAppDataPath[0]==GetSystemDrive()) vDirs.push_back(szAppDataPath); } bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_LOCAL_APPDATA, FALSE); //bRet = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_DEFAULT, szPath);; szPathFull = szPath; szPathFullEx = szPath; szPathFullEx += _T("\\Google\\Chrome\\User Data\\Default\\Preferences"); szPathFull += _T("\\Google\\Chrome\\User Data\\Default"); WCHAR szRecord[MAX_PATH] = {0}; std::vector<std::wstring> vLogCache; std::vector<std::wstring>::iterator itor; const WCHAR* Point = NULL; HRESULT hrRet = E_FAIL; std::vector<std::wstring> vcStrline; BYTE* pBuf = NULL; FILE* pFile = NULL; DWORD dwRealReadSize = 0; DWORD dwFileSize = _DoGetFileSizeByFileName(szPathFullEx); if (dwFileSize <= 0) { hrRet = E_FAIL; goto _Exit; } pBuf = new BYTE[dwFileSize * 2 + 2]; if (!pBuf) { hrRet = E_OUTOFMEMORY; goto _Exit; } ::ZeroMemory(pBuf, dwFileSize * 2 + 2); pFile = ::_wfopen(szPathFullEx, L"rt,ccs=UTF-8"); if (!pFile) { hrRet = E_FAIL; goto _Exit; } dwRealReadSize = (DWORD)::fread(pBuf, sizeof(WCHAR), dwFileSize, pFile); if (dwRealReadSize == 0) { hrRet = E_FAIL; goto _Exit; } WCHAR* pszInfo = (WCHAR*)pBuf; DWORD dwLineCount = _DoGetLineByBuf(pszInfo, (DWORD)::wcslen(pszInfo), vLogCache); for (itor = vLogCache.begin(); itor != vLogCache.end(); itor++) { szTarget = (*itor).c_str(); nPos = szTarget.Find(L"default_directory"); if (nPos != -1) { nPos = szTarget.Find(L":"); szTarget = szTarget.Right(szTarget.GetLength() - nPos - 3); nPos = szTarget.Find(L"\""); szTarget = szTarget.Left(nPos); break; } } // if (_wcsicmp(szRecord, L"") == 0) // { // bRet = FALSE; // goto _Exit; // } for (int nIndex=0; nIndex<szTarget.GetLength();) { if(szTarget.GetAt(nIndex)==L'\\'&&szTarget.GetAt(nIndex+1)==L'\\') { strPath += L"\\"; nIndex += 2; } else { strPath += szTarget.GetAt(nIndex); nIndex++; } } if(strPath.GetAt(0)==GetSystemDrive()||strPath[0]==GetSystemDrive()-32||strPath[0]==GetSystemDrive()+32) vDirs.push_back(strPath); else goto _Exit; hrRet = S_OK; bRet = TRUE; _Exit: if (pBuf) { delete []pBuf; pBuf = NULL; } if (pFile) { fclose(pFile); pFile = NULL; } return bRet; }
// 获得Firefox的下载目录 BOOL bigfilehelper::GetFirefoxDownloadDirs(std::vector<CString>& vDirs) { WCHAR szPath[MAX_PATH] = {0}; BOOL bRet = FALSE; CString szPathFull; CString szPathFullEx; CString szTarget; CString strPath = L""; int nPos = -1; WCHAR szAppDataPath[MAX_PATH] = { 0 }; WinVersion winVer; winVer = KGetWinVersion(); if(WINVERSION_WIN7 == winVer) { bRet = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_PERSONAL, FALSE); if(bRet) { CString tmpdir(szAppDataPath); tmpdir = tmpdir.Left(tmpdir.ReverseFind(L'\\')); tmpdir += L"\\downloads"; if(tmpdir.GetAt(0)==GetSystemDrive()) vDirs.push_back(tmpdir); } } else { bRet = SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_PERSONAL, FALSE); if(bRet) { wcscat(szAppDataPath,L"\\下载"); if(szAppDataPath[0]==GetSystemDrive()) vDirs.push_back(szAppDataPath); } } bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE); szPathFull = szPath; szPathFullEx = szPath; szPathFullEx += _T("\\Mozilla\\Firefox"); szPathFull += _T("\\Mozilla\\Firefox\\profiles.ini"); WCHAR szRecord[MAX_PATH] = {0}; std::vector<std::wstring> vLogCache; std::vector<std::wstring>::iterator itor; GetPrivateProfileString(L"Profile0", L"Path", NULL, szRecord, MAX_PATH - 1, szPathFull); szPathFullEx += L"\\"; szPathFullEx += szRecord; szPathFullEx += L"\\prefs.js"; const WCHAR* Point = NULL; HRESULT hrRet = E_FAIL; std::vector<std::wstring> vcStrline; BYTE* pBuf = NULL; FILE* pFile = NULL; DWORD dwRealReadSize = 0; DWORD dwFileSize = _DoGetFileSizeByFileName(szPathFullEx); if (dwFileSize <= 0) { hrRet = E_FAIL; goto _Exit; } pBuf = new BYTE[dwFileSize * 2 + 2]; if (!pBuf) { hrRet = E_OUTOFMEMORY; goto _Exit; } ::ZeroMemory(pBuf, dwFileSize * 2 + 2); pFile = ::_wfopen(szPathFullEx, L"rt,ccs=UTF-8"); if (!pFile) { hrRet = E_FAIL; goto _Exit; } dwRealReadSize = (DWORD)::fread(pBuf, sizeof(WCHAR), dwFileSize, pFile); if (dwRealReadSize == 0) { hrRet = E_FAIL; goto _Exit; } WCHAR* pszInfo = (WCHAR*)pBuf; DWORD dwLineCount = _DoGetLineByBuf(pszInfo, (DWORD)::wcslen(pszInfo), vLogCache); for (itor = vLogCache.begin(); itor != vLogCache.end(); itor++) { szTarget = (*itor).c_str(); nPos = szTarget.Find(L"browser.download.dir"); if (nPos != -1) { nPos = szTarget.Find(L","); szTarget = szTarget.Right(szTarget.GetLength() - nPos - 3); nPos = szTarget.Find(L"\""); szTarget = szTarget.Left(nPos); break; } } if (_wcsicmp(szTarget, L"") == 0) { return FALSE; } for (int nIndex=0; nIndex<szTarget.GetLength();) { if(szTarget.GetAt(nIndex)==L'\\'&&szTarget.GetAt(nIndex+1)==L'\\') { strPath += L"\\"; nIndex += 2; } else { strPath += szTarget.GetAt(nIndex); nIndex++; } } if(strPath.GetAt(0)==GetSystemDrive()||strPath[0]==GetSystemDrive()-32||strPath[0]==GetSystemDrive()+32) vDirs.push_back(strPath); else goto _Exit; hrRet = S_OK; _Exit: if (pBuf) { delete []pBuf; pBuf = NULL; } if (pFile) { fclose(pFile); pFile = NULL; } return TRUE; }
HRESULT KppUserLog::ReadOrgLog(std::vector<std::wstring>& vLogCache) { WCHAR wszTime[TIME_MAX_LEN + 1] = {0}; std::wstring strLog; const WCHAR* Point = NULL; HRESULT hrRet = E_FAIL; std::vector<std::wstring> vcStrline; BYTE* pBuf = NULL; FILE* pFile = NULL; DWORD dwRealReadSize = 0; if (!m_bInitFlag) { return E_FAIL; } _LockWork(); DWORD dwFileSize = _DoGetFileSizeByFileName(m_strPathName.c_str()); if (dwFileSize <= 0) { hrRet = E_FAIL; goto _Exit; } pBuf = new BYTE[dwFileSize + 2]; if (!pBuf) { hrRet = E_OUTOFMEMORY; goto _Exit; } ::ZeroMemory(pBuf, dwFileSize + 2); pFile = ::_wfopen(m_strPathName.c_str(), L"rt,ccs=UNICODE"); if (!pFile) { hrRet = E_FAIL; goto _Exit; } dwRealReadSize = (DWORD)::fread(pBuf, sizeof(WCHAR), dwFileSize/2, pFile); if (dwRealReadSize == 0) { hrRet = E_FAIL; goto _Exit; } WCHAR* pszInfo = (WCHAR*)pBuf; DWORD dwLineCount = _DoGetLineByBuf(pszInfo, (DWORD)::wcslen(pszInfo), vLogCache); hrRet = S_OK; _Exit: if (pBuf) { delete []pBuf; pBuf = NULL; } if (pFile) { fclose(pFile); pFile = NULL; } _UnlockWork(); return hrRet; }