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

[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={{49745D9C-4EE9-47A9-BF63-EC49B8DD02AD}
AppName=OpenSpace3D Templates   
AppVersion=1.0
AppVerName=OpenSpace3D Templates 1.0
AppPublisher=I-maginer
AppPublisherURL=http://www.openspace3d.com
AppSupportURL=http://www.openspace3d.com
AppUpdatesURL=http://www.openspace3d.com
DefaultDirName={code:GetScolInstallDir}
DefaultGroupName=OpenSpace3D
OutputDir=release
OutputBaseFilename=os3d_templates_setup
SetupIconFile=..\..\scol_applications\openspace3d\os3deditor\os3deditor.ico
Compression=lzma
SolidCompression=true
UninstallDisplayIcon={app}\scol.ico
InternalCompressLevel=max
VersionInfoVersion=1.0
VersionInfoCompany=I-maginer
VersionInfoDescription=OpenSpace3D Templates
VersionInfoCopyright=I-maginer 2021
MinVersion=0,5.01.2600
AppCopyright=I-maginer 2021
DisableProgramGroupPage=true
CreateAppDir=true
DisableDirPage=true
UsePreviousAppDir=false
SignTool=i-maginer
;sign setup i-maginer "C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool" sign /a /t http://timestamp.globalsign.com/scripts/timestamp.dll $f

[Languages]
Name: english; MessagesFile: compiler:Default.isl
Name: french; MessagesFile: compiler:Languages\French.isl

[Tasks]

[Files]
Source: ..\..\scol_applications\openspace3d\assets\templates\*; DestDir: {code:GetScolUserDir}\assets\templates; Flags: ignoreversion recursesubdirs createallsubdirs; Excludes: .svn,*.log

[Icons]
Name: {group}\{cm:UninstallProgram,OpenSpace3D Templates}; Filename: {uninstallexe}

[Run]

[CustomMessages]
french.NoScolInstalled=L'installation de OpenSpace3D n'a pas été trouvée. Installez OpenSpace3D depuis www.openspace3d.com puis réessayez.
english.NoScolInstalled=The OpenSpace3D installation can not be found. Install OpenSpace3D from www.openspace3d.com and retry.
french.BadScolInstalled=La version trouvée du Scol Voy@ger est obselète. Installez la dernière version du Scol Voy@ger depuis www.scolring.org puis réessayez.
english.BadScolInstalled=You must install the last version of Scol Voy@ger from www.scolring.org.

[Code]
#include "../common/common_type.iss"

var
	InternalMsgs: array of TInternalMsg;
var
	NeedVoyager: Boolean;
var
  ScolUserPartition: String;
var
  ScolLockedPartition: String;
var
  ScolDir: String;

#include "../common/common_code.iss"


function VoyagerIsNeeded(): Boolean;
begin
	Result := NeedVoyager;
end;


function GetScolUserDir(Default: String): String;
begin
  Result := ScolUserPartition;
end;

function GetScolLockedDir(Default: String): String;
begin
  Result := ScolLockedPartition;
end;

function GetVoyagerDir(): String;
begin
  Result := ScolDir;
end;

///////////////////////////////
// Scol install directory
function GetScolInstallDir(Default: String): String;
var
	UsmIni: String;
	UsmFile: String;
	ArrUsmIni: array of String;
  Value: String;
begin
  Value := GetScolDir(ExpandConstant('{pf}') + '\Scol Voyager');
	if (CheckScolVer(Value) = False) then begin
		NeedVoyager := True;
	end
	else begin
		NeedVoyager := False;
	end;
  
  ScolDir := Value;
  
  UsmFile := GetVoyagerDir() + '\usm.ini';
	// update usm.ini
	LoadStringFromFile(UsmFile, UsmIni);

	if FileExists(UsmFile) = true then begin
		FileCopy (UsmFile, GetVoyagerDir() + '\usm.bak', false);
  
    SetArrayLength(ArrUsmIni, 0);
    Strings2Array(UsmIni, ArrUsmIni);
  
    // add the OpenSpace3D partition
    InstallPartition(ArrUsmIni, './OpenSpace3D', True);
	  SaveStringsToFile(UsmFile, ArrUsmIni, false);
  end;
  
  ScolUserPartition := GetScolUserPartitionDir(Value, ExpandConstant('{userdocs}') + '\OpenSpace3D');
  ScolLockedPartition := GetScolLockedPartitionDir(Value, Value + '\Partition_LockedApp');
	Result := Value;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
	Uninstall: String;
begin
	//if (CurStep = ssInstall) then
end;


procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
	//if (CurUninstallStep = usUninstall) then
end;

procedure InitializeWizard();
begin
	if NeedVoyager = True then
  begin
		MsgBox(ExpandConstant('{cm:NoScolInstalled}'), mbInformation, MB_OK);
    Abort;
	end;
end;