unit Chilkat.Bz2;

{
  Pascal wrapper for Chilkat Bz2.
  Auto-generated by PascalWrapperGenerator -- do not edit manually.
}

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TBz2 wraps CkBz2 via the C bridge layer. }
  TBz2 = class(TChilkatBase)
  private
    FOnAbortCheck: TChilkatAbortCheckEvent;
    FOnPercentDone: TChilkatPercentDoneEvent;
    FOnProgressInfo: TChilkatProgressInfoEvent;
    function  GetLastErrorHtml: string;
    function  GetLastErrorText: string;
    function  GetLastErrorXml: string;
    function  GetVersion: string;
    function  GetDebugLogFilePath: string;
    procedure SetDebugLogFilePath(AValue: string);
    function  GetVerboseLogging: Boolean;
    procedure SetVerboseLogging(AValue: Boolean);
    function  GetLastMethodSuccess: Boolean;
    procedure SetLastMethodSuccess(AValue: Boolean);
    function  GetHeartbeatMs: Integer;
    procedure SetHeartbeatMs(AValue: Integer);
    function  GetAbortCurrent: Boolean;
    procedure SetAbortCurrent(AValue: Boolean);
    procedure SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
    procedure SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
    procedure SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
  public
    constructor Create;
    destructor  Destroy; override;

    property LastErrorHtml: string read GetLastErrorHtml;
    property LastErrorText: string read GetLastErrorText;
    property LastErrorXml: string read GetLastErrorXml;
    property Version: string read GetVersion;
    property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;
    property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;
    property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;
    property HeartbeatMs: Integer read GetHeartbeatMs write SetHeartbeatMs;
    property AbortCurrent: Boolean read GetAbortCurrent write SetAbortCurrent;

    { Event callbacks.  Return True from OnAbortCheck / OnPercentDone
      to abort the running method.  Callbacks are invoked on the
      thread that called the Chilkat method.  The HeartbeatMs
      property controls the AbortCheck frequency. }
    property OnAbortCheck: TChilkatAbortCheckEvent read FOnAbortCheck write SetOnAbortCheck;
    property OnPercentDone: TChilkatPercentDoneEvent read FOnPercentDone write SetOnPercentDone;
    property OnProgressInfo: TChilkatProgressInfoEvent read FOnProgressInfo write SetOnProgressInfo;

    function  CompressFile(const inFilename: string; const toPath: string): Boolean;
    function  UncompressFile(const inFilename: string; const toPath: string): Boolean;
    function  CompressBd(bd: TChilkatBase): Boolean;
    function  UncompressBd(bd: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkBz2_Create  = function(): Pointer; cdecl;
  TCkBz2_Dispose = procedure(handle: Pointer); cdecl;
  TCkBridgeAbortCheckCb   = function(userData: Pointer): Integer; cdecl;
  TCkBridgePercentDoneCb  = function(pctDone: Integer; userData: Pointer): Integer; cdecl;
  TCkBridgeProgressInfoCb = procedure(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
  TCkBz2_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkBz2_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkBz2_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkBz2_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkBz2_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkBz2_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkBz2_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkBz2_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkBz2_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkBz2_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkBz2_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkBz2_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkBz2_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkBz2_get_HeartbeatMs = function(handle: Pointer): Integer; cdecl;
  TCkBz2_put_HeartbeatMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkBz2_get_AbortCurrent = function(handle: Pointer): LongBool; cdecl;
  TCkBz2_put_AbortCurrent = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkBz2_CompressFile = function(handle: Pointer; inFilename: PAnsiChar; toPath: PAnsiChar): LongBool; cdecl;
  TCkBz2_UncompressFile = function(handle: Pointer; inFilename: PAnsiChar; toPath: PAnsiChar): LongBool; cdecl;
  TCkBz2_CompressBd = function(handle: Pointer; bd: Pointer): LongBool; cdecl;
  TCkBz2_UncompressBd = function(handle: Pointer; bd: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkBz2_Create:  TCkBz2_Create  = nil;
  CkBz2_Dispose: TCkBz2_Dispose = nil;
  CkBz2_SetAbortCheckCallback:   TCkBz2_SetAbortCheckCallback   = nil;
  CkBz2_SetPercentDoneCallback:  TCkBz2_SetPercentDoneCallback  = nil;
  CkBz2_SetProgressInfoCallback: TCkBz2_SetProgressInfoCallback = nil;
  CkBz2_get_LastErrorHtml: TCkBz2_get_LastErrorHtml = nil;
  CkBz2_get_LastErrorText: TCkBz2_get_LastErrorText = nil;
  CkBz2_get_LastErrorXml: TCkBz2_get_LastErrorXml = nil;
  CkBz2_get_Version: TCkBz2_get_Version = nil;
  CkBz2_get_DebugLogFilePath: TCkBz2_get_DebugLogFilePath = nil;
  CkBz2_put_DebugLogFilePath: TCkBz2_put_DebugLogFilePath = nil;
  CkBz2_get_VerboseLogging: TCkBz2_get_VerboseLogging = nil;
  CkBz2_put_VerboseLogging: TCkBz2_put_VerboseLogging = nil;
  CkBz2_get_LastMethodSuccess: TCkBz2_get_LastMethodSuccess = nil;
  CkBz2_put_LastMethodSuccess: TCkBz2_put_LastMethodSuccess = nil;
  CkBz2_get_HeartbeatMs: TCkBz2_get_HeartbeatMs = nil;
  CkBz2_put_HeartbeatMs: TCkBz2_put_HeartbeatMs = nil;
  CkBz2_get_AbortCurrent: TCkBz2_get_AbortCurrent = nil;
  CkBz2_put_AbortCurrent: TCkBz2_put_AbortCurrent = nil;
  CkBz2_CompressFile: TCkBz2_CompressFile = nil;
  CkBz2_UncompressFile: TCkBz2_UncompressFile = nil;
  CkBz2_CompressBd: TCkBz2_CompressBd = nil;
  CkBz2_UncompressBd: TCkBz2_UncompressBd = nil;

constructor TBz2.Create;
begin
  inherited Create;
  FHandle := CkBz2_Create();
end;

destructor TBz2.Destroy;
begin
  if FHandle <> nil then
    CkBz2_Dispose(FHandle);
  FHandle := nil;
  inherited;
end;

{ ---- Event callback thunks ---- }
{ Standalone cdecl functions registered with the C bridge.  The bridge
  passes back the userData pointer, which carries the Pascal object
  instance.  A non-zero return value aborts the running method. }

function TBz2_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TBz2;
begin
  Result := 0;
  obj := TBz2(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

function TBz2_PercentDoneThunk(pctDone: Integer; userData: Pointer): Integer; cdecl;
var
  obj: TBz2;
begin
  Result := 0;
  obj := TBz2(userData);
  if Assigned(obj) and Assigned(obj.FOnPercentDone) then
    if obj.FOnPercentDone(obj, pctDone) then Result := 1;
end;

procedure TBz2_ProgressInfoThunk(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
var
  obj: TBz2;
begin
  obj := TBz2(userData);
  if Assigned(obj) and Assigned(obj.FOnProgressInfo) then
    obj.FOnProgressInfo(obj, CkToStr(name), CkToStr(value));
end;

procedure TBz2.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkBz2_SetAbortCheckCallback(FHandle, @TBz2_AbortCheckThunk, Self)
  else
    CkBz2_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TBz2.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkBz2_SetPercentDoneCallback(FHandle, @TBz2_PercentDoneThunk, Self)
  else
    CkBz2_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TBz2.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkBz2_SetProgressInfoCallback(FHandle, @TBz2_ProgressInfoThunk, Self)
  else
    CkBz2_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TBz2.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkBz2_get_LastErrorHtml(FHandle));
end;

function TBz2.GetLastErrorText: string;
begin
  Result := CkToStr(CkBz2_get_LastErrorText(FHandle));
end;

function TBz2.GetLastErrorXml: string;
begin
  Result := CkToStr(CkBz2_get_LastErrorXml(FHandle));
end;

function TBz2.GetVersion: string;
begin
  Result := CkToStr(CkBz2_get_Version(FHandle));
end;

function TBz2.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkBz2_get_DebugLogFilePath(FHandle));
end;

procedure TBz2.SetDebugLogFilePath(AValue: string);
begin
  CkBz2_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TBz2.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkBz2_get_VerboseLogging(FHandle));
end;

procedure TBz2.SetVerboseLogging(AValue: Boolean);
begin
  CkBz2_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TBz2.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkBz2_get_LastMethodSuccess(FHandle));
end;

procedure TBz2.SetLastMethodSuccess(AValue: Boolean);
begin
  CkBz2_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TBz2.GetHeartbeatMs: Integer;
begin
  Result := CkBz2_get_HeartbeatMs(FHandle);
end;

procedure TBz2.SetHeartbeatMs(AValue: Integer);
begin
  CkBz2_put_HeartbeatMs(FHandle, AValue);
end;

function TBz2.GetAbortCurrent: Boolean;
begin
  Result := Boolean(CkBz2_get_AbortCurrent(FHandle));
end;

procedure TBz2.SetAbortCurrent(AValue: Boolean);
begin
  CkBz2_put_AbortCurrent(FHandle, LongBool(AValue));
end;

function TBz2.CompressFile(const inFilename: string; const toPath: string): Boolean;
begin
  Result := Boolean(CkBz2_CompressFile(FHandle, PAnsiChar(StrToCk(inFilename)), PAnsiChar(StrToCk(toPath))));
end;

function TBz2.UncompressFile(const inFilename: string; const toPath: string): Boolean;
begin
  Result := Boolean(CkBz2_UncompressFile(FHandle, PAnsiChar(StrToCk(inFilename)), PAnsiChar(StrToCk(toPath))));
end;

function TBz2.CompressBd(bd: TChilkatBase): Boolean;
begin
  Result := Boolean(CkBz2_CompressBd(FHandle, bd.Handle));
end;

function TBz2.UncompressBd(bd: TChilkatBase): Boolean;
begin
  Result := Boolean(CkBz2_UncompressBd(FHandle, bd.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkBz2_Create,  'CkBz2_Create');
  Chilkat_GetProcedureAddress(CkBz2_Dispose, 'CkBz2_Dispose');
  Chilkat_GetProcedureAddress(CkBz2_SetAbortCheckCallback, 'CkBz2_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkBz2_SetPercentDoneCallback, 'CkBz2_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkBz2_SetProgressInfoCallback, 'CkBz2_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkBz2_get_LastErrorHtml, 'CkBz2_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkBz2_get_LastErrorText, 'CkBz2_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkBz2_get_LastErrorXml, 'CkBz2_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkBz2_get_Version, 'CkBz2_get_Version');
  Chilkat_GetProcedureAddress(CkBz2_get_DebugLogFilePath, 'CkBz2_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkBz2_put_DebugLogFilePath, 'CkBz2_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkBz2_get_VerboseLogging, 'CkBz2_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkBz2_put_VerboseLogging, 'CkBz2_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkBz2_get_LastMethodSuccess, 'CkBz2_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkBz2_put_LastMethodSuccess, 'CkBz2_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkBz2_get_HeartbeatMs, 'CkBz2_get_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkBz2_put_HeartbeatMs, 'CkBz2_put_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkBz2_get_AbortCurrent, 'CkBz2_get_AbortCurrent');
  Chilkat_GetProcedureAddress(CkBz2_put_AbortCurrent, 'CkBz2_put_AbortCurrent');
  Chilkat_GetProcedureAddress(CkBz2_CompressFile, 'CkBz2_CompressFile');
  Chilkat_GetProcedureAddress(CkBz2_UncompressFile, 'CkBz2_UncompressFile');
  Chilkat_GetProcedureAddress(CkBz2_CompressBd, 'CkBz2_CompressBd');
  Chilkat_GetProcedureAddress(CkBz2_UncompressBd, 'CkBz2_UncompressBd');

end.
