home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / VPatch / Source / GenPat / VAppend.dpr < prev    next >
Text File  |  2003-08-11  |  2KB  |  77 lines

  1. program VAppend;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. var
  9.   fs, fo: File;
  10.   Patch: String;
  11.   OutFile: String = 'VPATCH.EXE';
  12.   Runtime: String = 'VPATCH.BIN';
  13.   o: LongWord;
  14.   Buf: Array[0..4095] of Byte;
  15.   Size, BufSize: Integer;
  16.  
  17. begin
  18.   WriteLn('VAppend v2.0');
  19.   WriteLn('============');
  20.   WriteLn;
  21.   WriteLn('(c) 2001-2002 Van de Sande Productions');
  22.   WriteLn('Website: http://www.tibed.net/vpatch');
  23.   WriteLn('E-mail:  koen@tibed.net');
  24.   WriteLn;
  25.   if ParamCount = 0 then begin
  26.     WriteLn('Use this program to append .PAT files to the VPatch runtime.');
  27.     WriteLn;
  28.     WriteLn('  VAPPEND (patch file) [output file] [runtime]');
  29.     WriteLn;
  30.     WriteLn('By default, the output file is VPATCH.EXE and the runtime is VPATCH.BIN');
  31.   end;
  32.   if not FileExists(ParamStr(1)) then begin
  33.     WriteLn('ERROR: Patch file not found');
  34.     Exit;
  35.   end;
  36.   Patch := ParamStr(1);
  37.   if ParamCount > 1 then OutFile := ParamStr(2);
  38.   if ParamCount > 2 then Runtime := ParamStr(3);
  39.   WriteLn('Patch:   '+Patch);
  40.   WriteLn('Runtime: '+Runtime);
  41.   WriteLn('Output:  '+OutFile);
  42.  
  43.   AssignFile(fo,OutFile);
  44.   Rewrite(fo,1);
  45.   //copy the runtime
  46.   AssignFile(fs,Runtime);
  47.   FileMode:=fmOpenRead;
  48.   Reset(fs,1);
  49.   BufSize:=4096;
  50.   o:=FileSize(fs);            //patch start offset
  51.   Size:=FileSize(fs);
  52.   while Size>0 do begin
  53.     if Size-BufSize<0 then BufSize:=Size;
  54.     BlockRead(fs,Buf,BufSize);
  55.     BlockWrite(fo,Buf,BufSize);
  56.     Dec(Size,BufSize);
  57.   end;
  58.   CloseFile(fs);
  59.   //do the patch
  60.   AssignFile(fs,Patch);
  61.   FileMode:=fmOpenRead;
  62.   Reset(fs,1);
  63.   BufSize:=4096;
  64.   Size:=FileSize(fs);
  65.   while Size>0 do begin
  66.     if Size-BufSize<0 then BufSize:=Size;
  67.     BlockRead(fs,Buf,BufSize);
  68.     BlockWrite(fo,Buf,BufSize);
  69.     Dec(Size,BufSize);
  70.   end;
  71.   CloseFile(fs);
  72.  
  73.   BlockWrite(fo,o,SizeOf(o));
  74.   CloseFile(fo);
  75.   WriteLn('Created.');
  76. end.
  77.