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*/)
  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. m_dtdays=AfxGetApp()->GetProfileInt (LYFZVERSION, "dtdays2", 5);
  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. }