Inno Setup,检测参数文件是否存在?

时间:2014-10-07 13:12:47

标签: file installation install windows-installer inno-setup

我为.NET项目创建了一个设置。目的是自动构建其他MSI和所需的软件包,以便它可以扫描系统,然后根据需要自动安装正确的软件包。

到目前为止我所拥有的:

[Files]
; Ensure all the prerequisites are installed
Source: "C:\3subTimeKeeingApp\3sunptk\prerequisites\mysql-connector-net-6.8.3.msi"; Check: needsMySQLNET; DestDir: "{tmp}"; DestName: "mysqlNET.msi"; Flags: solidbreak
Source: "C:\3subTimeKeeingApp\3sunptk\prerequisites\mysql-connector-odbc-5.3.2-win32.msi"; Check: needsMySQLODBC; DestDir: "{tmp}"; DestName: "mysqlODBC.msi"; Flags: solidbreak
Source: "C:\3subTimeKeeingApp\3sunptk\prerequisites\sharepointclientcomponents_x64.msi"; Check: (IsWin64 and needsSharePtClient); DestDir: "{tmp}"; DestName: "sharept.msi"; Flags: solidbreak
Source: "C:\3subTimeKeeingApp\3sunptk\prerequisites\sharepointclientcomponents_x86.msi"; Check: ((not IsWin64) and needsSharePtClient); DestDir: "{tmp}"; DestName: "sharept.msi"; Flags: solidbreak
Source: "C:\3subTimeKeeingApp\3sunptk\prerequisites\NDP451-KB2858728-x86-x64-AllOS-ENU.exe"; Check: needsFramework; DestDir: "{tmp}"; DestName: "NDP451.exe"; Flags: ignoreversion

[Run]
Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\mysqlNET.msi"""; 
Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\mysqlODBC.msi""";
Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\sharept.msi"""; 
Filename: "{tmp}\NDP451.exe"; Parameters: "/q:a /c:""install /l /q"""; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: Installing .NET Framework if needed. This may take several minutes.

[Code]
//--------------------------------------------------------------------------------
// .NET helpers
//--------------------------------------------------------------------------------
function isDotNet451Detected(): Boolean;
var 
  success: Boolean;
  release: Cardinal;
begin
  success := RegQueryDWordValue(HKLM, 
                        'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\', 
                        'Release', 
                        release);
//For .net versions
//http://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx#net_b 
  Result := success and (release = 378758);
end;

function needsFramework(): Boolean;
begin
  Result := (isDotNet451Detected = False);
end;
//--------------------------------------------------------------------------------
// MySQL .NET connector 6.8.3
//--------------------------------------------------------------------------------
function isMySQLNETconnectorInstalled(): Boolean;
var 
  success: Boolean;
  version: String;
begin
  success := RegQueryStringValue(HKLM, 
                        'SOFTWARE\Wow6432Node\MySQL AB\MySQL Connector/Net\', 
                        'Version', 
                        version); 
  Result := success and (CompareStr(version, '6.8.3') = 0);
end;

function needsMySQLNET(): Boolean;
begin
  Result := (isMySQLNETconnectorInstalled = False);
end;
//--------------------------------------------------------------------------------
// MySQL ODBC Connector 5.3
//--------------------------------------------------------------------------------
function isMySQLODBCconnectorInstalled(): Boolean;
var
  success: Boolean;
  version: String;
begin
  success := RegQueryStringValue(HKLM, 
                        'SOFTWARE\MySQL AB\MySQL Connector/ODBC 5.3\', 
                        'Version', 
                        version); 
  Result := success and (CompareStr(version, '5.3.2') = 0);
end;

function needsMySQLODBC(): boolean;
begin
  Result := (isMySQLODBCconnectorInstalled = False);
end;
//--------------------------------------------------------------------------------
// Sharepoint client components
//--------------------------------------------------------------------------------
function isSharepointClientInstalled(): Boolean;
begin
  Result := RegKeyExists(HKLM, 'SOFTWARE\Microsoft\SharePoint Client Components');
end;

function needsSharePtClient(): Boolean;
begin
  Result := (not isSharepointClientInstalled);
end;

检查'文件'部分工作得很好,但是' Run'部分尝试安装'参数'中指定的文件。选项,这些都没有出现,所以我收到一条错误信息。

我的问题是,有没有办法检测'参数'中指定的文件?在尝试安装之前是否存在?

我已尝试过安装但不确定如何使用它,因为它似乎不接受退货。

谢谢,

1 个答案:

答案 0 :(得分:1)

首先,我建议您将先决条件安装移至PrepareToInstall事件中。这是安装先决条件的适当位置。


要回答你的问题,不,在进入处理之前无法检测Parameters参数中指定的文件是否存在,以及您无法在脚本中获取该参数值。但是,如果您按照安装先决条件的方式继续工作,您仍然可以(至少)执行以下操作:

  • 还会为您的[Run]栏目
  • 重复使用现有的Check功能
  • 为您的[Run]部分条目Check功能编写,例如只使用FileExists功能(但需要从Parameters参数复制/粘贴这些文件名)
  • 使用AfterInstall函数立即运行刚刚处理的[Files]条目(这将改变执行安装程序的时间)