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

#define MyAppName "Quandl Toolbelt"
#define MyAppVersion "0.1"
#define MyAppPublisher "Quandl"
#define MyAppURL "http://www.quandl.com/"
#define MyAppExeName "quandl.bat"

[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={{BC3A2597-57FE-4B8E-8105-B2945862AA97}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=c:\Quandl
DisableDirPage=yes
DefaultGroupName={#MyAppName}
OutputBaseFilename=Quandl Setup
OutputDir=..\..\build\pkg\
Compression=lzma
SolidCompression=yes

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

[Files]
Source: "..\..\build\tarball\installer\rubyinstaller.exe"; DestDir: "{tmp}";
Source: "..\..\build\tarball\quandl-command\bin\*.*"; DestDir: "{app}\bin"; Flags: recursesubdirs;
Source: "..\..\build\tarball\quandl-command\lib\*.*"; DestDir: "{app}\lib"; Flags: recursesubdirs;
Source: "..\..\build\tarball\quandl-command\vendor\*.*"; DestDir: "{app}\vendor"; Flags: recursesubdirs;
Source: "..\..\build\tarball\quandl\quandl.bat"; DestDir: "{app}\bin"; Flags: recursesubdirs;

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

[Run]
Filename: "{tmp}\rubyinstaller.exe"; Parameters: "/verysilent /noreboot /nocancel /noicons /dir=""{app}/ruby-1.9.3"""; \
  Flags: shellexec waituntilterminated; StatusMsg: "Installing Ruby"; AfterInstall: MyProgress(1);
[Code]

procedure MyProgress(Mult: Integer);
begin
  WizardForm.ProgressGauge.Min := 0;
  WizardForm.ProgressGauge.Max := 100;
  WizardForm.ProgressGauge.Position := Mult*33;
end;

function NeedsAddPath(Param: string): boolean;
var
  OrigPath: string;
begin
  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
  // Pos() returns 0 if not found
  Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;

[UninstallDelete]
Type: filesandordirs; Name: "{app}/bin"
Type: filesandordirs; Name: "{app}/lib"
Type: filesandordirs; Name: "{app}/ruby-1.9.3"
Type: filesandordirs; Name: "{app}/vendor"
Type: filesandordirs; Name: "{app}/backup"
Type: filesandordirs; Name: "{app}/update"
Type: files; Name: "{app}/*"
Type: dirifempty; Name: "{app}"