unit Chilkat.UnixCompress;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TUnixCompress wraps CkUnixCompress via the C bridge layer. }
  TUnixCompress = 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 destPath: string): Boolean;
    function  CompressStringToFile(const inStr: string; const charset: string; const destPath: string): Boolean;
    function  UnTarZ(const zFilename: string; const destDir: string; bNoAbsolute: Boolean): Boolean;
    function  UncompressFile(const inFilename: string; const destPath: string): Boolean;
    function  UncompressFileToString(const zFilename: string; const charset: string): string;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkUnixCompress_Create  = function(): Pointer; cdecl;
  TCkUnixCompress_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;
  TCkUnixCompress_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkUnixCompress_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkUnixCompress_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkUnixCompress_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkUnixCompress_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkUnixCompress_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkUnixCompress_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkUnixCompress_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkUnixCompress_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkUnixCompress_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkUnixCompress_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkUnixCompress_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkUnixCompress_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkUnixCompress_get_HeartbeatMs = function(handle: Pointer): Integer; cdecl;
  TCkUnixCompress_put_HeartbeatMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkUnixCompress_get_AbortCurrent = function(handle: Pointer): LongBool; cdecl;
  TCkUnixCompress_put_AbortCurrent = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkUnixCompress_CompressFile = function(handle: Pointer; inFilename: PAnsiChar; destPath: PAnsiChar): LongBool; cdecl;
  TCkUnixCompress_CompressStringToFile = function(handle: Pointer; inStr: PAnsiChar; charset: PAnsiChar; destPath: PAnsiChar): LongBool; cdecl;
  TCkUnixCompress_UnTarZ = function(handle: Pointer; zFilename: PAnsiChar; destDir: PAnsiChar; bNoAbsolute: LongBool): LongBool; cdecl;
  TCkUnixCompress_UncompressFile = function(handle: Pointer; inFilename: PAnsiChar; destPath: PAnsiChar): LongBool; cdecl;
  TCkUnixCompress_UncompressFileToString = function(handle: Pointer; zFilename: PAnsiChar; charset: PAnsiChar): PAnsiChar; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkUnixCompress_Create:  TCkUnixCompress_Create  = nil;
  CkUnixCompress_Dispose: TCkUnixCompress_Dispose = nil;
  CkUnixCompress_SetAbortCheckCallback:   TCkUnixCompress_SetAbortCheckCallback   = nil;
  CkUnixCompress_SetPercentDoneCallback:  TCkUnixCompress_SetPercentDoneCallback  = nil;
  CkUnixCompress_SetProgressInfoCallback: TCkUnixCompress_SetProgressInfoCallback = nil;
  CkUnixCompress_get_LastErrorHtml: TCkUnixCompress_get_LastErrorHtml = nil;
  CkUnixCompress_get_LastErrorText: TCkUnixCompress_get_LastErrorText = nil;
  CkUnixCompress_get_LastErrorXml: TCkUnixCompress_get_LastErrorXml = nil;
  CkUnixCompress_get_Version: TCkUnixCompress_get_Version = nil;
  CkUnixCompress_get_DebugLogFilePath: TCkUnixCompress_get_DebugLogFilePath = nil;
  CkUnixCompress_put_DebugLogFilePath: TCkUnixCompress_put_DebugLogFilePath = nil;
  CkUnixCompress_get_VerboseLogging: TCkUnixCompress_get_VerboseLogging = nil;
  CkUnixCompress_put_VerboseLogging: TCkUnixCompress_put_VerboseLogging = nil;
  CkUnixCompress_get_LastMethodSuccess: TCkUnixCompress_get_LastMethodSuccess = nil;
  CkUnixCompress_put_LastMethodSuccess: TCkUnixCompress_put_LastMethodSuccess = nil;
  CkUnixCompress_get_HeartbeatMs: TCkUnixCompress_get_HeartbeatMs = nil;
  CkUnixCompress_put_HeartbeatMs: TCkUnixCompress_put_HeartbeatMs = nil;
  CkUnixCompress_get_AbortCurrent: TCkUnixCompress_get_AbortCurrent = nil;
  CkUnixCompress_put_AbortCurrent: TCkUnixCompress_put_AbortCurrent = nil;
  CkUnixCompress_CompressFile: TCkUnixCompress_CompressFile = nil;
  CkUnixCompress_CompressStringToFile: TCkUnixCompress_CompressStringToFile = nil;
  CkUnixCompress_UnTarZ: TCkUnixCompress_UnTarZ = nil;
  CkUnixCompress_UncompressFile: TCkUnixCompress_UncompressFile = nil;
  CkUnixCompress_UncompressFileToString: TCkUnixCompress_UncompressFileToString = nil;

constructor TUnixCompress.Create;
begin
  inherited Create;
  FHandle := CkUnixCompress_Create();
end;

destructor TUnixCompress.Destroy;
begin
  if FHandle <> nil then
    CkUnixCompress_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 TUnixCompress_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TUnixCompress;
begin
  Result := 0;
  obj := TUnixCompress(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

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

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

procedure TUnixCompress.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkUnixCompress_SetAbortCheckCallback(FHandle, @TUnixCompress_AbortCheckThunk, Self)
  else
    CkUnixCompress_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TUnixCompress.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkUnixCompress_SetPercentDoneCallback(FHandle, @TUnixCompress_PercentDoneThunk, Self)
  else
    CkUnixCompress_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TUnixCompress.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkUnixCompress_SetProgressInfoCallback(FHandle, @TUnixCompress_ProgressInfoThunk, Self)
  else
    CkUnixCompress_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TUnixCompress.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkUnixCompress_get_LastErrorHtml(FHandle));
end;

function TUnixCompress.GetLastErrorText: string;
begin
  Result := CkToStr(CkUnixCompress_get_LastErrorText(FHandle));
end;

function TUnixCompress.GetLastErrorXml: string;
begin
  Result := CkToStr(CkUnixCompress_get_LastErrorXml(FHandle));
end;

function TUnixCompress.GetVersion: string;
begin
  Result := CkToStr(CkUnixCompress_get_Version(FHandle));
end;

function TUnixCompress.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkUnixCompress_get_DebugLogFilePath(FHandle));
end;

procedure TUnixCompress.SetDebugLogFilePath(AValue: string);
begin
  CkUnixCompress_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TUnixCompress.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkUnixCompress_get_VerboseLogging(FHandle));
end;

procedure TUnixCompress.SetVerboseLogging(AValue: Boolean);
begin
  CkUnixCompress_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TUnixCompress.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkUnixCompress_get_LastMethodSuccess(FHandle));
end;

procedure TUnixCompress.SetLastMethodSuccess(AValue: Boolean);
begin
  CkUnixCompress_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TUnixCompress.GetHeartbeatMs: Integer;
begin
  Result := CkUnixCompress_get_HeartbeatMs(FHandle);
end;

procedure TUnixCompress.SetHeartbeatMs(AValue: Integer);
begin
  CkUnixCompress_put_HeartbeatMs(FHandle, AValue);
end;

function TUnixCompress.GetAbortCurrent: Boolean;
begin
  Result := Boolean(CkUnixCompress_get_AbortCurrent(FHandle));
end;

procedure TUnixCompress.SetAbortCurrent(AValue: Boolean);
begin
  CkUnixCompress_put_AbortCurrent(FHandle, LongBool(AValue));
end;

function TUnixCompress.CompressFile(const inFilename: string; const destPath: string): Boolean;
begin
  Result := Boolean(CkUnixCompress_CompressFile(FHandle, PAnsiChar(StrToCk(inFilename)), PAnsiChar(StrToCk(destPath))));
end;

function TUnixCompress.CompressStringToFile(const inStr: string; const charset: string; const destPath: string): Boolean;
begin
  Result := Boolean(CkUnixCompress_CompressStringToFile(FHandle, PAnsiChar(StrToCk(inStr)), PAnsiChar(StrToCk(charset)), PAnsiChar(StrToCk(destPath))));
end;

function TUnixCompress.UnTarZ(const zFilename: string; const destDir: string; bNoAbsolute: Boolean): Boolean;
begin
  Result := Boolean(CkUnixCompress_UnTarZ(FHandle, PAnsiChar(StrToCk(zFilename)), PAnsiChar(StrToCk(destDir)), LongBool(bNoAbsolute)));
end;

function TUnixCompress.UncompressFile(const inFilename: string; const destPath: string): Boolean;
begin
  Result := Boolean(CkUnixCompress_UncompressFile(FHandle, PAnsiChar(StrToCk(inFilename)), PAnsiChar(StrToCk(destPath))));
end;

function TUnixCompress.UncompressFileToString(const zFilename: string; const charset: string): string;
begin
  Result := CkToStr(CkUnixCompress_UncompressFileToString(FHandle, PAnsiChar(StrToCk(zFilename)), PAnsiChar(StrToCk(charset))));
end;

initialization
  Chilkat_GetProcedureAddress(CkUnixCompress_Create,  'CkUnixCompress_Create');
  Chilkat_GetProcedureAddress(CkUnixCompress_Dispose, 'CkUnixCompress_Dispose');
  Chilkat_GetProcedureAddress(CkUnixCompress_SetAbortCheckCallback, 'CkUnixCompress_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkUnixCompress_SetPercentDoneCallback, 'CkUnixCompress_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkUnixCompress_SetProgressInfoCallback, 'CkUnixCompress_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_LastErrorHtml, 'CkUnixCompress_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_LastErrorText, 'CkUnixCompress_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_LastErrorXml, 'CkUnixCompress_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_Version, 'CkUnixCompress_get_Version');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_DebugLogFilePath, 'CkUnixCompress_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkUnixCompress_put_DebugLogFilePath, 'CkUnixCompress_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_VerboseLogging, 'CkUnixCompress_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkUnixCompress_put_VerboseLogging, 'CkUnixCompress_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_LastMethodSuccess, 'CkUnixCompress_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkUnixCompress_put_LastMethodSuccess, 'CkUnixCompress_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_HeartbeatMs, 'CkUnixCompress_get_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkUnixCompress_put_HeartbeatMs, 'CkUnixCompress_put_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkUnixCompress_get_AbortCurrent, 'CkUnixCompress_get_AbortCurrent');
  Chilkat_GetProcedureAddress(CkUnixCompress_put_AbortCurrent, 'CkUnixCompress_put_AbortCurrent');
  Chilkat_GetProcedureAddress(CkUnixCompress_CompressFile, 'CkUnixCompress_CompressFile');
  Chilkat_GetProcedureAddress(CkUnixCompress_CompressStringToFile, 'CkUnixCompress_CompressStringToFile');
  Chilkat_GetProcedureAddress(CkUnixCompress_UnTarZ, 'CkUnixCompress_UnTarZ');
  Chilkat_GetProcedureAddress(CkUnixCompress_UncompressFile, 'CkUnixCompress_UncompressFile');
  Chilkat_GetProcedureAddress(CkUnixCompress_UncompressFileToString, 'CkUnixCompress_UncompressFileToString');

end.
