Export (0) Print
Expand All

Figure 1

Figure 1 Signatures for WinInet API
HANDLE FindFirstUrlCacheEntry(
    IN LPCTSTR lpszUrlSearchPattern,
    OUT LPINTERNET_CACHE_ENTRY_INFO lpFirstCacheEntryInfo,
    IN OUT LPDWORD lpdwFirstCacheEntryInfoBufferSize
);

BOOL FindNextUrlCacheEntry(
    IN HANDLE hEnumHandle,
    OUT LPINTERNET_CACHE_ENTRY_INFO lpNextCacheEntryInfo,
    IN OUT LPWORD lpdwNextCacheEntryInfoBufferSize
);

BOOL FindCloseUrlCache(
    IN HANDLE hEnumHandle
);
Figure 2 INTERNET_CACHE_ENTRY_INFO Structure
typedef struct _INTERNET_CACHE_ENTRY_INFO {
    DWORD dwStructSize;
    LPTSTR lpszSourceUrlName;
    LPTSTR lpszLocalFileName;
    DWORD CacheEntryType;
    DWORD dwUseCount;
    DWORD dwHitRate;
    DWORD dwSizeLow;
    DWORD dwSizeHigh;
    FILETIME LastModifiedTime;
    FILETIME ExpireTime;
    FILETIME LastAccessTime;
    FILETIME LastSyncTime;
    LPBYTE lpHeaderInfo;
    DWORD dwHeaderInfoSize;
    LPTSTR lpszFileExtension;
    union {
        DWORD dwReserved;
        DWORD dwExemptDelta;
    }
} INTERNET_CACHE_ENTRY_INFO, *LPINTERNET_CACHE_ENTRY_INFO;
Figure 3 Preincrement Implementation
cache_iterator& operator++()
{
    DWORD dwInitCacheEntrySize = 4096;
    m_lpCacheEntryInfo = 
        reinterpret_cast<LPINTERNET_CACHE_ENTRY_INFO>(new 
        char[dwInitCacheEntrySize]);
    m_lpCacheEntryInfo->dwStructSize = dwInitCacheEntrySize;

    if (!::FindNextUrlCacheEntry(m_hCacheEntry, m_lpCacheEntryInfo, 
                                 &dwInitCacheEntrySize))
    {
        delete [] m_lpCacheEntryInfo;

        switch (::GetLastError())
        {
        case ERROR_NO_MORE_ITEMS:
            ::FindCloseUrlCache(m_hCacheEntry);
            m_hCacheEntry = 0;
            break;

        case ERROR_INSUFFICIENT_BUFFER:
            // re-allocate and try
            m_lpCacheEntryInfo = 
                reinterpret_cast<LPINTERNET_CACHE_ENTRY_INFO>(new                               
                char[dwInitCacheEntrySize]);
            m_lpCacheEntryInfo->dwStructSize = dwInitCacheEntrySize;
            if (!::FindNextUrlCacheEntry(m_hCacheEntry, 
                m_lpCacheEntryInfo, &dwInitCacheEntrySize))
            {
                delete [] m_lpCacheEntryInfo;
                ::FindCloseUrlCache(m_hCacheEntry);
                m_hCacheEntry = 0;
            }
            break;

        default:
            ::FindCloseUrlCache(m_hCacheEntry);
            m_hCacheEntry = 0;
        }        
    }
    return *this;
}
Figure 4 FuncObjs.h
// FuncObjs.h - An STL Iterator for the Internet Explorer Cache
// 2000 by Samir Bajaj
//
// NOTES
//     This file contains the implementation of function objects
//     to illustrate the use of cache_iterator with STL algorithms.


#include "CacheIter.h"


template <typename T>
struct always_true: public std::unary_function<T, bool>
{
    bool operator()(T) { return true; }
};

struct display_cache_entry
{
    void operator()(INTERNET_CACHE_ENTRY_INFO CacheEntryInfo) const
    {
        if (CacheEntryInfo.lpszLocalFileName)
            std::cout << CacheEntryInfo.lpszLocalFileName << std::endl; 
    }
};

struct cache_file_size: std::binary_function<size_t, 
    INTERNET_CACHE_ENTRY_INFO, size_t>
{
    size_t operator()(size_t n, INTERNET_CACHE_ENTRY_INFO CacheEntryInfo)
    {
        if (CacheEntryInfo.lpszLocalFileName)
        {
            HANDLE hFile;
            if (INVALID_HANDLE_VALUE != (hFile = 
                          ::CreateFile(CacheEntryInfo.lpszLocalFileName,  
                                         GENERIC_READ, FILE_SHARE_READ |     
                                         FILE_SHARE_WRITE, 0,
                                         OPEN_EXISTING, 0, 0)))
            {
                n += ::GetFileSize(hFile, 0);
                ::CloseHandle(hFile);
            }
        }
        return n;
    }
};
Show:
© 2015 Microsoft