0

I try to make a setup wizard with InnoSetup software to deploy easily my program but I encounter currently a problem with my script.
I am used to make basic setup wizard but now I have to implement a new functionality whose :
I want to check if a file exist on the computer to not overwrite it.
I made like this (in the [files] section):

[Files]
Source: "{#MyAppExeFile}"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSrcFolder}*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#MyAppSrcFolder}FileFolder\testFile.py"; DestDir: "D:\Users\{username}\myFolderTest\"; Flags: ignoreversion recursesubdirs createallsubdirs;Check: needInstallFile(ExpandConstant('{username}'))

And i added this following [code] section:

[code]
function needInstallFile(user : string) : Boolean;
begin
  if IsTaskSelected('initFile') then begin
    if FileExists('D:\Users\' + user + '\myFolderTest\testFile.py') then begin  
      MsgBox('The file already exist', mbInformation, MB_OK);
      Result:=False;
      exit;
    end else begin
      Result:=True;
      exit;
    end;
   end;
end;

When i compile my code, it's work but if the file already exist, i have three popup (and not just one like i would want to have). I DON'T understand despite my researches on Internet.

If you have a lead to help me, I'm interested because i'm stuck.

Thank you in advance for your help.
PS : Sorry for my English, i am unfortunatly a french guy.

Thomas

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Archy
  • 59
  • 7
  • 2
    Why don't you use the `onlyifdoesntexist` flag? – Olivier Apr 01 '20 at 16:48
  • I agree with @Oliver, see [Inno Setup: Do not overwrite settings file, when installing an update](https://stackoverflow.com/q/45480309/850848). – Martin Prikryl Apr 01 '20 at 17:03
  • 1
    To answer your literal question, see [''Check' function is executing multiple times in Inno Setup](https://stackoverflow.com/q/46037128/850848). – Martin Prikryl Apr 01 '20 at 17:19
  • @Olivier, i must admit that i didn't know that this flag exist. I should better read the documentation [here](https://jrsoftware.org/ishelp/index.php?topic=filessection). But, i have to prevent users that file already exist (with popup) so i think, i must still use a check function. Thanks – Archy Apr 02 '20 at 09:33
  • @MartinPrikryl, thank you, i will check the post – Archy Apr 02 '20 at 09:34
  • The best flag to use is for my project : confirmoverwrite :) – Archy Apr 02 '20 at 11:42
  • So consider posting it as an answer. – Martin Prikryl Apr 02 '20 at 12:04

0 Answers0