BLACKFIRE69
12-10-2023, 01:52
FXPacker API
Introduction:
FXPacker started as a side project to 'FMXInno', primarily dedicated to safeguarding various data types, such as (graphical content: images, music, text, etc.), used in the installer from unauthorized access.
Changes:
This is Version 2. Let's review the changes it introduces.
1. Improved speed and reliability compared to previous versions.
-- Note: This may cause compatibility issues with previous versions.
2. Now supports larger files.
-- Please ensure that the total size of the files remains below 800 MB.
(Total_File_Size * 2 + Extra should be less than 2 GB)
3. Added new events:
-- OnProgress, OnDataSaving, OnItemUnpack, OnEncrypt, OnDecrypt.
4. Introduced additional functions.
-- For a better understanding of how to use these functions,
refer to the examples provided in the attachment.
Simple Example:
Pack:
var
FXOk: Boolean;
BufferA: AnsiString;
BufferW: WideString;
Count: Cardinal;
FSize: Integer;
LPtr: Longint;
begin
FXOk := FXPckrInit('@#123_Test', ExpandConstant('{src}\MySetup.exe'), False);
if FXOk then
begin
// Img1
FXPckrAddFile(ExpandConstant('{src}\Files\Img1.png '));
// Img2
FileSize(ExpandConstant('{src}\Files\Img2.png'), FSize);
SetLength(BufferA, FSize);
FXFileToBuffer1A(ExpandConstant('{src}\Files\Img2. png'), BufferA);
FXPckrAddFromBuffer1A('Img2.png', BufferA);
// Save
FXPckrSave(ExpandConstant('{src}\Setup.dat'));
end;
{ CleanUp }
FXPckrFree;
end;
Unpack:
var
FXOk: Boolean;
BufferA: AnsiString;
BufferW: WideString;
Count: Cardinal;
FSize: Integer;
LPtr: Longint;
begin
FXOk := FXUnPckrInit(ExpandConstant('{src}\Setup.dat'), '@#123_Test');
if not FXOk then
begin
ShowErr('Failed to initialize the setup. The installation process cannot continue.');
end else
begin
// Img1
FXUnPckrExtract('Img1.png', ExpandConstant('{src}'));
// Img2
FSize := FXUnPckrExtractFileSize('Img2.png');
SetLength(BufferA, FSize);
FXUnPckrExtractToBuffer1A('Img2.png', BufferA);
end;
{ CleanUp }
FXUnPckrFree;
end;
Functions / Methods:
{ Pckr }
function FXPckrInit(const Password, ExeFile: WideString; DebugMode: Boolean): Boolean;
function FXPckrAddFile(const FileName: WideString): Boolean;
function FXPckrAddFromStream(const DisplayFilename: WideString; Source: TStream): Boolean;
function FXPckrAddFromBuffer1A(const DisplayFilename: WideString; const Buffer: AnsiString): Boolean;
function FXPckrAddFromBuffer1W(const DisplayFilename: WideString; const Buffer: WideString): Boolean;
function FXPckrAddFromBuffer2A(const DisplayFilename: WideString; const Buffer: PAnsiChar; const Count: Cardinal): Boolean;
function FXPckrAddFromBuffer2W(const DisplayFilename: WideString; const Buffer: PWideChar; const Count: Cardinal): Boolean;
function FXPckrAddFromBuffer3AW(const DisplayFilename: WideString; const Buffer: Longint; const Count: Cardinal): Boolean;
procedure FXPckrSave(const DestPackfile: WideString);
procedure FXPckrFree;
{ Unpckr }
function FXUnPckrInit(const PackFile, Password: WideString): Boolean;
function FXUnPckrFileExist(const DisplayFilename: WideString): Boolean;
function FXUnPckrExtract(const DisplayFilename, DestPath: WideString): Boolean;
function FXUnPckrExtractToStream(const DisplayFilename: WideString; Dest: TStream): Boolean;
function FXUnPckrExtractToBuffer1A(const DisplayFilename: WideString; var Buffer: AnsiString): Boolean;
function FXUnPckrExtractToBuffer1W(const DisplayFilename: WideString; var Buffer: WideString): Boolean;
function FXUnPckrExtractToBuffer2A(const DisplayFilename: WideString; const Buffer: PAnsiChar; var Count: Cardinal): Boolean;
function FXUnPckrExtractToBuffer2W(const DisplayFilename: WideString; const Buffer: PWideChar; var Count: Cardinal): Boolean;
function FXUnPckrExtractToBuffer3AW(const DisplayFilename: WideString; const Buffer: Longint; var Count: Cardinal): Boolean;
function FXUnPckrExtractFileSize(const DisplayFilename: WideString): Cardinal;
procedure FXUnPckrFree;
{ Extra }
function FXBufferToFile1A(const Buffer: AnsiString; const OutFile: WideString): Boolean;
function FXBufferToFile1W(const Buffer: WideString; const OutFile: WideString): Boolean;
function FXBufferToFile2A(const Buffer: PAnsiChar; const Count: Cardinal; const OutFile: WideString): Boolean;
function FXBufferToFile2W(const Buffer: PWideChar; const Count: Cardinal; const OutFile: WideString): Boolean;
function FXBufferToFile3AW(const Buffer: Longint; const Count: Cardinal; const OutFile: WideString): Boolean;
function FXFileToBuffer1A(const FileName: WideString; var Buffer: AnsiString): Boolean;
function FXFileToBuffer1W(const FileName: WideString; var Buffer: WideString): Boolean;
function FXFileToBuffer2A(const FileName: WideString; const Buffer: PAnsiChar; var Count: Cardinal): Boolean;
function FXFileToBuffer2W(const FileName: WideString; const Buffer: PWideChar; var Count: Cardinal): Boolean;
function FXFileToBuffer3AW(const FileName: WideString; const Buffer: Longint; var Count: Cardinal): Boolean;
function FXCastStringToIntegerA(var S: AnsiString): LongInt;
function FXCastStringToIntegerW(var S: WideString): LongInt;
function FXCastIntegerToStringA(const L: LongInt): AnsiString;
function FXCastIntegerToStringW(const L: LongInt): WideString;
function FXAnsiBufferToStr(const ABuffer: AnsiString): WideString;
function FXFreeBufferA(const Buffer: PAnsiChar): Integer;
function FXFreeBufferW(const Buffer: PWideChar): Integer;
{ Events }
procedure FXArchiveOnProgress(Callback: TArchiveOnProg);
procedure FXArchiveOnSaving(Callback: TArchiveOnProg);
procedure FXPackItemOnProgress(Callback: TItemOnProg);
procedure FXUnpackItemOnProgress(Callback: TItemOnProg);
procedure FXEncryptOnProgress(Callback: TCryptOnProg);
procedure FXDecryptOnProgress(Callback: TCryptOnProg);
.
Introduction:
FXPacker started as a side project to 'FMXInno', primarily dedicated to safeguarding various data types, such as (graphical content: images, music, text, etc.), used in the installer from unauthorized access.
Changes:
This is Version 2. Let's review the changes it introduces.
1. Improved speed and reliability compared to previous versions.
-- Note: This may cause compatibility issues with previous versions.
2. Now supports larger files.
-- Please ensure that the total size of the files remains below 800 MB.
(Total_File_Size * 2 + Extra should be less than 2 GB)
3. Added new events:
-- OnProgress, OnDataSaving, OnItemUnpack, OnEncrypt, OnDecrypt.
4. Introduced additional functions.
-- For a better understanding of how to use these functions,
refer to the examples provided in the attachment.
Simple Example:
Pack:
var
FXOk: Boolean;
BufferA: AnsiString;
BufferW: WideString;
Count: Cardinal;
FSize: Integer;
LPtr: Longint;
begin
FXOk := FXPckrInit('@#123_Test', ExpandConstant('{src}\MySetup.exe'), False);
if FXOk then
begin
// Img1
FXPckrAddFile(ExpandConstant('{src}\Files\Img1.png '));
// Img2
FileSize(ExpandConstant('{src}\Files\Img2.png'), FSize);
SetLength(BufferA, FSize);
FXFileToBuffer1A(ExpandConstant('{src}\Files\Img2. png'), BufferA);
FXPckrAddFromBuffer1A('Img2.png', BufferA);
// Save
FXPckrSave(ExpandConstant('{src}\Setup.dat'));
end;
{ CleanUp }
FXPckrFree;
end;
Unpack:
var
FXOk: Boolean;
BufferA: AnsiString;
BufferW: WideString;
Count: Cardinal;
FSize: Integer;
LPtr: Longint;
begin
FXOk := FXUnPckrInit(ExpandConstant('{src}\Setup.dat'), '@#123_Test');
if not FXOk then
begin
ShowErr('Failed to initialize the setup. The installation process cannot continue.');
end else
begin
// Img1
FXUnPckrExtract('Img1.png', ExpandConstant('{src}'));
// Img2
FSize := FXUnPckrExtractFileSize('Img2.png');
SetLength(BufferA, FSize);
FXUnPckrExtractToBuffer1A('Img2.png', BufferA);
end;
{ CleanUp }
FXUnPckrFree;
end;
Functions / Methods:
{ Pckr }
function FXPckrInit(const Password, ExeFile: WideString; DebugMode: Boolean): Boolean;
function FXPckrAddFile(const FileName: WideString): Boolean;
function FXPckrAddFromStream(const DisplayFilename: WideString; Source: TStream): Boolean;
function FXPckrAddFromBuffer1A(const DisplayFilename: WideString; const Buffer: AnsiString): Boolean;
function FXPckrAddFromBuffer1W(const DisplayFilename: WideString; const Buffer: WideString): Boolean;
function FXPckrAddFromBuffer2A(const DisplayFilename: WideString; const Buffer: PAnsiChar; const Count: Cardinal): Boolean;
function FXPckrAddFromBuffer2W(const DisplayFilename: WideString; const Buffer: PWideChar; const Count: Cardinal): Boolean;
function FXPckrAddFromBuffer3AW(const DisplayFilename: WideString; const Buffer: Longint; const Count: Cardinal): Boolean;
procedure FXPckrSave(const DestPackfile: WideString);
procedure FXPckrFree;
{ Unpckr }
function FXUnPckrInit(const PackFile, Password: WideString): Boolean;
function FXUnPckrFileExist(const DisplayFilename: WideString): Boolean;
function FXUnPckrExtract(const DisplayFilename, DestPath: WideString): Boolean;
function FXUnPckrExtractToStream(const DisplayFilename: WideString; Dest: TStream): Boolean;
function FXUnPckrExtractToBuffer1A(const DisplayFilename: WideString; var Buffer: AnsiString): Boolean;
function FXUnPckrExtractToBuffer1W(const DisplayFilename: WideString; var Buffer: WideString): Boolean;
function FXUnPckrExtractToBuffer2A(const DisplayFilename: WideString; const Buffer: PAnsiChar; var Count: Cardinal): Boolean;
function FXUnPckrExtractToBuffer2W(const DisplayFilename: WideString; const Buffer: PWideChar; var Count: Cardinal): Boolean;
function FXUnPckrExtractToBuffer3AW(const DisplayFilename: WideString; const Buffer: Longint; var Count: Cardinal): Boolean;
function FXUnPckrExtractFileSize(const DisplayFilename: WideString): Cardinal;
procedure FXUnPckrFree;
{ Extra }
function FXBufferToFile1A(const Buffer: AnsiString; const OutFile: WideString): Boolean;
function FXBufferToFile1W(const Buffer: WideString; const OutFile: WideString): Boolean;
function FXBufferToFile2A(const Buffer: PAnsiChar; const Count: Cardinal; const OutFile: WideString): Boolean;
function FXBufferToFile2W(const Buffer: PWideChar; const Count: Cardinal; const OutFile: WideString): Boolean;
function FXBufferToFile3AW(const Buffer: Longint; const Count: Cardinal; const OutFile: WideString): Boolean;
function FXFileToBuffer1A(const FileName: WideString; var Buffer: AnsiString): Boolean;
function FXFileToBuffer1W(const FileName: WideString; var Buffer: WideString): Boolean;
function FXFileToBuffer2A(const FileName: WideString; const Buffer: PAnsiChar; var Count: Cardinal): Boolean;
function FXFileToBuffer2W(const FileName: WideString; const Buffer: PWideChar; var Count: Cardinal): Boolean;
function FXFileToBuffer3AW(const FileName: WideString; const Buffer: Longint; var Count: Cardinal): Boolean;
function FXCastStringToIntegerA(var S: AnsiString): LongInt;
function FXCastStringToIntegerW(var S: WideString): LongInt;
function FXCastIntegerToStringA(const L: LongInt): AnsiString;
function FXCastIntegerToStringW(const L: LongInt): WideString;
function FXAnsiBufferToStr(const ABuffer: AnsiString): WideString;
function FXFreeBufferA(const Buffer: PAnsiChar): Integer;
function FXFreeBufferW(const Buffer: PWideChar): Integer;
{ Events }
procedure FXArchiveOnProgress(Callback: TArchiveOnProg);
procedure FXArchiveOnSaving(Callback: TArchiveOnProg);
procedure FXPackItemOnProgress(Callback: TItemOnProg);
procedure FXUnpackItemOnProgress(Callback: TItemOnProg);
procedure FXEncryptOnProgress(Callback: TCryptOnProg);
procedure FXDecryptOnProgress(Callback: TCryptOnProg);
.