// DelHC.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "DelHC.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // DelHC dialog DelHC::DelHC(CWnd* pParent /*=NULL*/) : CDialog(DelHC::IDD, pParent) { //{{AFX_DATA_INIT(DelHC) m_dtdays = 5; //}}AFX_DATA_INIT } void DelHC::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(DelHC) DDX_Control(pDX, IDC_SPIN1, m_spin1); DDX_Control(pDX, IDC_LIST1, m_List1); DDX_Text(pDX, IDC_EDITyear, m_dtdays); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(DelHC, CDialog) //{{AFX_MSG_MAP(DelHC) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // DelHC message handlers //extern void DeleteDirectory(CString strDir); CString DelHC::GetCreateTime2(CString path) { CFileFind finder; path.TrimRight("\\"); BOOL bWorking = finder.FindFile(path); if(bWorking) { finder.FindNextFile( ); CTime tm; finder.GetCreationTime(tm); CTimeSpan dt=CTime::GetCurrentTime()-tm; CString str; str.Format("%d天前:", dt.GetDays()); if(dt.GetDays()>=m_dtdays) { ::DeleteDirectory (path); // 递归删除缓存; return ""; } return str; } return ""; } BOOL DelHC::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_spin1.SetRange(1, 100); CString version = _T ("Version 1.0"); m_dtdays=AfxGetApp()->GetProfileInt (version, "dtdays2", 5); UpdateData(0); LoadItem(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void DelHC::OnOK() { // TODO: Add extra validation here int pos=m_List1.GetCurSel(); if(pos==-1) { AfxMessageBox("请先选中项目!");return; } if(AfxMessageBox("是否清除此缓存?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return; CString str; m_List1.GetText(pos, str); pos=str.Find(":"); if(pos!=-1)str=str.Right(str.GetLength()-pos-1); char path[MAX_PATH]; ::GetSystemDirectory (path, MAX_PATH); CString sysdir=path; sysdir+="\\lyfz"; ::CreateDirectory (sysdir, NULL); sysdir+="\\"; sysdir+=str; ::DeleteDirectory (sysdir); // 递归删除缓存; LoadItem() ; } void DelHC::LoadItem() { m_List1.ResetContent (); char path[MAX_PATH]; ::GetSystemDirectory (path, MAX_PATH); CString sysdir=path; sysdir+="\\lyfz"; ::CreateDirectory (sysdir, NULL); sysdir+="\\"; CString str,str2; using namespace helper_coffs; ffsco o; o.dirs(0); o.find(LPCSTR(sysdir), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); for (it = coo.begin();coo.end() != it;it ++) { str=(*it).c_str(); if(str==sysdir)continue; str.TrimRight("\\"); str2=GetCreateTime2(str);if(str2=="")continue; // AfxMessageBox(str.Right(str.GetLength()-str.ReverseFind('\\')-1)); if(m_List1.GetCount()%2) m_List1.AddEntry( str2+str.Right(str.GetLength()-str.ReverseFind('\\')-1) , g_gridcol1, m_List1.GetCount()); else m_List1.AddEntry( str2+str.Right(str.GetLength()-str.ReverseFind('\\')-1) , g_gridcol2, m_List1.GetCount()); } m_List1.Invalidate (); } void DelHC::OnButton1() { // TODO: Add your control notification handler code here if(AfxMessageBox("是否全部清除缓存?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return; char path[MAX_PATH]; ::GetSystemDirectory (path, MAX_PATH); CString sysdir=path; sysdir+="\\lyfz"; ::DeleteDirectory (sysdir); // 递归删除缓存; LoadItem() ; } void DelHC::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here UpdateData(); CString version = _T ("Version 1.0"); AfxGetApp()->WriteProfileInt (version, "dtdays2", m_dtdays); }