DelHC.cpp 3.7 KB

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