需求背景:
innosetup原则上是安装哪些文件就卸载那些文件。
但实际上往往会在应用的使用过程中,会生成一些日志文件。在卸载的时候,不能删掉,会提示手动清理。
这样还是挺影响体验的。
解决方法:
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usDone then
begin
//删除 {app} 文件夹及其中所有文件
DelTree(ExpandConstant('{app}'), True, True, True);
end;
end;
卸载不干净的情况:
[UninstallRun]
Filename: "{cmd}"; Parameters: "/c rd /s /q ""{app}"""; Flags: hidewizard runhidden
[UninstallDelete]
Name: {app}; Type: filesandordirs
卸载时循环删除文件
function Delete_Files(): Boolean;
begin
result := false;
while result = false do
begin
//删除文件夹
if DelTree(ExpandConstant('{app}\Python'), True, True, True) then
begin
result := true
end;
end;
//删除文件
//DeleteFile(ExpandConstant('C:\a.txt'));
//DeleteFile(ExpandConstant('{app}\c.txt'));
end;
function UninstallNeedRestart (): Boolean;
var
ResultStr: String;
ResultCode: Integer;
CmdStr: String;
ret: Integer;
begin
result := false;
Delete_Files()
end;
Inno setup 删除指定文件
方法一
[UninstallDelete]
;删除文件,{app}:安装目录
Type: files; Name: "{app}\vcruntime140d.dll";
Type: files; Name: "{app}\ucrtbased.dll";
;删除文件夹
Type: filesandordirs; Name: "{app}";
方法二
[code]
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
//删除文件夹
DelTree(ExpandConstant('{app}\platform'), True, True, True);
//删除文件
DeleteFile(ExpandConstant('C:\a.txt'));
DeleteFile(ExpandConstant('{app}\c.txt'));
end;