Inno setup 如何从TOutPutProgressWizardPage的Inno安装程序中退出安装:
我有一段时间对此有意见了。在这篇文章之前,我从来没有在网上寻求过帮助 我已经使用Inno Setup编写了一个安装程序。它安装了很多东西,其中之一就是Java开发工具包的最新版本。我的问题是我需要检查JDK安装是否存在。如果没有,请退出安装。如果不是因为我正在使用TOutPutProgressWiazrdPage向用户演示这个过程,这似乎很容易。在“中止”或“退出”之前,一切正常。在碰到其中任何一个之后,安装就失控了。请,任何帮助都将不胜感激。我的示例代码如下:Inno setup 如何从TOutPutProgressWizardPage的Inno安装程序中退出安装:,inno-setup,pascal,Inno Setup,Pascal,我有一段时间对此有意见了。在这篇文章之前,我从来没有在网上寻求过帮助 我已经使用Inno Setup编写了一个安装程序。它安装了很多东西,其中之一就是Java开发工具包的最新版本。我的问题是我需要检查JDK安装是否存在。如果没有,请退出安装。如果不是因为我正在使用TOutPutProgressWiazrdPage向用户演示这个过程,这似乎很容易。在“中止”或“退出”之前,一切正常。在碰到其中任何一个之后,安装就失控了。请,任何帮助都将不胜感激。我的示例代码如下: //JDK Install pr
//JDK Install
procedure InstallJDK();
var
ErrorCode, x: Integer;
Return,Path: String;
Paths: TArrayOfString;
begin
if (IsComponentSelectedLog('Prerequisites\JDK')) then
begin
GetJavaVersion();
Path := GetEnv('path'); //(TNG-1463)
if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_LESS_THAN) and (Installed_Java_Version <> '') then
begin
if (Pos(Lowercase(JDK_ORACLE_DIR + '\jdk1.6.0_18'), Lowercase(Path)) <> 0) or (Pos(Lowercase(JDK_SUN_DIR + '\jdk1.6.0_18'), Lowercase(Path)) <> 0) or (Pos(Lowercase(JDK_ORACLE_DIR + '\jdk1.6.0_22'), Lowercase(Path)) <> 0)then
begin
SetFormText('Removing JDK Version: ' + Installed_Java_Version + '...', 'Preparing System...', JavaInstallationPage);
//Remove Java Update 1.6.0_18
ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{26A24AE4-039D-4CA4-87B4-2F83216018FF} /L ' + TNG_Install_Log_Dir + '\ju_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
UpdateProgressBar(PBarJavaInstall, 76);
//Remove JDK 1.6.0_18
ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{32A3A4F4-B792-11D6-A78A-00B0D0160180} /L ' + TNG_Install_Log_Dir + '\jdk_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
UpdateProgressBar(PBarJavaInstall, 80);
//Remove Java Update 1.6.0_22
ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{26A24AE4-039D-4CA4-87B4-2F83216022FF} /L ' + TNG_Install_Log_Dir + '\ju_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
UpdateProgressBar(PBarJavaInstall, 76);
//Remove JDK 1.6.0_22
ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{32A3A4F4-B792-11D6-A78A-00B0D0160220} /L ' + TNG_Install_Log_Dir + '\jdk_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
UpdateProgressBar(PBarJavaInstall, 80);
//Remove JDK 1.6.0_18 Directories
if DirExists(JDK_SUN_DIR + '\jdk1.6.0_18') then
begin
DelTree(JDK_SUN_DIR + '\jdk1.6.0_18', True, True, True);
end;
if DirExists(JDK_ORACLE_DIR + '\jdk1.6.0_18') then
begin
DelTree(JDK_ORACLE_DIR + '\jdk1.6.0_18', True, True, True);
end;
//Remove JDK 1.6.0_22 Directories
if DirExists(JDK_ORACLE_DIR + '\jdk1.6.0_22') then
begin
DelTree(JDK_ORACLE_DIR + '\jdk1.6.0_22', True, True, True);
end;
//Clean Up Path
if (Pos(Lowercase(JDK_ORACLE_DIR), Lowercase(Path)) <> 0) or (Pos(Lowercase(JDK_SUN_DIR), Lowercase(Path)) <> 0) then
begin
Paths := Split(Path,';',0);
Path := '';
for x := 0 to GetArrayLength(Paths)-1 do
begin
if (Pos(Lowercase(JDK_ORACLE_DIR), Lowercase(Paths[x])) <> 0) or (Pos(Lowercase(JDK_SUN_DIR), Lowercase(Paths[x])) <> 0) then
begin
Paths[x] := '';
end;
end;
for x := 0 to GetArrayLength(Paths)-1 do
begin
if Paths[x] <> '' then
begin
if path = '' then
begin
Path := Paths[x];
end
else
Path := Path + ';' + Paths[x];
end;
end;
end;
SetxEnv('path', ExpandConstant(Path));
UpdateProgressBar(PBarPostInstall1, 100);
end;
GetJavaVersion();
end;
if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_LESS_THAN) then
begin
//Install JDK
Log('In Progress......Executing jdk-6u23-windows-i586.exe');
UpdateProgressBar(PBarJavaInstall, 10);
if (CheckSupportExist('jdk-6u23-windows-i586.exe')) then
begin
Create_Dir(ExpandConstant('{sd}\apps'), JavaInstallationPage);
Create_Dir(JDK_ORACLE_DIR, JavaInstallationPage);
Create_Dir(ExpandConstant('{sd}\TNG2.0'), JavaInstallationPage);
Create_Dir(ExpandConstant('{sd}\TNG2.0\install'), JavaInstallationPage);
SetFormText('Installing JDK Version: ' + JDK_MIN_VERSION + '...', 'Preparing System...', JavaInstallationPage);
ShellExecLog('open', 'jdk-6u23-windows-i586.exe', '/s /v /qn" ADDLOCAL=ALL REBOOT=SUPPRESS INSTALLDIR=' + JDK_Dir + ' /L ' + TNG_Install_Log_Dir + '\jdk_' + JDK_MIN_VERSION + '_install.log"', ExpandConstant('{src}\Support\'), SW_HIDE, ewNoWait, ErrorCode);
UpdateProgressBarUntilProgressHasEnded('jdk-6u23-windows-i586.exe', 100, 2, JavaInstallationPage, PBarJavaInstall);
GetJavaVersion();
if (not (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL)) then
begin
Log('Failed......' + JDK + ' ' + JDK_MIN_VERSION + ' Installation : Versions do not match.');
LogError('Failed......' + JDK + ' ' + JDK_MIN_VERSION + ' Installation');
ExitSetup := True;
end
else if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL) then
begin
Log('Success......' + JDK + ' ' + Installed_Java_Version + ' Installed');
if GetEnv('JAVA_HOME') <> JDK_Dir then
begin
ErrorCode := SetxEnv('JAVA_HOME', ExpandConstant(JDK_Dir));
end;
//(TNG-1463) Prepend the %Java_Home%\bin so that it is the first JDK in the system's path
SetxEnv('path', ExpandConstant(JDK_Bin_DIR + ';' + Path));
end;
end
else
begin
MsgBox('Please re-run the install after the jdk-6u23-windows-i586.exe support install is placed in the support folder.', mbInformation, MB_OK);
Log('User chose not to install the ' + JDK + ' ' + JDK_MIN_VERSION);
ExitSetup := True;
end;
end
else if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL) then
begin
Log('Already Installed......' + JDK + ' ' + JDK_MIN_VERSION);
end
else
begin
LogError('Failed......' + JDK + ' Installation');
ExitSetup := True;
end;
end;
end;
//Activate Setup Page
//
procedure JavaInstallationPage_Activate(Page: TWizardPage);
var
ErrorCode: Integer;
begin
//Install JDK
InstallJDK()
if (ExitSetup = True) then
begin
try
finally
JavaInstallationPage.Hide;
end;
**Abort**;
end;
end;
procedure InitializeWizard();
begin
// Installation Page
JavaInstallationPage := CreateOutputProgressPage('JDK Installation', 'Setup is preparing the system.....');
//JavaInstallationPage := CreateCustomPage(wpSQL_No_SQL_SelectSqlServer, 'POS Manufacturer Settings', 'Please select a supported manufacturer or select default');
lblJavaInstallDescription1 := TLabel.Create(JavaInstallationPage);
with lblJavaInstallDescription1 do
begin
Top := 1;
Caption := '';
AutoSize := True;
Parent := JavaInstallationPage.Surface;
end;
lblJavaInstallDescription2 := TLabel.Create(PreInstallationPage);
with lblJavaInstallDescription2 do
begin
Top := lblJavaInstallDescription1.Top + lblJavaInstallDescription1.Height + 5;
Caption := 'Installing Java Development Kit...';
AutoSize := True;
Parent := JavaInstallationPage.Surface;
end;
PBarJavaInstall := TNewProgressBar.Create(JavaInstallationPage);
with PBarJavaInstall do
begin
Parent := JavaInstallationPage.Surface;
Width := JavaInstallationPage.SurfaceWidth;
Top := lblJavaInstallDescription2.Top + lblJavaInstallDescription2.Height + 3;
Height := 19;
Max := 105;
end;
JavaInstallationPage.OnActivate := @JavaInstallationPage_Activate;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
ErrorCode: Integer;
DisplayJavaInstallPage: boolean;
FileName: string;
FileLines: TArrayOfString;
begin
if CurPageID = wpTomCatPortSettings then
begin
DisplayJavaInstallPage := True;
end;
if DisplayJavaInstallPage then
begin
GetJavaVersion();
if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) <> VERSION_EQUAL) then
begin
JavaInstallationPage.Show;
try
finally
JavaInstallationPage.Hide;
end;
if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) <> VERSION_EQUAL) then
begin
**Abort**;
end;
end;
end;
if (not LocalesPopulated) and (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL) and (PageCount >= 4) and isComponentSelected('XPressPOS\MWB\Locale') then
begin
// Configure MWB_Localization Settings Page
FileName := ExpandConstant('{tmp}\GetAllAvailableLocalesbyLocale.class');
ExtractTemporaryFile(ExtractFileName(FileName));
FileName := ExpandConstant('{tmp}\GetLocaleDisplayName.class');
ExtractTemporaryFile(ExtractFileName(FileName));
FileName := ExpandConstant('{tmp}\GetLocaleByDescription.class');
ExtractTemporaryFile(ExtractFileName(FileName));
if SelectedLangauge <> 'es' then
begin
#if Debug == "True"
ShellExecLog('open', 'cmd', ExpandConstant('/K "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale en US > .\Localizations.txt"'), '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
#else
ShellExecLog('open', 'cmd', ExpandConstant('/C "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale en US > .\Localizations.txt"'), '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
#endif
end
else
begin
#if Debug == "True"
ShellExecLog('open', 'cmd', ExpandConstant('/K "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale en MX > .\Localizations.txt"'), '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
#else
ShellExecLog('open', 'cmd', ExpandConstant('/C "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale es MX > .\Localizations.txt"'), '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
#endif
end;
lstLocalizations.Items.clear;
chkDisplayUnsupported.Checked := False;
if LoadStringsFromFile(ExpandConstant('{tmp}\Localizations.txt'), FileLines) then
begin
for I := 0 to GetArrayLength(FileLines)-1 do
begin
if ((FileLines[I] = 'English (United States)') or (FileLines[I] = 'Spanish (Mexico)')) then
begin
lstLocalizations.Items.Add(FileLines[I]);
end;
end;
end;
LocalesPopulated := True;
end;
Result := True;
end;
function BackButtonClick(CurPageID: Integer): Boolean;
begin
PageCount := PageCount - 1;
Result := True;
end;
//JDK安装
程序InstallJDK();
变量
错误代码,x:整数;
返回,路径:字符串;
路径:TArrayOfString;
开始
如果(IsComponentSelectedLog('Premissions\JDK')),则
开始
GetJavaVersion();
路径:=GetEnv('Path')//(TNG-1463)
如果(比较版本(已安装的Java版本、JDK最小版本)=版本小于)和(已安装的Java版本“”),则
开始
如果(Pos(小写(JDK_ORACLE_DIR+'\jdk1.6.0_18')、小写(Path))0)或(Pos(小写(JDK_SUN_DIR+'\jdk1.6.0_18')、小写(Path))0)或(Pos(小写(JDK_ORACLE_DIR+'\jdk1.6.0_22')、小写(Path))0),则
开始
SetFormText('Removing JDK Version:'+Installed_Java_Version+''…','Preparing System…',JavaInstallationPage);
//删除Java更新1.6.0_18
ShellExecLog('open',ExpandConstant('cmd'),ExpandConstant('/C“start/w MsiExec/qn/X{26A24AE4-039D-4CA4-87B4-2F83216018FF}/L'+TNG_Install_Log_Dir+'\ju_'+Installed__Java_Version+'.\u uninstall.Log“),ExpandConstant('{sys}'),SW HIDE,ewwaitunterminated,ErrorCode);
UpdateProgressBar(PBarJavaInstall,76);
//删除JDK 1.6.0_18
ShellExecLog('open',ExpandConstant('cmd'),ExpandConstant('/C“start/w MsiExec/qn/X{32A3A4F4-B792-11D6-A78A-00B0D0160180}/L'+TNG_Install_Log_Dir+'\jdk'+Installed_Java_Version+'.\u uninstall.Log'),ExpandConstant('{sys}'),SW HIDE,ewwaitunterminated,ErrorCode);
UpdateProgressBar(PBarJavaInstall,80);
//删除Java更新1.6.0_22
ShellExecLog('open',ExpandConstant('cmd'),ExpandConstant('/C“start/w MsiExec/qn/X{26A24AE4-039D-4CA4-87B4-2F83216022FF}/L'+TNG_Install_Log_Dir+'\ju_'+Installed__Java_Version+'.\u uninstall.Log“),ExpandConstant('{sys}'),SW HIDE,ewwaitunterminated,ErrorCode);
UpdateProgressBar(PBarJavaInstall,76);
//删除JDK 1.6.0_22
ShellExecLog('open',ExpandConstant('cmd'),ExpandConstant('/C“start/w MsiExec/qn/X{32A3A4F4-B792-11D6-A78A-00B0D0160220}/L'+TNG_Install_Log_Dir+'\jdk'+Installed_Java_Version+'.\u uninstall.Log'),ExpandConstant('{sys}'),SW HIDE,ewwaituted,ErrorCode);
UpdateProgressBar(PBarJavaInstall,80);
//删除JDK1.6.0_18目录
如果存在DIR(JDK_SUN_DIR+'\jdk1.6.0_18'),则
开始
DelTree(JDK_SUN_DIR+'\jdk1.6.0_18',True,True,True);
结束;
如果存在DIR(JDK_ORACLE_DIR+'\jdk1.6.0_18'),则
开始
DelTree(JDK_ORACLE_DIR+'\jdk1.6.0_18',True,True,True);
结束;
//删除JDK 1.6.0_22目录
如果存在DIR(JDK_ORACLE_DIR+'\jdk1.6.0_22'),则
开始
DelTree(JDK_ORACLE_DIR+'\jdk1.6.0_22',True,True,True);
结束;
//清理道路
如果(Pos(小写(JDK_ORACLE_DIR)、小写(Path))0)或(Pos(小写(JDK_SUN_DIR)、小写(Path))0),则
开始
路径:=拆分(路径“;”,0);
路径:='';
对于x:=0到GetArrayLength(路径)-1 do
开始
如果(Pos(小写(JDK_ORACLE_DIR)、小写(路径[x])0)或(Pos(小写(JDK_SUN_DIR)、小写(路径[x])0),则
开始
路径[x]:='';
结束;
结束;
对于x:=0到GetArrayLength(路径)-1 do
开始
如果路径[x]'',则
开始
如果路径='',则
开始
路径:=路径[x];
结束
其他的
路径:=路径+';'+路径[x];
结束;
结束;
结束;
SetxEnv('path',ExpandConstant(path));
UpdateProgressBar(pbarPostInstall1100);
结束;
GetJavaVersion();
结束;
如果(比较版本(已安装的Java版本、JDK最小版本)=版本小于),则
开始
//安装JDK
日志(“正在……执行jdk-6u23-windows-i586.exe”);
UpdateProgressBar(PBarJavaInstall,10);
如果(CheckSupportExist('jdk-6u23-windows-i586.exe'),则
开始
创建_Dir(ExpandConstant({sd}\apps'),JavaInstallationPage);
创建目录(JDK\U ORACLE\U目录,JavaInstallationPage);
创建_Dir(ExpandConstant({sd}\TNG2.0'),JavaInstallationPage);
创建目录(ExpandConstant({sd}\TNG2.0\install'),JavaInstallationPage);
SetFormText('Installing JDK Version:'+JDK_MIN_Version+''.','Preparing System…',JavaInstallationPage);
ShellExecLog('open','jdk-6u23-windows-i586.exe',/s/v/qn“ADDLOCAL=ALL REBOOT=SUPPRESS INSTALLDIR='+jdk_Dir+'/L'+TNG_Install_Log_Dir+'\jdk_'+jdk_umin_VERSION+''u Install.Log',ExpandConstant('src}\Support\')、SW_HIDE、ewNoWait、ewNoWait、ErrorCode);
UpdateProgressBarUntilProgressHasEnded('jdk-6u23