/// <summary> /// Gets information about a file in the internet explorer cache /// </summary> /// <param name="Url">The url of the file to check the cache for</param> /// <returns>The Internet_Cache_Entry_Info about the file</returns> public static bool GetUrlCacheEntryInfo(string url, out Internet_Cache_Entry_Info cacheInfo) { if (url == null) { cacheInfo = new Internet_Cache_Entry_Info(); return(false); } // Set up buffer int bufferSize = Marshal.SizeOf(typeof(Internet_Cache_Entry_Info)) + url.Length + Kernel32.MAX_PATH; IntPtr buffer = Marshal.AllocCoTaskMem(bufferSize); try { // Get the URL Cache info while (!GetUrlCacheEntryInfo(url, buffer, ref bufferSize)) { switch (Marshal.GetLastWin32Error()) { // Grow the buffer case ERROR.INSUFFICIENT_BUFFER: buffer = Marshal.ReAllocCoTaskMem(buffer, bufferSize); break; // Didn't find the file! case ERROR.FILE_NOT_FOUND: cacheInfo = new Internet_Cache_Entry_Info(); return(false); // Some other exception occurred default: cacheInfo = new Internet_Cache_Entry_Info(); return(false); } } // The resulting cache info cacheInfo = (Internet_Cache_Entry_Info)Marshal.PtrToStructure(buffer, typeof(Internet_Cache_Entry_Info)); return(true); } finally { Marshal.FreeCoTaskMem(buffer); } }
/// <summary> /// Gets information about a file in the internet explorer cache /// </summary> /// <param name="Url">The url of the file to check the cache for</param> /// <returns>The Internet_Cache_Entry_Info about the file</returns> public static bool GetUrlCacheEntryInfo(string url, out Internet_Cache_Entry_Info cacheInfo) { if (url == null) { cacheInfo = new Internet_Cache_Entry_Info(); return false; } // Set up buffer int bufferSize = Marshal.SizeOf(typeof(Internet_Cache_Entry_Info)) + url.Length + Kernel32.MAX_PATH; IntPtr buffer = Marshal.AllocCoTaskMem(bufferSize); try { // Get the URL Cache info while (!GetUrlCacheEntryInfo(url, buffer, ref bufferSize)) { switch (Marshal.GetLastWin32Error()) { // Grow the buffer case ERROR.INSUFFICIENT_BUFFER: buffer = Marshal.ReAllocCoTaskMem(buffer, bufferSize); break; // Didn't find the file! case ERROR.FILE_NOT_FOUND: cacheInfo = new Internet_Cache_Entry_Info(); return false; // Some other exception occurred default: cacheInfo = new Internet_Cache_Entry_Info(); return false; } } // The resulting cache info cacheInfo = (Internet_Cache_Entry_Info)Marshal.PtrToStructure(buffer, typeof(Internet_Cache_Entry_Info)); return true; } finally { Marshal.FreeCoTaskMem(buffer); } }