unit Chilkat.ZipCrc;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TZipCrc wraps CkZipCrc via the C bridge layer. }
  TZipCrc = 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);
    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;

    { 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;

    procedure BeginStream;
    function  EndStream: LongWord;
    function  FileCrc(const path: string): LongWord;
    function  ToHex(crc: LongWord): string;
    function  CrcString(const str: string; const charset: string): LongWord;
    function  CrcSb(sb: TChilkatBase; const charset: string): LongWord;
    function  CrcBd(bd: TChilkatBase): LongWord;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkZipCrc_Create  = function(): Pointer; cdecl;
  TCkZipCrc_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;
  TCkZipCrc_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkZipCrc_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkZipCrc_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkZipCrc_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkZipCrc_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkZipCrc_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkZipCrc_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkZipCrc_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkZipCrc_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkZipCrc_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkZipCrc_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkZipCrc_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkZipCrc_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkZipCrc_BeginStream = procedure(handle: Pointer); cdecl;
  TCkZipCrc_EndStream = function(handle: Pointer): LongWord; cdecl;
  TCkZipCrc_FileCrc = function(handle: Pointer; path: PAnsiChar): LongWord; cdecl;
  TCkZipCrc_ToHex = function(handle: Pointer; crc: LongWord): PAnsiChar; cdecl;
  TCkZipCrc_CrcString = function(handle: Pointer; str: PAnsiChar; charset: PAnsiChar): LongWord; cdecl;
  TCkZipCrc_CrcSb = function(handle: Pointer; sb: Pointer; charset: PAnsiChar): LongWord; cdecl;
  TCkZipCrc_CrcBd = function(handle: Pointer; bd: Pointer): LongWord; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkZipCrc_Create:  TCkZipCrc_Create  = nil;
  CkZipCrc_Dispose: TCkZipCrc_Dispose = nil;
  CkZipCrc_SetAbortCheckCallback:   TCkZipCrc_SetAbortCheckCallback   = nil;
  CkZipCrc_SetPercentDoneCallback:  TCkZipCrc_SetPercentDoneCallback  = nil;
  CkZipCrc_SetProgressInfoCallback: TCkZipCrc_SetProgressInfoCallback = nil;
  CkZipCrc_get_LastErrorHtml: TCkZipCrc_get_LastErrorHtml = nil;
  CkZipCrc_get_LastErrorText: TCkZipCrc_get_LastErrorText = nil;
  CkZipCrc_get_LastErrorXml: TCkZipCrc_get_LastErrorXml = nil;
  CkZipCrc_get_Version: TCkZipCrc_get_Version = nil;
  CkZipCrc_get_DebugLogFilePath: TCkZipCrc_get_DebugLogFilePath = nil;
  CkZipCrc_put_DebugLogFilePath: TCkZipCrc_put_DebugLogFilePath = nil;
  CkZipCrc_get_VerboseLogging: TCkZipCrc_get_VerboseLogging = nil;
  CkZipCrc_put_VerboseLogging: TCkZipCrc_put_VerboseLogging = nil;
  CkZipCrc_get_LastMethodSuccess: TCkZipCrc_get_LastMethodSuccess = nil;
  CkZipCrc_put_LastMethodSuccess: TCkZipCrc_put_LastMethodSuccess = nil;
  CkZipCrc_BeginStream: TCkZipCrc_BeginStream = nil;
  CkZipCrc_EndStream: TCkZipCrc_EndStream = nil;
  CkZipCrc_FileCrc: TCkZipCrc_FileCrc = nil;
  CkZipCrc_ToHex: TCkZipCrc_ToHex = nil;
  CkZipCrc_CrcString: TCkZipCrc_CrcString = nil;
  CkZipCrc_CrcSb: TCkZipCrc_CrcSb = nil;
  CkZipCrc_CrcBd: TCkZipCrc_CrcBd = nil;

constructor TZipCrc.Create;
begin
  inherited Create;
  FHandle := CkZipCrc_Create();
end;

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

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

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

procedure TZipCrc.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkZipCrc_SetAbortCheckCallback(FHandle, @TZipCrc_AbortCheckThunk, Self)
  else
    CkZipCrc_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TZipCrc.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkZipCrc_SetPercentDoneCallback(FHandle, @TZipCrc_PercentDoneThunk, Self)
  else
    CkZipCrc_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TZipCrc.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkZipCrc_SetProgressInfoCallback(FHandle, @TZipCrc_ProgressInfoThunk, Self)
  else
    CkZipCrc_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TZipCrc.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkZipCrc_get_LastErrorHtml(FHandle));
end;

function TZipCrc.GetLastErrorText: string;
begin
  Result := CkToStr(CkZipCrc_get_LastErrorText(FHandle));
end;

function TZipCrc.GetLastErrorXml: string;
begin
  Result := CkToStr(CkZipCrc_get_LastErrorXml(FHandle));
end;

function TZipCrc.GetVersion: string;
begin
  Result := CkToStr(CkZipCrc_get_Version(FHandle));
end;

function TZipCrc.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkZipCrc_get_DebugLogFilePath(FHandle));
end;

procedure TZipCrc.SetDebugLogFilePath(AValue: string);
begin
  CkZipCrc_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TZipCrc.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkZipCrc_get_VerboseLogging(FHandle));
end;

procedure TZipCrc.SetVerboseLogging(AValue: Boolean);
begin
  CkZipCrc_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TZipCrc.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkZipCrc_get_LastMethodSuccess(FHandle));
end;

procedure TZipCrc.SetLastMethodSuccess(AValue: Boolean);
begin
  CkZipCrc_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

procedure TZipCrc.BeginStream;
begin
  CkZipCrc_BeginStream(FHandle);
end;

function TZipCrc.EndStream: LongWord;
begin
  Result := CkZipCrc_EndStream(FHandle);
end;

function TZipCrc.FileCrc(const path: string): LongWord;
begin
  Result := CkZipCrc_FileCrc(FHandle, PAnsiChar(StrToCk(path)));
end;

function TZipCrc.ToHex(crc: LongWord): string;
begin
  Result := CkToStr(CkZipCrc_ToHex(FHandle, crc));
end;

function TZipCrc.CrcString(const str: string; const charset: string): LongWord;
begin
  Result := CkZipCrc_CrcString(FHandle, PAnsiChar(StrToCk(str)), PAnsiChar(StrToCk(charset)));
end;

function TZipCrc.CrcSb(sb: TChilkatBase; const charset: string): LongWord;
begin
  Result := CkZipCrc_CrcSb(FHandle, sb.Handle, PAnsiChar(StrToCk(charset)));
end;

function TZipCrc.CrcBd(bd: TChilkatBase): LongWord;
begin
  Result := CkZipCrc_CrcBd(FHandle, bd.Handle);
end;

initialization
  Chilkat_GetProcedureAddress(CkZipCrc_Create,  'CkZipCrc_Create');
  Chilkat_GetProcedureAddress(CkZipCrc_Dispose, 'CkZipCrc_Dispose');
  Chilkat_GetProcedureAddress(CkZipCrc_SetAbortCheckCallback, 'CkZipCrc_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkZipCrc_SetPercentDoneCallback, 'CkZipCrc_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkZipCrc_SetProgressInfoCallback, 'CkZipCrc_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkZipCrc_get_LastErrorHtml, 'CkZipCrc_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkZipCrc_get_LastErrorText, 'CkZipCrc_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkZipCrc_get_LastErrorXml, 'CkZipCrc_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkZipCrc_get_Version, 'CkZipCrc_get_Version');
  Chilkat_GetProcedureAddress(CkZipCrc_get_DebugLogFilePath, 'CkZipCrc_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkZipCrc_put_DebugLogFilePath, 'CkZipCrc_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkZipCrc_get_VerboseLogging, 'CkZipCrc_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkZipCrc_put_VerboseLogging, 'CkZipCrc_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkZipCrc_get_LastMethodSuccess, 'CkZipCrc_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkZipCrc_put_LastMethodSuccess, 'CkZipCrc_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkZipCrc_BeginStream, 'CkZipCrc_BeginStream');
  Chilkat_GetProcedureAddress(CkZipCrc_EndStream, 'CkZipCrc_EndStream');
  Chilkat_GetProcedureAddress(CkZipCrc_FileCrc, 'CkZipCrc_FileCrc');
  Chilkat_GetProcedureAddress(CkZipCrc_ToHex, 'CkZipCrc_ToHex');
  Chilkat_GetProcedureAddress(CkZipCrc_CrcString, 'CkZipCrc_CrcString');
  Chilkat_GetProcedureAddress(CkZipCrc_CrcSb, 'CkZipCrc_CrcSb');
  Chilkat_GetProcedureAddress(CkZipCrc_CrcBd, 'CkZipCrc_CrcBd');

end.
