C# 读取临时文件夹gtk算法
来源:互联网 发布:查重软件免费 编辑:程序博客网 时间:2024/06/10 01:06
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr FindFirstUrlCacheEntry(
[MarshalAs(UnmanagedType.LPTStr)] string lpszUrlSearchPattern,
IntPtr lpFirstCacheEntryInfo,
ref int lpdwFirstCacheEntryInfoBufferSize);
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool FindNextUrlCacheEntry(
IntPtr hEnumHandle,
IntPtr lpNextCacheEntryInfo,
ref int lpdwNextCacheEntryInfoBufferSize);
[DllImport("wininet.dll")]
public static extern bool FindCloseUrlCache(
IntPtr hEnumHandle);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int FileTimeToSystemTime(
IntPtr lpFileTime,
IntPtr lpSystemTime);
#region 引入dll
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct INTERNET_CACHE_ENTRY_INFO
{
public int dwStructSize;
public IntPtr lpszSourceUrlName;
public IntPtr lpszLocalFileName;
public int CacheEntryType;
public int dwUseCount;
public int dwHitRate;
public int dwSizeLow;
public int dwSizeHigh;
public FILETIME LastModifiedTime;
public FILETIME ExpireTime;
public FILETIME LastAccessTime;
public FILETIME LastSyncTime;
public IntPtr lpHeaderInfo;
public int dwHeaderInfoSize;
public IntPtr lpszFileExtension;
public int dwExemptDelta;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
const int ERROR_NO_MORE_ITEMS = 259;
#endregion
#region FileTimeToSystemTime
private string FILETIMEtoDataTime(FILETIME time)
{
IntPtr filetime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FILETIME)));
IntPtr systime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SYSTEMTIME)));
Marshal.StructureToPtr(time, filetime, true);
FileTimeToSystemTime(filetime, systime);
SYSTEMTIME st = (SYSTEMTIME)Marshal.PtrToStructure(systime, typeof(SYSTEMTIME));
string Time = st.wYear.ToString() + "." + st.wMonth.ToString() + "." + st.wDay.ToString() + "." + st.wHour.ToString() + "." + st.wMinute.ToString() + "." + st.wSecond.ToString();
return Time;
}
#endregion
#region 加载数据
void FileOk_Click()
{
int nNeeded = 0, nBufSize;
IntPtr buf;
INTERNET_CACHE_ENTRY_INFO CacheItem;
IntPtr hEnum;
bool r;
FindFirstUrlCacheEntry(null, IntPtr.Zero, ref nNeeded);
if (Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS)
return;
nBufSize = nNeeded;
buf = Marshal.AllocHGlobal(nBufSize);
hEnum = FindFirstUrlCacheEntry(null, buf, ref nNeeded);
bool zz = true;
while (zz)
{
CacheItem = (INTERNET_CACHE_ENTRY_INFO)Marshal.PtrToStructure(buf,
typeof(INTERNET_CACHE_ENTRY_INFO));
string modifiedTime = FILETIMEtoDataTime(CacheItem.LastModifiedTime);
string expireTime = FILETIMEtoDataTime(CacheItem.ExpireTime);
string accessTime = FILETIMEtoDataTime(CacheItem.LastAccessTime);
string syncTime = FILETIMEtoDataTime(CacheItem.LastSyncTime);
#region 获得数据,存入数据库
try
{
//此處遍歷CacheItem即可
//例如
string s = Marshal.PtrToStringAuto(CacheItem.lpszSourceUrlName);
// string s = Marshal.PtrToStringAuto(CacheItem.lpszLocalFileName);
// textBox1.Text = textBox1.Text + s + Environment.NewLine;
//MessageBox.Show(s);
bool find = (s.Contains("g_tk="));
bool find1 = (s.Contains(qq));
// MessageBox.Show("find"+find.ToString());
// MessageBox.Show("find1"+find1.ToString());
if (find == true & find1 == true)
{
//MessageBox.Show(s);
Regex reg = new Regex(@"g_tk=[0-9]{6,13}");
MatchCollection mc = reg.Matches(s);
if (mc.Count != 0)
{
zz = false;
textBox2.Text = mc[0].Value.Replace("g_tk=", "");
MessageBox.Show("提取成功!");
textBox5.Text = "http://user.qzone.qq.com/";
}
else
{
webBrowser1.Refresh();
FileOk_Click();
}
zz = false;
// MessageBox.Show(mc[0].Value.Replace("g_tk=",""));
break;
}
}
catch
{
//異常處理
}
#endregion
nNeeded = nBufSize;
r = FindNextUrlCacheEntry(hEnum, buf, ref nNeeded);
if (!r && Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS)
break;
if (!r && nNeeded > nBufSize)
{
nBufSize = nNeeded;
buf = Marshal.ReAllocHGlobal(buf, (IntPtr)nBufSize);
FindNextUrlCacheEntry(hEnum, buf, ref nNeeded);
}
}
//MessageBox.Show("提取成功!");
Marshal.FreeHGlobal(buf);
}
#endregion
public static extern IntPtr FindFirstUrlCacheEntry(
[MarshalAs(UnmanagedType.LPTStr)] string lpszUrlSearchPattern,
IntPtr lpFirstCacheEntryInfo,
ref int lpdwFirstCacheEntryInfoBufferSize);
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool FindNextUrlCacheEntry(
IntPtr hEnumHandle,
IntPtr lpNextCacheEntryInfo,
ref int lpdwNextCacheEntryInfoBufferSize);
[DllImport("wininet.dll")]
public static extern bool FindCloseUrlCache(
IntPtr hEnumHandle);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int FileTimeToSystemTime(
IntPtr lpFileTime,
IntPtr lpSystemTime);
#region 引入dll
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct INTERNET_CACHE_ENTRY_INFO
{
public int dwStructSize;
public IntPtr lpszSourceUrlName;
public IntPtr lpszLocalFileName;
public int CacheEntryType;
public int dwUseCount;
public int dwHitRate;
public int dwSizeLow;
public int dwSizeHigh;
public FILETIME LastModifiedTime;
public FILETIME ExpireTime;
public FILETIME LastAccessTime;
public FILETIME LastSyncTime;
public IntPtr lpHeaderInfo;
public int dwHeaderInfoSize;
public IntPtr lpszFileExtension;
public int dwExemptDelta;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
const int ERROR_NO_MORE_ITEMS = 259;
#endregion
#region FileTimeToSystemTime
private string FILETIMEtoDataTime(FILETIME time)
{
IntPtr filetime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FILETIME)));
IntPtr systime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SYSTEMTIME)));
Marshal.StructureToPtr(time, filetime, true);
FileTimeToSystemTime(filetime, systime);
SYSTEMTIME st = (SYSTEMTIME)Marshal.PtrToStructure(systime, typeof(SYSTEMTIME));
string Time = st.wYear.ToString() + "." + st.wMonth.ToString() + "." + st.wDay.ToString() + "." + st.wHour.ToString() + "." + st.wMinute.ToString() + "." + st.wSecond.ToString();
return Time;
}
#endregion
#region 加载数据
void FileOk_Click()
{
int nNeeded = 0, nBufSize;
IntPtr buf;
INTERNET_CACHE_ENTRY_INFO CacheItem;
IntPtr hEnum;
bool r;
FindFirstUrlCacheEntry(null, IntPtr.Zero, ref nNeeded);
if (Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS)
return;
nBufSize = nNeeded;
buf = Marshal.AllocHGlobal(nBufSize);
hEnum = FindFirstUrlCacheEntry(null, buf, ref nNeeded);
bool zz = true;
while (zz)
{
CacheItem = (INTERNET_CACHE_ENTRY_INFO)Marshal.PtrToStructure(buf,
typeof(INTERNET_CACHE_ENTRY_INFO));
string modifiedTime = FILETIMEtoDataTime(CacheItem.LastModifiedTime);
string expireTime = FILETIMEtoDataTime(CacheItem.ExpireTime);
string accessTime = FILETIMEtoDataTime(CacheItem.LastAccessTime);
string syncTime = FILETIMEtoDataTime(CacheItem.LastSyncTime);
#region 获得数据,存入数据库
try
{
//此處遍歷CacheItem即可
//例如
string s = Marshal.PtrToStringAuto(CacheItem.lpszSourceUrlName);
// string s = Marshal.PtrToStringAuto(CacheItem.lpszLocalFileName);
// textBox1.Text = textBox1.Text + s + Environment.NewLine;
//MessageBox.Show(s);
bool find = (s.Contains("g_tk="));
bool find1 = (s.Contains(qq));
// MessageBox.Show("find"+find.ToString());
// MessageBox.Show("find1"+find1.ToString());
if (find == true & find1 == true)
{
//MessageBox.Show(s);
Regex reg = new Regex(@"g_tk=[0-9]{6,13}");
MatchCollection mc = reg.Matches(s);
if (mc.Count != 0)
{
zz = false;
textBox2.Text = mc[0].Value.Replace("g_tk=", "");
MessageBox.Show("提取成功!");
textBox5.Text = "http://user.qzone.qq.com/";
}
else
{
webBrowser1.Refresh();
FileOk_Click();
}
zz = false;
// MessageBox.Show(mc[0].Value.Replace("g_tk=",""));
break;
}
}
catch
{
//異常處理
}
#endregion
nNeeded = nBufSize;
r = FindNextUrlCacheEntry(hEnum, buf, ref nNeeded);
if (!r && Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS)
break;
if (!r && nNeeded > nBufSize)
{
nBufSize = nNeeded;
buf = Marshal.ReAllocHGlobal(buf, (IntPtr)nBufSize);
FindNextUrlCacheEntry(hEnum, buf, ref nNeeded);
}
}
//MessageBox.Show("提取成功!");
Marshal.FreeHGlobal(buf);
}
#endregion
- C# 读取临时文件夹gtk算法
- C#自我总结: 获取系统临时文件夹
- GTK文件读取进度条
- 用C#获取系统中的临时文件夹或windows安装文件夹
- .net临时文件夹
- gtk 实现键盘按键的读取
- 基于读取车载RFID标签自动开关车库门c#算法实现
- gtk
- GTK+
- gtk.....
- GTK +
- GTK
- GTK+
- gtk
- gtk+
- gtk
- gtk
- GTK
- hdu 1540
- 灰狼汇编视频笔记 上
- X264的调试与移植
- 关于java中的try-catch-finally语句和return
- 大灰狼的汇编视频教程笔记(下)
- C# 读取临时文件夹gtk算法
- POJ 2991 - Crane
- USACO Contact,难题,运算符重载,QuickSort,
- Android中View绘制流程以及invalidate()等相关方法分析
- 财报对比:GREE和DeNA由来已久的竞争
- 使用oprofile查找性能瓶颈
- 夜,小记流水夏日
- Eclipse 中安装ADT出错
- Eclipse Alt+/ 智能提示失效