user3063775
user3063775

Reputation: 35

INNO - checking file is installed with msgbox

Want to check if 1 file is in directory and if so not to reinstall, do message, and stop program. Near it with code but when I add message it repeats 4 times and still installs! Can you or anyone correct what I am doing please Many thanks Michael

#define MyAppName "Secretary Assistant"
#define MyAppVersion "3.74"
#define MyAppPublisher ""

[Setup]
AppId={{807EB06A-3962-4AF0-967B-D14B0FEF4E9C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName=C:\Users\{username}\Google Drive\Congregation
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputBaseFilename=Secretary Assistant 3.74 Setup
Compression=lzma
SolidCompression=yes
UsePreviousAppDir=no
DirExistsWarning=No
DisableWelcomePage=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "D:\GoogleDrive\MapSecAssist\CongData.accdb"; DestDir: "{app}"; Flags:      ignoreversion;  Check: File1(ExpandConstant('{app}\CongData.accdb')); 

[Code]
function File1(FilePath3: String): Boolean;
begin
If FileExists(FilePath3) then 
Result := False
else
Result := True
begin
if FileExists(FilePath3) then
 MsgBox('Congregation Data file is already in your directory ' + FilePath3 + '.    '#13 #13 +
'Setup would OVERWRITE this DATA FILE.'#13 #13+
'Please "Back it up" and then DELETE it from this Directory then start install again !',       mbError, MB_OK);
 end; 
 end; 

Upvotes: 1

Views: 281

Answers (1)

RobeN
RobeN

Reputation: 5456

On your place I would use BeforeInstall instead of Check.

Example below:

[Files]
Source: "D:\GoogleDrive\MapSecAssist\CongData.accdb"; DestDir: "{app}"; 
 Flags: ignoreversion; BeforeInstall: File1; 

[Code]
var CancelWithoutPrompt: boolean;

function InitializeSetup(): Boolean;
begin
  CancelWithoutPrompt := false;
  result := true;
end;

procedure File1;
begin
    if FileExists(ExpandConstant('{app}\CongData.accdb')) then 
      begin
        MsgBox('Congregation Data file is already in your directory ' +
             ExpandConstant('{app}') + '.    '#13 #13 +
        'Setup would OVERWRITE this DATA FILE.'#13 #13+
        'Please "Back it up" and then DELETE it from this Directory then 
             start install again !', mbError, MB_OK);
        CancelWithoutPrompt := true;
        WizardForm.Close;
      end;
end; 

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  if CurPageID=wpInstalling then
    Confirm := not CancelWithoutPrompt;
end;

Upvotes: 2

Related Questions