我的安装程序如何选择删除最初没有创建的文件?

Dai*_*tsu 2 delphi inno-setup

我将所有程序的设置存储在appdata目录%appdata%/ MyProgram中.当出现问题并且用户必须重新安装时,我想询问是否删除该目录中的数据.我正在使用Inno Setup并添加了一个自定义页面来提示用户:

if DirExists(ExpandConstant('{userappdata}\MyProgram')) then
begin
  appdataPage := CreateInputOptionPage(wpSelectTasks,
    'Stored Settings', 'Would you like to remove settings before re-install?',
    'Please specify if you would like to remove the current settings before re-installing MyProgram.', True, False);
  appdataPage.Add('Remove current settings (Recommended if MyProgram is having problems).');
  appdataPage.Add('Keep all my settings and just reinstall.');
  //appdataPage.Add();
  appdataPage.Values[0] := true;
end;
Run Code Online (Sandbox Code Playgroud)

安装程序不会将数据放在那里,但程序会生成它,因此卸载程序不会自动删除它.我也不能指望卸载程序正在运行; 很多用户只是再次运行安装程序.

如何处理此对话框中的选择,以便他们点击"重新安装前删除"我删除文件夹%appdata%/ MyProgram?我不想总是删除它,但给他们选择.

Rob*_*ell 7

您不需要自定义页面来执行此操作.只需设置一个这样的可选任务:

[Tasks]
Name: deletefiles; Description: 'Remove any existing settings'; Flags: unchecked
Run Code Online (Sandbox Code Playgroud)

然后在安装和卸载部分中删除这些文件

[InstallDelete]
Type: files; Name: {userappdata}\MyProgram\*.whatever; Tasks: deletefiles

[UninstallDelete]
Type: files; Name: {userappdata}\MyProgram\*.whatever;
Run Code Online (Sandbox Code Playgroud)

可以选择在重新安装期间删除这些文件,但在卸载期间始终会删除这些文件.

但是要注意如何指定通配符,以确保只丢弃正确类型的临时文件.