我将所有程序的设置存储在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;
安装程序不会将数据放在那里,但是程序会生成它,因此卸载程序不会自动删除它。我也不能指望卸载程序正在运行;很多用户只是再次运行安装程序。
如何处理此对话框中的选择,以便点击“重新安装前删除”我删除文件夹%appdata%/ MyProgram?我不想总是删除它,但给他们选择。
答案 0 :(得分:7)
您不需要自定义页面来执行此操作。只需设置一个类似这样的可选任务:
[Tasks]
Name: deletefiles; Description: 'Remove any existing settings'; Flags: unchecked
然后在安装和卸载部分
中删除这些文件[InstallDelete]
Type: files; Name: {userappdata}\MyProgram\*.whatever; Tasks: deletefiles
[UninstallDelete]
Type: files; Name: {userappdata}\MyProgram\*.whatever;
可以选择在重新安装期间删除这些文件,但在卸载过程中始终会删除这些文件。
请注意如何指定通配符,以确保只丢弃正确类型的临时文件。
答案 1 :(得分:3)
可能还有其他方法,但下面应该这样做:
[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;
答案 2 :(得分:1)
你没有。 :)好吧,你不应该,不管怎么说,这就是卸载者难以理解的原因。
卸载程序不删除它的原因是因为它是一个非常糟糕的主意。如果用户犯了错误,并且您的卸载程序删除了大量用户输入数据(如果您编写了会计应用程序,则会删除财务信息),该怎么办?如果他们无意中将数据放入与您的应用无关的文件夹,该怎么办?卸载程序不会删除因某些原因未安装的任何内容。
处理此问题的更好方法与每个其他卸载程序的工作方式相同。告诉用户您无法删除该文件夹,因为它不是空的。然后,他们可以删除它(或将其移动到其他位置,或撤消他们不打算运行的卸载),而不会有任何意外数据丢失的风险。