Inno Setup:如何在安装时覆盖但在更改时不覆盖? [英] Inno Setup: How to overwrite on install but not on change?
问题描述
我知道如何使用此方法覆盖文件
I know how to overwrite the files using this method
[Files]
Source: "Project\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs onlyifdoesntexist; Permissions: everyone-full
但是,当我使用安装或更改程序"部分中的更改"选项更改程序时,我不想覆盖文件.
But when I change the program using the Change option in 'Install Or Change Program' section I want to not overwrite the files.
我为安装程序创建更改选项,如下所示:
I create the change option for my installer like this:
[setup]
AppModifyPath="{srcexe}" /modify=1
我该怎么做?
推荐答案
首先,您的代码似乎有误.使用onlyifdoesntexist
标志,文件将永远不会被覆盖,这与您声明的相反.
First, your code seems wrong. With the onlyifdoesntexist
flag, the files are never overwritten, contrary to what you claim.
无论如何,一种解决方案是创建两个[Files]
条目,一个覆盖,而另一个不覆盖.并使用Pascal脚本为相应的安装模式选择条目.
Anyway, a solution is to create two [Files]
entries, one that overwrites and one that does not. And use the Pascal scripting to pick the entry for a respective installation mode.
[Files]
Source: "Project\*"; DestDir: "{app}"; Flags: ... onlyifdoesntexist; ...; Check: IsUpgrade
Source: "Project\*"; DestDir: "{app}"; Flags: ...; ...; Check: not IsUpgrade
IsUpgrade
实现的示例:
[Code]
function IsUpgrade: Boolean;
var
S: string;
InnoSetupReg: string;
AppPathName: string;
begin
{ The ExpandConstant is here for Inno Script Studio, }
{ which generated AppId in a form of GUID. }
{ The leading { of the GUID has to be doubled in Inno Setup, }
{ and the ExpandConstant collapses that back to single {. }
InnoSetupReg :=
ExpandConstant(
'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1');
AppPathName := 'Inno Setup: App Path';
Result :=
RegQueryStringValue(HKLM, InnoSetupReg, AppPathName, S) or
RegQueryStringValue(HKCU, InnoSetupReg, AppPathName, S);
end;
另请参见 Pascal脚本:检查参数.
这篇关于Inno Setup:如何在安装时覆盖但在更改时不覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!