2013-03-26 64 views
14

我想为我的软件(这是一个C#软件)配置Inno安装程序。 我打算发布我的软件的很多版本,如果我的应用程序的旧版本已经安装在计算机上,我想更改inno setup安装程序界面。 在这种情况下,用户不应该能够更改安装目录。创建一个安装程序,将执行更新,如果已经安装了旧版本

有四种情况:

第一种情况:这是我的产品的第一次安装,Inno Setup的程序正常进行。

第二种情况:该产品已经安装完毕且安装程序包含更新的版本。用户不能选择目标文件夹。他可以运行更新。

第三种情况:如果安装程序包含的版本比安装的版本旧,则更新将被禁用,并且应显示消息。

第四种情况:安装程序版本与安装版本相同。如果需要,用户可以修复他的执行版本。

InnoSetup可以做到吗?

回答

6

如果您的AppID在应用程序的生命周期中保持不变,Inno Setup会自动处理案例1,2和4。
您还可以使用以下[Setup]指令隐藏的目录和组页:

DisableDirPage=auto 
DisableGroupPage=auto 

有关详细信息,请参阅本ISXKB article。对于案例3,假设您的文件版本正确,Inno不会降级任何内容,但它实际上不会对用户发出警告。要做到这一点,您需要添加代码来检查这一点,很可能在InitializeSetup()事件函数中。

+2

其实,如果你使用脚本向导来创建自己的脚本,然后应用程序文件的默认是添加'ignoreversion'标志,在这种情况下,降级实际上将降级的所有文件。为了确认用户确实想要这么做,添加一条警告消息可能是一个好主意,但是否则应该可以正常工作 - 假设您的应用程序本身可以应付降级(例如,数据兼容性问题)。如果没有,那么你应该添加一个错误,而不是一个警告。 – Miral 2013-03-27 19:51:00

+1

@病毒我没有注意到。感谢您的高举。 – Deanna 2013-03-28 09:30:35

+0

用于检查'InitializeSetup'的示例逻辑将非常棒...我假设已经有一些定义已经出现在inno中... – Assimilater 2017-06-19 19:08:38

8

如果你想对用户有一些反馈,你可以尝试类似的东西。 首先,您的更新应该与您的主应用程序具有相同的AppId名称。 然后您可以设置一些检查,即显示消息以通知用户有关状态。

#define MyAppVersion "1.2.2.7570" 
#define MyAppName "MyApp Update" 

[Setup] 
AppId=MyApp 
AppName={#MyAppName} 
AppVersion={#MyAppVersion} 
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1,InstallLocation} 
DisableDirPage=True 

[CustomMessages] 
MyAppOld=The Setup detected application version 
MyAppRequired=The installation of {#MyAppName} requires MyApp to be installed.%nInstall MyApp before installing this update.%n%n 
MyAppTerminated=The setup of update will be terminated. 

[Code] 
var 
InstallLocation: String; 

function GetInstallString(): String; 
var 
InstPath: String; 
InstallString: String; 
begin 
InstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1'); 
InstallString := ''; 
if not RegQueryStringValue(HKLM, InstPath, 'InstallLocation', InstallString) then 
RegQueryStringValue(HKCU, InstPath, 'InstallLocation', InstallString); 
Result := InstallString; 
InstallLocation := InstallString; 
end; 

function InitializeSetup: Boolean; 
var 
V: Integer; 
sUnInstallString: String; 
Version: String; 
begin 
    if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'UninstallString') then begin 
     RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'DisplayVersion', Version); 
     if Version =< ExpandConstant('{#MyAppVersion}') then begin 
      Result := True; 
      GetInstallString(); 
     end 
     else begin 
MsgBox(ExpandConstant('{cm:MyAppOld}'+Version+'.'+#13#10#13#10+'{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK); 
     Result := False; 
    end; 
end 
else begin 
    MsgBox(ExpandConstant('{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK); 
    Result := False; 
end; 
end; 
+0

1.检查是否安装了应用程序; 2.检查应用程序版本; 3.比较App版本和更新版本; 3A。如果更新更新然后安装; 3B。如果更新较旧,则不要安装; 3C。如果应用程序不存在,则不安装 – RobeN 2013-03-26 14:15:33

+0

Inno已自动记住安装目录,使您的'DefaultDirName'代码冗余。您也不会为第一次安装指定默认值。 – Deanna 2013-03-26 15:04:19

+0

这只是更新代码,不是基本应用程序... – RobeN 2013-03-26 15:10:25

相关问题