How to configure Inno Setup to uninstall everything?

后端 未结 9 1217
渐次进展
渐次进展 2020-12-13 14:33

I am new to Inno Setup. Stuck on one issue ~ how to configure the uninstall piece to remove all files, folders, subfolders, and even new files/folders etc. created by applic

相关标签:
9条回答
  • 2020-12-13 15:15

    There are cases to want to delete files which were not initially written to the user's disk at time of installation. One of these cases is when you have an application that updates itself when it is started. New files can be added to the disk in this manner which are not a part of the uninstaller.

    For this case I suggest that you create a "patch manifest" file which keeps a running record of what files should be in the {app} directory. Find below a sample of code that reads from a file in the {app} dir called 'patch_manifest.txt'

    procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
    var
      i: Integer;
      arrayLen: Longint;
      item: String;
      itemsToDelete: Array of String;
    begin
      case CurUninstallStep of
        usUninstall:
          begin
            LoadStringsFromFile(ExpandConstant('{app}') + '\patch_manifest.txt', itemsToDelete);
            arrayLen := GetArrayLength(itemsToDelete);
            for i := 0 to arrayLen-1 do
              begin
              item := ExpandConstant('{app}') + '\' + itemsToDelete[i];
              if FileExists(item) then
                DeleteFile(item);
              if DirExists(item) then
                RemoveDir(item);
              end;
          end;
      end;
    end;
    

    and a sample of the patch_manifest.txt

    data/something_here.dat
    data/moredatahere.dat
    data/
    Launcher.exe
    patch_manifest.txt
    

    Note: The order of the lines in the patch_manifest is important. All files within a directory should first be listed followed by the directory - directories which are not empty cannot be delete.

    Your application should be shipped with a patch_manifest and the patch_manifest should be updated with every patch. Make this part of your build process so you don't forget to update it!

    It is very important that you do not delete by wildcard (.) even if you prompt the user. Uninstaller's have elevated privileges which could potentially destroy a user's computer. Take the case of a user who accidentally installed your application to C:\Windows\ or C:\Program Files.

    Another good idea is to verify that the file is in fact "your file" by performing an MD5 check prior to deleting it. In this case your patch_manifest.txt would not only include the relative path to the file but also the MD5 checksum.

    0 讨论(0)
  • 2020-12-13 15:16

    Isn't that the default if your don't specify "uninsneveruninstall" for an entry?

    edit - Sorry I hadn't realised you were talking about newly created data files.

    0 讨论(0)
  • 2020-12-13 15:17

    This should do the trick:

    [Dirs]
    Name: "{app}"; Flags: uninsalwaysuninstall
    
    0 讨论(0)
提交回复
热议问题