简体   繁体   English

Inno Setup - 检查文件是否存在于目标中,否则如果不中止安装

[英]Inno Setup - Check if file exist in destination or else if doesn't abort the installation

I need my installer to check if a file exists in the destination location, and if is not there, then the installation aborts. 我需要安装程序检查目标位置是否存在文件,如果不存在,则安装将中止。 My project is a update patch, so I want the installer to avoid installing the update files if the main exe of the application is not in the destination. 我的项目是一个更新补丁,所以如果应用程序的主exe不在目标中,我希望安装程序避免安装更新文件。 How can I do this? 我怎样才能做到这一点?

Can someone give an example of code to check file version through the Windows registry? 有人可以通过Windows注册表提供代码示例来检查文件版本吗?

[Files]
Source C:\filename.exe; DestDir {app}; Flags: ignoreversion; BeforeInstall: CheckForFile;

[code]

procedure CheckForFile(): Boolean;
begin
  if (FileExists('c:\somefile.exe')) then
  begin
    MsgBox('File exists, install continues', mbInformation, MB_OK);
    Result := True;
  end
  else
  begin
    MsgBox('File does not exist, install stops', mbCriticalError, MB_OK);
    Result := False;
  end;
end;

Just don't let the user proceed until they pick the correct folder. 只是不要让用户继续,直到他们选择正确的文件夹。

function NextButtonClick(PageId: Integer): Boolean;
begin
    Result := True;
    if (PageId = wpSelectDir) and not FileExists(ExpandConstant('{app}\yourapp.exe')) then begin
        MsgBox('YourApp does not seem to be installed in that folder.  Please select the correct folder.', mbError, MB_OK);
        Result := False;
        exit;
    end;
end;

Of course, it's also a good idea to try to automatically pick the correct folder for them, eg. 当然,尝试为它们自动选择正确的文件夹也是一个好主意,例如。 by retrieving the correct location out of the registry. 通过从注册表中检索正确的位置。

Another solution would be the InitializeSetup() : 另一个解决方案是InitializeSetup()

Credit: Manfred 图片来源: 曼弗雷德

[code]
   function InitializeSetup(): Boolean;
   begin
     if (FileExists(ExpandConstant('{pf}\{#MyAppName}\somefile.exe'))) then
     begin
       MsgBox('Installation validated', mbInformation, MB_OK);
       Result := True;
     end
     else
     begin
       MsgBox('Abort installation', mbCriticalError, MB_OK);
       Result := False;
     end;
   end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM