[Setup]
AppName=StarCraft II - Wings Of Liberty
AppVerName=StarCraft II - Wings Of Liberty
DefaultDirName={pf}\StarCraft II
OutputBaseFilename=setup
Compression=lzma2/Normal
DiskSpanning=yes
DiskSliceSize=1550000000
SlicesPerDisk=3
ShowLanguageDialog=Auto
OutputDir=.\Compiled
SetupIconFile=.\Wizard_Res\icon.ico
WizardImageFile=.\Wizard_Res\WizardImage.bmp
WizardSmallImageFile=.\Wizard_Res\WizardSmallImage.bmp
DefaultGroupName=StarCraft II

[Files]

Source: .\Wizard_Res\BGI*.bmp; DestDir: {tmp}; Flags: dontcopy
Source: .\Wizard_Res\InstallLoop.mp3; DestDir: {tmp}; Flags: dontcopy
Source: vcredist_x86.exe; DestDir: {tmp}; Flags: dontcopy
Source: InnoCallback.dll; DestDir: {tmp}; Flags: dontcopy
Source: GameuxInstallHelper.dll; DestDir: {app}; Flags: ignoreversion
Source: F:\StarCraft II\*; DestDir: {app}; Flags: ignoreversion recursesubdirs

[Tasks]

Name: desktopicon; Description: {cm:CreateDesktopIcon}
Name: ShortCuts; Description: {cm:AdditionalIcons}

[Registry]

Root: HKLM; Subkey: SOFTWARE\Blizzard Entertainment; Flags: uninsdeletekeyifempty
Root: HKLM; Subkey: SOFTWARE\Blizzard Entertainment\StarCraft II Retail; ValueName: GamePath; ValueType: String; ValueData: {app}\StarCraft II.exe; Flags: uninsdeletekey
Root: HKLM; Subkey: SOFTWARE\Blizzard Entertainment\StarCraft II Retail; ValueName: InstallPath; ValueType: String; ValueData: {app}\; Flags: uninsdeletekey
Root: HKCU; Subkey: SOFTWARE\Blizzard Entertainment; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: SOFTWARE\Blizzard Entertainment\Battle.net; Flags: uninsdeletekey
Root: HKCU; Subkey: SOFTWARE\Blizzard Entertainment\Launcher; Flags: uninsdeletekey
Root: HKCU; Subkey: SOFTWARE\Blizzard Entertainment\Launcher\DriverInfo; Flags: uninsdeletekey
Root: HKCU; Subkey: SOFTWARE\Blizzard Entertainment\Launcher\DriverInfo; ValueName: modifieddate; ValueType: String; ValueData: Sat, 24 Jul 2010 03:59:26 GMT; Flags: uninsdeletekey

;Supporting an Upgrade from Windows XP for current user (Game Explorer)
Root: HKCU; Subkey: Software\Classes\Software\Microsoft\Windows\CurrentVersion\GameUX\GamesToFindOnWindowsUpgrade\{code:GetGUIDStr}; Flags: uninsdeletekey; check: CheckXPOs()
Root: HKCU; Subkey: Software\Classes\Software\Microsoft\Windows\CurrentVersion\GameUX\GamesToFindOnWindowsUpgrade; ValueName: GDFBinaryPath; ValueType: String; ValueData: {app}; Flags: uninsdeletekey; check: CheckXPOs()
Root: HKCU; Subkey: Software\Classes\Software\Microsoft\Windows\CurrentVersion\GameUX\GamesToFindOnWindowsUpgrade; ValueName: GameInstallPath; ValueType: String; ValueData: {app}; Flags: uninsdeletekey; check: CheckXPOs()
;Supporting an Upgrade from Windows XP for current user (Game Explorer)

[Dirs]

;Supporting an Upgrade from Windows XP for current user (Game Explorer)
Name: {localappdata}\Microsoft\Windows\GameExplorer\{code:GetGUIDStr}\PlayTasks; check: CheckXPOs()
Name: {localappdata}\Microsoft\Windows\GameExplorer\{code:GetGUIDStr}\SupportTasks; check: CheckXPOs()
;Supporting an Upgrade from Windows XP for current user (Game Explorer)

[Run]
Filename: {tmp}\vcredist_x86.exe; Parameters: /Q; StatusMsg: {cm:run} Microsoft Visual C++...
Filename: {app}\StarCraft II.exe; Description: {cm:LaunchProgram,StarCraft II}; flags: unchecked postinstall

[Icons]

Name: {userdesktop}\StarCraft II; Filename: {app}\StarCraft II.exe; WorkingDir: {app}; Tasks: desktopicon
Name: {group}\Battle.net Account Management; Filename: {app}\Support\BattlenetAccount.url; WorkingDir: {app}\Support; Tasks: ShortCuts
Name: {group}\Blizzard Technical Support; Filename: {app}\Support\TechSupport.url; WorkingDir: {app}\Support; Tasks: ShortCuts
Name: {group}\StarCraft II - Manual; Filename: {app}\Support\Manual.pdf; WorkingDir: {app}\Support; Tasks: ShortCuts
Name: {group}\StarCraft II - Map Editor; Filename: {app}\Support\SC2Editor.exe; WorkingDir: {app}\Support; Tasks: ShortCuts
Name: {group}\StarCraft II - Repair; Filename: {app}\Support\Repair.exe; WorkingDir: {app}\Support; Tasks: ShortCuts
Name: {group}\StarCraft II; Filename: {app}\StarCraft II.exe; WorkingDir: {app};Tasks: ShortCuts
Name: {group}\{cm:UninstallProgram,StarCraft II}; Filename: {uninstallexe}; WorkingDir: {app}; Tasks: ShortCuts

[CustomMessages]

en.taskentry1=Play
en.Uninstall=%1 Uninstall
it.Uninstall=%1 Disinstallazione
es.Uninstall=%1 Desinstalar
de.Uninstall=%1 Deinstallieren
fr.Uninstall=%1 Désinstaller
en.About=&About...
it.About=&Informazioni su...
es.About=&Acerca de...
de.About=&Über...
fr.About=&À Propos...
en.Run=Install
it.Run=Installazione
es.Run=Instalar
de.Run=Installieren
fr.Run=Installer
en.removemsg=Do you wish to remove your saved games and settings?
it.removemsg=Vuoi rimuovere i salvataggi e le impostazioni utente?
fr.removemsg=Voulez-vous supprimer vos parties sauvegardées et les paramètres?
de.removemsg=Möchten Sie Ihre gespeicherten Spiele und Einstellungen zu entfernen?
es.removemsg=¿Desea eliminar sus juegos guardados y ajustes?

[Languages]
; These files are stubs
; To achieve better results after recompilation, use the real language files

Name: en; MessagesFile: compiler:Default.isl; licensefile: .\eula.rtf
Name: it; MessagesFile: compiler:languages\italian.isl; licensefile: .\eula.rtf
Name: de; MessagesFile: compiler:languages\german.isl; licensefile:  .\eula.rtf
Name: es; MessagesFile: compiler:languages\spanish.isl; licensefile: .\eula.rtf
Name: fr; MessagesFile: compiler:languages\french.isl; licensefile:  .\eula.rtf


[Code]

const
  PlayTask = 0;
  SupportTask= 1;
  AllUsers = 2;
  Current = 3;
  GE_resource = '\Support\SC2Switcher.exe';
  bgicount= 5;
  
type
  TGUID = record
  Data1: Longword;
  Data2,
  Data3: Word;
  Data4: array [0..7] of byte;
end;

type
  Timgname = record
  name: string;
end;

type
  TSlideShow=procedure();

var
  GUID: TGUID;
  i,c: integer;
  bgImage : TBitmapImage;
  Tid: LongWord;
  names: array of Timgname;
  AboutButton: TNewButton;



//Funzioni Windows API
function WrapCallback(callback:TSlideShow; paramcount:integer):longword;
external 'wrapcallback@files:innocallback.dll stdcall';
function SetTimer(hWnd: longword; nIDEvent, uElapse: longword; lpTimerFunc: longword): longword;
external 'SetTimer@user32.dll stdcall';
function KillTimer(hWnd, nIDEvent: LongWord): LongWord;
external 'KillTimer@user32 stdcall delayload';
function GetDC(HWND: DWord): DWord;
external 'GetDC@user32.dll stdcall';
function GetDeviceCaps(DC: DWord; Index: Integer): Integer;
external 'GetDeviceCaps@gdi32.dll stdcall';
function ReleaseDC(HWND: DWord;DC: DWord): Integer;
external 'ReleaseDC@user32.dll stdcall';
function ShowWindow(hWnd: DWord; nCmdShow: Integer): boolean;
external 'ShowWindow@user32.dll stdcall';
function SetWindowLong(hWnd: DWord; nIndex: Integer; dwNewLong: Longint):Longint;
external 'SetWindowLongA@user32.dll stdcall';
function GenerateGUID(var GUID: TGUID): Cardinal;
external 'GenerateGUID@files:GameuxInstallHelper.dll stdcall setuponly';
function AddToGameExplorer(Binary: String; Path: String; InstallType: Integer; var GUID: TGUID): Cardinal;
external 'AddToGameExplorerA@files:GameuxInstallHelper.dll stdcall setuponly';
function CreateTask(InstallType: Integer; var GUID: TGUID; TaskType: Integer; TaskNumber: Integer; TaskName: String; Binary: String; Parameters: String): Cardinal;
external 'CreateTaskA@files:GameuxInstallHelper.dll stdcall setuponly';
function RetrieveGUIDForApplication(Binary: String; var GUID: TGUID): Cardinal;
external 'RetrieveGUIDForApplicationA@{app}\GameuxInstallHelper.dll stdcall uninstallonly';
function RemoveFromGameExplorer(var GUID: TGUID): Cardinal;
external 'RemoveFromGameExplorer@{app}\GameuxInstallHelper.dll stdcall uninstallonly';
function RemoveTasks(var GUID: TGUID): Cardinal;
external 'RemoveTasks@{app}\GameuxInstallHelper.dll stdcall uninstallonly';
function SHGetFolderPath(hwndOwner,nFolder,hToken: Integer; dwFlags: DWord; pszPath: PChar): Cardinal;
external 'SHGetFolderPathA@shell32.dll stdcall';
function StringFromGUID2(var GUID: TGUID; lpsz: PAnsiChar; cchMax: integer): Integer;
external 'StringFromGUID2@Ole32.dll stdcall';
function mciSendString(lpstrCommand, lpstrReturnString: PChar; uReturnLength: UINT; hWndCallback: DWord): Integer;
external 'mciSendStringA@winmm.dll stdcall';


function CheckXPOs(): Boolean;

begin

if GetWindowsVersion shr 24 < 6 then Result:=TRUE

end;

function GetScreenHeight(): integer;
var
    dc: DWord;

begin
 dc:=GetDC(MainForm.Handle);
 Result:=GetDeviceCaps(dc,10);
 ReleaseDC(MainForm.Handle,dc);
end;

function GetScreenWidth(): integer;
 var
    dc: DWord;

begin
 dc:=GetDC(MainForm.Handle);
 Result:=GetDeviceCaps(dc,8);
 ReleaseDC(MainForm.Handle,dc);
end;

function IntToHex(l:longword; digits:integer):string;

var hexchars:string;

begin

 hexchars:='0123456789ABCDEF';
 setlength(result,digits);

 while (digits>0) do begin

   result[digits]:=hexchars[l mod 16+1];
   l:=l div 16;
   digits:=digits-1;

end;

end;

function GetGUIDStr(Param: string): string;

begin

Result:='{'+IntToHex(GUID.Data1,8)+'-'+
        IntToHex(GUID.Data2,4)+'-'+
        IntToHex(GUID.Data3,4)+'-'+
        IntToHex(GUID.Data4[0],2)+IntToHex(GUID.Data4[1],2)+'-'+
        IntToHex(GUID.Data4[2],2)+IntToHex(GUID.Data4[3],2)+
        IntToHex(GUID.Data4[4],2)+IntToHex(GUID.Data4[5],2)+
        IntToHex(GUID.Data4[6],2)+IntToHex(GUID.Data4[7],2)+
        '}';
end;


function InitializeSetup(): Boolean;

var
  appath: string;
  ResultCode: Integer;

begin

  if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Blizzard Entertainment\StarCraft II Retail') then
   begin
    RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Blizzard Entertainment\StarCraft II Retail',
     'InstallPath', appath)
    Exec((appath +'\unins000.exe'), '', '', SW_SHOW,
     ewWaitUntilTerminated, ResultCode)
    end else
    begin
    Result := TRUE
    end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);

begin
  if CurUninstallStep = usUninstall then
  begin
    if not CheckXPOs then
    begin
    RetrieveGUIDForApplication(ExpandConstant('{app}'+GE_resource), GUID);
    RemoveFromGameExplorer(GUID);
    RemoveTasks(GUID);
    UnloadDll(ExpandConstant('{app}\GameuxInstallHelper.dll'));
    end;
    if MsgBox(ExpandConstant('{cm:removemsg}'), mbConfirmation, MB_YESNO)=IDYES then
     begin
    DelTree(ExpandConstant('{userdocs}'+'\StarCraft II'), True, True, True);
     end;
    end;
  end;


procedure CurStepChanged(CurStep: TSetupStep);
begin

 if CurStep = ssInstall then
    GenerateGUID(GUID);
    
 if not CheckXPOs then
 begin
 
    if CurStep = ssPostInstall then
    
  begin
  
    AddToGameExplorer(ExpandConstant('{app}'+GE_resource), ExpandConstant('{app}'), Current, GUID);
    CreateTask(3, GUID, PlayTask, 0,'', ExpandConstant('{app}\StarCraft II.exe'), '');
    CreateTask(3, GUID, PlayTask, 1,'Map Editor', ExpandConstant('{app}\Support\SC2Editor.exe'), '');
    CreateTask(3, GUID, PlayTask, 2,'Repair', ExpandConstant('{app}\Support\Repair.exe'), '');
    CreateTask(3, GUID, SupportTask, 0,'Battle.net Account Management', ExpandConstant('http://eu.battle.net/account'), '');
    CreateTask(3, GUID, SupportTask, 1,'Blizzard Technical Support', ExpandConstant('http://eu.starcraft2.com/support/'), '');
    
  end;
 end;
end;

procedure SlideShow();

var
bgipercents: integer;

begin

bgipercents:=WizardForm.ProgressGauge.Max div bgicount
if  (WizardForm.ProgressGauge.Position >= bgipercents*c) and (WizardForm.ProgressGauge.Position < WizardForm.ProgressGauge.Max) then begin
bgImage.bitmap.LoadFromFile(expandConstant('{tmp}\'+names[c].name));
c:=c+1

end;
end;

procedure CurPageChanged(CurPageID: Integer);

  var timercallback : longword;
  var MCIstr: Pansichar;
      
  begin

  if (CurPageID = wpInstalling) then

   begin
   With WizardForm Do Begin

     ClientWidth:=310
     ClientHeight:=145
     BorderIcons := [];
     top:=GetScreenHeight-ClientHeight-35
     left:=GetScreenWidth-ClientWidth-10
     PageNameLabel.Visible:=false;
     PageDescriptionLabel.Visible:=false;
     WizardSmallBitmapImage.visible:=true;
     WizardSmallBitmapImage.Width:= ClientWidth;
     WizardSmallBitmapImage.Left:=0;
     ProgressGauge.parent := WizardForm.InstallingPage;
     ProgressGauge.Top := 30;
     ProgressGauge.Left := 0;
     ProgressGauge.Width := 230;
     ProgressGauge.Height := 15;

     CancelButton.Parent := WizardForm.InstallingPage;
     CancelButton.Top := ProgressGauge.Top + ProgressGauge.Height + 3;
     CancelButton.Left := ((ProgressGauge.Width - CancelButton.Width) div 2);

     FilenameLabel.Width := 250
     FilenameLabel.Top := 15
     FilenameLabel.Left := 0

    end;
    
    mciSendString('OPEN ' + ExpandConstant('{tmp}') + '\InstallLoop.mp3 TYPE MPEGVIDEO ALIAS InstallMusicLoop', MCIstr, 255, 0);
    mciSendString('PLAY InstallMusicLoop REPEAT', MCIstr, 255, 0);
    c:=1;
    bgImage.Show;
    ShowWindow(Mainform.Handle,SW_SHOWMAXIMIZED);
    timercallback:=WrapCallBack(@SlideShow,0);
    Tid:=settimer(0,0,1000,timercallback)

  end;

   if (CurPageID = wpFinished) then
   begin

   With WizardForm Do Begin

    ClientWidth:=497;
    ClientHeight:=360;
    BorderIcons := [biSystemMenu, biMinimize, biMaximize];
    top:=((GetScreenHeight-ClientHeight)div 2);
    left:=((GetScreenWidth-ClientWidth)div 2);

    end;
    
    mciSendString('STOP InstallMusicLoop', MCIstr, 255, 0);
    ShowWindow(Mainform.Handle,SW_HIDE);

   end;
   
   if (CurPageID = wpWelcome) then AboutButton.Enabled:=True
   else AboutButton.Enabled:=False;

  end;

function ShouldSkipPage(PageID: Integer): Boolean;

begin
if (PageID = wpSelectProgramGroup) then
 begin
 if not CheckXPOs then Result:=TRUE
 end;
end;

procedure AboutButtonOnClick(Sender: TObject);

begin
 MsgBox('StarCraft II: Wings Of Liberty - Inno Setup script by Peterf1999', mbInformation, mb_Ok);
end;

procedure InitializeWizard();

begin

with wizardform do begin

  AboutButton := TNewButton.Create(Wizardform);
  AboutButton.Left := Wizardform.ClientWidth - CancelButton.Left - CancelButton.Width;
  AboutButton.Top := CancelButton.Top;
  AboutButton.Width := CancelButton.Width+18;
  AboutButton.Height := CancelButton.Height;
  AboutButton.Caption :=ExpandConstant('{cm:About}');
  AboutButton.OnClick := @AboutButtonOnClick;
  AboutButton.Parent :=Wizardform ;
  WizardSmallBitmapImage.visible:=true;
  WizardSmallBitmapImage.Width:=250;
  WizardSmallBitmapImage.Height:=58;
  WizardSmallBitmapImage.Left:=0;
  PageDescriptionLabel.Visible:=false;
  PageNameLabel.Width:=ClientWidth-PageNameLabel.left-250;
  PageNameLabel.Left:=ClientWidth-PageNameLabel.Width;
  bgImage:=TBitmapImage.Create(MainForm);
  bgImage.Align:=alClient;
  bgImage.Stretch:=False;
  bgImage.Parent:=MainForm;
  bgImage.Center:=True;
  bgImage.BackColor:=$000000;
  SetWindowLong(MainForm.Handle,-16,$80000000);

  end;

   for i:=0 to bgicount -1  do begin
   
     SetArrayLength(names,i+1);
     names[i].name:='BGI'+IntToStr(i)+'.bmp';
     ExtractTemporaryFile(names[i].name);
     
   end;
   
   ExtractTemporaryFile('InstallLoop.mp3');
   ExtractTemporaryFile('vcredist_x86.exe');
   bgImage.bitmap.LoadFromFile(expandConstant('{tmp}\'+names[0].name));

end;

Procedure DeInitializeSetup;

Begin
    KillTimer(0, Tid)
End;

procedure InitializeUninstallProgressForm();

begin

with UninstallProgressForm do begin

  ClientWidth:= 497
  ClientHeight:= 145
  BorderIcons := [];
  PageNameLabel.Visible:=false;
  PageDescriptionLabel.Visible:=true;
  PageDescriptionLabel.Caption:=ExpandConstant('{cm:Uninstall,StarCraft II}');
  PageDescriptionLabel.Font.Name:='Arial';
  PageDescriptionLabel.Font.Size:=16;
  PageDescriptionLabel.Font.Style:=[fsBold];
  ProgressBar.Top := 33;
  ProgressBar.Left := (ClientWidth-ProgressBar.Width-5)div 2;
  ProgressBar.Width := 417;
  ProgressBar.Height := 15;

 end;
end;



