我的安装程序如何可以选择删除最初创建的文件? [英] How can my installer optionally delete some files it didn't initially create?

查看:136
本文介绍了我的安装程序如何可以选择删除最初创建的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I store all my program's settings in the appdata directory %appdata%/MyProgram. When there is a problem and the user has to reinstall, I want to ask whether to delete the data in that directory. I am using Inno Setup and added a custom page to prompt the user:

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;

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

The installer doesn't put the data there, but the program generates it, thus the uninstaller won't delete it automatically. I also can't count on the uninstaller being run; a lot of users just run the installer again.

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

How can I handle the selection from this dialog so that if they click 'remove before re-install' I delete the folder %appdata%/MyProgram? I don't want to always delete it, but give them the option.

推荐答案

可能有其他方法,但下面应该这样做:

There could be other ways but the below should do it:

[Dirs]    
Name: {userappdata}\MyProgram; BeforeInstall: BeforeInstallAppData;
...

[Code]

var
  appDataDir: string;
  appDataPage: TInputOptionWizardPage;

procedure InitializeWizard;
begin
  appdataDir := AddBackslash(ExpandConstant('{userappdata}\MyProgram')); 
 if DirExists(appDataDir) 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.Values[0] := true;
  end;
end;

procedure BeforeInstallAppData;
begin
  if DirExists(appDataDir) and appDataPage.Values[0] then
    DelTree(appDataDir, True, True, True);
end;

这篇关于我的安装程序如何可以选择删除最初创建的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆