home *** CD-ROM | disk | FTP | other *** search
/ Computer Installation Guide - Dragon Clan Series / CD2.iso / ZIP / WWPACK / WWP304 / PASCAL / CRC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-01-05  |  4.6 KB  |  123 lines

  1. {  CRC.PAS 1.01   Copyright (c) 1995-96 by Piotr Warezak and Rafal Wierzbicki
  2.  
  3.    This program demonstrates how to use WWP_CRC unit (WWP_CRC.TPU file)
  4.    and CHECK_IF_PACKED function (CHK_WWP.PAS file).
  5.  
  6.    Compiled version of this program is a part of the WWPACK distribution
  7.    package (CRC.EXE file).
  8.  
  9.    This program is public domain and may be freely distributed.
  10.  
  11.    ==========================================================================
  12.  
  13.    Incompatibility problems please report to:  awarezak@krysia.uni.lodz.pl
  14.    or to any official WWPACK distribution site.
  15.  
  16.    ==========================================================================  }
  17.  
  18. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X-}           {create the smallest code}
  19. {$M 16384,0,655360}
  20.  
  21. program crccheck;
  22. uses crt,dos,wwp_crc;                                           {use WWP_CRC module}
  23. var header:array [1..16] of word;
  24.     directory:array[1..201] of string[12];
  25.     f:file;
  26.     count:word;
  27.     dir:searchrec;
  28.     path:dirstr;
  29.     ext:extstr;
  30.     nazwa:namestr;
  31.     k,ver:word;
  32.  
  33. procedure read_directory;                                       {read directory}
  34. var help_string:string[12];                                     {and store filenames}
  35.     i,j:word;                                                   {to the array}
  36. begin
  37.   findfirst(paramstr(1),$27,dir);count:=0;
  38.   while (doserror=0) and (count<201) do                         {search for files}
  39.   begin
  40.     inc(count);
  41.     directory[count]:=dir.name;
  42.     findnext(dir);
  43.   end;
  44.   if count>200 then                                             {more than 200 files?}
  45.   begin
  46.     writeln('Error: too many files matching to the filespec.');
  47.     halt;
  48.   end;
  49.   if count=0 then                                               {no files found?}
  50.   begin
  51.     writeln('File not found.');halt;
  52.   end;
  53.   if count>1 then                                               {sort files}
  54.     for i:=1 to count-1 do
  55.       for j:=i+1 to count do
  56.         if directory[i]<directory[j] then
  57.           begin
  58.             help_string:=directory[j];
  59.             directory[j]:=directory[i];
  60.             directory[i]:=help_string;
  61.           end;
  62. end;
  63.  
  64. {$I chk_wwp.pas}                                                {use CHECK_IF_PACKED function}
  65.  
  66. begin
  67.   writeln('■  CRC_Check 1.01   for EXE files packed with WWPACK 3.03/3.04  ■');
  68.   writeln('■         Written by Piotr Warezak and Rafal Wierzbicki         ■');
  69.   writeln('■  This program is public domain and may be freely distributed  ■');
  70.   writeln;
  71.   if paramstr(1)='' then
  72.   begin
  73.     writeln('Usage: CRC filename.exe    (paths and wildcards are allowed)');
  74.     halt;
  75.   end;
  76.  
  77.   filemode:=0;read_directory;                                   {init: read directory}
  78.   fsplit(paramstr(1),path,nazwa,ext);                           {init: check path}
  79.   repeat
  80.     assign(f,path+directory[count]);reset(f,1);k:=ioresult;     {open file}
  81.     if k=0 then
  82.     begin
  83.       ver:=255;
  84.       if filesize(f)>32 then                                    {check if WWPACKed}
  85.       begin
  86.         blockread(f,header[1],32);
  87.         if (header[1]=23117) or (header[1]=19802) then ver:=check_if_packed(f);
  88.       end;
  89.       write('    ',directory[count]);
  90.       gotoxy(20,wherey);
  91.       if ((ver>17) and (ver<21)) or ((ver>21) and (ver<25)) then{check is packed with 'P','PP' or 'PU'}
  92.       begin
  93.         if check_crc(f)=0 then                                  {check CRC (execute check_crc function from WWP_CRC unit}
  94.         begin
  95.           write('CRC: correct');                                {CRC is OK!}
  96.           gotoxy(1,wherey);writeln('√');
  97.         end
  98.         else
  99.         begin
  100.           write('Bad CRC!');                                    {Bad CRC!}
  101.           gotoxy(1,wherey);writeln('!!!');
  102.         end;
  103.       end
  104.       else
  105.       begin                                                     {when not EXE or not WWPACKed}
  106.         if ver=255 then writeln('This is not an EXE file')
  107.                    else
  108.                    begin
  109.                      write('The file isn''t packed with WWPACK ''P/PP/PU''');
  110.                      gotoxy(2,wherey);writeln('?');
  111.                    end;
  112.       end;
  113.     end
  114.     else
  115.     begin                                                       {when error while opening the file}
  116.       write('-   ',directory[count]);
  117.       gotoxy(20,wherey);writeln('Error while reading.');
  118.     end;
  119.     close(f);                                                   {close file}
  120.     dec(count);                                                 {and check the next one}
  121.   until count=0;
  122.   writeln('Finished.');                                         {finish!}
  123. end.