1 { ------------------------------------------------------------------------------
\r
3 UCL_Decompress -- Example using a UCL Decompression stream with KOL
\r
5 This file is part of the DIUcl package.
\r
7 Copyright (c) 2003 Ralf Junker - The Delphi Inspiration
\r
10 This program is free software; you can redistribute it and/or modify
\r
11 it under the terms of the GNU General Public License as published by
\r
12 the Free Software Foundation; either version 2 of the License, or
\r
13 (at your option) any later version.
\r
15 This program is distributed in the hope that it will be useful,
\r
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
18 GNU General Public License for more details.
\r
20 You should have received a copy of the GNU General Public License
\r
21 along with this program; if not, write to the Free Software
\r
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
24 Ralf Junker - The Delphi Inspiration
\r
25 <delphi@zeitungsjunge.de>
\r
26 http://www.zeitungsjunge.de/delphi/
\r
28 UCL is Copyright (c) 1996-2002 Markus Franz Xaver Johannes Oberhumer
\r
29 All Rights Reserved.
\r
31 Markus F.X.J. Oberhumer
\r
32 <markus@oberhumer.com>
\r
33 http://www.oberhumer.com/opensource/ucl/
\r
35 ------------------------------------------------------------------------------ }
\r
43 KOL, // Download from http://bonanzas.rinet.ru
\r
47 // Cut from Classes.TStream.CopyFrom with some small modifications...
\r
48 function StreamCopy(Dest, Source: PStream; Count: DWORD): DWORD;
\r
50 MaxBufSize = $80000;
\r
59 Source.Seek ( 0, spBegin);
\r
60 Count := Source.Size;
\r
63 if Count > MaxBufSize then BufSize := MaxBufSize else BufSize := Count;
\r
64 GetMem(Buffer, BufSize);
\r
65 try // => try .. finally works for 'Exit' command even without Kol_Err.pas !
\r
67 if Count > BufSize then Need := BufSize else Need := Count;
\r
68 Readed := Source.Read(Buffer^, Need);
\r
69 if Readed = STREAM_ERROR then Exit;
\r
70 if Dest.Write(Buffer^, Readed) = STREAM_ERROR then Exit;
\r
72 Inc(Result, Readed);
\r
73 until (Count = 0) or (Readed = 0) or (Readed = STREAM_ERROR);
\r
75 // Exit brings us here...
\r
76 FreeMem(Buffer, BufSize);
\r
87 if ParamCount < 2 then
\r
89 WriteLn('Usage: UCL_Decompress.exe UCL-Compressed-File OutFile');
\r
90 WriteLn('Press Enter to exit');
\r
96 Source := NewReadFileStream(ParamStr(1));
\r
98 if Source.Size = STREAM_ERROR then Exit;
\r
99 Dest := NewWriteFileStream(ParamStr(2));
\r
101 if Dest.Size = STREAM_ERROR then Exit;
\r
102 if Source.Read(Size, 4) <> 4 then Exit;
\r
103 if not NewUclDDStream(UclStream, $40000, Source, nil) then Exit;
\r
104 { If you receive a compilation error here, make sure to define
\r
105 the KOL compiler directive. There are various options to do so:
\r
107 1. Project -> Options -> Directives/Conditionals -> Conditional Defines,
\r
110 2. There is a also ready-made entry in DIUclStreams.pas which you can
\r
113 When done, make sure to rebuild the project: Projects -> Build. }
\r
114 Error := not (StreamCopy(Dest, UclStream, Size) = Size);
\r
119 DeleteFile(PChar(ParamStr(2)));
\r