2020-12-16 11:40:13 -05:00
|
|
|
|
{ Copyright 2019-2021 Espressif Systems (Shanghai) CO LTD
|
2019-04-28 22:36:03 -04:00
|
|
|
|
SPDX-License-Identifier: Apache-2.0 }
|
|
|
|
|
|
|
|
|
|
{ ------------------------------ Custom steps before the main installation flow ------------------------------ }
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
SetupAborted: Boolean;
|
|
|
|
|
|
|
|
|
|
function InstallationSuccessful(): Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := not SetupAborted;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
<event('InitializeWizard')>
|
|
|
|
|
procedure InitializeDownloader();
|
|
|
|
|
begin
|
|
|
|
|
idpDownloadAfter(wpReady);
|
|
|
|
|
end;
|
|
|
|
|
|
2019-07-24 00:44:30 -04:00
|
|
|
|
{ If IDF_TOOLS_PATH is set in the environment,
|
|
|
|
|
set the default installation directory accordingly.
|
|
|
|
|
Note: here we read IDF_TOOLS_PATH using GetEnv rather than
|
2020-11-10 02:40:01 -05:00
|
|
|
|
by getting it from registry, in case the user has set
|
2019-07-24 00:44:30 -04:00
|
|
|
|
IDF_TOOLS_PATH as a system environment variable manually. }
|
|
|
|
|
<event('InitializeWizard')>
|
|
|
|
|
procedure UpdateInstallDir();
|
|
|
|
|
var
|
|
|
|
|
EnvToolsPath: String;
|
|
|
|
|
begin
|
|
|
|
|
EnvToolsPath := GetEnv('IDF_TOOLS_PATH');
|
|
|
|
|
if EnvToolsPath <> '' then
|
|
|
|
|
begin
|
|
|
|
|
WizardForm.DirEdit.Text := EnvToolsPath;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
|
<event('NextButtonClick')>
|
|
|
|
|
function PreInstallSteps(CurPageID: Integer): Boolean;
|
|
|
|
|
var
|
|
|
|
|
DestPath: String;
|
|
|
|
|
begin
|
|
|
|
|
Result := True;
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if CurPageID <> wpReady then begin
|
|
|
|
|
Exit;
|
|
|
|
|
end;
|
2019-04-28 22:36:03 -04:00
|
|
|
|
|
|
|
|
|
ForceDirectories(ExpandConstant('{app}\dist'));
|
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if (IsOfflineMode) then begin
|
|
|
|
|
ForceDirectories(ExpandConstant('{app}\releases'));
|
|
|
|
|
IDFZIPFileVersion := IDFDownloadVersion;
|
|
|
|
|
IDFZIPFileName := ExpandConstant('{app}\releases\esp-idf-bundle.zip');
|
|
|
|
|
Exit;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
|
if not GitUseExisting then
|
|
|
|
|
begin
|
|
|
|
|
DestPath := ExpandConstant('{app}\dist\{#GitInstallerName}');
|
|
|
|
|
if FileExists(DestPath) then
|
|
|
|
|
begin
|
|
|
|
|
Log('Git installer already downloaded: ' + DestPath);
|
|
|
|
|
end else begin
|
|
|
|
|
idpAddFile('{#GitInstallerDownloadURL}', DestPath);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
if not IDFUseExisting then
|
|
|
|
|
begin
|
|
|
|
|
IDFAddDownload();
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ ------------------------------ Custom steps after the main installation flow ------------------------------ }
|
|
|
|
|
|
|
|
|
|
procedure AddPythonGitToPath();
|
|
|
|
|
var
|
|
|
|
|
EnvPath: String;
|
|
|
|
|
PythonLibPath: String;
|
2020-08-28 06:33:48 -04:00
|
|
|
|
EnvPythonHome: String;
|
|
|
|
|
PythonNoUserSite: String;
|
2019-04-28 22:36:03 -04:00
|
|
|
|
begin
|
|
|
|
|
EnvPath := GetEnv('PATH');
|
|
|
|
|
|
|
|
|
|
if not GitUseExisting then
|
|
|
|
|
GitExecutablePathUpdateAfterInstall();
|
|
|
|
|
|
|
|
|
|
EnvPath := PythonPath + ';' + GitPath + ';' + EnvPath;
|
|
|
|
|
Log('Setting PATH for this process: ' + EnvPath);
|
|
|
|
|
SetEnvironmentVariable('PATH', EnvPath);
|
|
|
|
|
|
2019-07-24 00:44:30 -04:00
|
|
|
|
{ Set IDF_TOOLS_PATH variable, in case it was set to a different value in the environment.
|
|
|
|
|
The installer will set the variable to the new value in the registry, but we also need the
|
|
|
|
|
new value to be visible to this process. }
|
|
|
|
|
SetEnvironmentVariable('IDF_TOOLS_PATH', ExpandConstant('{app}'))
|
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
{ Set PYTHONNOUSERSITE variable True to avoid loading packages from AppData\Roaming. }
|
|
|
|
|
{ https://doc.pypy.org/en/latest/man/pypy.1.html#environment }
|
|
|
|
|
{ If set to a non-empty value, equivalent to the -s option. Don’t add the user site directory to sys.path. }
|
|
|
|
|
if (IsPythonNoUserSite) then begin
|
|
|
|
|
PythonNoUserSite := 'True';
|
|
|
|
|
end else begin
|
|
|
|
|
PythonNoUserSite := '';
|
|
|
|
|
end;
|
|
|
|
|
Log('PYTHONNOUSERSITE=' + PythonNoUserSite);
|
|
|
|
|
SetEnvironmentVariable('PYTHONNOUSERSITE', PythonNoUserSite);
|
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
|
{ Log and clear PYTHONPATH variable, as it might point to libraries of another Python version}
|
|
|
|
|
PythonLibPath := GetEnv('PYTHONPATH')
|
|
|
|
|
Log('PYTHONPATH=' + PythonLibPath)
|
|
|
|
|
SetEnvironmentVariable('PYTHONPATH', '')
|
2020-08-28 06:33:48 -04:00
|
|
|
|
|
|
|
|
|
{ Log and clear PYTHONHOME, the existence of PYTHONHOME might cause trouble when creating virtualenv. }
|
|
|
|
|
{ The error message when creating virtualenv: }
|
|
|
|
|
{ Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding. }
|
|
|
|
|
EnvPythonHome := GetEnv('PYTHONHOME')
|
|
|
|
|
Log('PYTHONHOME=' + EnvPythonHome)
|
|
|
|
|
SetEnvironmentVariable('PYTHONHOME', '')
|
2019-04-28 22:36:03 -04:00
|
|
|
|
end;
|
|
|
|
|
|
2020-12-16 11:40:13 -05:00
|
|
|
|
procedure InstallEmbeddedPython();
|
|
|
|
|
var
|
|
|
|
|
EmbeddedPythonPath: String;
|
|
|
|
|
CmdLine: String;
|
|
|
|
|
begin
|
|
|
|
|
if (Pos('tools', PythonPath) <> 1) then begin
|
|
|
|
|
Exit;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
EmbeddedPythonPath := ExpandConstant('{app}\') + PythonExecutablePath;
|
|
|
|
|
UpdatePythonVariables(EmbeddedPythonPath);
|
|
|
|
|
Log('Checking existence of Embedded Python: ' + EmbeddedPythonPath);
|
|
|
|
|
if (FileExists(EmbeddedPythonPath)) then begin
|
2020-08-28 06:33:48 -04:00
|
|
|
|
Log('Embedded Python found.');
|
2020-12-16 11:40:13 -05:00
|
|
|
|
Exit;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
CmdLine := ExpandConstant('{tmp}\7za.exe x -o{app}\tools\idf-python\' + PythonVersion + '\ -r -aoa "{app}\dist\idf-python-' + PythonVersion + '-embed-win64.zip"');
|
2020-12-16 11:40:13 -05:00
|
|
|
|
DoCmdlineInstall('Extracting Python Interpreter', 'Using Embedded Python', CmdLine);
|
|
|
|
|
end;
|
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
|
<event('CurStepChanged')>
|
|
|
|
|
procedure PostInstallSteps(CurStep: TSetupStep);
|
|
|
|
|
var
|
|
|
|
|
Err: Integer;
|
|
|
|
|
begin
|
|
|
|
|
if CurStep <> ssPostInstall then
|
|
|
|
|
exit;
|
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
ExtractTemporaryFile('7za.exe');
|
|
|
|
|
|
2020-12-16 11:40:13 -05:00
|
|
|
|
InstallEmbeddedPython();
|
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
|
try
|
|
|
|
|
AddPythonGitToPath();
|
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if not IDFUseExisting then begin
|
|
|
|
|
if (IsOfflineMode) then begin
|
|
|
|
|
IDFOfflineInstall();
|
|
|
|
|
end else begin
|
|
|
|
|
IDFDownloadInstall();
|
|
|
|
|
end;
|
|
|
|
|
end;
|
2019-04-28 22:36:03 -04:00
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if WizardIsTaskSelected('UseMirror') then
|
2020-09-25 07:40:23 -04:00
|
|
|
|
begin
|
|
|
|
|
SetEnvironmentVariable('IDF_GITHUB_ASSETS', 'dl.espressif.com/github_assets')
|
|
|
|
|
end;
|
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
|
IDFToolsSetup();
|
|
|
|
|
|
2019-08-20 02:37:45 -04:00
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if WizardIsTaskSelected('CreateLinkStartCmd') then
|
2019-08-20 02:37:45 -04:00
|
|
|
|
begin
|
2019-11-22 05:55:42 -05:00
|
|
|
|
CreateIDFCommandPromptShortcut('{autostartmenu}\Programs\ESP-IDF');
|
2019-08-20 02:37:45 -04:00
|
|
|
|
end;
|
2020-11-10 02:40:01 -05:00
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if WizardIsTaskSelected('CreateLinkStartPowerShell') then
|
2020-08-28 06:33:48 -04:00
|
|
|
|
begin
|
|
|
|
|
CreateIDFPowershellShortcut('{autostartmenu}\Programs\ESP-IDF' );
|
|
|
|
|
end;
|
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if WizardIsTaskSelected('CreateLinkDeskCmd') then
|
2019-11-22 05:55:42 -05:00
|
|
|
|
begin
|
|
|
|
|
CreateIDFCommandPromptShortcut('{autodesktop}');
|
|
|
|
|
end;
|
|
|
|
|
|
2020-08-28 06:33:48 -04:00
|
|
|
|
if WizardIsTaskSelected('CreateLinkDeskPowerShell') then
|
2020-08-28 06:33:48 -04:00
|
|
|
|
begin
|
|
|
|
|
CreateIDFPowershellShortcut('{autodesktop}');
|
|
|
|
|
end;
|
|
|
|
|
|
2019-04-28 22:36:03 -04:00
|
|
|
|
except
|
|
|
|
|
SetupAborted := True;
|
|
|
|
|
if MsgBox('Installation log has been created, it may contain more information about the problem.' + #13#10
|
|
|
|
|
+ 'Display the installation log now?', mbConfirmation, MB_YESNO or MB_DEFBUTTON1) = IDYES then
|
|
|
|
|
begin
|
|
|
|
|
ShellExec('', 'notepad.exe', ExpandConstant('{log}'), ExpandConstant('{tmp}'), SW_SHOW, ewNoWait, Err);
|
|
|
|
|
end;
|
|
|
|
|
Abort();
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
<event('ShouldSkipPage')>
|
|
|
|
|
function SkipFinishedPage(PageID: Integer): Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
|
|
if PageID = wpFinished then
|
|
|
|
|
begin
|
|
|
|
|
Result := SetupAborted;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
2020-08-28 06:33:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function IsPowerShellInstalled(): Boolean;
|
|
|
|
|
begin
|
2020-08-28 06:33:48 -04:00
|
|
|
|
Result := ((not SetupAborted) and (WizardIsTaskSelected('CreateLinkDeskPowerShell') or WizardIsTaskSelected('CreateLinkStartPowerShell')));
|
2020-08-28 06:33:48 -04:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function IsCmdInstalled(): Boolean;
|
|
|
|
|
begin
|
2020-08-28 06:33:48 -04:00
|
|
|
|
Result := ((not SetupAborted) and (WizardIsTaskSelected('CreateLinkDeskCmd') or WizardIsTaskSelected('CreateLinkStartCmd')));
|
2020-08-28 06:33:48 -04:00
|
|
|
|
end;
|