program crc; {$APPTYPE CONSOLE} {$WARN SYMBOL_PLATFORM OFF} uses crc32, SysUtils, Windows; var ConScrBuf: Console_Screen_Buffer_Info; PReport: pointer; //Options: DisplayFullFilename: boolean = False; IncludeHidden: boolean = False; IncludeSystem: boolean = False; ScanSubDirs: boolean = False; DisplayHelp: boolean = False; SupressReport: boolean = False; Buffer: Integer = $FFFFF; //1 Megabyte procedure ShowHelp; begin Writeln('CRC32 Calculator v1.11 - Andrew Koupparis 2003'); Writeln('Usage: CRC32 [/?]'); Writeln(' CRC32 filename [/F /H /S /D /Bxxxx /R]'); Writeln; Writeln('Wildcards are allowed'); Writeln('/F to display full filename'); Writeln('/H to include hidden files'); Writeln('/S to include system files'); Writeln('/D to scan subdirectories'); Writeln('/Bxxxx to set the buffer size in Kbytes - Default = 1024'); Writeln('/R to supress progress report'); Writeln('/? displays this screen'); Writeln('Parameters may stack'); end; procedure ShowProgress(Percentage: Integer); begin Write(IntToStr(Percentage)+'%'); SetConsoleCursorPosition(TTextRec(Output).Handle,ConScrBuf.dwCursorPosition); end; procedure ScanFile(Filename:TFilename); var FileResult: Cardinal; begin if DisplayFullFilename then Write(ExpandFileName(Filename)+' - ') else Write(ExtractFileName(Filename)+' - '); GetConsoleScreenBufferInfo(TTextRec(Output).Handle,ConScrBuf); //Store our position FileResult:=FileCRC32(Filename,PReport); if CRCError then Writeln('Error') else Writeln('CRC32: '+IntToHex(FileResult,8)); end; procedure ScanPath(Path:string; Attrib:Integer); var DirRec, SearchRec: TSearchRec; Filename: TFilename; Dir: String; begin Dir:=ExtractFilePath(Path); if FindFirst(Path,Attrib,SearchRec)=0 then begin //file search repeat Filename:=Dir+SearchRec.Name; ScanFile(FileName); until FindNext(SearchRec)<>0; SysUtils.FindClose(SearchRec); end; if ScanSubDirs then begin //check for directories if FindFirst(ExtractFilePath(Path)+'*.*',faDirectory,DirRec)<>0 then Exit; repeat if (DirRec.Attr and faDirectory)=faDirectory then if (DirRec.Name<>'.') and (DirRec.Name<>'..') then ScanPath(ExtractFilePath(Path)+DirRec.Name+'\'+ExtractFileName(Path),Attrib); until FindNext(DirRec)<>0; SysUtils.FindClose(DirRec); end; end; procedure CheckParameters; var Count, Index: Integer; {Separator: set of Char;} CheckStr: string; begin {Separator:=['/'];} if ParamCount=0 then begin DisplayHelp:=True; Exit; end; for count:=1 to ParamCount do if ParamStr(count)[1]='/' {in Separator} then begin CheckStr:=UpperCase(ParamStr(count)); index:=2; while index<=length(CheckStr) do begin if CheckStr[index]='F' then DisplayFullFilename:=True; if CheckStr[index]='H' then IncludeHidden:=True; if CheckStr[index]='S' then IncludeSystem:=True; if CheckStr[index]='D' then ScanSubDirs:=True; if CheckStr[index]='?' then begin DisplayHelp:=True; Exit; end; if CheckStr[index]='R' then SupressReport:=True; if CheckStr[index]='B' then try Buffer:=StrToInt(Copy(CheckStr,index+1,Length(CheckStr)))*1024; except DisplayHelp:=True; Exit; end; index:=index+1; //check if next char is option end; end; end; var Path: String; Attrib: Integer; begin CheckParameters; MaxCRCBufferSize:=Buffer; if DisplayHelp then ShowHelp else begin Path:=ParamStr(1); Attrib:=0; If IncludeHidden then Attrib:=faHidden; if IncludeSystem then Attrib:=Attrib+faSysFile; if SupressReport then PReport:=nil else PReport:=@ShowProgress; ScanPath(Path,Attrib); end; end.