Installation 是否仅在需要卸载时处理此卸载程序代码?
我在Installation 是否仅在需要卸载时处理此卸载程序代码?,installation,inno-setup,uninstallation,pascalscript,Installation,Inno Setup,Uninstallation,Pascalscript,我在[code]部分中有此代码,此代码仅在我运行卸载程序时运行: ////////////// // Uninstaller ////////////// const DeleteFiles = true; DeleteSubdirs = false; // Initialize the Inno Setup Uninstaller skin style. function InitializeUninstall: Boolean; begin Result := True;
[code]
部分中有此代码,此代码仅在我运行卸载程序时运行:
//////////////
// Uninstaller
//////////////
const
DeleteFiles = true;
DeleteSubdirs = false;
// Initialize the Inno Setup Uninstaller skin style.
function InitializeUninstall: Boolean;
begin
Result := True;
LoadVCLStyle_UnInstall(ExpandConstant('{app}\uninstall.vsf'));
end;
// Deinitialize the Inno Setup Uninstaller skin style.
procedure DeinitializeUninstall();
begin
UnLoadVCLStyles_UnInstall;
UnloadDll(ExpandConstant('{app}\uninstall.dll'));
DeleteFile(ExpandConstant('{app}\uninstall.dll'));
DelTree(ExpandConstant('{app}\'), true, DeleteFiles, DeleteSubdirs);
end;
问题是,DeleteFile
和DelTree
的DeinitializeUninstall
过程中的指令会运行,即使用户在InnoSetup卸载程序询问用户是否确实要卸载软件时选择了Yes或No,我指的是用户对该图像的选择:
当然,我知道这个过程意味着什么,为什么我的指令会运行,甚至选择No,因为无论我选择什么,卸载程序都是去初始化的,但我找不到正确的方法来有效地执行此操作
因此,仅当用户选择“是”确实要求卸载时,我才需要处理以下两条说明,但这些说明也应在卸载过程结束时运行(即我所提供的DeinitializeUninstall
过程):
我如何做到这一点?解决方案,多亏了针对
提示的@TLama,多亏了我举了一个例子来实现这一点:
//////////////
// Uninstaller
//////////////
Const
DeleteFiles = True; // Determines whether to delete all the files of the {app} dir.
DeleteSubdirs = False; // Determines whether to delete all the sub-folders of the {app} dir.
Var
UninstallIsDemanded: Boolean; // Determines whether the user accepted or denied the uninstallation prompt.
UninstallSuccess : Boolean; // Determines whether the uninstallation succeeded.
// Occurs when the uninstaller current page changes.
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then begin
UninstallIsDemanded:= True;
end;
if CurUninstallStep = usDone then begin
UninstallSuccess:= True;
end;
end;
// Deletes the VCL skin dll file.
procedure DeleteSkin();
begin
DeleteFile(ExpandConstant('{app}\uninstall.dll'));
end;
// Deletes the 'app}' file/folder contents.
procedure DeleteApplication(DeleteFiles: Boolean; DeleteSubdirs: Boolean);
begin
DelTree(ExpandConstant('{app}\'), true, DeleteFiles, DeleteSubdirs);
end;
// Initialize the Inno Setup Uninstaller skin style.
function InitializeUninstall: Boolean;
begin
Result := True;
LoadVCLStyle_UnInstall(ExpandConstant('{app}\uninstall.vsf'));
end;
// Deinitialize the Inno Setup Uninstaller skin style.
procedure DeinitializeUninstall();
begin
UnLoadVCLStyles_UnInstall;
UnloadDll(ExpandConstant('{app}\uninstall.dll'));
if UninstallSuccess = True then begin
DeleteSkin();
DeleteApplication(DeleteFiles, DeleteSubdirs);
end;
end;
@特拉玛:我不知道你为什么删除了答案,但你的答案非常好,帮助我解决了这个问题。请验证我的答案中修改的代码是否正确,因为我不是任何使用pascal脚本的专家。。。再次感谢!我删除了我的答案,因为我认为你问的不是你想要的。用户接受确认对话框后,卸载仍可能失败。我认为这是指示卸载过程成功的步骤(这是您希望执行清理的条件)。
//////////////
// Uninstaller
//////////////
Const
DeleteFiles = True; // Determines whether to delete all the files of the {app} dir.
DeleteSubdirs = False; // Determines whether to delete all the sub-folders of the {app} dir.
Var
UninstallIsDemanded: Boolean; // Determines whether the user accepted or denied the uninstallation prompt.
UninstallSuccess : Boolean; // Determines whether the uninstallation succeeded.
// Occurs when the uninstaller current page changes.
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then begin
UninstallIsDemanded:= True;
end;
if CurUninstallStep = usDone then begin
UninstallSuccess:= True;
end;
end;
// Deletes the VCL skin dll file.
procedure DeleteSkin();
begin
DeleteFile(ExpandConstant('{app}\uninstall.dll'));
end;
// Deletes the 'app}' file/folder contents.
procedure DeleteApplication(DeleteFiles: Boolean; DeleteSubdirs: Boolean);
begin
DelTree(ExpandConstant('{app}\'), true, DeleteFiles, DeleteSubdirs);
end;
// Initialize the Inno Setup Uninstaller skin style.
function InitializeUninstall: Boolean;
begin
Result := True;
LoadVCLStyle_UnInstall(ExpandConstant('{app}\uninstall.vsf'));
end;
// Deinitialize the Inno Setup Uninstaller skin style.
procedure DeinitializeUninstall();
begin
UnLoadVCLStyles_UnInstall;
UnloadDll(ExpandConstant('{app}\uninstall.dll'));
if UninstallSuccess = True then begin
DeleteSkin();
DeleteApplication(DeleteFiles, DeleteSubdirs);
end;
end;