Reputation: 277
I have created a shortcut named Myapp
in the desktop. My installed app changes that shortcut, if I choose to others languages, for example: Spanish or French. Then the shorcut name changes to: Myapp Spanish
or Myapp French
.
That s why Inno Setup can not detect it on uninstall. And this doesn't work wither :
[UninstallDelete]
Type: files; Name: "{commondesktop}\Myapp*.ink";`
Upvotes: 1
Views: 227
Reputation: 202088
To delete files matching a mask on uninstall, you can use:
[Code]
function DeleteWithMask(Path, Mask: string): Boolean;
var
FindRec: TFindRec;
FilePath: string;
begin
Result := FindFirst(Path + '\' + Mask, FindRec);
if not Result then
begin
Log(Format('"%s" not found', [Path + '\' + Mask]));
end
else
begin
try
repeat
FilePath := Path + '\' + FindRec.Name;
if not DeleteFile(FilePath) then
begin
Log(Format('Error deleting "%s"', [FilePath]));
end
else
begin
Log(Format('Deleted "%s"', [FilePath]));
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
begin
Log('Deleting shortcuts')
DeleteWithMask(ExpandConstant('{commondesktop}'), 'Myapp*.ink');
end;
end;
(I'm not sure, what .ink
is about, though)
Safer would be to iterate all shortcut files in the folder (desktop), deleting only those that point to your application.
See my answer to Check for existence of a shortcut pointing to a specific target in Inno Setup.
If I understand your question correctly, your application can already identify the correct shortcut file (as it seems to rename or delete the old shortcut, when the language changes). In that case, consider adding the "uninstall shortcut" functions to the application itself. Make the application process (undocumented) command-line switch to delete the shortcut (e.g. /DeleteShortcut
). And use that from [UninstallRun]
section:
[UninstallRun]
Filename: "{app}\MyApp.exe"; Parameters: "/DeleteShortcut"; RunOnceId: "DeleteShortcut"
Upvotes: 1