; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Epic Miner"
#define MyAppVersion "1.5.0"
#define MyAppPublisher "EpicCash, Inc."
#define MyAppURL "http://www.epiccash.com/"
#define MyAppExeName "epic-miner.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{15509F6E-FEA0-425D-9281-93AAAE1D19C0}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputBaseFilename=epic-miner
Compression=lzma
SolidCompression=yes
WizardStyle=classic
ArchitecturesAllowed=x64
ArchitecturesInstallIn64BitMode=x64
AlwaysRestart = no
ChangesEnvironment=True

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

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

[Files]
Source: ".\target\release\epic-miner.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: ".\epic-miner.toml"; DestDir: "{app}"; Flags: ignoreversion
Source: ".\target\release\plugins\cuckatoo_lean_cpu_avx2_31.cuckooplugin"; DestDir: "{app}\plugins"; Flags: ignoreversion
Source: ".\target\release\plugins\cuckatoo_lean_cpu_compat_31.cuckooplugin"; DestDir: "{app}\plugins"; Flags: ignoreversion
Source: ".\target\release\plugins\cuckatoo_lean_cpu_compat_19.cuckooplugin"; DestDir: "{app}\plugins"; Flags: ignoreversion
Source: ".\target\release\plugins\ocl_cuckatoo.cuckooplugin"; DestDir: "{app}\plugins"; Flags: ignoreversion
Source: ".\dependencies\vc_redist.x64.exe"; DestDir: {tmp}; Flags: deleteafterinstall

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Code]
function NeedsAddPath(Param: string): boolean;
var
  OrigPath: string;
  ParamExpanded: string;
begin
  //expand the setup constants like {app} from Param
  ParamExpanded := ExpandConstant(Param);
  if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
    'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
    'Path', OrigPath)
  then begin
    Result := True;
    exit;
  end;
  // look for the path with leading and trailing semicolon and with or without \ ending
  // Pos() returns 0 if not found
  Result := Pos(';' + UpperCase(ParamExpanded) + ';', ';' + UpperCase(OrigPath) + ';') = 0;  
  if Result = True then
     Result := Pos(';' + UpperCase(ParamExpanded) + '\;', ';' + UpperCase(OrigPath) + ';') = 0; 
end;

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
    ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; \
    Check: NeedsAddPath('{app}')

[Run]
Filename: {tmp}\vc_redist.x64.exe; \
    Parameters: "/q /passive /Q:a /c:""msiexec /q /i vcredist.msi"""; \
    StatusMsg: "Installing VC++ 2017 Redistributables..."
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

