main.iss.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. { Copyright 2019 Espressif Systems (Shanghai) PTE 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 PythonUseExisting then
  41. begin
  42. DestPath := ExpandConstant('{app}\dist\{#PythonInstallerName}');
  43. if FileExists(DestPath) then
  44. begin
  45. Log('Python installer already downloaded: ' + DestPath);
  46. end else begin
  47. idpAddFile('{#PythonInstallerDownloadURL}', DestPath);
  48. end;
  49. end;
  50. if not GitUseExisting then
  51. begin
  52. DestPath := ExpandConstant('{app}\dist\{#GitInstallerName}');
  53. if FileExists(DestPath) then
  54. begin
  55. Log('Git installer already downloaded: ' + DestPath);
  56. end else begin
  57. idpAddFile('{#GitInstallerDownloadURL}', DestPath);
  58. end;
  59. end;
  60. if not IDFUseExisting then
  61. begin
  62. IDFAddDownload();
  63. end;
  64. end;
  65. { ------------------------------ Custom steps after the main installation flow ------------------------------ }
  66. procedure AddPythonGitToPath();
  67. var
  68. EnvPath: String;
  69. PythonLibPath: String;
  70. begin
  71. EnvPath := GetEnv('PATH');
  72. if not PythonUseExisting then
  73. PythonExecutablePathUpdateAfterInstall();
  74. if not GitUseExisting then
  75. GitExecutablePathUpdateAfterInstall();
  76. EnvPath := PythonPath + ';' + GitPath + ';' + EnvPath;
  77. Log('Setting PATH for this process: ' + EnvPath);
  78. SetEnvironmentVariable('PATH', EnvPath);
  79. { Set IDF_TOOLS_PATH variable, in case it was set to a different value in the environment.
  80. The installer will set the variable to the new value in the registry, but we also need the
  81. new value to be visible to this process. }
  82. SetEnvironmentVariable('IDF_TOOLS_PATH', ExpandConstant('{app}'))
  83. { Log and clear PYTHONPATH variable, as it might point to libraries of another Python version}
  84. PythonLibPath := GetEnv('PYTHONPATH')
  85. Log('PYTHONPATH=' + PythonLibPath)
  86. SetEnvironmentVariable('PYTHONPATH', '')
  87. end;
  88. <event('CurStepChanged')>
  89. procedure PostInstallSteps(CurStep: TSetupStep);
  90. var
  91. Err: Integer;
  92. begin
  93. if CurStep <> ssPostInstall then
  94. exit;
  95. try
  96. AddPythonGitToPath();
  97. if not IDFUseExisting then
  98. IDFDownload();
  99. IDFToolsSetup();
  100. if WizardIsTaskSelected('createlnk') then
  101. begin
  102. CreateIDFCommandPromptShortcut('{autostartmenu}\Programs\ESP-IDF');
  103. end;
  104. if WizardIsTaskSelected('createdsk') then
  105. begin
  106. CreateIDFCommandPromptShortcut('{autodesktop}');
  107. end;
  108. if WizardIsTaskSelected('wdexcl') then
  109. begin
  110. RegisterIDFToolsExecutablesInWD();
  111. end;
  112. except
  113. SetupAborted := True;
  114. if MsgBox('Installation log has been created, it may contain more information about the problem.' + #13#10
  115. + 'Display the installation log now?', mbConfirmation, MB_YESNO or MB_DEFBUTTON1) = IDYES then
  116. begin
  117. ShellExec('', 'notepad.exe', ExpandConstant('{log}'), ExpandConstant('{tmp}'), SW_SHOW, ewNoWait, Err);
  118. end;
  119. Abort();
  120. end;
  121. end;
  122. <event('ShouldSkipPage')>
  123. function SkipFinishedPage(PageID: Integer): Boolean;
  124. begin
  125. Result := False;
  126. if PageID = wpFinished then
  127. begin
  128. Result := SetupAborted;
  129. end;
  130. end;