testcache.cpp
来源:互联网 发布:知乎日报mac 百度网盘 编辑:程序博客网 时间:2024/06/10 02:39
#include "stdafx.h"
#include "TestCache.h"
#include<WinInet.h>
#include<Windows.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#pragma comment(lib, "Wininet.lib")
#include<map>
#include<vector>
using namespace std;
// The one and only application object
CWinApp theApp;
using namespace std;
struct WebCacheInfo
{
CString strOriPath;
CString strNewPath;
WebCacheInfo(const CString & str,const CString & str1)
{
strOriPath = str;
strNewPath = str1;
};
};
BOOL fun( vector<CString> &vUrls, map< CString,WebCacheInfo>& mapCaches)
{
DWORD dwEntrySize = 0;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry ;
for( int i = 0; i < vUrls.size(); i++ )
{
CString str = vUrls[i];
TCHAR m_lpUrlName[100] ;
_tcscpy(m_lpUrlName, str);
if (!GetUrlCacheEntryInfo( m_lpUrlName, NULL, &dwEntrySize))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO)new BYTE[dwEntrySize];
if (lpCacheEntry != NULL)
{
if (GetUrlCacheEntryInfo( m_lpUrlName,lpCacheEntry, &dwEntrySize))
{
CString m_lpUrlNamePath = lpCacheEntry->lpszLocalFileName;
int nLenth = 0;
nLenth = lstrlen(m_lpUrlNamePath);
int nPos1 = m_lpUrlNamePath.ReverseFind('\\');
CString m_strPath = m_lpUrlNamePath.Right( nLenth - nPos1);
CString m_strLinpath = _T("C:\\Users\\lenovo\\Desktop\\cache") + m_strPath;
CString str;
str.Format(_T("%s"),m_lpUrlName);
CString m_strAll = str + (L"\r\n")+ m_lpUrlNamePath +(L"\r\n")+ (L"\r\n");
FILE *file = NULL;
file = fopen("C:/Users/lenovo/Desktop/cache/cache.txt","ab+");
if (file != NULL)
fwrite(m_strAll, sizeof(TCHAR), m_strAll.GetLength(), file);
if (file != NULL)
{
fclose(file) ;
file = NULL;
}
// mapCaches.insert(make_pair("(i++",WebCacheInfo(lpCacheEntry->lpszLocalFileName,m_strLinpath)));
CopyFile( lpCacheEntry->lpszLocalFileName , m_strLinpath , FALSE);
}
}
if (lpCacheEntry != NULL)
{
delete []lpCacheEntry;
lpCacheEntry = NULL;
}
}
}
return TRUE;
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
vector<CString> vUrls ;
map<CString ,WebCacheInfo> mapCaches;
vUrls.push_back(L"http://www.taobao.com/");
vUrls.push_back(L"https://www.baidu.com/");
vUrls.push_back(L"http://www.jd.com/");
fun(vUrls,mapCaches);
int nRetCode = 0;
//HMODULE hModule = ::GetModuleHandle(NULL);
//DWORD dwEntrySize = 0;
//LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry;
//TCHAR m_lpUrlName [] = _T("http://www.taobao.com/"); //https://www.alipay.com/
//if (!GetUrlCacheEntryInfo( m_lpUrlName, NULL, &dwEntrySize))
//{
// if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER)
// return FALSE;
// else
// lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO)new BYTE[dwEntrySize];
// if (lpCacheEntry != NULL)
// {
// if (GetUrlCacheEntryInfo( m_lpUrlName,lpCacheEntry, &dwEntrySize))
// {
// CString m_lpUrlNamePath = lpCacheEntry->lpszLocalFileName;
// int nLenth = 0;
// nLenth = lstrlen(m_lpUrlNamePath);
// int nPos1 = m_lpUrlNamePath.ReverseFind('\\');
// //CString m_strPath = m_lpUrlNamePath.Right(nLenth - nPos - lstrlen(_T("C:")));
// CString m_strPath = m_lpUrlNamePath.Right( nLenth - nPos1);
// CString m_strLinpath = _T("C:\\Users\\newbie\\Desktop\\cache") + m_strPath;
// CString str;
// str.Format(_T("%s"),m_lpUrlName);
// CString m_strAll = str + (L"\r\n")+ m_lpUrlNamePath +(L"\r\n")+ (L"\r\n");
// FILE *file = NULL;
// file = fopen("C:/Users/newbie/Desktop/cache/cache.txt","ab+");
// if (file != NULL)
// fwrite(m_strAll, sizeof(TCHAR), m_strAll.GetLength(), file);
// if (file != NULL)
// { fclose(file) ; file = NULL;}
// CopyFile( lpCacheEntry->lpszLocalFileName , m_strLinpath , FALSE);
// }
// }
// if (lpCacheEntry != NULL)
// {
// delete []lpCacheEntry;
// lpCacheEntry = NULL;
// }
//}
system("pause");
return nRetCode;
}
0 0
- testcache.cpp
- cpp
- CPP
- CPP
- cpp
- cpp
- CPP
- CPP
- ClientSockThread.cpp&&ClientUrlThread.cpp
- cpp调用其他cpp
- ex34a.cpp&&ex34aDoc.cpp&&ex34aView.cpp
- MainFrm.cpp&&ServerThread.cpp&&SheetConfig.cpp
- CPP thread
- cpp->html
- CFaderWnd.cpp
- PasswordReminder.cpp
- object.cpp
- CmdTarget.cpp
- 关于http这种无状态协议如何解决页面传递参数的若干解决方案
- P51 第16题:输入三个整数a,b,c,请按从小到大的顺序输出
- #define SREG (*(volatile unsigned CHAR *)0x5F)
- Strings类的简单使用-代码优雅之道Guava(一)
- (4)设计模式:Strategy
- testcache.cpp
- Linux入门:忘记root密码怎么办
- Java中的for循环
- OpenCV中feature2D学习——FAST特征点检测
- <Android>自定义View
- Swift 区间类型
- hdu 1029
- SQL更新某字段中的部分值语句
- UISearchBar搜索