DelHC.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // DelHC.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "DelHC.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // DelHC dialog
  13. DelHC::DelHC(CWnd* pParent /*=NULL*/): CDialog(DelHC::IDD, pParent),m_bIs64Bit(FALSE)
  14. {
  15. //{{AFX_DATA_INIT(DelHC)
  16. m_dtdays = 5;
  17. //}}AFX_DATA_INIT
  18. }
  19. void DelHC::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(DelHC)
  23. DDX_Control(pDX, IDC_SPIN1, m_spin1);
  24. DDX_Control(pDX, IDC_LIST1, m_List1);
  25. DDX_Text(pDX, IDC_EDITyear, m_dtdays);
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(DelHC, CDialog)
  29. //{{AFX_MSG_MAP(DelHC)
  30. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  31. ON_WM_DESTROY()
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // DelHC message handlers
  36. //extern void DeleteDirectory(CString strDir);
  37. CString DelHC::GetCreateTime2(CString path)
  38. {
  39. CFileFind finder;
  40. path.TrimRight("\\");
  41. BOOL bWorking = finder.FindFile(path);
  42. if(bWorking)
  43. {
  44. finder.FindNextFile( );
  45. CTime tm;
  46. finder.GetCreationTime(tm);
  47. CTimeSpan dt=CTime::GetCurrentTime()-tm;
  48. CString str;
  49. str.Format("%d天前:", dt.GetDays());
  50. if(dt.GetDays()>=m_dtdays)
  51. {
  52. ::DeleteDirectory (path); // 递归删除缓存;
  53. return "";
  54. }
  55. return str;
  56. }
  57. return "";
  58. }
  59. BOOL DelHC::OnInitDialog()
  60. {
  61. CDialog::OnInitDialog();
  62. // TODO: Add extra initialization here
  63. m_spin1.SetRange(1, 100);
  64. m_dtdays=AfxGetApp()->GetProfileInt (LYFZVERSION, "dtdays2", 5);
  65. m_bIs64Bit = IsWow64();
  66. UpdateData(0);
  67. LoadItem();
  68. return TRUE; // return TRUE unless you set the focus to a control
  69. // EXCEPTION: OCX Property Pages should return FALSE
  70. }
  71. void DelHC::OnOK()
  72. {
  73. // TODO: Add extra validation here
  74. int pos=m_List1.GetCurSel();
  75. if(pos==-1)
  76. {
  77. AfxMessageBox("请先选中项目!");return;
  78. } if(AfxMessageBox("是否清除此缓存?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  79. CString str;
  80. m_List1.GetText(pos, str);
  81. pos=str.Find(":");
  82. if(pos!=-1)str=str.Right(str.GetLength()-pos-1);
  83. char path[MAX_PATH];
  84. ::GetSystemDirectory (path, MAX_PATH);
  85. CString sysdir=path;
  86. sysdir+="\\lyfz";
  87. ::CreateDirectory (sysdir, NULL);
  88. sysdir+="\\";
  89. sysdir+=str;
  90. ::DeleteDirectory (sysdir); // 递归删除缓存;
  91. LoadItem() ;
  92. }
  93. void DelHC::LoadItem()
  94. {
  95. m_List1.ResetContent ();
  96. char path[MAX_PATH];
  97. ::GetSystemDirectory(path, MAX_PATH);
  98. CString sysdir=path;
  99. sysdir+="\\lyfz";
  100. ::CreateDirectory(sysdir, NULL);
  101. sysdir+="\\";
  102. CString str,str2;
  103. using namespace helper_coffs;
  104. ffsco o;
  105. o.dirs(0);
  106. o.find(LPCSTR(sysdir), LPCSTR("*.*"));
  107. ffsco::typeT coo;
  108. ffsco::typeT::iterator it;
  109. coo = o.co_dir();
  110. for (it = coo.begin();coo.end() != it;it ++)
  111. {
  112. str=(*it).c_str();
  113. if(str==sysdir)continue;
  114. str.TrimRight("\\");
  115. str2=GetCreateTime2(str);if(str2=="")continue;
  116. // AfxMessageBox(str.Right(str.GetLength()-str.ReverseFind('\\')-1));
  117. if(m_List1.GetCount()%2)
  118. m_List1.AddEntry( str2+str.Right(str.GetLength()-str.ReverseFind('\\')-1) , g_gridcol1, m_List1.GetCount());
  119. else
  120. m_List1.AddEntry( str2+str.Right(str.GetLength()-str.ReverseFind('\\')-1) , g_gridcol2, m_List1.GetCount());
  121. }
  122. m_List1.Invalidate ();
  123. }
  124. void DelHC::OnButton1()
  125. {
  126. // TODO: Add your control notification handler code here
  127. if(AfxMessageBox("是否全部清除缓存?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  128. char path[MAX_PATH];
  129. ::GetSystemDirectory (path, MAX_PATH);
  130. CString sysdir=path;
  131. sysdir+="\\lyfz";
  132. ::DeleteDirectory (sysdir); // 递归删除缓存;
  133. LoadItem() ;
  134. }
  135. void DelHC::OnDestroy()
  136. {
  137. CDialog::OnDestroy();
  138. // TODO: Add your message handler code here
  139. UpdateData();
  140. AfxGetApp()->WriteProfileInt (LYFZVERSION, "dtdays2", m_dtdays);
  141. }