unit pylACXHead;

{
  ACX plugin interface for oMega Commander.
  Interface version: 3.0
  Pylonos.com LLC (c)
  https://pylonos.com
}

interface

const

{ Version of the plugin interface }
  PlugACXVers_Major             = 3;
  PlugACXVers_Minor             = 0;

  PlugWCXVers_Major             = 2;
  PlugWCXVers_Minor             = 21;

{ The error codes are returned to the calling application }
  E_SUCCESS                     = 0;    // Successful execution
  E_END_ARCHIVE                 = 10;   // No more files in archive (archive end)
  E_NO_MEMORY                   = 11;   // Not enough memory
  E_BAD_DATA                    = 12;   // Data error
  E_BAD_ARCHIVE                 = 13;   // CRC error in archive data
  E_UNKNOWN_FORMAT              = 14;   // Invalid archive format
  E_EOPEN                       = 15;   // Impossible to open existing file
  E_ECREATE                     = 16;   // Impossible to create a file
  E_ECLOSE                      = 17;   // Error closing the file
  E_EREAD                       = 18;   // Error reading file
  E_EWRITE                      = 19;   // Error writing file
  E_SMALL_BUF                   = 20;   // Buffer is too small
  E_EABORTED                    = 21;   // Operation was interrupted by the user
  E_NO_FILES                    = 22;   // Files not found
  E_TOO_MANY_FILES              = 23;   // Too many files to archive
  E_NOT_SUPPORTED               = 24;   // Not supported operation

  E_EX_UNKNOWN_ERR              = 201;  // Unknown error
  E_EX_ENCRYPTED                = 202;  // File/archive is encrypted and not be processed (decryption isn't supported)
  E_EX_FILE_TOO_BIG             = 203;  // File is too big
  E_EX_FILE_IN_USE              = 204;  // File is locked/in use and can't be processed
  E_EX_NOT_SUPPORTED_METHOD     = 205;  // Archive method isn't supported
  E_EX_SKIP                     = 206;  // File was skipped
  E_EX_MAYBE_DISKFULL           = 207;  // Maybe disk full

{ Open archive flags }
  PK_OM_LIST                    = 0;    // View archive content
  PK_OM_EXTRACT                 = 1;    // Unpack archive

{ Flags for ProcessFileW, ProcessFile }
  PK_SKIP                       = 0;    // Skip file (without unpacking)
  PK_TEST                       = 1;    // Test integrity of the file
  PK_EXTRACT                    = 2;    // Unpack the file to disk

{ Flags for tChangeVolProcW, tChangeVolProc }
  PK_VOL_ASK                    = 0;    // Ask the user about location of the next volume
  PK_VOL_NOTIFY                 = 1;    // Notify the application, that the next volume can be unpackd

{ Flags for PackFiles, PackFilesW }
  PK_PACK_MOVE_FILES            = 1;    // Delete the input file after archiving
  PK_PACK_SAVE_PATHS            = 2;    // Save file paths
  PK_PACK_ENCRYPT               = 4;    // Request file password during encryption

{ Flags for ArcPackFilesW }
  PK_PACKEX_MOVE_FILES          = 1;
  PK_PACKEX_SAVE_PATHS          = 2;
  PK_PACKEX_ENCRYPT             = 4;
  PK_PACKEX_ENCRYPTLIST         = 8;
  PK_PACKEX_SOLID               = 16;

{ Flags of the tArcPlugInitData.out_PackerCaps, GetPackCaps }
  PK_CAPS_NEW                   = 1;    // Can create new archives
  PK_CAPS_MODIFY                = 2;    // Can change existing archives
  PK_CAPS_MULTIPLE              = 4;    // Archive can contain multiple files
  PK_CAPS_DELETE                = 8;    // Can delete files
  PK_CAPS_OPTIONS               = 16;   // Settings dialog exists
  PK_CAPS_MEMPACK               = 32;   // Supports archiving to memory
  PK_CAPS_BY_CONTENT            = 64;   // Detect archive type by content
  PK_CAPS_SEARCHTEXT            = 128;  // Can search text in archive
  PK_CAPS_HIDE                  = 256;  // Show as a regular file (hide archive icon), don't open on Enter, only on Ctrl+PgDn
  PK_CAPS_ENCRYPT               = 512;  // Plug-in supports parameter PK_PACK_ENCRYPT

{ Flags for StartMemPackW, StartMemPack }
  MEM_OPTIONS_WANTHEADERS       = 1;    // Return archive headers with packed data

{ Return values of PackToMem }
  MEMPACK_OK                    = 0;    // Function call finished OK, but there is more data
  MEMPACK_DONE                  = 1;    // Function call finished OK, there is no more data

{ Flags for PkSetCryptCallback }
  PK_CRYPTOPT_MASTERPASS_SET    = 1;    // The user already has a master password defined

{ Flags for PkCryptProc callback }
  PK_CRYPT_SAVE_PASSWORD        = 1;
  PK_CRYPT_LOAD_PASSWORD        = 2;
  PK_CRYPT_LOAD_PASSWORD_NO_UI  = 3;    // Load password only if master password has already been entered!
  PK_CRYPT_COPY_PASSWORD        = 4;    // Copy encrypted password to new archive name
  PK_CRYPT_MOVE_PASSWORD        = 5;    // Move password when renaming an archive
  PK_CRYPT_DELETE_PASSWORD      = 6;    // Delete password

{ Parameter types for ArcParamToPlug }
  PK_PARTOPLUG_PASSWORD         = 0;
  PK_PARTOPLUG_LANGUAGE         = 1;

{ Parameter types for ArcParamFromPlug }
  PK_PARFROMPLUG_STAGE          = 0;
  PK_PARFROMPLUG_FILESIZE       = 1;

{ Return values of ArcGetPasswordW }
  PK_GETPASS_OK                 = 0;
  PK_GETPASS_CANCEL             = 1;
  PK_GETPASS_SKIP               = 2;
  PK_GETPASS_TOOLONGPASS        = 3;
  PK_GETPASS_UNEXPECTED_ERR     = -1;

{ Flags for TArcInitPluginDataW.out_PackerCapsEx }
  PK_CAPEX_MYSELF_ASK_PASS      = 1;
  PK_CAPEX_CURFILE_ASK_PASS     = 2;
  PK_CAPEX_ENCRYPTLIST          = 4;
  PK_CAPEX_SOLID                = 8;

{ Codes of tArcOpenDataW.out_ArcPropFlags }
  PK_ARC_VOLUME                 = $0001; // Volume attribute (archive volume)
  PK_ARC_COMMENT                = $0002; // Archive comment present
  PK_ARC_LOCK                   = $0004; // Archive lock attribute
  PK_ARC_SOLID                  = $0008; // Solid archive
  PK_ARC_AUTHENCITY_INFO        = $0020; // Authenticity information present
  PK_ARC_RECOVERY_RECORD        = $0040; // Recovery record present
  PK_ARC_HEADERS_ENCRYPTED      = $0080; // Block headers are encrypted
  PK_ARC_FIRST_VOL              = $0100; // First volume (set only by RAR 3.0 and later)

{ Codes of tArcOpenDataW.ExFlags }
  PK_ARCEX_LOCK_ASK_PASS        = $001;

{ Codes of tHeaderDataExW.Flags, tHeaderDataEx.Flags, THeaderData.Flags }
  PK_HF_PREVVOL                 = $0001;
  PK_HF_NEXTVOL                 = $0002;
  PK_HF_ENCRYPT                 = $0004;
  PK_HF_COMMENT                 = $0008;
  PK_HF_SOLID                   = $0010;

{ Threshold for progressbars double percents for TArcProcessDataProcW, TProcessDataProcW, TProcessDataProc }
  PK_DOUBLEPROGRESS             = -100000;


  MAX_PATH = 260;

type
  LONG_PTR = NativeInt;
  HWND = NativeUInt;

{ The functions calling by a plugin }
  TArcProcessDataProcW = function(Session: LONG_PTR; FileName: PWideChar; Size: LongInt): LongInt; stdcall;
  TArcGetPasswordProcW = function(Session: LONG_PTR; hArcData: THandle; ArcFileName, FileNameInArc, PasswordBuf: PWideChar; PasswordMaxLen: Integer): Integer; stdcall;
  TArcShowDialogProcW = function(Session: LONG_PTR; WinCaption, FormattedText, ControlsDesc, ResultsBuffer: PWideChar; pResultsBufferLen: PInteger; ImageIndex: Integer): Integer; stdcall;
  TArcParamFromPlugProc = function(Session: LONG_PTR; hArcData: THandle; ParameterType: Integer; ParameterData: LONG_PTR): Integer; stdcall;

  TChangeVolProc = function(ArcVolName: PAnsiChar; Mode: LongInt): LongInt; stdcall;
  TChangeVolProcW = function(ArcVolName: PWideChar; Mode: LongInt): LongInt; stdcall;
  TProcessDataProc = function(FileName: PAnsiChar; Size: LongInt): LongInt; stdcall;
  TProcessDataProcW = function(FileName: PWideChar; Size: LongInt): LongInt; stdcall;
  TPkCryptProc = function(CryptoNr: Integer; Mode: Integer; ArchiveName, Password: PAnsiChar; MaxLen: Integer): Integer; stdcall;
  TPkCryptProcW = function(CryptoNr: Integer; Mode: Integer; ArchiveName, Password: PWideChar; MaxLen: Integer): Integer; stdcall;

  PChangeVolProc = ^TChangeVolProc;
  PChangeVolProcW = ^TChangeVolProcW;
  PProcessDataProc = ^TProcessDataProc;
  PProcessDataProcW = ^TProcessDataProcW;
  PArcProcessDataProcW = ^TArcProcessDataProcW;
  PPkCryptProc = ^TPkCryptProc;
  PPkCryptProcW = ^TPkCryptProcW;

  THeaderData = packed record
    ArcName:    array[0..259] of AnsiChar;
    FileName:   array[0..259] of AnsiChar;
    Flags:      Cardinal;
    PackSize:   Cardinal;
    UnpSize:    Cardinal;
    HostOS:     Cardinal;
    FileCRC:    Cardinal;
    FileTime:   Cardinal;
    UnpVer:     Cardinal;
    Method:     Cardinal;
    FileAttr:   Cardinal;
    CmtBuf:     PAnsiChar;
    CmtBufSize: Cardinal;
    CmtSize:    Cardinal;
    CmtState:   Cardinal;
  end;
  PHeaderData = ^THeaderData;

  THeaderDataEx = packed record
    ArcName:      array[0..1023] of AnsiChar;
    FileName:     array[0..1023] of AnsiChar;
    Flags:        Cardinal;
    PackSize:     Cardinal;
    PackSizeHigh: Cardinal;
    UnpSize:      Cardinal;
    UnpSizeHigh:  Cardinal;
    HostOS:       Cardinal;
    FileCRC:      Cardinal;
    FileTime:     Cardinal;
    UnpVer:       Cardinal;
    Method:       Cardinal;
    FileAttr:     Cardinal;
    CmtBuf:       PAnsiChar;
    CmtBufSize:   Cardinal;
    CmtSize:      Cardinal;
    CmtState:     Cardinal;
    Reserved:     array[0..1023] of AnsiChar;
  end;

  THeaderDataExW = packed record
    ArcName:      array[0..1023] of WideChar;
    FileName:     array[0..1023] of WideChar;
    Flags:        Cardinal;
    PackSize:     Cardinal;
    PackSizeHigh: Cardinal;
    UnpSize:      Cardinal;
    UnpSizeHigh:  Cardinal;
    HostOS:       Cardinal;
    FileCRC:      Cardinal;
    FileTime:     Cardinal;
    UnpVer:       Cardinal;
    Method:       Cardinal;
    FileAttr:     Cardinal;
    CmtBuf:       PAnsiChar;
    CmtBufSize:   Cardinal;
    CmtSize:      Cardinal;
    CmtState:     Cardinal;
    Reserved:     array[0..1023] of AnsiChar;
  end;

  TOpenArchiveData = packed record
    ArcName:    PAnsiChar;
    OpenMode:   Integer;
    OpenResult: Integer;
    CmtBuf:     PAnsiChar;
    CmtBufSize: Integer;
    CmtSize:    Integer;
    CmtState:   Integer;
  end;
  POpenArchiveData = ^TOpenArchiveData;

  TOpenArchiveDataW = packed record
    ArcName:    PWideChar;
    OpenMode:   Integer;
    OpenResult: Integer;
    CmtBuf:     PWideChar;
    CmtBufSize: Integer;
    CmtSize:    Integer;
    CmtState:   Integer;
  end;

  TArcOpenDataW = packed record
    ArcNameW:         PWideChar;
    OpenMode:         Cardinal;
    out_OpenResult:   Cardinal;
    out_ArcPropFlags: Cardinal;
    ExFlags:          Cardinal;
    Session:          LONG_PTR;
    ProcessDataW:     TArcProcessDataProcW;
    Reserved:         array[0..7] of LONG_PTR;
  end;

  TArcInitPluginDataW = packed record
    VersMajor:           Word;
    VersMinor:           Word;
    out_VersMajor:       Word;
    out_VersMinor:       Word;
    PluginFileName:      PWideChar;
    ArcGetPasswordW:     TArcGetPasswordProcW;
    ArcShowDialogW:      TArcShowDialogProcW;
    ArcParamFromPlug:    TArcParamFromPlugProc;
    ChangeVolProc:       TChangeVolProc;
    ChangeVolProcW:      TChangeVolProcW;
    DefaultIniNameW:     array[0..MAX_PATH-1] of WideChar;
    out_Extensions:      PWideChar;
    out_PackerCaps:      Cardinal;
    out_PackerCapsEx:    Cardinal;
    Reserved:            array[0..7] of LONG_PTR;
  end;
  PArcInitPluginDataW = ^TArcInitPluginDataW;

  TArcStageTypes = ( astNormal, astPrepareArchive );
  TArcProcessingStageData = packed record
    ArcStageType: TArcStageTypes;
    TotalFilesSize: Int64;
    TotalFilesCount: Int64;
    Reserved: LONG_PTR;
  end;
  PArcProcessingStageData = ^TArcProcessingStageData;

  TPackDefaultParamStruct = packed record
    Size:                      Integer;
    PluginInterfaceVersionLow: Integer;
    PluginInterfaceVersionHi:  Integer;
    DefaultIniName:            array[0..MAX_PATH-1] of AnsiChar;
  end;
  PPackDefaultParamStruct = ^TPackDefaultParamStruct;

{ The functions of a plugin }
  TArcInitPluginProcW = function(pData: PArcInitPluginDataW): LongBool; stdcall;
  TArcOpenProcW = function(var ArchiveData: tArcOpenDataW): THandle; stdcall;
  TArcParamToPlugProc = function(Session: LONG_PTR; hArcData: THandle; ParameterType: Integer; ParameterData: LONG_PTR): Integer; stdcall;
  TArcPackFilesProcW = function(PackedFile, SubPath, SrcPath, AddList: PWideChar; Flags: Integer; Size: Int64; Session: LONG_PTR; ProcessDataW: TArcProcessDataProcW; Reserved: Pointer): Integer; stdcall;
  TArcDeleteFilesProcW = function(PackedFile, DeleteList: PWideChar; Session: LONG_PTR; ProcessDataW: TArcProcessDataProcW; Reserved: Pointer): Integer; stdcall;

  TOpenArchiveProc = function(var ArchiveData: TOpenArchiveData): THandle; stdcall;
  TOpenArchiveProcW = function(var ArchiveData: TOpenArchiveDataW): THandle; stdcall;
  TReadHeaderProc = function(hArcData: THandle; var HeaderData: THeaderData): Integer; stdcall;
  TReadHeaderExProc = function(hArcData: THandle; var HeaderDataEx: THeaderDataEx): Integer; stdcall;
  TReadHeaderExProcW = function(hArcData: THandle; var HeaderDataExW: THeaderDataExW): Integer; stdcall;
  TProcessFileProc = function(hArcData: THandle; Operation: Integer; DestPath, DestName: PAnsiChar): Integer; stdcall;
  TProcessFileProcW = function(hArcData: THandle; Operation: Integer; DestPath, DestName: PWideChar): Integer; stdcall;
  TDeleteFilesProc = function(PackedFile, DeleteList: PAnsiChar): Integer; stdcall;
  TDeleteFilesProcW = function(PackedFile, DeleteList: PWideChar): Integer; stdcall;
  TCloseArchiveProc = function(hArcData: THandle): Integer; stdcall;
  TPackFilesProc = function(PackedFile, SubPath, SrcPath, AddList: PAnsiChar; Flags: Integer): Integer; stdcall;
  TPackFilesProcW = function(PackedFile, SubPath, SrcPath, AddList: PWideChar; Flags: Integer): Integer; stdcall;
  TGetPackerCapsProc = function: Integer; stdcall;
  TSetProcessDataProcProc = procedure(hArcData: THandle; ProcessDataProc: TProcessDataProc); stdcall;
  TSetProcessDataProcProcW = procedure(hArcData: THandle; ProcessDataProcW: TProcessDataProcW); stdcall;
  TSetChangeVolProcProc = procedure(hArcData: THandle; ChangeVolProc: TChangeVolProc); stdcall;
  TSetChangeVolProcProcW = procedure(hArcData: THandle; ChangeVolProcW: TChangeVolProcW); stdcall;
  TConfigurePackerProc = procedure(Parent: HWND; DLLinstance: HINST); stdcall;
  TStartMemPackProc = function(Options: Integer; FileName: PAnsiChar): THandle; stdcall;
  TStartMemPackProcW = function(Options: Integer; FileName: PWideChar): THandle; stdcall;
  TPackToMemProc = function(hMemPack: THandle; BufIn: PAnsiChar; InLen: Integer; Taken: PInteger; BufOut: PAnsiChar; OutLen: Integer; Written: PInteger; SeekBy: Integer): Integer; stdcall;
  TDoneMemPackProc = function(hMemPack: THandle): Integer; stdcall;
  TCanYouHandleThisFileProc = function(FileName: PAnsiChar): LongBool; stdcall;
  TCanYouHandleThisFileProcW = function(FileName: PWideChar): LongBool; stdcall;
  TPackSetDefaultParamsProc = procedure(dps: pPackDefaultParamStruct); stdcall;
  TPkSetCryptCallbackProc = procedure(pPkCryptProc: TPkCryptProc; CryptoNr: Integer; Flags: Integer); stdcall;
  TPkSetCryptCallbackProcW = procedure(pPkCryptProcW: TPkCryptProcW; CryptoNr: Integer; Flags: Integer); stdcall;
  TGetBackgroundFlagsProc = function: Integer; stdcall;

implementation

end.