www.pudn.com > SafeClean.rar > FinalDeletion.cpp


// FinalDeletion.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "SafeClean.h" 
#include "FinalDeletion.h" 
#include "Afxcmn.h" 
 
 
#include "stdio.h" 
#include "conio.h" 
#include "sys/stat.h" 
#include "io.h" 
#include "sys/types.h" 
#include "stdlib.h" 
#include "direct.h" 
#include "string.h" 
 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// FinalDeletion dialog 
 
int nCount_Of_Execution=0,GetEditing; 
int j,NFiles=0,NFileSize=0,len1,len2; 
FILE *fs,*ftp,*file,*tfile,*longf; 
char *pFileName; 
char *PATH = "C:\\Windows\\notepad.exe "; 
extern BYTE newAttribute=0; 
CFileException e; 
 
FinalDeletion::FinalDeletion(CWnd* pParent /*=NULL*/) 
	: CDialog(FinalDeletion::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(FinalDeletion) 
	m_DText = _T("NB: Double Click files in the list to remove from list.\n Right click to edit/browse/quikview "); 
	//}}AFX_DATA_INIT 
	 
	 
} 
 
 
void FinalDeletion::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(FinalDeletion) 
	DDX_Control(pDX, IDC_COMPRESS, m_compress); 
	DDX_Control(pDX, IDC_REPORT, m_Report); 
	DDX_Control(pDX, IDCANCEL, m_Cancel); 
	DDX_Control(pDX, ID_DELETE, m_Delete); 
	DDX_Control(pDX, IDC_ANIMATE_DEL, m_AniDel); 
	DDX_Control(pDX, IDC_DELLIST, m_List); 
	DDX_Text(pDX, IDC_DELTEXT, m_DText); 
	//}}AFX_DATA_MAP 
	CRect rect; 
	m_List.GetClientRect(&rect); 
	int nCol = rect.Width()/5; 
    m_List.InsertColumn(0,"File",LVCFMT_LEFT,nCol); 	 
    m_List.InsertColumn(1,"Path",LVCFMT_LEFT,nCol); 	 
    m_List.InsertColumn(2,"Size",LVCFMT_LEFT,nCol);  
	m_List.InsertColumn(3,"Last Access",LVCFMT_LEFT,nCol);  
	m_List.InsertColumn(4,"Access Time",LVCFMT_LEFT,nCol);  
	FinalDeletion::FinalFileList(); 
	 
	m_Delete.LoadBitmap(IDB_3RED); 
	m_Cancel.LoadBitmap(IDB_3CANCEL); 
	m_Report.LoadBitmap(IDB_REPORT); 
	//m_compress.LoadBitmap(IDB_3RED); 
	m_compress.LoadBitmap(IDB_COMPRESS); 
 
	CString text1=_T("Delete all files from the shown list."); 
    m_Delete.SetToolTipText(&text1);  
 
	CString text2=_T("Report the log file of liberated space."); 
    m_Report.SetToolTipText(&text2);  
 
	CString text3=_T("Canel the action and go back"); 
    m_Cancel.SetToolTipText(&text3);  
	 
     
	 
} 
 
 
BEGIN_MESSAGE_MAP(FinalDeletion, CDialog) 
	//{{AFX_MSG_MAP(FinalDeletion) 
	ON_BN_CLICKED(ID_DELETE, OnDelete) 
	ON_BN_CLICKED(IDC_REPORT, OnReport) 
	ON_BN_CLICKED(IDC_COMPRESS, OnCompress) 
	ON_NOTIFY(NM_DBLCLK, IDC_DELLIST, OnDblclkDellist) 
	ON_WM_CONTEXTMENU() 
	ON_WM_NCHITTEST() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// FinalDeletion message handlers 
 
void FinalDeletion::FinalFileList() 
{ 
 
 
	fcloseall(); 
    LVITEM Lvi; 
	CString FileName,Path; 
    char Lmsg[_MAX_PATH],msg[_MAX_PATH]; 
	 
	int TotalKb=0; 
	int Length,Day,Month,Year,Hour,Minute,in; 
    int i=-1,nice=-1; 
    CString String1; 
	fs=fopen("c:\\Temp\\~safe.nct","r+"); 
	 if(fs==NULL){ 
		 AfxMessageBox("DATABASE CORRUPTED!!!!!!   Rescan. Or No drive Selected."); 
		 exit(0); 
	 } 
 
	 ftp=fopen("c:\\Temp\\~Path.nct","r+"); 
	 if(ftp==NULL){ 
		 AfxMessageBox("DATABASE CORRUPTED!!!!!! Rescan. Or No Drive Selected."); 
		 exit(1); 
	 } 
     
	file=fopen("c:\\Temp\\flogview.ini","w+"); 
	if(file==NULL){ 
		 AfxMessageBox("DATABASE CORRUPTED!!!!!! Rescan. Or No Drive Selected."); 
		 exit(1); 
	 } 
     
	longf=fopen("c:\\Temp\\long.nct","r+"); 
	if(longf==NULL){ 
		 AfxMessageBox("DATABASE CORRUPTED!!!!!! Rescan. Or No Drive Selected."); 
		 exit(1); 
	 } 
 
	 
	 while(!feof(fs)) 
	 { 
	   i=i+1; 
	   fscanf(fs,"%s %d %d %d %d %d %d %d ",FileName,&Length,&Day,&Month,&Year,&Hour,&Minute,&in); 
	   if(Length < 0){ 
		   GetDlgItem(ID_DELETE)->EnableWindow(FALSE); 
		   GetDlgItem(IDC_COMPRESS)->EnableWindow(FALSE); 
		   GetDlgItem(IDC_DELLIST)->EnableWindow(FALSE); 
		   AfxMessageBox("No Junk file found on this drive");fcloseall();break;exit(0); 
	   } 
	   TotalKb = TotalKb + Length; 
	   fgets(msg,_MAX_PATH, ftp); 
 
       len1=strlen(msg); 
       msg[len1-1]='\0'; 
 
	    fgets(Lmsg,_MAX_PATH,longf); 
        len2=strlen(Lmsg); 
        Lmsg[len2-1]='\0';  
 
	    
       CString String; 
       Lvi.mask =  LVIF_IMAGE | LVIF_TEXT; 
       String.Format(_T(Lmsg)); 
 
        Lvi.iItem = i; 
		Lvi.iSubItem = 0; 
		Lvi.pszText = (LPTSTR)(LPCTSTR)(String); 
		Lvi.iImage = 0;		// There are 8 images in the image list 
		m_List.InsertItem(&Lvi); 
 
 
 
		String.Format(_T("%s"),msg); 
		Lvi.iSubItem =1; 
		Lvi.pszText = (LPTSTR)(LPCTSTR)(String); 
		m_List.SetItem(&Lvi); 
 
		String.Format(_T("%d bytes"),Length); 
		Lvi.iSubItem =2; 
		Lvi.pszText = (LPTSTR)(LPCTSTR)(String); 
       	m_List.SetItem(&Lvi); 
 
		String.Format(_T("%d:%d:%d"),Day,Month,Year); 
		Lvi.iSubItem =3; 
		Lvi.pszText = (LPTSTR)(LPCTSTR)(String); 
       	m_List.SetItem(&Lvi); 
 
 
		String.Format(_T("%d.%d"),Hour,Minute); 
		Lvi.iSubItem =4; 
		Lvi.pszText = (LPTSTR)(LPCTSTR)(String); 
       	m_List.SetItem(&Lvi); 
 
	 } 
	 NFiles = i; 
	 NFileSize = TotalKb; 
	 fprintf(file,"%d %d",NFiles+1,NFileSize); 
fcloseall(); 
 
  
} 
 
 
void FinalDeletion::OnDelete()  
{ 
	// TODO: Add your control notification handler code here 
	GetDlgItem(ID_DELETE)->EnableWindow(FALSE); 
	GetDlgItem(IDC_DELTEXT)->ShowWindow(FALSE); 
	GetDlgItem(IDC_ANIMATE_DEL)->ShowWindow(TRUE); 
    
 m_AniDel.Open(IDR_AVIDEL); 
 m_AniDel.Play( 0, -1,-1 ); 
  
 fcloseall(); 
 char msg[256]; 
  
 int Lenght; 
 CFile aFile; 
 ftp=fopen("c:\\Temp\\~Path.nct","r"); 
 if(ftp==NULL) 
 {AfxMessageBox("DataBase Failed!!!!!!!!!!");exit(0);} 
 
while(!feof(ftp)) 
{ 
	        pFileName=NULL; 
           fgets(msg,_MAX_PATH, ftp); 
		   Lenght=strlen(msg); 
           msg[Lenght-1]='\0'; 
		   _chmod(msg,_S_IWRITE); 
 
 
           CFileStatus status; 
           CFile::GetStatus( msg, status ); 
           status.m_attribute = newAttribute; 
                 if( !aFile.Open(msg, CFile::modeCreate | CFile::modeWrite, &e ) ) 
				 { 
                   #ifdef _DEBUG 
                    //   afxDump << "File could not be opened " << e.m_cause << "\n"; 
                   #endif 
				 } 
 
           else 
		   { 
	         aFile.Close();  
             CFile::SetStatus( msg, status ); 
           _unlink(msg); 
		   } 
 
_unlink(msg); 
 
} 
fcloseall(); 
	_unlink("C:\\~Safe.nct"); 
	_unlink("C:\\~Path.nct"); 
	_unlink("C:\\long.nct"); 
	_unlink("C:\\tmp.nct"); 
	_unlink("C:\\TLong.nct"); 
	_unlink("C:\\edit.nct"); 
	m_List.DeleteAllItems();  
	AfxMessageBox("Finished........"); 
	m_AniDel.Stop(); 
   	m_AniDel.Close(); 
 
	int ffiles=0,fsize=0,tfiles=0,tsize=0; 
	tfile=fopen("c:\\Temp\\tlogview.ini","r+"); 
	if((tfile==NULL) && (tfile==NULL)){AfxMessageBox("             ERROR! \n It seems that you have not installed this product on c drive.\n Install/ReInstall the product on C-Drive only as is.   \n    Else mail the author for other reason. ");CDialog::OnCancel();} 
	file=fopen("c:\\Temp\\flogview.ini","r+"); 
	if((file==NULL) && (file==NULL)){AfxMessageBox("             ERROR! \n It seems that you have not installed this product on c drive.\n Install/ReInstall the product on C-Drive only as is.   \n    Else mail the author for other reason. ");CDialog::OnCancel();} 
	fscanf(file,"%d %d",&ffiles,&fsize); 
	fscanf(tfile,"%d %d",&tfiles,&tsize); 
	fcloseall(); 
	tfile=fopen("c:\\Temp\\tlogview.ini","w+"); 
	if(tfile==NULL){AfxMessageBox("Error Writing Disk! \nDisk write protect error");fcloseall();exit(0);} 
	fprintf(tfile,"%d %d",ffiles+tfiles,fsize+tsize); 
	fcloseall(); 
	CDialog::OnCancel();  
		 
		 
} 
 
 
 
void FinalDeletion::OnCancel()  
{ 
	// TODO: Add extra cleanup here 
	fcloseall(); 
	_unlink("C:\\~Safe.nct"); 
	_unlink("C:\\~Path.nct"); 
	_unlink("C:\\long.nct"); 
	_unlink("C:\\tmp.nct"); 
	_unlink("C:\\TLong.nct"); 
	_unlink("C:\\edit.nct"); 
	CDialog::OnCancel(); 
} 
 
 
void FinalDeletion::OnReport()  
{ 
	// TODO: Add your control notification handler code here 
	LogFiles m_Log; 
	m_Log.DoModal(); 
	 
} 
 
void FinalDeletion::OnCompress()  
{ 
	// TODO: Add your control notification handler code here 
 
	 
	   WinExec("C:\\Program Files\\Nexus CompuSoft Tech\\Safe-Clean\\Program\\Zip.exe",SW_SHOW); 
		 
} 
 
void FinalDeletion::OnDblclkDellist(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
 
 
      CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_DELLIST); 
       ASSERT(pListCtrl != NULL); 
         POSITION pos = m_List.GetFirstSelectedItemPosition(); 
          if (pos == NULL) 
                   TRACE0("No items were selected!\n"); 
               else 
			   { 
                  while (pos) 
				  { 
                       int nItem = m_List.GetNextSelectedItem(pos); 
                       GetEditing = nItem; 
	              } 
			   } 
 
            FILE *editing,*tmp,*Long,*CLong; 
            fcloseall(); 
            char msg[_MAX_PATH],lmsg[_MAX_PATH];//,*getme,path[256]; 
            int Lenght; 
            editing=fopen("c:\\Temp\\~Path.nct","r"); 
            tmp=fopen("c:\\Temp\\tmp.nct","w+"); 
			Long=fopen("c:\\Temp\\Long.nct","r"); 
			CLong=fopen("c:\\Temp\\TLong.nct","w+"); 
 
            if((editing==NULL) || (tmp==NULL) || (Long ==NULL)){AfxMessageBox("Safe-Clean caused an fault expection at 0x7fh.");exit(0);} 
            int count=-1; 
               while(!feof(editing)) 
			   { 
                 fgets(msg,_MAX_PATH, editing); 
				 fgets(lmsg,_MAX_PATH,Long); 
                 count+=1; 
                     if(count == GetEditing) 
					 { 
	                  //strcpy(path,PATH); 
                      //getme=strcat(path,msg); 
                       
            	      m_List.DeleteItem(GetEditing);  
	 
					 } 
                      else 
					  { 
					   fprintf(tmp,"%s",msg); 
					   fprintf(CLong,"%s",lmsg); 
                       *msg='\0'; 
					   *lmsg='\0'; 
					  } 
                  
			   } 
			   fcloseall(); 
			   FILE *tx,*rx; 
			   tx=fopen("c:\\Temp\\~Path.nct","w+"); 
			   rx=fopen("c:\\Temp\\tmp.nct","r"); 
			   //int ch; 
			   char txt[_MAX_PATH]; 
			   if((tx==NULL) || (rx==NULL)) 
			   { 
				   AfxMessageBox("Safe-Clean has performed and illegal opeartion at 0x7fh and will close coolely"); exit(0); 
			   } 
               while(!feof(rx)) 
			   { 
				fgets(txt,_MAX_PATH, rx); 
		        Lenght=strlen(txt); 
                //txt[Lenght-1]='\0';    
                //fprintf(tx,"%s",txt); 
				fputs(txt,tx); 
				*txt='\0'; 
			   } 
              fcloseall(); 
			    
 
			  tx=fopen("c:\\Temp\\TLong.nct","r"); 
			   rx=fopen("c:\\Temp\\Long.nct","w+"); 
			   //int ch; 
			  // char txt[_MAX_PATH]; 
			   if((tx==NULL) || (rx==NULL)) 
			   { 
				   AfxMessageBox("Safe-Clean has performed and illegal opeartion at 0x7fh and will close coolely"); exit(0); 
			   } 
               while(!feof(tx)) 
			   { 
				fgets(txt,_MAX_PATH, tx); 
		        Lenght=strlen(txt); 
                //txt[Lenght-1]='\0';    
                //fprintf(tx,"%s",txt); 
				fputs(txt,rx); 
				*txt='\0'; 
			   } 
 
			  // } 
			   fcloseall(); 
 
 
	*pResult = 0; 
} 
 
 
 
 
 
 
/*void FinalDeletion::OnRclickDellist(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
 
	*pResult = 0; 
}*/ 
 
 
 
 
void FinalDeletion::OnContextMenu(CWnd* pWnd, CPoint point)  
{ 
	// TODO: Add your message handler code here 
	// TODO: Add your control notification handler code here 
 
//LPPOINT lpPoint;	 
//LPRECT lprect; 
	 
CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_DELLIST); 
      ASSERT(pListCtrl != NULL); 
      POSITION pos = m_List.GetFirstSelectedItemPosition(); 
//	  CPoint point = m_List.GetSelectionMark(); 
         if (pos == NULL) 
           TRACE0("No items were selected!\n"); 
          else 
		  { 
               while (pos) 
			   { 
                  int nItemE = m_List.GetNextSelectedItem(pos); 
				  //GetCursorPos(lpPoint); 
				 // m_List.GetViewRect(lprect); 
				  //CListCtrl::    
				   
                   //GetEditing = nItemE; 
				  FILE *edit; 
				  edit=fopen("c:\\Temp\\edit.nct","w+"); 
				  if(edit==NULL){AfxMessageBox("This programme had performed an illegal operation and will exit");exit(0);} 
				  fprintf(edit,"%d",nItemE); 
				  fclose(edit); 
 
			   } 
		  } 
 
		       
 
 CMenu menu; 
 VERIFY(menu.LoadMenu(IDR_MENU2)); 
 CMenu* pPopup = menu.GetSubMenu(0); 
 ASSERT(pPopup != NULL);                             //x=300y=230 
 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y, AfxGetMainWnd()); 
 
	 
	 
}