-
Notifications
You must be signed in to change notification settings - Fork 2
/
PowerArc.pas
673 lines (602 loc) · 21.5 KB
/
PowerArc.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
unit PowerArc;
{| PowerArc 1.3.1 /5 Apr 2001/
| Copyright (c) 2000,2001 SoftLab MIL-TEC Ltd
| Web http://www.softcomplete.com
| Email [email protected]
| Data compression library for Delphi and C++ Builder
|}
{-------------------------------------------------------------------------------
What's new in ver.1.3.1
+ change interface proc names
RegisterPowerArcModule -> PowerArcRegisterModule
SetOptions -> PowerArcSetOptions
Compress -> PowerArcCompress
Decompress -> PowerArcDecompress
+ change param order in PowerArcCompress
was:
function PowerArcCompress(ArcIdx: integer; InStream,OutStream: TStream;
const ArcOpt: string = ''; ProgressCallback: TProgressCallback = nil): Boolean;
now:
function PowerArcCompress(InStream,OutStream: TStream;
ArcIdx: integer = iPowerBZIP; const ArcOpt: string = '';
ProgressCallback: TProgressCallback = nil): Boolean;
--------------------------------------------------------------------------------
What's new in ver.1.3
+ full progress callback support
+ TProgressCallback changed type definition
+ update BZIP core to ver.1.0.1
+ implementation BZIP as default built-in method
+ RegisterPowerArcModule now check for dups
+ fix memory leak: free Options list
+ fix bug in Read/Write methods in implementation of stream interface
-------------------------------------------------------------------------------}
interface
uses SysUtils, Windows, Classes, PowerAcrModuleInfo, bzLib;
type
EPowerArcError = class(Exception);
TProgressCallback = procedure (Current: integer) of object;
const // default compression method
iPowerBZIP = 0;
var // loadable compression engines
iPowerZIP: integer = 0;
iPowerRANK: integer = 0;
iPowerPPM: integer = 0;
function PowerArcRegisterModule(const Name: string): integer;
procedure PowerArcSetOptions(ArcIdx: integer; const ArcOpt: string);
function PowerArcCompress(InStream,OutStream: TStream;
ArcIdx: integer = iPowerBZIP; const ArcOpt: string = '';
ProgressCallback: TProgressCallback = nil): Boolean; overload;
function PowerArcCompress(const Buffer; Size: integer; OutStream: TStream;
ArcIdx: integer = iPowerBZIP; const ArcOpt: string = '';
ProgressCallback: TProgressCallback = nil): Boolean; overload;
function PowerArcDecompress(InStream,OutStream: TStream;
ProgressCallback: TProgressCallback = nil): Boolean;
//============================ Stream interface ================================
type
{ TPowerArcCompressStream compresses data on the fly as data is written to it,
and stores the compressed data to another stream.
TPowerArcCompressStream is write-only and strictly sequential. Reading from the
stream will raise an exception. Using Seek to move the stream pointer
will raise an exception.
Output data is cached internally, written to the output stream only when
the internal output buffer is full. All pending output data is flushed
when the stream is destroyed.
The Position property returns the number of uncompressed bytes of
data that have been written to the stream so far.
The OnProgress event is called each time the output buffer is filled and
written to the output stream. This is useful for updating a progress
indicator when you are writing a large chunk of data to the compression
stream in a single call.}
TPowerArcCompressStream = class(TStream)
private
Base: TStream;
ArcIdx: integer;
ArcOpt: string;
Thread: TThread;
hReadPipe,
hWritePipe: THandle;
TotalWrited: integer;
BZCompressionStream: TBZCompressionStream;
FOnProgress: TProgressCallback;
procedure DoProgress(Current: integer);
public
constructor Create(BaseStream: TStream; FArcIdx: integer = iPowerBZIP;
const FArcOpt: string = '');
destructor Destroy; override;
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
function Seek(Offset: Longint; Origin: Word): Longint; override;
property OnProgress: TProgressCallback read FOnProgress write FOnProgress;
end;
{ TPowerArcDecompressStream decompresses data on the fly as data is read from it.
Compressed data comes from a separate source stream. TPowerArcDecompressStream
is read-only and unidirectional; you can seek forward in the stream, but not
backwards. The special case of setting the stream position to zero is
allowed. Seeking forward decompresses data until the requested position in
the uncompressed data has been reached. Seeking backwards, seeking relative
to the end of the stream, requesting the size of the stream, and writing to
the stream will raise an exception.
The Position property returns the number of bytes of uncompressed data that
have been read from the stream so far.
The OnProgress event is called each time the internal input buffer of
compressed data is exhausted and the next block is read from the input stream.
This is useful for updating a progress indicator when you are reading a
large chunk of data from the decompression stream in a single call.}
TPowerArcDecompressStream = class(TStream)
private
Base: TStream;
ArcIdx: integer;
Thread: TThread;
hReadPipe,
hWritePipe: THandle;
TotalReaded: integer;
BZDecompressionStream: TBZDecompressionStream;
FOnProgress: TProgressCallback;
procedure DoProgress(Current: integer);
public
constructor Create(BaseStream: TStream);
destructor Destroy; override;
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
function Seek(Offset: Longint; Origin: Word): Longint; override;
property OnProgress: TProgressCallback read FOnProgress write FOnProgress;
end;
//==============================================================================
type
// callback's
TReadFunc = function (Data: Pointer; var Buffer; Size: integer): integer; stdcall;
TWriteFunc = function (Data: Pointer; const Buffer; Size: integer): integer; stdcall;
// dll entryes
TPowerArcSetOptions = procedure (Opt: PChar); stdcall;
TPowerArcCompress = procedure (Data: Pointer; Opt: PChar; ReadFunc: TReadFunc;
WriteFunc: TWriteFunc); stdcall;
TPowerArcCompressMem = procedure (Data: Pointer; Opt: PChar; Mem: Pointer;
MemSize: integer; WriteFunc: TWriteFunc); stdcall;
TPowerArcDecompress = function (Data: Pointer; ReadFunc: TReadFunc;
WriteFunc: TWriteFunc): Boolean; stdcall;
// dll registration info
TPowerArcModule = record
Name: string;
hLib: THandle;
Info: PPowerArcModuleInfo;
Options: TStringList;
SetOptions: TPowerArcSetOptions;
Compress: TPowerArcCompress;
CompressMem: TPowerArcCompressMem;
Decompress: TPowerArcDecompress;
end;
var
PowerArcModules: array of TPowerArcModule;
implementation
const
PipeSize = 4*4096;
type
TPowerArcData = record
InStream,OutStream: TStream;
Current: integer;
ProgressCallback: TProgressCallback;
end;
function ReadFunc(Data: Pointer; var Buffer; Size: integer): integer; stdcall;
begin
Result:=TPowerArcData(Data^).InStream.Read(Buffer,Size);
if Assigned(TPowerArcData(Data^).ProgressCallback) then begin
Inc(TPowerArcData(Data^).Current,Result);
TPowerArcData(Data^).ProgressCallback(TPowerArcData(Data^).Current);
end;
end;
function WriteFunc(Data: Pointer; const Buffer; Size: integer): integer; stdcall;
begin
Result:=TPowerArcData(Data^).OutStream.Write(Buffer,Size);
end;
function ValidArcIdx(ArcIdx: integer): Boolean;
begin
Result:=(ArcIdx >= 0) and (ArcIdx < Length(PowerArcModules));
end;
procedure PowerArcSetOptions(ArcIdx: integer; const ArcOpt: string);
begin
// no opt for default method
if (ArcIdx <> iPowerBZIP) and ValidArcIdx(ArcIdx) then
PowerArcModules[ArcIdx].SetOptions(PChar(ArcOpt));
end;
function PowerArcCompress(InStream,OutStream: TStream;
ArcIdx: integer; const ArcOpt: string;
ProgressCallback: TProgressCallback): Boolean;
var Data: TPowerArcData;
begin
Result:=False;
if ArcIdx = iPowerBZIP then begin
OutStream.Write(PowerArcModules[ArcIdx].Info^.ModuleID[0],8);
BZCompress(InStream,OutStream,ProgressCallback);
Result:=True;
end else if ValidArcIdx(ArcIdx) then try
Data.InStream:=InStream;
Data.OutStream:=OutStream;
Data.ProgressCallback:=ProgressCallback;
Data.Current:=0;
OutStream.Write(PowerArcModules[ArcIdx].Info^.ModuleID[0],8);
PowerArcModules[ArcIdx].Compress(@Data,PChar(ArcOpt),ReadFunc,WriteFunc);
Result:=True;
except
end;
end;
type
TMapMemoryStream = class (TCustomMemoryStream)
private
FReadOnly: Boolean;
public
constructor Create(Buf: Pointer; Size: integer; ReadOnly: Boolean);
function Write(const Buffer; Count: integer): integer; override;
end;
constructor TMapMemoryStream.Create(Buf: Pointer; Size: integer; ReadOnly: Boolean);
begin
inherited Create;
SetPointer(Buf,Size);
FReadOnly:=ReadOnly;
end;
function TMapMemoryStream.Write(const Buffer; Count: integer): integer;
begin
if FReadOnly then Result:=0
else begin
if Position+Count > Size then Result:=Size-Position
else Result:=Count;
Move(Buffer, Pointer(integer(Memory) + Position)^, Result);
Seek(Result,1);
end;
end;
function PowerArcCompress(const Buffer; Size: integer; OutStream: TStream;
ArcIdx: integer; const ArcOpt: string;
ProgressCallback: TProgressCallback): Boolean;
var Data: TPowerArcData;
MapMemoryStream: TMapMemoryStream;
begin
if Assigned(ProgressCallback) then begin
if ArcIdx = iPowerBZIP then begin
OutStream.Write(PowerArcModules[ArcIdx].Info^.ModuleID[0],8);
BZCompress(Buffer,Size,OutStream,ProgressCallback);
Result:=True;
end else begin
MapMemoryStream:=TMapMemoryStream.Create(@Buffer,Size,True);
try
Result:=PowerArcCompress(MapMemoryStream,OutStream,ArcIdx,ArcOpt,ProgressCallback);
finally
MapMemoryStream.Free;
end;
end;
end else begin
Result:=False;
if ArcIdx = iPowerBZIP then begin
OutStream.Write(PowerArcModules[ArcIdx].Info^.ModuleID[0],8);
BZCompress(Buffer,Size,OutStream);
Result:=True;
end else if ValidArcIdx(ArcIdx) then try
Data.OutStream:=OutStream;
OutStream.Write(PowerArcModules[ArcIdx].Info^.ModuleID[0],8);
PowerArcModules[ArcIdx].CompressMem(@Data,PChar(ArcOpt),@Buffer,Size,WriteFunc);
Result:=True;
except
end;
end;
end;
function PowerArcDecompress(InStream,OutStream: TStream;
ProgressCallback: TProgressCallback): Boolean;
var ModuleID: packed array[0..7] of Char;
j: integer;
Data: TPowerArcData;
begin
Result:=False;
InStream.Read(ModuleID[0],8);
for j:=0 to Length(PowerArcModules)-1 do
if PowerArcModules[j].Info^.ModuleID = ModuleID then try
if j = iPowerBZIP then
BZDecompress(InStream,OutStream)
else begin
Data.InStream:=InStream;
Data.OutStream:=OutStream;
Data.ProgressCallback:=ProgressCallback;
Data.Current:=0;
PowerArcModules[j].Decompress(@Data,ReadFunc,WriteFunc);
end;
Result:=True;
Exit;
except
end;
end;
function PowerArcRegisterModule(const Name: string): integer;
type TGetPowerArcModuleInfo = function: PPowerArcModuleInfo;
var PowerArcModule: TPowerArcModule;
GetPowerArcModuleInfo: TGetPowerArcModuleInfo;
POpt: PChar;
j: integer;
begin
Result:=-1;
PowerArcModule.hLib:=LoadLibrary(PChar(Name));
if PowerArcModule.hLib <> 0 then begin
PowerArcModule.Name:=Name;
GetPowerArcModuleInfo:=TGetPowerArcModuleInfo(GetProcAddress(PowerArcModule.hLib,
'GetPowerArcModuleInfo'));
PowerArcModule.Info:=GetPowerArcModuleInfo;
// check that module exists
for j:=0 to Length(PowerArcModules)-1 do
if PowerArcModules[j].Info^.ModuleID = PowerArcModule.Info.ModuleID then begin
Result:=j;
FreeLibrary(PowerArcModule.hLib);
Exit;
end;
// continue init
PowerArcModule.SetOptions:=TPowerArcSetOptions(GetProcAddress(PowerArcModule.hLib,'SetOptions'));
PowerArcModule.Compress:=TPowerArcCompress(GetProcAddress(PowerArcModule.hLib,'Compress'));
PowerArcModule.CompressMem:=TPowerArcCompressMem(GetProcAddress(PowerArcModule.hLib,'CompressMem'));
PowerArcModule.Decompress:=TPowerArcDecompress(GetProcAddress(PowerArcModule.hLib,'Decompress'));
if Assigned(GetPowerArcModuleInfo) and
(PowerArcModule.Info^.Signature = PowerArcModuleSignature) and
Assigned(PowerArcModule.SetOptions) and
Assigned(PowerArcModule.Compress) and
Assigned(PowerArcModule.CompressMem) and
Assigned(PowerArcModule.Decompress) then begin
PowerArcModule.Options:=TStringList.Create;
POpt:=PowerArcModule.Info^.Options;
while POpt^ <> #0 do begin
PowerArcModule.Options.Add(POpt);
POpt:=POpt+StrLen(POpt)+1;
end;
SetLength(PowerArcModules,Length(PowerArcModules)+1);
PowerArcModules[Length(PowerArcModules)-1]:=PowerArcModule;
Result:=Length(PowerArcModules)-1;
end else
FreeLibrary(PowerArcModule.hLib);
end;
end;
procedure PowerArcUnregisterModules;
var j: integer;
begin
for j:=0 to Length(PowerArcModules)-1 do begin
if PowerArcModules[j].hLib <> 0 then
FreeLibrary(PowerArcModules[j].hLib);
PowerArcModules[j].Options.Free;
end;
PowerArcModules:=nil;
end;
{ TCompressThread }
type
TCompressThread = class(TThread)
private
Done: Boolean;
CompressStream: TPowerArcCompressStream;
protected
procedure Execute; override;
end;
{ TCompressThread }
function ReadCompressFunc(Data: Pointer; var Buffer; Size: integer): integer; stdcall;
begin
if not Windows.ReadFile(TPowerArcCompressStream(Data).hReadPipe,Buffer,Size,DWORD(Result),nil) then
Result:=-1;
end;
function WriteCompressFunc(Data: Pointer; const Buffer; Size: integer): integer; stdcall;
begin
Result:=TPowerArcCompressStream(Data).Base.Write(Buffer,Size);
end;
procedure TCompressThread.Execute;
begin
try
CompressStream.Base.Write(PowerArcModules[CompressStream.ArcIdx].Info^.ModuleID[0],8);
PowerArcModules[CompressStream.ArcIdx].Compress(CompressStream,
PChar(CompressStream.ArcOpt),ReadCompressFunc,WriteCompressFunc);
except
end;
CloseHandle(CompressStream.hReadPipe);
Done:=True;
end;
{ TPowerArcCompressStream }
constructor TPowerArcCompressStream.Create(BaseStream: TStream;
FArcIdx: integer; const FArcOpt: string);
begin
inherited Create;
Base:=BaseStream;
ArcIdx:=FArcIdx;
ArcOpt:=FArcOpt;
Thread:=nil;
FOnProgress:=nil;
TotalWrited:=0;
if not ValidArcIdx(ArcIdx) then
raise EPowerArcError.Create('Invalid acrhive index');
if ArcIdx = iPowerBZIP then begin
Base.Write(PowerArcModules[ArcIdx].Info^.ModuleID[0],8);
BZCompressionStream:=TBZCompressionStream.Create(Base);
BZCompressionStream.OnProgress:=DoProgress;
end else
BZCompressionStream:=nil;
end;
destructor TPowerArcCompressStream.Destroy;
begin
if Thread <> nil then begin
CloseHandle(hWritePipe);
while not TCompressThread(Thread).Done do Sleep(0);
Thread.Free;
end;
if BZCompressionStream <> nil then
BZCompressionStream.Free;
inherited;
end;
procedure TPowerArcCompressStream.DoProgress(Current: integer);
begin
if Assigned(FOnProgress) then FOnProgress(Current);
end;
function TPowerArcCompressStream.Read(var Buffer; Count: Integer): Longint;
begin
raise EPowerArcError.Create('Invalid stream operation');
end;
function TPowerArcCompressStream.Seek(Offset: Integer;
Origin: Word): Longint;
begin
if (Offset = 0) and (Origin = soFromCurrent) then
Result := TotalWrited
else
raise EPowerArcError.Create('Invalid stream operation');
end;
function TPowerArcCompressStream.Write(const Buffer;
Count: Integer): Longint;
var Ret: Boolean;
ActualWrite: DWORD;
P: PChar;
begin
if ArcIdx = iPowerBZIP then
Result:=BZCompressionStream.Write(Buffer,Count)
else if Count > 0 then begin
if Thread = nil then begin
CreatePipe(hReadPipe,hWritePipe,nil,PipeSize);
Thread:=TCompressThread.Create(True);
TCompressThread(Thread).CompressStream:=Self;
TCompressThread(Thread).Done:=False;
Thread.FreeOnTerminate:=False;
Thread.Resume;
end;
//Windows.WriteFile(hWritePipe,Buffer,Count,DWORD(Result),nil);
Result:=0;
P:=PChar(@Buffer);
while Count > 0 do begin
Ret:=Windows.WriteFile(hWritePipe,P^,Count,ActualWrite,nil);
if not Ret or (Ret and (ActualWrite = 0)) then begin
if Result = 0 then Result:=-1;
Break;
end;
Dec(Count,ActualWrite);
Inc(Result,ActualWrite);
Inc(P,ActualWrite);
Sleep(0);
end;
end else
Result:=0;
if Result > 0 then begin
Inc(TotalWrited,Result);
if ArcIdx <> iPowerBZIP then
DoProgress(TotalWrited);
end;
end;
{ TDecompressThread }
type
TDecompressThread = class(TThread)
private
Done: Boolean;
DecompressStream: TPowerArcDecompressStream;
protected
procedure Execute; override;
end;
{ TDecompressThread }
function ReadDecompressFunc(Data: Pointer; var Buffer; Size: integer): integer; stdcall;
begin
Result:=TPowerArcDecompressStream(Data).Base.Read(Buffer,Size);
end;
function WriteDecompressFunc(Data: Pointer; const Buffer; Size: integer): integer; stdcall;
begin
if not Windows.WriteFile(TPowerArcDecompressStream(Data).hWritePipe,Buffer,Size,DWORD(Result),nil) then
Result:=-1;
end;
procedure TDecompressThread.Execute;
begin
try
PowerArcModules[DecompressStream.ArcIdx].Decompress(DecompressStream,
ReadDecompressFunc,WriteDecompressFunc);
except
end;
CloseHandle(DecompressStream.hWritePipe);
Done:=True;
end;
{ TPowerArcDecompressStream }
constructor TPowerArcDecompressStream.Create(BaseStream: TStream);
var ModuleID: packed array[0..7] of Char;
j: integer;
begin
inherited Create;
Base:=BaseStream;
Thread:=nil;
FOnProgress:=nil;
TotalReaded:=0;
if Base.Read(ModuleID[0],8) = 8 then
for j:=0 to Length(PowerArcModules)-1 do
if PowerArcModules[j].Info^.ModuleID = ModuleID then begin
if j = iPowerBZIP then begin
BZDecompressionStream:=TBZDecompressionStream.Create(Base);
BZDecompressionStream.OnProgress:=DoProgress;
end else
BZDecompressionStream:=nil;
ArcIdx:=j;
Exit;
end;
raise EPowerArcError.Create('Invalid acrhive index');
end;
destructor TPowerArcDecompressStream.Destroy;
begin
if Thread <> nil then begin
CloseHandle(hReadPipe);
while not TDecompressThread(Thread).Done do Sleep(0);
Thread.Free;
end;
if BZDecompressionStream <> nil then
BZDecompressionStream.Free;
inherited;
end;
procedure TPowerArcDecompressStream.DoProgress(Current: integer);
begin
if Assigned(FOnProgress) then FOnProgress(Current);
end;
function TPowerArcDecompressStream.Read(var Buffer;
Count: Integer): Longint;
var Ret: Boolean;
ActualRead: DWORD;
P: PChar;
begin
if ArcIdx = iPowerBZIP then
Result:=BZDecompressionStream.Read(Buffer,Count)
else if Count > 0 then begin
if Thread = nil then begin
CreatePipe(hReadPipe,hWritePipe,nil,PipeSize);
Thread:=TDecompressThread.Create(True);
TDecompressThread(Thread).DecompressStream:=Self;
TDecompressThread(Thread).Done:=False;
Thread.FreeOnTerminate:=False;
Thread.Resume;
end;
Result:=0;
P:=PChar(@Buffer);
while Count > 0 do begin
Ret:=Windows.ReadFile(hReadPipe,P^,Count,ActualRead,nil);
if not Ret or (Ret and (ActualRead = 0)) then begin
if Result = 0 then Result:=-1;
Break;
end;
Dec(Count,ActualRead);
Inc(Result,ActualRead);
Inc(P,ActualRead);
Sleep(0);
end;
end else
Result:=0;
if Result > 0 then begin
Inc(TotalReaded,Result);
if ArcIdx <> iPowerBZIP then
DoProgress(TotalReaded);
end;
end;
function TPowerArcDecompressStream.Seek(Offset: Integer;
Origin: Word): Longint;
begin
if (Offset = 0) and (Origin = soFromCurrent) then
Result := TotalReaded
else
raise EPowerArcError.Create('Invalid stream operation');
end;
function TPowerArcDecompressStream.Write(const Buffer;
Count: Integer): Longint;
begin
raise EPowerArcError.Create('Invalid stream operation');
end;
// register default compression engine
procedure RegisterBZIP;
var POpt: PChar;
begin
SetLength(PowerArcModules,1);
with PowerArcModules[iPowerBZIP] do begin
Name:='';
hLib:=0;
Info:=BZGetPowerArcModuleInfo;
Options:=TStringList.Create;
POpt:=Info^.Options;
while POpt^ <> #0 do begin
Options.Add(POpt);
POpt:=POpt+StrLen(POpt)+1;
end;
SetOptions:=nil;
Compress:=nil;
CompressMem:=nil;
Decompress:=nil;
end;
end;
{ TCallbackObj }
initialization
RegisterBZIP;
iPowerRANK:=PowerArcRegisterModule('PowerRANK.dll');
iPowerZIP:=PowerArcRegisterModule('PowerZIP.dll');
iPowerPPM:=PowerArcRegisterModule('PowerPPM.dll');
finalization
PowerArcUnregisterModules;
end.