How to save uninstall files inside the uninstaller?

Is there a way to make uninstall files (JPEG, DLL, PNG ...) included in unins000.exe? If yes, enter the code.

+4
source share
2 answers

There is no way to do this. Inno removal mechanism cannot contain embedded files.

But, on the other hand, there is no particular need for this - you can simply install any required files (in a subfolder of the application folder, if you want to keep things in order).

The only real reason that installation files are embedded in the installer is because it makes downloading easier. The uninstaller does not have this excuse.

+7
source

Inno Setup .

( ).

, Unicode Inno , UTF-8. ( PowerShell, Inno Setup).


[Code]:

function CryptStringToBinary(
  sz: string; cch: LongWord; flags: LongWord; binary: string; var size: LongWord;
  skip: LongWord; flagsused: LongWord): Integer;
  external 'CryptStringToBinaryW@crypt32.dll stdcall';

const
  CRYPT_STRING_HEX = $04;

procedure WriteBinaryStringToStream(S: string; Stream: TStream);
var
  Buffer: string;
  Size: LongWord;
begin
  SetLength(Buffer, (Length(S) div 4) + 1);
  Size := Length(S) div 2;
  if (CryptStringToBinary(S, Length(S), CRYPT_STRING_HEX, Buffer, Size, 0, 0) = 0) or
     (Size <> Length(S) div 2) then
  begin
    RaiseException('Error decoding binary string');
  end;

  Stream.WriteBuffer(Buffer, Size);
end;  

function StreamFromBinaryString(S: string): TStream;
begin
  Result := TStringStream.Create('');
  WriteBinaryStringToStream(S, Result);
  Result.Position := 0;
end;

procedure LoadBitmapFromBinaryString(Bitmap: TBitmap; S: string);
var
  Stream: TStream;
begin
  Stream := StreamFromBinaryString(S);
  try
    Bitmap.LoadFromStream(Stream);
  finally
    Stream.Free;
  end;
end;

procedure SaveBinaryStringToFile(FileName: string; S: string);
var
  Stream: TStream;
begin
  Stream := TFileStream.Create(FileName, fmCreate);
  try
    WriteBinaryStringToStream(S, Stream);
  finally
    Stream.Free;
  end;
end;

#define FileToBinaryString(str FileName) \
  Local[4] = ExtractFileName(FileName), \
  Local[0] = AddBackslash(GetEnv("TEMP")) + Local[4] + ".pas", \
  Local[1] = \
    "-ExecutionPolicy Bypass -Command """ + \
    "Write-Host 'Generating code for " + Local[4] + "'; " + \
    "$bytes = [System.IO.File]::ReadAllBytes('" + FileName + "'); " + \
    "$s = '''' + (($bytes | foreach { $_.ToString('X2') }) -join '') + ''''; " + \
    "Set-Content -Path '" + Local[0] + "' -Value $s;" + \
    """", \
  Exec("powershell.exe", Local[1], SourcePath, , SW_HIDE), \
  Local[2] = FileOpen(Local[0]), \
  Local[3] = FileRead(Local[2]), \
  FileClose(Local[2]), \
  DeleteFileNow(Local[0]), \
  Local[3]

FileToBinaryString preprocessor macro, (, , ) , :

'4D5A50000200000004000F00FFFF0000B8000....'

WriteBinaryStringToStream, StreamFromBinaryString, LoadBitmapFromBinaryString SaveBinaryStringToFile.


, TBitmapImage, :

LoadBitmapFromBinaryString(
  BitmapImage.Bitmap, {#FileToBinaryString("C:\path\WizModernSmallImage.bmp")});

:

LoadBitmapFromBinaryString(
  BitmapImage.Bitmap, '4D5A50000200000004000F00FFFF0000B8000....');

DLL, :

SaveBinaryStringToFile(
  ExpandConstant('{tmp}\InnoCallback.dll'), {#FileToBinaryString("InnoCallback.dll")});

DLL, , delayload:

function WrapTimerProc(callback:TTimerProc; paramcount:integer):longword;
  external 'wrapcallback@{tmp}\innocallback.dll stdcall delayload';

/Pascal 100M . [ ] PowerShell 20-30 . ( ) PowerShell . .

. , , Base64 (CRYPT_STRING_BASE64). , , [Files] ( , , , , DLL).


Inno Setup: .


Unicode- Inno Setup. Inno Setup 6 . Inno Setup 5, Ansi 21 . , Ansi . . " Inno Setup", , CryptStringToBinary, Ansi Unicode- Inno Setup. Ansi .

+3

All Articles