UPD: SevenZip - prepare Unix support

This commit is contained in:
Alexander Koblov 2024-11-10 15:36:43 +03:00
commit f2b3345653
5 changed files with 323 additions and 46 deletions

View file

@ -60,9 +60,9 @@ type
GetNumberOfFormats: TGetNumberOfFormatsFunc;
GetNumberOfMethods: TGetNumberOfMethodsFunc;
SetLargePageMode: TSetLargePageMode;
SetCodecs: function(compressCodecsInfo: ICompressCodecsInfo): HRESULT; stdcall;
CreateDecoder: function(Index: Cardinal; IID: PGUID; out Decoder): HRESULT; stdcall;
CreateEncoder: function(Index: Cardinal; IID: PGUID; out Coder): HRESULT; stdcall;
SetCodecs: function(compressCodecsInfo: ICompressCodecsInfo): HRESULT; winapi;
CreateDecoder: function(Index: Cardinal; IID: PGUID; out Decoder): HRESULT; winapi;
CreateEncoder: function(Index: Cardinal; IID: PGUID; out Coder): HRESULT; winapi;
end;
{ TCodecInfo }
@ -87,10 +87,10 @@ type
public
constructor Create(ACodecs: TFPGObjectList<TCodecInfo>; ALibraries: TFPGObjectList<TLibraryInfo>);
public
function GetNumberOfMethods(NumMethods: PCardinal): HRESULT; stdcall;
function GetProperty(Index: Cardinal; PropID: TPropID; out Value: TPropVariant): HRESULT; stdcall;
function CreateDecoder(Index: Cardinal; IID: PGUID; out Decoder): HRESULT; stdcall;
function CreateEncoder(Index: Cardinal; IID: PGUID; out Coder): HRESULT; stdcall;
function GetNumberOfMethods(NumMethods: PCardinal): HRESULT; winapi;
function GetProperty(Index: Cardinal; PropID: TPropID; out Value: TPropVariant): HRESULT; winapi;
function CreateDecoder(Index: Cardinal; IID: PGUID; out Decoder): HRESULT; winapi;
function CreateEncoder(Index: Cardinal; IID: PGUID; out Coder): HRESULT; winapi;
end;
procedure LoadLibraries;
@ -113,14 +113,14 @@ begin
FLibraries:= ALibraries;
end;
function TCompressCodecsInfo.GetNumberOfMethods(NumMethods: PCardinal): HRESULT; stdcall;
function TCompressCodecsInfo.GetNumberOfMethods(NumMethods: PCardinal): HRESULT; winapi;
begin
NumMethods^:= FCodecs.Count;
Result:= S_OK;
end;
function TCompressCodecsInfo.GetProperty(Index: Cardinal; PropID: TPropID; out
Value: TPropVariant): HRESULT; stdcall;
Value: TPropVariant): HRESULT; winapi;
var
ACodecInfo: TCodecInfo;
begin
@ -141,7 +141,7 @@ begin
end;
function TCompressCodecsInfo.CreateDecoder(Index: Cardinal; IID: PGUID; out
Decoder): HRESULT; stdcall;
Decoder): HRESULT; winapi;
var
ACodecInfo: TCodecInfo;
ALibraryInfo: TLibraryInfo;
@ -159,7 +159,7 @@ begin
end;
function TCompressCodecsInfo.CreateEncoder(Index: Cardinal; IID: PGUID; out
Coder): HRESULT; stdcall;
Coder): HRESULT; winapi;
var
ACodecInfo: TCodecInfo;
ALibraryInfo: TLibraryInfo;

View file

@ -43,10 +43,10 @@ type
constructor Create(AStream: TStream; const ASfxModule: String);
destructor Destroy; override;
// ISequentialOutStream
function Write(Data: Pointer; Size: Cardinal; ProcessedSize: PCardinal): HRESULT; stdcall;
function Write(Data: Pointer; Size: Cardinal; ProcessedSize: PCardinal): HRESULT; winapi;
// IOutStream
function Seek(Offset: Int64; SeekOrigin: Cardinal; NewPosition: PInt64): HRESULT; stdcall;
function SetSize(NewSize: Int64): HRESULT; stdcall;
function Seek(Offset: Int64; SeekOrigin: Cardinal; NewPosition: PInt64): HRESULT; winapi;
function SetSize(NewSize: Int64): HRESULT; winapi;
end;
implementation
@ -82,7 +82,7 @@ begin
end;
function TSfxSevenzipOutStream.Write(Data: Pointer; Size: Cardinal;
ProcessedSize: PCardinal): HRESULT; stdcall;
ProcessedSize: PCardinal): HRESULT; winapi;
var
Processed: Cardinal;
begin
@ -98,7 +98,7 @@ begin
end;
function TSfxSevenzipOutStream.Seek(Offset: Int64; SeekOrigin: Cardinal;
NewPosition: PInt64): HRESULT; stdcall;
NewPosition: PInt64): HRESULT; winapi;
var
NewPos: Int64;
NewOffset: Int64;
@ -123,7 +123,7 @@ begin
Result := S_FALSE;
end;
function TSfxSevenzipOutStream.SetSize(NewSize: Int64): HRESULT; stdcall;
function TSfxSevenzipOutStream.SetSize(NewSize: Int64): HRESULT; winapi;
begin
if Assigned(FStream) then
begin

View file

@ -813,9 +813,9 @@ type
function GetSupportsNestedArchive: Boolean; virtual;
public
{ IInterface }
// function QueryInterface(const IID: TGUID; out Obj): HRESULT; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
// function QueryInterface(const IID: TGUID; out Obj): HRESULT; winapi;
function _AddRef: Integer; winapi;
function _Release: Integer; winapi;
public
PropNames: array of WideString;
PropValues: array of TPropVariant;
@ -2076,10 +2076,10 @@ type
constructor Create(AStream: TStream; AOwnsStream: Boolean; ATruncateOnRelease: Boolean); overload;
destructor Destroy; override;
// ISequentialOutStream
function Write(Data: Pointer; Size: Cardinal; ProcessedSize: PCardinal): HRESULT; stdcall;
function Write(Data: Pointer; Size: Cardinal; ProcessedSize: PCardinal): HRESULT; winapi;
// IOutStream
function Seek(Offset: Int64; SeekOrigin: Cardinal; NewPosition: PInt64): HRESULT; stdcall;
function SetSize(NewSize: Int64): HRESULT; stdcall;
function Seek(Offset: Int64; SeekOrigin: Cardinal; NewPosition: PInt64): HRESULT; winapi;
function SetSize(NewSize: Int64): HRESULT; winapi;
end;
TJclSevenzipNestedInStream = class(TJclStream)
@ -2108,11 +2108,11 @@ type
constructor Create(AStream: TStream; AOwnsStream: Boolean); overload;
destructor Destroy; override;
// ISequentialInStream
function Read(Data: Pointer; Size: Cardinal; ProcessedSize: PCardinal): HRESULT; stdcall;
function Read(Data: Pointer; Size: Cardinal; ProcessedSize: PCardinal): HRESULT; winapi;
// IInStream
function Seek(Offset: Int64; SeekOrigin: Cardinal; NewPosition: PInt64): HRESULT; stdcall;
function Seek(Offset: Int64; SeekOrigin: Cardinal; NewPosition: PInt64): HRESULT; winapi;
// IStreamGetSize
function GetSize(Size: PInt64): HRESULT; stdcall;
function GetSize(Size: PInt64): HRESULT; winapi;
end;
TJclSevenzipOpenCallback = class(TInterfacedObject, IArchiveOpenCallback,
@ -2122,10 +2122,10 @@ type
public
constructor Create(AArchive: TJclCompressionArchive);
// IArchiveOpenCallback
function SetCompleted(Files: PInt64; Bytes: PInt64): HRESULT; stdcall;
function SetTotal(Files: PInt64; Bytes: PInt64): HRESULT; stdcall;
function SetCompleted(Files: PInt64; Bytes: PInt64): HRESULT; winapi;
function SetTotal(Files: PInt64; Bytes: PInt64): HRESULT; winapi;
// ICryptoGetTextPassword
function CryptoGetTextPassword(password: PBStr): HRESULT; stdcall;
function CryptoGetTextPassword(password: PBStr): HRESULT; winapi;
end;
TJclSevenzipExtractCallback = class(TInterfacedObject, IUnknown, IProgress,
@ -2137,16 +2137,16 @@ type
constructor Create(AArchive: TJclCompressionArchive);
// IArchiveExtractCallback
function GetStream(Index: Cardinal; out OutStream: ISequentialOutStream;
askExtractMode: Cardinal): HRESULT; stdcall;
function PrepareOperation(askExtractMode: Cardinal): HRESULT; stdcall;
function SetOperationResult(resultEOperationResult: Integer): HRESULT; stdcall;
askExtractMode: Cardinal): HRESULT; winapi;
function PrepareOperation(askExtractMode: Cardinal): HRESULT; winapi;
function SetOperationResult(resultEOperationResult: Integer): HRESULT; winapi;
// IProgress
function SetCompleted(CompleteValue: PInt64): HRESULT; stdcall;
function SetTotal(Total: Int64): HRESULT; stdcall;
function SetCompleted(CompleteValue: PInt64): HRESULT; winapi;
function SetTotal(Total: Int64): HRESULT; winapi;
// ICryptoGetTextPassword
function CryptoGetTextPassword(password: PBStr): HRESULT; stdcall;
function CryptoGetTextPassword(password: PBStr): HRESULT; winapi;
// ICompressProgressInfo
function SetRatioInfo(InSize: PInt64; OutSize: PInt64): HRESULT; stdcall;
function SetRatioInfo(InSize: PInt64; OutSize: PInt64): HRESULT; winapi;
end;
TJclSevenzipUpdateCallback = class(TInterfacedObject, IUnknown, IProgress,
@ -2158,23 +2158,23 @@ type
public
constructor Create(AArchive: TJclCompressionArchive);
// IProgress
function SetCompleted(CompleteValue: PInt64): HRESULT; stdcall;
function SetTotal(Total: Int64): HRESULT; stdcall;
function SetCompleted(CompleteValue: PInt64): HRESULT; winapi;
function SetTotal(Total: Int64): HRESULT; winapi;
// IArchiveUpdateCallback
function GetProperty(Index: Cardinal; PropID: Cardinal; out Value: tagPROPVARIANT): HRESULT; stdcall;
function GetStream(Index: Cardinal; out InStream: ISequentialInStream): HRESULT; stdcall;
function GetProperty(Index: Cardinal; PropID: Cardinal; out Value: tagPROPVARIANT): HRESULT; winapi;
function GetStream(Index: Cardinal; out InStream: ISequentialInStream): HRESULT; winapi;
function GetUpdateItemInfo(Index: Cardinal; NewData: PInteger;
NewProperties: PInteger; IndexInArchive: PCardinal): HRESULT; stdcall;
function SetOperationResult(OperationResult: Integer): HRESULT; stdcall;
NewProperties: PInteger; IndexInArchive: PCardinal): HRESULT; winapi;
function SetOperationResult(OperationResult: Integer): HRESULT; winapi;
// IArchiveUpdateCallback2
function GetVolumeSize(Index: Cardinal; Size: PInt64): HRESULT; stdcall;
function GetVolumeSize(Index: Cardinal; Size: PInt64): HRESULT; winapi;
function GetVolumeStream(Index: Cardinal;
out VolumeStream: ISequentialOutStream): HRESULT; stdcall;
out VolumeStream: ISequentialOutStream): HRESULT; winapi;
// ICryptoGetTextPassword2
function CryptoGetTextPassword2(PasswordIsDefined: PInteger;
Password: PBStr): HRESULT; stdcall;
Password: PBStr): HRESULT; winapi;
// ICompressProgressInfo
function SetRatioInfo(InSize: PInt64; OutSize: PInt64): HRESULT; stdcall;
function SetRatioInfo(InSize: PInt64; OutSize: PInt64): HRESULT; winapi;
end;
type

View file

@ -0,0 +1,195 @@
unit ActiveX;
{$mode delphi}
{.$define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN}
{
p7zip and 7-Zip before v23 used virtual destructor in IUnknown,
if _WIN32 is not defined.
It used virtual destructor, because some compilers don't like virtual
interfaces without virtual destructor.
IUnknown in Windows (_WIN32) doesn't use virtual destructor in IUnknown.
We still can define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN here,
if we want to be compatible with old plugin interface of p7zip and 7-Zip before v23.
v23:
In new 7-Zip v23 we try to be more compatible with original IUnknown from _WIN32.
So we do not define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN here
}
interface
uses
SysUtils, Types, Windows;
const
STREAM_SEEK_SET = 0;
STREAM_SEEK_CUR = 1;
STREAM_SEEK_END = 2;
E_ABORT = HRESULT($80004004);
E_INVALIDARG = HRESULT($80070057);
VT_EMPTY = 0;
VT_NULL = 1;
VT_I2 = 2;
VT_I4 = 3;
VT_R4 = 4;
VT_R8 = 5;
VT_CY = 6;
VT_DATE = 7;
VT_BSTR = 8;
VT_DISPATCH = 9;
VT_ERROR = 10;
VT_BOOL = 11;
VT_VARIANT = 12;
VT_UNKNOWN = 13;
VT_DECIMAL = 14;
// VBA reserves 15 for future use
VT_I1 = 16;
VT_UI1 = 17;
VT_UI2 = 18;
VT_UI4 = 19;
VT_I8 = 20;
VT_UI8 = 21;
VT_INT = 22;
VT_UINT = 23;
VT_VOID = 24;
VT_HRESULT = 25;
VT_PTR = 26;
VT_SAFEARRAY = 27;
VT_CARRAY = 28;
VT_USERDEFINED = 29;
VT_LPSTR = 30;
VT_LPWSTR = 31;
// VBA reserves 32-35 for future use
VT_RECORD = 36;
VT_INT_PTR = 37;
VT_UINT_PTR = 38;
VT_FILETIME = 64;
VT_BLOB = 65;
VT_STREAM = 66;
VT_STORAGE = 67;
VT_STREAMED_OBJECT = 68;
VT_STORED_OBJECT = 69;
VT_BLOB_OBJECT = 70;
VT_CF = 71;
VT_CLSID = 72;
VT_VERSIONED_STREAM = 73;
VT_BSTR_BLOB = $0fff;
VT_VECTOR = $1000;
VT_ARRAY = $2000;
VT_BYREF = $4000;
VT_RESERVED = $8000;
VT_ILLEGAL = $ffff;
VT_ILLEGALMASKED = $0fff;
VT_TYPEMASK = $0fff;
type
TOleChar = Types.TOleChar;
POleStr = Types.POleStr;
PPOleStr = Types.PPOleStr;
TBStr = POleStr;
BSTR = POLESTR;
PBStr = ^TBStr;
PROPID = UInt32;
TPROPID = PROPID;
PPROPID = ^PROPID;
VARIANT_BOOL = wordbool;
_VARIANT_BOOL = VARIANT_BOOL;
SCODE = Long;
CY = CURRENCY;
DATE = DOUBLE;
PROPVAR_PAD1 = WORD;
PROPVAR_PAD2 = WORD;
PROPVAR_PAD3 = WORD;
{ size of this record must be 16, i.e. match Variant }
TPROPVARIANT = packed record
vt : TVarType;
wReserved1 : PROPVAR_PAD1;
wReserved2 : PROPVAR_PAD2;
wReserved3 : PROPVAR_PAD3;
case longint of
0 : ( cVal : CHAR );
1 : ( bVal : UCHAR );
2 : ( iVal : SHORT );
3 : ( uiVal : USHORT );
4 : ( lVal : LONG );
5 : ( ulVal : ULONG );
6 : ( intVal : longINT );
7 : ( uintVal : UINT );
8 : ( hVal : LARGE_INTEGER );
9 : ( uhVal : ULARGE_INTEGER );
10 : ( fltVal : SINGLE );
11 : ( dblVal : DOUBLE );
12 : ( boolVal : VARIANT_BOOL );
13 : ( bool : _VARIANT_BOOL );
14 : ( scode : SCODE );
15 : ( cyVal : CY );
16 : ( date : DATE );
17 : ( filetime : TFileTime );
18 : ( puuid : ^CLSID );
20 : ( bstrVal : BSTR );
23 : ( pszVal : LPSTR );
24 : ( pwszVal : LPWSTR );
end;
PROPVARIANT = TPROPVARIANT;
TagPROPVARIANT = TPROPVARIANT;
PPropVariant = ^TPROPVARIANT;
{$IFDEF Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN}
type
IUnknown = interface(System.IUnknown)
['{1E891736-3630-4316-A24F-B549F732452B}']
procedure Dummy; winapi;
procedure Dummy2; winapi;
end;
{ TInterfacedObject }
TInterfacedObject = class(System.TInterfacedObject)
procedure Dummy; winapi;
procedure Dummy2; winapi;
end;
{$ENDIF}
function Succeeded(Res: HResult) : Boolean;inline;
implementation
function Succeeded(Res: HResult) : Boolean;inline;
begin
Result := Res and $80000000 = 0;
end;
{$IFDEF Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN}
{ TInterfacedObject }
procedure TInterfacedObject.Dummy;
begin
end;
procedure TInterfacedObject.Dummy2;
begin
end;
{$ENDIF}
end.

View file

@ -0,0 +1,82 @@
unit Windows;
{$mode delphi}
interface
uses
SysUtils, Types;
const
ERROR_SUCCESS = 0;
MAXDWORD = High(DWORD);
E_OUTOFMEMORY = HRESULT($8007000E);
FILE_ATTRIBUTE_ARCHIVE = faArchive;
FILE_ATTRIBUTE_DIRECTORY = faDirectory;
type
UCHAR = byte;
WCHAR = WideChar;
HWND = UIntPtr;
UINT = cardinal;
ULONG = cardinal;
USHORT = word;
SHORT = smallint;
WINT = longint;
LONG = longint;
LONG64= int64;
ULONG64 = qword;
ULONG32 = cardinal;
DWORD = cardinal;
LONGLONG = int64;
ULONGLONG = qword;
LARGE_INTEGER = record
case byte of
0: (LowPart : DWORD;
HighPart : LONG);
1: (QuadPart : LONGLONG);
end;
PLARGE_INTEGER = ^LARGE_INTEGER;
_LARGE_INTEGER = LARGE_INTEGER;
TLargeInteger = Int64;
PLargeInteger = ^TLargeInteger;
ULARGE_INTEGER = record
case byte of
0: (LowPart : DWORD;
HighPart : DWORD);
1: (QuadPart : ULONGLONG);
end;
PULARGE_INTEGER = ^ULARGE_INTEGER;
_ULARGE_INTEGER = ULARGE_INTEGER;
TULargeInteger = QWord;
PULargeInteger = ^TULargeInteger;
CLSID = TGUID;
LPSTR = Pchar;
LPWSTR = PWideChar;
procedure ZeroMemory(Destination: Pointer; Length: UIntPtr); inline;
procedure CopyMemory(Destination, Source: Pointer; Length: UIntPtr); inline;
implementation
procedure ZeroMemory(Destination: Pointer; Length: UIntPtr);
begin
FillChar(Destination^, Length, 0);
end;
procedure CopyMemory(Destination, Source: Pointer; Length: UIntPtr);
begin
Move(Source^, Destination^, Length);
end;
end.