#define MyAppName "Verdnatura"
#define MyAppVersion "4"
#define MyAppPublisher "Verdnatura"
#define MyAppURL "https://www.verdnatura.es/"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
AppId={{1BFBC7A1-64B3-41E0-8A8E-0D29043EA8A3}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
CreateAppDir=yes
DefaultDirName={commonpf}\{#MyAppName}
DefaultGroupName={#MyAppName}
//The images are in \\server\Programas\Verdnatura\installationImages
//WizardSmallImageFile=src\wizardSmallImage.bmp
//WizardImageFile=src\wizardImage.bmp
LicenseFile=src\LICENSE.txt
SetupIconFile=src\icon.ico
UninstallDisplayIcon={app}\icon.ico
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin
DisableStartupPrompt=yes
OutputDir=..
OutputBaseFilename=vn-access
;SignTool=signtool.exe sign \
  /a /f $qC:\cert.pfx$q /n $q{#MyAppPublisher}$q /t http://timestamp.comodoca.com/authenticode /d $q{#MyAppName}$q $f

[Languages]
Name: "es"; MessagesFile: "compiler:Languages\Spanish.isl"

[Dirs]
Name: "{app}"; \
  Flags: uninsalwaysuninstall
Name: "{sd}\fotos"; \
  Flags: uninsalwaysuninstall; \
  Permissions: users-modify

[Files]
Source: "deps\*"; \
  DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallExe;
Source: "odbc\*"; \
  DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallMsi;
Source: "src\*"; \
  DestDir: "{app}"; Flags: ignoreversion
Source: "icons\*"; \
  DestDir: "{app}\icons"; Flags: ignoreversion
Source: "ocx\*"; \
  DestDir: {sys}; Flags: onlyifdoesntexist regserver 32bit
Source: "fonts\Roboto - *"; \
  DestDir: "{fonts}"; FontInstall: "Roboto"; Flags: onlyifdoesntexist uninsneveruninstall
Source: "fonts\Lucida Sans - *"; \
  DestDir: "{fonts}"; FontInstall: "Lucida Sans"; Flags: onlyifdoesntexist uninsneveruninstall
Source: "fonts\Code128B.ttf"; \
  DestDir: "{fonts}"; FontInstall: "Code128B"; Flags: onlyifdoesntexist uninsneveruninstall
Source: "fonts\CCode39.ttf"; \
  DestDir: "{fonts}"; FontInstall: "CCode39"; Flags: onlyifdoesntexist uninsneveruninstall
Source: "fonts\Free 3 of 9.ttf"; \
  DestDir: "{fonts}"; FontInstall: "Free 3 of 9"; Flags: onlyifdoesntexist uninsneveruninstall
Source: "fonts\Free 3 of 9 Extended.ttf"; \
  DestDir: "{fonts}"; FontInstall: "Free 3 of 9 Extended"; Flags: onlyifdoesntexist uninsneveruninstall
Source: "fonts\IDAutomationHC39M.ttf"; \
  DestDir: "{fonts}"; FontInstall: "IDAutomationHC39M"; Flags: onlyifdoesntexist uninsneveruninstall
Source: "fonts\MRV Code39extMA.ttf"; \
  DestDir: "{fonts}"; FontInstall: "MRV Code39extMA"; Flags: onlyifdoesntexist uninsneveruninstall

[Tasks]
Name: "desktopicon"; \
  Description: "{cm:CreateDesktopIcon}"; \
  GroupDescription: "{cm:AdditionalIcons}";

[Components]
Name: "tpv"; \
  Description: "Terminal Punto Venta"; \
  Types: full compact
Name: "ent"; \
  Description: "Entradas"; \
  Types: full compact
Name: "com"; \
  Description: "Comparativa"; \
  Types: full compact
Name: "enc"; \
  Description: "Encajado"; \
  Types: full
Name: "eti"; \
  Description: "Etiquetas"; \
  Types: full
Name: "lab"; \
  Description: "Laboral"; \
  Types: full
Name: "srv"; \
  Description: "Server"; \
  Types: full
Name: "vn"; \
  Description: "Library"; \
  Types: full

[Icons]
Name: "{group}\Terminal Punto Venta"; \
  Parameters: "tpv"; \
  Components: tpv; \
  IconFileName: "{app}\icons\tpv.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"
Name: "{group}\Entradas"; \
  Parameters: "ent"; \
  Components: ent; \
  IconFileName: "{app}\icons\ent.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"
Name: "{group}\Comparativa"; \
  Parameters: "com"; \
  Components: com; \
  IconFileName: "{app}\icons\com.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"
Name: "{group}\Encajado"; \
  Parameters: "enc"; \
  Components: enc; \
  IconFileName: "{app}\icons\enc.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"
Name: "{group}\Etiquetas"; \
  Parameters: "eti"; \
  Components: eti; \
  IconFileName: "{app}\icons\eti.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"
Name: "{group}\Laboral"; \
  Parameters: "lab"; \
  Components: lab; \
  IconFileName: "{app}\icons\lab.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"
Name: "{group}\Server"; \
  Parameters: "srv"; \
  Components: srv; \
  IconFileName: "{app}\icons\enc.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"
Name: "{group}\Library"; \
  Parameters: "vn"; \
  Components: vn; \
  IconFileName: "{app}\icons\enc.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"

;Desktop icons

Name: "{commondesktop}\Terminal Punto Venta"; \
  Parameters: "tpv"; \
  Components: tpv; \
  IconFileName: "{app}\icons\tpv.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
Name: "{commondesktop}\Entradas"; \
  Parameters: "ent"; \
  Components: ent; \
  IconFileName: "{app}\icons\ent.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
Name: "{commondesktop}\Comparativa"; \
  Parameters: "com"; \
  Components: com; \
  IconFileName: "{app}\icons\com.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
Name: "{commondesktop}\Encajado"; \
  Parameters: "enc"; \
  Components: enc; \
  IconFileName: "{app}\icons\enc.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
Name: "{commondesktop}\Etiquetas"; \
  Parameters: "eti"; \
  Components: eti; \
  IconFileName: "{app}\icons\eti.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
Name: "{commondesktop}\Laboral"; \
  Parameters: "lab"; \
  Components: lab; \
  IconFileName: "{app}\icons\lab.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
Name: "{commondesktop}\Server"; \
  Parameters: "srv"; \
  Components: srv; \
  IconFileName: "{app}\icons\enc.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
Name: "{commondesktop}\Library"; \
  Parameters: "vn"; \
  Components: vn; \
  IconFileName: "{app}\icons\enc.ico"; \
  FileName: "{app}\vn-access.hta"; \
  WorkingDir: "{app}"; \
  Tasks: desktopicon
   
[Code]

procedure InstallExe;
var
  StatusText: String;
  ResultCode: Integer;
  ExeFile: String;
begin
  ExeFile := ExpandConstant(CurrentFilename);
  StatusText := WizardForm.StatusLabel.Caption;
  WizardForm.StatusLabel.Caption := CurrentFilename +'...';
  WizardForm.ProgressGauge.Style := npbstMarquee;
  Log(WizardSelectedComponents(False));
  try
    if not Exec(ExeFile, '/Q', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
    begin
      MsgBox(CurrentFilename +' installation failed with code: ' + IntToStr(ResultCode) + '.',
        mbError, MB_OK);
      WizardForm.Close;       
    end;
  finally
    WizardForm.StatusLabel.Caption := StatusText;
    WizardForm.ProgressGauge.Style := npbstNormal;
  end;
end;

procedure InstallMsi;
var
  StatusText: String;
  ResultCode: Integer;
  MsiFile: String;
begin
  MsiFile := ExpandConstant(CurrentFilename);
  StatusText := WizardForm.StatusLabel.Caption;
  WizardForm.StatusLabel.Caption := CurrentFilename +'...';
  WizardForm.ProgressGauge.Style := npbstMarquee;
  Log(WizardSelectedComponents(False));
  try
    if not Exec('msiexec', '/quiet /i '+ MsiFile, '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
    begin
      MsgBox(CurrentFilename +' installation failed with code: ' + IntToStr(ResultCode) + '.',
        mbError, MB_OK);
      WizardForm.Close;       
    end;
  finally
    WizardForm.StatusLabel.Caption := StatusText;
    WizardForm.ProgressGauge.Style := npbstNormal;
  end;
end;