main.iss.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. { Copyright 2019-2021 Espressif Systems (Shanghai) CO LTD
  2. SPDX-License-Identifier: Apache-2.0 }
  3. { ------------------------------ Custom steps before the main installation flow ------------------------------ }
  4. var
  5. SetupAborted: Boolean;
  6. function InstallationSuccessful(): Boolean;
  7. begin
  8. Result := not SetupAborted;
  9. end;
  10. <event('InitializeWizard')>
  11. procedure InitializeDownloader();
  12. begin
  13. idpDownloadAfter(wpReady);
  14. end;
  15. { If IDF_TOOLS_PATH is set in the environment,
  16. set the default installation directory accordingly.
  17. Note: here we read IDF_TOOLS_PATH using GetEnv rather than
  18. by getting it from registry, in case the user has set
  19. IDF_TOOLS_PATH as a system environment variable manually. }
  20. <event('InitializeWizard')>
  21. procedure UpdateInstallDir();
  22. var
  23. EnvToolsPath: String;
  24. begin
  25. EnvToolsPath := GetEnv('IDF_TOOLS_PATH');
  26. if EnvToolsPath <> '' then
  27. begin
  28. WizardForm.DirEdit.Text := EnvToolsPath;
  29. end;
  30. end;
  31. <event('NextButtonClick')>
  32. function PreInstallSteps(CurPageID: Integer): Boolean;
  33. var
  34. DestPath: String;
  35. begin
  36. Result := True;
  37. if CurPageID <> wpReady then
  38. exit;
  39. ForceDirectories(ExpandConstant('{app}\dist'));
  40. if not GitUseExisting then
  41. begin
  42. DestPath := ExpandConstant('{app}\dist\{#GitInstallerName}');
  43. if FileExists(DestPath) then
  44. begin
  45. Log('Git installer already downloaded: ' + DestPath);
  46. end else begin
  47. idpAddFile('{#GitInstallerDownloadURL}', DestPath);
  48. end;
  49. end;
  50. if not IDFUseExisting then
  51. begin
  52. IDFAddDownload();
  53. end;
  54. end;
  55. { ------------------------------ Custom steps after the main installation flow ------------------------------ }
  56. procedure AddPythonGitToPath();
  57. var
  58. EnvPath: String;
  59. PythonLibPath: String;
  60. begin
  61. EnvPath := GetEnv('PATH');
  62. if not GitUseExisting then
  63. GitExecutablePathUpdateAfterInstall();
  64. EnvPath := PythonPath + ';' + GitPath + ';' + EnvPath;
  65. Log('Setting PATH for this process: ' + EnvPath);
  66. SetEnvironmentVariable('PATH', EnvPath);
  67. { Set IDF_TOOLS_PATH variable, in case it was set to a different value in the environment.
  68. The installer will set the variable to the new value in the registry, but we also need the
  69. new value to be visible to this process. }
  70. SetEnvironmentVariable('IDF_TOOLS_PATH', ExpandConstant('{app}'))
  71. { Log and clear PYTHONPATH variable, as it might point to libraries of another Python version}
  72. PythonLibPath := GetEnv('PYTHONPATH')
  73. Log('PYTHONPATH=' + PythonLibPath)
  74. SetEnvironmentVariable('PYTHONPATH', '')
  75. end;
  76. procedure InstallEmbeddedPython();
  77. var
  78. EmbeddedPythonPath: String;
  79. CmdLine: String;
  80. begin
  81. if (Pos('tools', PythonPath) <> 1) then begin
  82. Exit;
  83. end;
  84. EmbeddedPythonPath := ExpandConstant('{app}\') + PythonExecutablePath;
  85. UpdatePythonVariables(EmbeddedPythonPath);
  86. Log('Checking existence of Embedded Python: ' + EmbeddedPythonPath);
  87. if (FileExists(EmbeddedPythonPath)) then begin
  88. Exit;
  89. end;
  90. CmdLine := ExpandConstant('{tmp}\7za.exe x -o{app}\tools\python\' + PythonVersion + '\ -r -aoa "{app}\dist\idf-python-' + PythonVersion + '-embed-win64.zip"');
  91. DoCmdlineInstall('Extracting Python Interpreter', 'Using Embedded Python', CmdLine);
  92. end;
  93. <event('CurStepChanged')>
  94. procedure PostInstallSteps(CurStep: TSetupStep);
  95. var
  96. Err: Integer;
  97. begin
  98. if CurStep <> ssPostInstall then
  99. exit;
  100. ExtractTemporaryFile('7za.exe')
  101. InstallEmbeddedPython();
  102. try
  103. AddPythonGitToPath();
  104. if not IDFUseExisting then
  105. IDFDownload();
  106. if WizardIsTaskSelected('idf_tools_use_mirror') then
  107. begin
  108. SetEnvironmentVariable('IDF_GITHUB_ASSETS', 'dl.espressif.com/github_assets')
  109. end;
  110. IDFToolsSetup();
  111. if WizardIsTaskSelected('CreateLnkStartCmd') then
  112. begin
  113. CreateIDFCommandPromptShortcut('{autostartmenu}\Programs\ESP-IDF');
  114. end;
  115. if WizardIsTaskSelected('CreateLnkStartPs') then
  116. begin
  117. CreateIDFPowershellShortcut('{autostartmenu}\Programs\ESP-IDF' );
  118. end;
  119. if WizardIsTaskSelected('CreateLnkDeskCmd') then
  120. begin
  121. CreateIDFCommandPromptShortcut('{autodesktop}');
  122. end;
  123. if WizardIsTaskSelected('CreateLnkDeskPs') then
  124. begin
  125. CreateIDFPowershellShortcut('{autodesktop}');
  126. end;
  127. if WizardIsTaskSelected('wdexcl') then
  128. begin
  129. RegisterIDFToolsExecutablesInWD();
  130. end;
  131. except
  132. SetupAborted := True;
  133. if MsgBox('Installation log has been created, it may contain more information about the problem.' + #13#10
  134. + 'Display the installation log now?', mbConfirmation, MB_YESNO or MB_DEFBUTTON1) = IDYES then
  135. begin
  136. ShellExec('', 'notepad.exe', ExpandConstant('{log}'), ExpandConstant('{tmp}'), SW_SHOW, ewNoWait, Err);
  137. end;
  138. Abort();
  139. end;
  140. end;
  141. <event('ShouldSkipPage')>
  142. function SkipFinishedPage(PageID: Integer): Boolean;
  143. begin
  144. Result := False;
  145. if PageID = wpFinished then
  146. begin
  147. Result := SetupAborted;
  148. end;
  149. end;
  150. function IsPowerShellInstalled(): Boolean;
  151. begin
  152. Result := ((not SetupAborted) and (WizardIsTaskSelected('CreateLnkDeskPs') or WizardIsTaskSelected('CreateLnkStartPs')));
  153. end;
  154. function IsCmdInstalled(): Boolean;
  155. begin
  156. Result := ((not SetupAborted) and (WizardIsTaskSelected('CreateLnkDeskCmd') or WizardIsTaskSelected('CreateLnkStartCmd')));
  157. end;