{
 Free disk C clear for computers with WINDOWS.
 ***************************************************************************
 (C) Copyright Sandul Yura Valentinovich.
 (R) Monday, 3 February 2003 year.
 All rights reserved.

     This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the Free
 Software Foundation; either version 2 of the License, or (at your option)
 any later version.
     This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied	warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 more details.
     You should have received a copy of the GNU General Public License along
 with this program; if not, write to the Free Software Foundation, Inc., 675
 Mass Ave, Cambridge, MA 02139,	USA.
}
{$A-,B+,D-,E-,F-,G-,I-,L-,N-,O-,P+,Q-,R-,S-,T-,V-,X-,Y-}
{$M 65520,0,0}
Program KillConvicts;
Uses Dos,Crt;
Const
    ConvictDirectories : Array[1..15] Of String = (
'C:\WINDOWS\RECENT','C:\WINDOWS\ALLUSE~1','C:\WINDOWS\TEMP',
'C:\WINDOWS\APPLOG','C:\WINDOWS\COOKIES','C:\WINDOWS\HISTORY',
'C:\WINDOWS\INSTAL~1','C:\WINDOWS\NETHOOD','C:\WINDOWS\PIF',
'C:\WINDOWS\PRINTH~1','C:\WINDOWS\SPOOL','C:\WINDOWS\TEMPLA~1',
'C:\WINDOWS\TEMPOR~1','C:\_RESTORE','C:\RECYCLED');
    ConvictFiles : Array[1..16] Of String = (
'C:\VIDEOROM.BIN','C:\WINDOWS\SHELLI~1','C:\WINDOWS\TTFCACHE',
'C:\WINDOWS\NETWORKS','C:\WINDOWS\PROTOCOLS','C:\WINDOWS\SERVICES',
'C:\WINDOWS\MODEMCPL.TXT','C:\WINDOWS\NDISLOG.TXT','C:\WINDOWS\NOHIBER.TXT',
'C:\WINDOWS\RESUME.TXT','C:\WINDOWS\SCHEDLOG.TXT','C:\WINDOWS\POWERPNT.INI',
'C:\WINDOWS\WAVEMIX.INI','C:\WINDOWS\WINFILE.INI','C:\WINDOWS\PROGMAN.INI',
'C:\WINDOWS\VMMHIBER.W9X');
    ConvictExtensions : Array[1..9] Of String = (
'BAK','TMP','OLD','DOS','SWP','LOG','GID','~','$$$');
    MustExistDirectory : String = 'C:\WINDOWS\SENDTO';
Procedure KillConvictFile(FileName : String);
Var
  ConvictFile   : File;
  FileAttribute : Word;
Begin
 GoToXY(1,WhereY-1);
 ClrEol;
 WriteLn('Killing convict file. Please waith...');
 ClrEol;
 Write(Copy(FileName,1,79));
 Assign(ConvictFile,FileName);
 GetFAttr(ConvictFile,FileAttribute);
 SetFAttr(ConvictFile,0);
 Erase(ConvictFile);
 GoToXY(1,WhereY-1);
 ClrEol;
 If IOResult=0 Then WriteLn('File is succefully dead!') Else
 Begin
  SetFAttr(ConvictFile,FileAttribute);
  WriteLn('File is life!');
 end;
end;
Procedure RemoveConvictDirectory(DirectoryName : String);
Begin
 GoToXY(1,WhereY-1);
 ClrEol;
 WriteLn('Removing convict directory. Please waith...');
 ClrEol;
 Write(Copy(DirectoryName,1,79));
 RmDir(DirectoryName);
 GoToXY(1,WhereY-1);
 ClrEol;
 If IOResult=0 Then WriteLn('Directory is succefully removed!') Else
 WriteLn('Directory is life!');
end;
Function IsEmpty(DirectoryName : String) : Boolean;
Var
  Find : SearchRec;
Begin
 FindFirst(DirectoryName+'\*.*',AnyFile,Find);
 DosError:=0;
 FindNext(Find);
 FindNext(Find);
 IsEmpty:=DosError=18;
 DosError:=0;
end;
Procedure KillConvictDirectory(DirectoryName : String);
Var
  Find : SearchRec;
Begin
 FindFirst(DirectoryName+'\*.*',AnyFile,Find);
 FindNext(Find);
 DosError:=0;
 GoToXY(1,WhereY-1);
 ClrEol;
 WriteLn('Killing convict directory. Please waith...');
 ClrEol;
 Write(Copy(DirectoryName,1,79));
 FindNext(Find);
 If DosError=18 Then
 Begin
  RemoveConvictDirectory(DirectoryName);
  DosError:=0;
  Exit;
 end;
 Repeat
  If (Find.Attr And Directory)<>0 Then
  KillConvictDirectory(DirectoryName+'\'+Find.Name)
  Else KillConvictFile(DirectoryName+'\'+Find.Name);
  FindNext(Find);
 Until DosError=18;
 If IsEmpty(DirectoryName) Then RemoveConvictDirectory(DirectoryName);
end;
Procedure WorkDirectory(DirectoryName : String);
Var
  Find  : SearchRec;
  Index : Byte;
Begin
 FindFirst(DirectoryName+'\*.*',AnyFile,Find);
 FindNext(Find);
 DosError:=0;
 GoToXY(1,WhereY-1);
 ClrEol;
 WriteLn('Working directory...');
 ClrEol;
 Write(Copy(DirectoryName,1,79));
 FindNext(Find);
 If DosError=18 Then
 Begin
  RemoveConvictDirectory(DirectoryName);
  DosError:=0;
  Exit;
 end;
 Repeat
  If (Find.Attr And Directory)<>0 Then
  Begin
   For Index:=1 To 16 Do
   Begin
    If Index=16 Then Break;
    If ConvictDirectories[Index]=DirectoryName+'\'+Find.Name Then Break;
   end;
   If Index<16 Then KillConvictDirectory(DirectoryName+'\'+Find.Name) Else
   If Index=16 Then
   Begin
    If IsEmpty(DirectoryName+'\'+Find.Name) Then
    RemoveConvictDirectory(DirectoryName+'\'+Find.Name)
    Else WorkDirectory(DirectoryName+'\'+Find.Name);
   end;
  end Else
  Begin
   For Index:=1 To 17 Do
   Begin
    If Index=17 Then Break;
    If ConvictFiles[Index]=DirectoryName+'\'+Find.Name Then Break;
   end;
   If Index<17 Then KillConvictFile(DirectoryName+'\'+Find.Name) Else
   If DirectoryName<>MustExistDirectory Then
   Begin
    If Find.Size=0 Then KillConvictFile(DirectoryName+'\'+Find.Name) Else
    If Pos('.',Find.Name)>0 Then
    Begin
     For Index:=1 To 10 Do
     Begin
      If Index=10 Then Break;
      If Copy(Find.Name,Pos('.',Find.Name)+1,3)=ConvictExtensions[Index] Then
      Break;
     end;
     If Index<9 Then KillConvictFile(DirectoryName+'\'+Find.Name);
    end;
   end;
  end;
  FindNext(Find);
 Until DosError=18;
 If IsEmpty(DirectoryName) Then
 RemoveConvictDirectory(DirectoryName);
end;
Begin
 WriteLn;
 WriteLn('Free disk C clear for computers with WINDOWS.');
 WriteLn;
 WriteLn('(C) Copyright Sandul Yura Valentinovich.');
 WriteLn('(R) Monday, 3 February 2003 year.');
 WriteLn('All rights reserved.');
 WriteLn('*******************************************************************************');
 WriteLn('    This program is free software; you can redistribute it and/or modify it');
 WriteLn('under the terms of the GNU General Public License as published by the Free');
 WriteLn('Software Foundation; either version 2 of the License, or (at your option) any');
 WriteLn('later version.');
 WriteLn('    This program is distributed in the hope that it will be useful, but WITHOUT');
 WriteLn('ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS');
 WriteLn('FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.');
 WriteLn('    You should have received a copy of the GNU General Public License along');
 WriteLn('with this program; if not, write to the Free Software Foundation, Inc., 675');
 WriteLn('Mass Ave, Cambridge, MA 02139, USA.');
 WriteLn('*******************************************************************************');
 WriteLn;
 WriteLn('Are your sure to clear all temporary files from the disk: C in your computer?');
 WriteLn('ENTER=Yes, ESC=No.');
 Case ReadKey Of
 #13: WorkDirectory('C:');
 #27: Exit;
 end;
 GoToXY(1,WhereY);
 ClrEol;
 GoToXY(1,WhereY-1);
 ClrEol;
 WriteLn('Disk C is free for temporary and invalid files.');
end.