www.pudn.com > SafeClean.rar > DiskClean.cpp
// DiskClean.cpp : implementation file // #include "stdafx.h" #include "SafeClean.h" #include "DiskClean.h" #include "Direct.h" #include "stdio.h" #include "io.h" #include "sys/types.h" #include#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern BYTE newAttribute1=0; CFileException eNew; CFile aFileNew; ///////////////////////////////////////////////////////////////////////////// // DiskClean dialog int Flag=655; char Path[80],*Ori; int ProgressBar; char buffer[_MAX_PATH]; CString PointerToDirectory; DiskClean::DiskClean(CWnd* pParent /*=NULL*/) : CDialog(DiskClean::IDD, pParent) { //{{AFX_DATA_INIT(DiskClean) m_IntCookies = FALSE; m_IntExpHistory = FALSE; m_OffWebPages = FALSE; m_RecycleBin = FALSE; m_TempIntFiles = FALSE; m_WinRecentDocs = FALSE; m_WinTemp = FALSE; m_StaticText = _T("It's safe to select all option, and sweeper will wipe your junk off!"); m_StaticTextForTemp = _T("Display's the current status of the files/folder "); //}}AFX_DATA_INIT } void DiskClean::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(DiskClean) DDX_Control(pDX, IDCANCEL, m_Cancel); DDX_Control(pDX, IDC_CLEARALL, m_ClearAll); DDX_Control(pDX, ID_CLEANIT, m_CleanIt); DDX_Control(pDX, IDC_SELECTALL, m_SelectAll); DDX_Control(pDX, IDC_PROGBARTRACK, m_ProgBarTrack); DDX_Check(pDX, IDC_INTCOOKIES, m_IntCookies); DDX_Check(pDX, IDC_INTEXPHISTORY, m_IntExpHistory); DDX_Check(pDX, IDC_OFFWEBPAGES, m_OffWebPages); DDX_Check(pDX, IDC_RECYCLEBIN, m_RecycleBin); DDX_Check(pDX, IDC_TEMPINTERFILES, m_TempIntFiles); DDX_Check(pDX, IDC_WINRECDOCS, m_WinRecentDocs); DDX_Check(pDX, IDC_WINTEMP, m_WinTemp); DDX_Text(pDX, IDC_STATICTEXT, m_StaticText); DDX_Text(pDX, IDC_STATICTEXTFORTEMP, m_StaticTextForTemp); DDX_Control(pDX, IDC_LINK, m_Link); m_Link.SetURL(_T("http://talele.50megs.com/suggest.htm")); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(DiskClean, CDialog) //{{AFX_MSG_MAP(DiskClean) ON_BN_CLICKED(IDC_TEMPINTERFILES, OnTempinterfiles) ON_BN_CLICKED(IDC_INTEXPHISTORY, OnIntexphistory) ON_BN_CLICKED(IDC_INTCOOKIES, OnIntcookies) ON_BN_CLICKED(IDC_OFFWEBPAGES, OnOffwebpages) ON_BN_CLICKED(IDC_RECYCLEBIN, OnRecyclebin) ON_BN_CLICKED(IDC_WINTEMP, OnWintemp) ON_BN_CLICKED(IDC_WINRECDOCS, OnWinrecdocs) ON_BN_CLICKED(IDC_SELECTALL, OnSelectall) ON_BN_CLICKED(IDC_CLEARALL, OnClearall) ON_BN_CLICKED(IDC_VIEWFILES, OnViewfiles) ON_BN_CLICKED(ID_CLEANIT, OnCleanit) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // DiskClean message handlers void DiskClean::OnTempinterfiles() { // TODO: Add your control notification handler code here Flag=0; if(m_TempIntFiles == TRUE) { m_TempIntFiles = FALSE; } else { m_TempIntFiles = TRUE; m_StaticText.Format("The Temporary Internet Files folder contains Web pages stored on your hard disk for quick viewing. Your personalized settings for Web pages will be left intact."); UpdateData(FALSE); } } void DiskClean::OnIntexphistory() { // TODO: Add your control notification handler code here Flag=1; if(m_IntExpHistory == TRUE) { m_IntExpHistory = FALSE; } else { m_IntExpHistory = TRUE; m_StaticText.Format("The History folder contains links to page you've visited , for quick access to recently viewed pages."); UpdateData(FALSE); } } void DiskClean::OnIntcookies() { // TODO: Add your control notification handler code here Flag=2; if(m_IntCookies == TRUE) { m_IntCookies = FALSE; } else { m_IntCookies = TRUE; m_StaticText.Format("The Cookies will be cleaned. This are temporary files ,its safe to sweep them off."); UpdateData(FALSE); } } void DiskClean::OnOffwebpages() { // TODO: Add your control notification handler code here Flag=3; if(m_OffWebPages == TRUE) { m_OffWebPages = FALSE; } else { m_OffWebPages = TRUE; m_StaticText.Format("The will be clearing off line Pages. "); UpdateData(FALSE); } } void DiskClean::OnRecyclebin() { // TODO: Add your control notification handler code here Flag=4; if(m_RecycleBin == TRUE) { m_RecycleBin = FALSE; } else { m_RecycleBin = TRUE; m_StaticText.Format("The Recycle Bin contains files you have deleted from your computer. These files are not permanently removed until you empty the Recycle Bin."); UpdateData(FALSE); } } void DiskClean::OnWintemp() { // TODO: Add your control notification handler code here Flag=5; if(m_WinTemp == TRUE) { m_WinTemp = FALSE; } else { m_WinTemp = TRUE; m_StaticText.Format("Programs sometimes store temporary information in a TEMP folder. Before a program closes, it usually deletes this information.You can safely delete temporary files that have not been modified in over a week."); UpdateData(FALSE); } } void DiskClean::OnWinrecdocs() { // TODO: Add your control notification handler code here Flag=6; if(m_WinRecentDocs == TRUE) { m_WinRecentDocs = FALSE; } else { m_WinRecentDocs = TRUE; m_StaticText.Format("The Documents history will be cleaned. This are temporary history files ,its safe to sweep them off."); UpdateData(FALSE); } } void DiskClean::OnSelectall() { // TODO: Add your control notification handler code here Flag=655; m_StaticText.Format("Lets Junk off the garbage.It's Safe to choose this option,It won't harm your O.S. or make it unstable. "); m_IntCookies=TRUE; m_IntExpHistory=TRUE; m_OffWebPages=TRUE; m_RecycleBin=TRUE; m_TempIntFiles=TRUE; m_WinRecentDocs=TRUE; m_WinTemp=TRUE; m_StaticTextForTemp = _T("Display's the current status of the files/folder "); UpdateData(FALSE); } void DiskClean::OnClearall() { // TODO: Add your control notification handler code here m_StaticText.Format(" "); m_IntCookies=FALSE; m_IntExpHistory=FALSE; m_OffWebPages=FALSE; m_RecycleBin=FALSE; m_TempIntFiles=FALSE; m_WinRecentDocs=FALSE; m_WinTemp=FALSE; m_StaticText = _T("Duh !!!! Once again the same Gratifying job of selection,Its really tough to select,Empty box looks more fascinating than the filled one ,Hummmmmm So Nice... "); UpdateData(FALSE); } void DiskClean::OnViewfiles() { // TODO: Add your control notification handler code here char buffer[_MAX_PATH]; _getcwd( buffer, _MAX_PATH ); *Path=NULL; for(int i=0;i<8 ;i++) { if(strncmp("winbootdir",_environ[i],10)==0) { strcpy(Path,(_environ[i])+11); break; break; } } switch(Flag) { case 0 : _chdir(Path);WinExec("explorer.exe Temporary Internet Files",SW_SHOWMAXIMIZED);break; case 1 : _chdir(Path);WinExec("explorer.exe History",SW_SHOWMAXIMIZED);break; case 2 : _chdir(Path);WinExec("explorer.exe Cookies",SW_SHOWMAXIMIZED); break; case 3 : _chdir(Path);WinExec("explorer.exe Offline Web Pages",SW_SHOWMAXIMIZED); break; case 4 : WinExec("explorer.exe C:\\Recycled",SW_SHOWMAXIMIZED); break; case 5 : _chdir(Path);WinExec("explorer.exe Temp",SW_SHOWMAXIMIZED);break; case 6 : _chdir(Path);WinExec("explorer.exe Recent",SW_SHOWMAXIMIZED); break; default: AfxMessageBox("Select Check Box to Explore"); } _chdir(buffer); } void DiskClean::OnCleanit() { // TODO: Add your control notification handler code here GetDlgItem(IDC_SELECTALL)->EnableWindow(FALSE); GetDlgItem(IDC_CLEARALL)->EnableWindow(FALSE); GetDlgItem(IDC_VIEWFILES)->EnableWindow(FALSE); GetDlgItem(IDCANCEL)->EnableWindow(FALSE); GetDlgItem(IDC_PROGBARTRACK)->ShowWindow(TRUE); m_ProgBarTrack.SetRange(0,7); m_ProgBarTrack.SetPos(0); for(int i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } if(m_IntCookies==TRUE) { ProgressBar = 1; *Path=NULL; for(int i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } strcat(Path,"\\Cookies"); if(_chdir(Path)==0){ DiskClean::DeleteFilesFunction("*.*"); m_ProgBarTrack.SetPos(ProgressBar); } *Path=NULL; for(i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } strcat(Path,"\\Locals~1\\Tempor~1\\content.ie5"); if(_chdir(Path)==0){ DiskClean::DeleteTempFiles("*.*"); m_ProgBarTrack.SetPos(ProgressBar); } else{ } } if(m_IntExpHistory==TRUE) { ProgressBar = 2; *Path=NULL; for(int i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } strcat(Path,"\\History"); if(_chdir(Path)==0){ DiskClean::DeleteTempFiles("*.*"); m_ProgBarTrack.SetPos(ProgressBar); } else{ } } if(m_OffWebPages==TRUE) { ProgressBar = 3; *Path=NULL; for(int i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } strcat(Path,"\\Offlin~1"); if(_chdir(Path)==0){ DiskClean::DeleteFilesFunction("*.*"); m_ProgBarTrack.SetPos(ProgressBar); } else{ } } if(m_RecycleBin==TRUE) { ProgressBar = 4; static char path[_MAX_PATH]; CString Drive; char buffer[_MAX_PATH]; _getcwd( buffer, _MAX_PATH ); /* Save current drive. */ if(_chdir("C:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } if(_chdir("D:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } if(_chdir("E:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } if(_chdir("F:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } if(_chdir("G:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } if(_chdir("H:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } if(_chdir("I:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } if(_chdir("J:\\Recycled")==0) { DiskClean::DeleteTempFiles("*.*"); } _chdir(buffer); m_ProgBarTrack.SetPos(ProgressBar); } if(m_TempIntFiles==TRUE) { ProgressBar = 5; *Path=NULL; for(int i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } strcat(Path,"\\Tempor~1"); if(_chdir(Path)==0){ DiskClean::DeleteTempFiles("*.*"); //_mkdir(Path); m_ProgBarTrack.SetPos(ProgressBar); } else{ } } if(m_WinRecentDocs==TRUE) { ProgressBar = 6; *Path=NULL; for(int i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } strcat(Path,"\\Recent"); if(_chdir(Path)==0){ DiskClean::DeleteFilesFunction("*.*"); m_ProgBarTrack.SetPos(ProgressBar); } else{ } } if(m_WinTemp==TRUE) { ProgressBar = 7; *Path=NULL; for(int i=0;i<8 ;i++) {if(strncmp("winbootdir",_environ[i],10)==0){ strcpy(Path,(_environ[i])+11);break;break;} } strcat(Path,"\\Temp"); //MessageBox(Path); if(_chdir(Path)==0) { DiskClean::DeleteTempFiles("*.*"); m_ProgBarTrack.SetPos(ProgressBar); } else{ _mkdir(Path); } } m_ProgBarTrack.SetPos(7); m_StaticTextForTemp.Format("Finished"); Sleep(445); m_ProgBarTrack.SetPos(0); UpdateData(FALSE); GetDlgItem(IDC_SELECTALL)->EnableWindow(TRUE); GetDlgItem(IDC_CLEARALL)->EnableWindow(TRUE); GetDlgItem(IDC_VIEWFILES)->EnableWindow(TRUE); GetDlgItem(IDCANCEL)->EnableWindow(TRUE); GetDlgItem(IDC_PROGBARTRACK)->ShowWindow(FALSE); } DiskClean::DeleteFilesFunction(char *Temp) { CFileException e; CFile aFile; _chdir(Path); CFileFind finder; BOOL bWorking = finder.FindFile("*.*"); while (bWorking) { bWorking = finder.FindNextFile(); m_StaticTextForTemp.Format(finder.GetFilePath()); _chmod(finder.GetFileName(),_S_IWRITE ); CFileStatus status; CFile::GetStatus( finder.GetFileName(), status ); status.m_attribute = newAttribute1; if( !aFile.Open(finder.GetFileName(), CFile::modeCreate | CFile::modeWrite, &e ) ) { #ifdef _DEBUG // afxDump << "File could not be opened " << e.m_cause << "\n"; #endif } else { aFile.Close(); CFile::SetStatus(finder.GetFileName(), status ); _unlink(finder.GetFileName()); } _unlink(finder.GetFileName()); } DiskClean::UpdateWindow(); } DiskClean::DeleteTempFiles(char *Temp) { CFileFind finder; BOOL bWorking = finder.FindFile("*.*"); while (bWorking) { bWorking = finder.FindNextFile(); _chmod(finder.GetFileName(),_S_IWRITE ); //_unlink(finder.GetFilePath()); //okay leave it _chmod(finder.GetFileName(),_S_IWRITE ); CFileStatus status; CFile::GetStatus( finder.GetFileName(), status ); status.m_attribute = newAttribute1; if( !aFileNew.Open(finder.GetFileName(), CFile::modeCreate | CFile::modeWrite, &eNew ) ) { #ifdef _DEBUG // afxDump << "File could not be opened " << e.m_cause << "\n"; #endif } else { aFileNew.Close(); CFile::SetStatus(finder.GetFileName(), status ); _unlink(finder.GetFileName()); _unlink(finder.GetFileName()); } m_StaticTextForTemp.Format(finder.GetFilePath()); UpdateData(FALSE); if(finder.IsDirectory()!=0 &&finder.GetFileName()!='.'&&finder.GetFileName()!=".." ) { _chdir(finder.GetFileName()); DiskClean::DeleteTempFiles("*.*"); } } _rmdir(PointerToDirectory); _rmdir(finder.GetFileName()); PointerToDirectory = ( _getcwd( buffer, _MAX_PATH )); _chdir(".."); DiskClean::UpdateWindow(); }