Creating a hard link with Inno installation

I have thousands of my own installers that require a critical dll file for the uninstall phase, this dll file is about 2 MB in size to avoid unnecessary disk space (2 MB * 100 installers) I would like to save the file once in {cf}then create a hard link for The following installers that require this file.

I can create a hard link in Inno Setup without using external applications like mklink.exe .

This is a brief example of what I have, all of my installers follow the same “structure”:

[Files]
; VCL Styles
Source: {tmp}\uninstall.vsf; DestDir: {app}; Flags: ignoreversion
Source: {tmp}\uninstall.dll; DestDir: {app}; Flags: ignoreversion uninsneveruninstall

; Temp files
Source: {tmp}\*; DestDir: {tmp}; Excludes: uninstall.dll, uninstall.vsf; Flags: recursesubdirs createallsubdirs ignoreversion

; Program
Source: {app}\*; DestDir: {app}; Flags: recursesubdirs createallsubdirs ignoreversion

As you can see, I am moving uninstall.dll to {app}, but what I would like to do is: If this does not happen, copy delete. dll to the file {cf}\InnoSetup\uninstall.dllpath to the file and make a hard link to {app}\uninstall.dllif the file already exists, then just create a hardlink, nothing more, I will not store uninstall.dll file in {app}\uninstall.dll, I just want a symbolic link because the uninstall.dll file never must be removed.

How could I do this?

+4
source share
1 answer

Inno Setup does not support creating hard links.


mklink . Windows. Windows XP, . DLL, mklink .


CreateHardLink " Code ".

#define MyApp "MyApp"
#define UninstallDll "uninstall.dll"

[Files]
Source: "{#UninstallDll}"; DestDir: "{cf}\{#MyApp}"; \
  Flags: ignoreversion uninsneveruninstall

[Code]
function CreateHardLink(lpFileName, lpExistingFileName: string;
  lpSecurityAttributes: Integer): Boolean;
  external 'CreateHardLinkW@kernel32.dll stdcall';

procedure CurStepChanged(CurStep: TSetupStep);
var
  ExistingFile, NewFile: string;
begin
  if CurStep = ssPostInstall then
  begin
    ExistingFile := ExpandConstant('{cf}\{#MyApp}\{#UninstallDll}');
    NewFile := ExpandConstant('{app}\{#UninstallDll}');
    if CreateHardLink(NewFile, ExistingFile, 0) then
    begin
      Log('Hardlink created');
    end
      else
    if FileCopy(ExistingFile, NewFile, False) then
    begin
      { FAT file system? }
      Log('Hardlink could not be created, file copied instead');
    end
      else
    begin
      MsgBox('Cannot install {#UninstallDll}', mbError, MB_OK);
    end;
  end;
end;

( Unicode- Inno Setup - Inno Setup 6)

:

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then
  begin
    if DeleteFile(ExpandConstant('{app}\{#UninstallDll}')) then
    begin
      Log('File deleted');
    end
      else
    begin
      Log('Cannot delete file');
    end;
  end;
end;

, [UninstallDelete]. , , .


" Inno Setup".

CreateHardLink . - . , ( ). , . ( ), . . . ( ).

. .

mklink ( ). , ( ). , . ( ). , ( ), ( ). , .

. .

mklink, /H:

/H .

, ( , CreateSymbolicLink). , , , , -, . , CreateHardLink.

+5

Source: https://habr.com/ru/post/1610340/


All Articles