Inno Setup不支持原生创建硬链接。
我不认为
mklink
是外部应用程序。它是一个内置的 Windows 工具。因此,如果您不需要支持 Windows XP,则可以放心地依赖它。或者,如果
mklink
不可用,可以回退到常规安装 DLL。请保留 HTML 标签。
或者使用 Code
部分中的 CreateHardLink
函数。
[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
Log('Hardlink could not be created, file copied instead');
end
else
begin
MsgBox('Cannot install {#UninstallDll}', mbError, MB_OK);
end;
end;
end;
(在Inno Setup 6中,仅支持
Unicode版本进行测试)
卸载时请不要忘记删除该文件:
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
创建一个硬链接。硬链接是指向相同内容的另一个引用。基本上,硬链接与原始文件无法区分(实际上,原始文件也是硬链接)。原始文件和硬链接都只是指向相同内容的引用。如果您删除原始文件(或新的硬链接),则实际上只会删除对内容的一个引用。只有最后一个引用被删除时,才会删除内容。硬链接不会占用磁盘上的额外空间(内容仅存储一次)。
有关详细信息,请参见Wikipedia上的硬链接文章。
mklink
默认创建符号链接(又称为软链接)。符号链接类似于快捷方式,它是对原始文件的引用(而不是内容)。它本身是一个文件,包含指向目标文件的路径。符号链接具有自己的大小(由指向目标文件的引用占用)。如果您删除原始文件,则符号链接仍然存在(因为原始文件没有对符号链接的引用),但变为无效(内容已经丢失)。同样,这类似于快捷方式。
有关详细信息,请参见维基百科上的符号链接文章。
如果添加/H
开关,您可以使用mklink
创建硬链接:
/H 创建硬链接而不是符号链接。
如果你想创建符号链接而不是硬链接,那就是另一个问题(尽管答案很简单,使用
CreateSymbolicLink
函数)。但是要再次注意,硬链接
不会占用磁盘上的额外空间,这似乎是你关心的问题。因此,我认为你应该继续使用
CreateHardLink
函数。