summaryrefslogtreecommitdiff
path: root/tools/innosetup/code.iss
blob: 1b98cce53b8586b075ce1f15101fbf156dea8815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
//
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) DIGITEO - 2010-2012 - Allan CORNET
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
//
//------------------------------------------------------------------------------
// Inno Setup Script (5.3 and more) for Scilab (UNICODE version required)
//
//------------------------------------------------------------------------------

function IsProcessorFeaturePresent(ProcessorFeature: DWORD): Boolean;
external 'IsProcessorFeaturePresent@kernel32.dll stdcall';

function GetModuleHandle(lpModuleName: LongInt): LongInt;
external 'GetModuleHandleA@kernel32.dll stdcall';

var
    AboutModulesButton: TButton;
    OriginalOnTypesComboChange: TNotifyEvent;

//------------------------------------------------------------------------------
function isCLIType(): Boolean;
  begin
    Result := true;
    if (IsComponentSelected( ExpandConstant('{#COMPN_JVM_MODULE}'))) then
      begin
        Result := false;
      end;
  end;
//------------------------------------------------------------------------------
function getExecNameForDesktop(Param: String): String;
  begin
    if (isCLIType() = true) then
      begin
        Result := ExpandConstant('{app}') + '\bin\scilex.exe';
      end
    else
      begin
        Result := ExpandConstant('{app}') + '\bin\wscilex.exe';
      end;
  end;
//------------------------------------------------------------------------------
function DoTaskInstall_MKL: Boolean;
  begin
    Result := true;
    if (IsComponentSelected( ExpandConstant('{#COMPN_MKL_CPU_LIBRARY}') ) = true) then
      begin
        Result := Install_commons_MKL();
        if (Result = true) then
          begin
            Result := Install_MKL();
          end
      end;
  end;
//------------------------------------------------------------------------------
function DoTaskInstall_MKL_FFTW: Boolean;
  begin
    Result := true;
    if (IsComponentSelected( ExpandConstant('{#COMPN_FFTW_MKL_LIBRARY}') ) = true) then
      begin
        Result := Install_MKL_FFTW();
      end;
  end;
//------------------------------------------------------------------------------
function DoTasksJustAfterInstall: Boolean;
  begin
    Result := true;
    Result := CreateModulesFile();
    Result := DoTaskInstall_MKL();
    Result := DoTaskInstall_MKL_FFTW();
  end;
//------------------------------------------------------------------------------
function GetJREVersion(): String;
begin
    Result := '';

    if Is64BitInstallMode() or not IsWin64() then
    begin
        //64 bits installation or 32 bits OS -> same registry path
        RegQueryStringValue( HKLM, 'SOFTWARE\JavaSoft\Java Runtime Environment', 'CurrentVersion', Result );
    end else begin
        // Scilab 32 bits sur Windows 64 bits
        RegQueryStringValue( HKLM, 'SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment', 'CurrentVersion', Result );
    end
end;
//------------------------------------------------------------------------------
 function CheckJREVersion(): Boolean;
  var
    jreVersion:  String;
    minJREVersionRegistry:  String;
  begin
    //
    // Initialize min java version constant
    //
    minJREVersionRegistry := ExpandConstant('{#javaSpecificationVersion}');
    //
    // now we check the version of the installed JRE
    //
    jreVersion := GetJREVersion();
    if ( jreVersion = '' ) then begin
      Result := false;
    end else if ( jreVersion < minJREVersionRegistry ) then begin
      Result := false;
    end else begin
      Result := true;
    end;
  end;
//------------------------------------------------------------------------------
 function VerifyJREVersion() : Boolean;
  var
    bJREVersion: Boolean;
  begin
    bJREVersion := CheckJREVersion();

    if ( bJREVersion <> true ) then begin
        SuppressibleMsgBox( CustomMessage('MsgBoxJavaDetection1') + #13 +
          CustomMessage('MsgBoxJavaDetection2') + ExpandConstant('{#javaSpecificationVersion}') + '.',
          mbError, MB_OK, MB_OK );
    end;

    Result := bJREVersion;
  end;
//------------------------------------------------------------------------------
procedure ButtonAboutModulesOnClick(Sender: TObject);
var
  ErrorCode: Integer;

begin
    if not ShellExec('', ExpandConstant('{#MODULES_LIST_WEB_PAGE}'),
             '', '', SW_SHOW, ewNoWait, ErrorCode) then
    begin
      // handle failure if necessary
      SuppressibleMsgBox( CustomMessage('MsgBoxWebOpen'),mbError, MB_OK, MB_OK );
    end;
end;
//------------------------------------------------------------------------------
 function BackButtonClick(CurPageID: Integer): Boolean;
  begin
    Result := true;
    if (CurPageId = wpSelectProgramGroup) then
      begin
        AboutModulesButton.Visible := true;
      end else begin
        AboutModulesButton.Visible := false;
      end;
  end;
//------------------------------------------------------------------------------
function NextButtonClick_Download_MKL(): Boolean;
  Var
    bRes : Boolean;
  begin
    Result := true;
    if (IsComponentSelected( ExpandConstant('{#COMPN_MKL_CPU_LIBRARY}') ) = true) then
      begin
        bRes := Download_commons_MKL();
        if ( bRes = true ) then
          begin
            bRes := Download_MKL();
          end;
      end;
  end;
//------------------------------------------------------------------------------
function NextButtonClick_Download_MKL_FFTW(): Boolean;
  Var
    bRes : Boolean;
  begin
    Result := true;
    if (IsComponentSelected( ExpandConstant('{#COMPN_FFTW_MKL_LIBRARY}') ) = true) then
      begin
        bRes := Download_MKL_FFTW();
      end;
  end;
//------------------------------------------------------------------------------
function NextButtonClick(CurPageID: Integer): Boolean;
  Var
    bRes : Boolean;

  begin
    Result := true;

    if (CurPageID = wpWelcome) then
      begin
        if (Is64BitInstallMode() = false) then
          begin
            if IsWin64() then
              begin
                SuppressibleMsgBox(CustomMessage('MsgBoxX64Ready'), mbInformation, MB_OK, MB_OK );
              end;
          end;

        if (IsProcessorFeaturePresent(10) = false) then
          begin
            bRes := false;
            SuppressibleMsgBox(CustomMessage('MsgBoxSSERequired'), mbError, MB_OK, MB_OK );
            Result := false;
          end;
      end;

    if (CurPageId = wpSelectDir) then
      begin
        AboutModulesButton.Visible := true;
      end else begin
        AboutModulesButton.Visible := false;
      end;

    if (CurPageID =  wpReady) then
      begin
        bRes := NextButtonClick_Download_MKL();
        bRes := NextButtonClick_Download_MKL_FFTW();
      end;

    if (CurPageId = wpSelectComponents) then
      begin
        if ( IsComponentSelected( ExpandConstant('{#COMPN_JRE}') ) = false ) then
          begin
            bRes := VerifyJREVersion();
            if ( bRes = false ) then
              begin
                Result := false;
              end;
          end;

        if ( (IsComponentSelected( ExpandConstant('{#COMPN_DEVTOOLS}') ) = false) and (IsComponentSelected( ExpandConstant('{#COMPN_TOOLBOX_SKELETON}') ) = true) ) then
          begin
              SuppressibleMsgBox( CustomMessage('MsgBoxDevToolsRequired1') + #13 +
                CustomMessage('MsgBoxDevToolsRequired2'),
                mbError, MB_OK, MB_OK );
            Result := false;
          end;

          if ( (IsComponentSelected( ExpandConstant('{#COMPN_DEVTOOLS}') ) = false) and (IsComponentSelected( ExpandConstant('{#COMPN_TESTS}') ) = true) ) then
          begin
            SuppressibleMsgBox( CustomMessage('MsgBoxDevToolsRequired3') + #13 +
                CustomMessage('MsgBoxDevToolsRequired2'),
                mbError, MB_OK, MB_OK );
            Result := false;
          end;

      end;
  end;
//------------------------------------------------------------------------------
procedure DeinitializeUninstall;
var
    Names: TArrayOfString;
    iLen: Integer;
begin
    //read registry to find others scilab installation in the same arch
    if RegGetSubkeyNames(HKLM, 'Software\Scilab', Names) then
    begin
        iLen := length(Names);
        if iLen > 0 then
        begin
            RegWriteStringValue(HKLM, 'Software\Scilab', 'LASTINSTALL', Names[iLen - 1]);
        end else begin
            //no other install in the same arch
            //remove LASTINSTALL key and Scilab registry folder ( auto )
            RegDeleteValue(HKLM, 'Software\Scilab', 'LASTINSTALL');
        end;
    end;
end;
//------------------------------------------------------------------------------
function InitializeSetup: Boolean;
  Var
    Version: TWindowsVersion;
#ifdef SCILAB_WITHOUT_JRE
    bRes : Boolean;
#endif
  begin
    Result := True;
    GetWindowsVersionEx(Version);

    if Version.NTPlatform and (Version.Major > 4) then
      begin
        Result := True;
      end else begin
          SuppressibleMsgBox(CustomMessage('MsgBoxWinVer'), mbCriticalError, MB_OK, MB_OK);
          Result := False;
          Exit;
      end
#ifdef SCILAB_WITHOUT_JRE
    bRes := CheckJREVersion();
    if ( bRes = false ) then
    begin
      SuppressibleMsgBox(CustomMessage('MsgBoxJRENotFound')+ '(' +ExpandConstant('{#javaSpecificationVersion}') + ')' + #13 +
        CustomMessage('MsgBoxJREURL')+ #13 +
        CustomMessage('MsgBoxJREReinstall')
        , mbCriticalError, MB_OK, MB_OK);
       Result := False;
       Exit;
    end else begin
      Result := True;
    end
#endif
  end;
//------------------------------------------------------------------------------
procedure OnTypesComboChange(Sender: TObject);
var
  ItemIndex: Integer;
  Res: Boolean;
begin
  OriginalOnTypesComboChange(Sender);
end;
//------------------------------------------------------------------------------
procedure CreateTheWizardPages;
var
  CancelButton: TButton;
begin
  CancelButton := WizardForm.CancelButton;

  AboutModulesButton := TButton.Create(WizardForm);
  AboutModulesButton.Left := WizardForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  AboutModulesButton.Top := CancelButton.Top;
  AboutModulesButton.Width := CancelButton.Width * 2;

  AboutModulesButton.Caption := CustomMessage('ButtonAboutModules');

  AboutModulesButton.Height := CancelButton.Height;

  AboutModulesButton.OnClick := @ButtonAboutModulesOnClick;
  AboutModulesButton.Parent := CancelButton.Parent;
  AboutModulesButton.Visible := false;

  CreateOfflineInstallationCheckBox;

  OriginalOnTypesComboChange := WizardForm.TypesCombo.OnChange;
  WizardForm.TypesCombo.OnChange := @OnTypesComboChange;
end;
//------------------------------------------------------------------------------
procedure InitializeWizard();
begin
  CreateTheWizardPages;
end;
//------------------------------------------------------------------------------
//convert Boolean expresion in string ( debug function )
function BoolToStr(Value : Boolean) : String;
begin
  if Value then
    result := 'true'
  else
    result := 'false';
end;
//------------------------------------------------------------------------------
//check user rights
function IsAdminUser(): Boolean;
begin
  Result := (IsAdminLoggedOn or IsPowerUserLoggedOn);
end;
//------------------------------------------------------------------------------
//returns default install path ( take care of user rights )
function DefDirRoot(Param: String): String;
begin
  if IsAdminUser then
    //program files path
    Result := ExpandConstant('{pf}')
  else
    //local app data path
    Result := ExpandConstant('{localappdata}')
end;