Inno Setup:避免关闭应用程序/任务,除非安装新版本

问题描述 投票:0回答:1

我的程序有 4 个服务,第一个小服务控制其他三个服务(将它们停止在文件服务器上以进行覆盖)。第一个非常小且简单,通常不应关闭(仅当较新时)。

[Files]
Source: "ctrlserversvc3.exe"; DestDir: "{code:GetInstallDir|Program}"

它位于

Files
部分。 Inno Setup 每次都会要求我关闭服务并在最后重新启动它。但它应该只询问我设置中的服务何时有较新的版本,而不是当它是相同版本时。

当没有任何更改时,如何告诉 Inno Setup 跳过此文件或问题?

inno-setup
1个回答
0
投票

不幸的是,Inno Setup 在检查文件是否被锁定之前不会检查文件版本。应该的,恕我直言。因为如果版本相同的话,文件最终不会被安装。

无论如何,您可以使用

Check
参数;

自己实现检查
[Files]
Source: "ctrlserversvc3.exe"; DestDir: "{code:GetInstallDir|Program}"; \
    Check: IsNewer('{#GetVersionNumbersString("ctrlserversvc3.exe")}')
[Code]

procedure CutVersionPart(var VersionString: string; var VersionPart: Word);
var
  P: Integer;
begin
  P := Pos('.', VersionString);
  if P > 0 then
  begin
    VersionPart := StrToIntDef(Copy(VersionString, 1, P - 1), 0);
    Delete(VersionString, 1, P);
  end
    else
  begin
    VersionPart := StrToIntDef(VersionString, 0);
    VersionString := '';
  end;
end;

function IsNewer(InstalledVersion: string): Boolean;
var
  Filename: string;
  ExistingMS, ExistingLS: Cardinal;
  ExistingMajor, ExistingMinor, ExistingRev, ExistingBuild: Cardinal;
  InstalledMajor, InstalledMinor, InstalledRev, InstalledBuild: Word;
begin
  Filename := ExpandConstant(CurrentFilename);
  Log(Format('Checking if %s should be installed', [Filename]));
  if not FileExists(Filename) then
  begin
    Log(Format('File %s does not exist yet, allowing installation', [FileName]));
    Result := True;
  end
    else
  if not GetVersionNumbers(FileName, ExistingMS, ExistingLS) then
  begin
    Log(Format('Cannot retrieve version of existing file %s, allowing installation',
      [FileName]));
    Result := True;
  end
    else
  begin
    ExistingMajor := ExistingMS shr 16;
    ExistingMinor := ExistingMS and $FFFF;
    ExistingRev := ExistingLS shr 16;
    ExistingBuild := ExistingLS and $FFFF;
    Log(Format('Existing file %s version: %d.%d.%d.%d',
      [FileName, ExistingMajor, ExistingMinor, ExistingRev, ExistingBuild]));

    Log(Format('Installing version: %s', [InstalledVersion]));
    CutVersionPart(InstalledVersion, InstalledMajor);
    CutVersionPart(InstalledVersion, InstalledMinor);
    CutVersionPart(InstalledVersion, InstalledRev);
    CutVersionPart(InstalledVersion, InstalledBuild);
    Log(Format('Installing version: %d.%d.%d.%d',
      [InstalledMajor, InstalledMinor, InstalledRev, InstalledBuild]));

    if (InstalledMajor > ExistingMajor) or
       ((InstalledMajor = ExistingMajor) and (InstalledMinor > ExistingMinor)) or
       ((InstalledMajor = ExistingMajor) and (InstalledMinor = ExistingMinor) and
        (InstalledRev > ExistingRev)) then
    begin
      Log('Installing file that is newer than existing file, ' +
        'allowing installation.');
      Result := True;
    end
      else
    begin
      Log('Installing file that is same or older than existing file, ' +
        'skipping installation.');
      Result := False;
    end;
  end;
end;
© www.soinside.com 2019 - 2024. All rights reserved.