| 1 |
{ |
| 2 |
Double Commander |
| 3 |
------------------------------------------------------------------------- |
| 4 |
SevenZip archiver plugin |
| 5 |
|
| 6 |
Copyright (C) 2015 Alexander Koblov ([email protected]) |
| 7 |
|
| 8 |
This library is free software; you can redistribute it and/or |
| 9 |
modify it under the terms of the GNU Lesser General Public |
| 10 |
License as published by the Free Software Foundation; either |
| 11 |
version 2.1 of the License, or (at your option) any later version. |
| 12 |
|
| 13 |
This library is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
Lesser General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU Lesser General Public |
| 19 |
License along with this library; if not, write to the Free Software |
| 20 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 |
} |
| 22 |
|
| 23 |
unit DCJclCompression; |
| 24 |
|
| 25 |
{$mode delphi} |
| 26 |
|
| 27 |
interface |
| 28 |
|
| 29 |
uses |
| 30 |
Classes, SysUtils, SevenZip; |
| 31 |
|
| 32 |
type |
| 33 |
|
| 34 |
{ TSfxSevenzipOutStream } |
| 35 |
|
| 36 |
TSfxSevenzipOutStream = class(TInterfacedObject, ISequentialOutStream, |
| 37 |
IOutStream, IUnknown) |
| 38 |
private |
| 39 |
FStream: TStream; |
| 40 |
FSfxLength: Int64; |
| 41 |
FSfxModule: String; |
| 42 |
public |
| 43 |
constructor Create(AStream: TStream; const ASfxModule: String); |
| 44 |
destructor Destroy; override; |
| 45 |
// ISequentialOutStream |
| 46 |
function Write(Data: Pointer; Size: Cardinal; ProcessedSize: PCardinal): HRESULT; stdcall; |
| 47 |
// IOutStream |
| 48 |
function Seek(Offset: Int64; SeekOrigin: Cardinal; NewPosition: PInt64): HRESULT; stdcall; |
| 49 |
function SetSize(NewSize: Int64): HRESULT; stdcall; |
| 50 |
end; |
| 51 |
|
| 52 |
implementation |
| 53 |
|
| 54 |
uses |
| 55 |
ActiveX, JwaWinError; |
| 56 |
|
| 57 |
{ TSfxSevenzipOutStream } |
| 58 |
|
| 59 |
constructor TSfxSevenzipOutStream.Create(AStream: TStream; const ASfxModule: String); |
| 60 |
var |
| 61 |
SfxModule: TFileStream; |
| 62 |
begin |
| 63 |
inherited Create; |
| 64 |
|
| 65 |
FStream := AStream; |
| 66 |
FSfxModule := ASfxModule; |
| 67 |
|
| 68 |
SfxModule:= TFileStream.Create(FSfxModule, fmOpenRead or fmShareDenyNone); |
| 69 |
try |
| 70 |
FStream.Seek(0, soBeginning); |
| 71 |
FSfxLength := FStream.CopyFrom(SfxModule, SfxModule.Size); |
| 72 |
finally |
| 73 |
SfxModule.Free; |
| 74 |
end; |
| 75 |
end; |
| 76 |
|
| 77 |
destructor TSfxSevenzipOutStream.Destroy; |
| 78 |
begin |
| 79 |
FStream.Free; |
| 80 |
|
| 81 |
inherited Destroy; |
| 82 |
end; |
| 83 |
|
| 84 |
function TSfxSevenzipOutStream.Write(Data: Pointer; Size: Cardinal; |
| 85 |
ProcessedSize: PCardinal): HRESULT; stdcall; |
| 86 |
var |
| 87 |
Processed: Cardinal; |
| 88 |
begin |
| 89 |
if Assigned(FStream) then |
| 90 |
begin |
| 91 |
Result := S_OK; |
| 92 |
Processed := FStream.Write(Data^, Size); |
| 93 |
if Assigned(ProcessedSize) then |
| 94 |
ProcessedSize^ := Processed; |
| 95 |
end |
| 96 |
else |
| 97 |
Result := S_FALSE; |
| 98 |
end; |
| 99 |
|
| 100 |
function TSfxSevenzipOutStream.Seek(Offset: Int64; SeekOrigin: Cardinal; |
| 101 |
NewPosition: PInt64): HRESULT; stdcall; |
| 102 |
var |
| 103 |
NewPos: Int64; |
| 104 |
NewOffset: Int64; |
| 105 |
begin |
| 106 |
if Assigned(FStream) then |
| 107 |
begin |
| 108 |
Result := S_OK; |
| 109 |
if SeekOrigin <> STREAM_SEEK_SET then |
| 110 |
NewOffset := Offset |
| 111 |
else begin |
| 112 |
NewOffset := Offset + FSfxLength; |
| 113 |
end; |
| 114 |
// STREAM_SEEK_SET = 0 = soBeginning |
| 115 |
// STREAM_SEEK_CUR = 1 = soCurrent |
| 116 |
// STREAM_SEEK_END = 2 = soEnd |
| 117 |
NewPos := FStream.Seek(NewOffset, TSeekOrigin(SeekOrigin)); |
| 118 |
if NewPos < FSfxLength then Exit(E_INVALIDARG); |
| 119 |
if Assigned(NewPosition) then |
| 120 |
NewPosition^ := NewPos - FSfxLength; |
| 121 |
end |
| 122 |
else |
| 123 |
Result := S_FALSE; |
| 124 |
end; |
| 125 |
|
| 126 |
function TSfxSevenzipOutStream.SetSize(NewSize: Int64): HRESULT; stdcall; |
| 127 |
begin |
| 128 |
if Assigned(FStream) then |
| 129 |
begin |
| 130 |
Result := S_OK; |
| 131 |
FStream.Size := NewSize + FSfxLength; |
| 132 |
end |
| 133 |
else |
| 134 |
Result := S_FALSE; |
| 135 |
end; |
| 136 |
|
| 137 |
end. |
| 138 |
|