2020-12-16 16:40:13 +00:00
|
|
|
{ Copyright 2019-2021 Espressif Systems (Shanghai) CO LTD
|
2019-04-29 02:36:03 +00:00
|
|
|
SPDX-License-Identifier: Apache-2.0 }
|
|
|
|
|
|
|
|
{ ------------------------------ Page to select the version of ESP-IDF to download ------------------------------ }
|
|
|
|
|
|
|
|
var
|
|
|
|
IDFDownloadPage: TInputOptionWizardPage;
|
|
|
|
IDFDownloadAvailableVersions: TArrayOfString;
|
|
|
|
IDFDownloadPath, IDFDownloadVersion: String;
|
|
|
|
|
|
|
|
function GetSuggestedIDFDirectory(): String;
|
|
|
|
var
|
|
|
|
BaseName: String;
|
|
|
|
RepeatIndex: Integer;
|
|
|
|
begin
|
|
|
|
{ Start with Desktop\esp-idf name and if it already exists,
|
|
|
|
keep trying with Desktop\esp-idf-N for N=2 and above. }
|
|
|
|
BaseName := ExpandConstant('{userdesktop}\esp-idf');
|
|
|
|
Result := BaseName;
|
|
|
|
RepeatIndex := 1;
|
|
|
|
while DirExists(Result) do
|
|
|
|
begin
|
|
|
|
RepeatIndex := RepeatIndex + 1;
|
|
|
|
Result := BaseName + '-' + IntToStr(RepeatIndex);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetIDFVersionDescription(Version: String): String;
|
|
|
|
begin
|
|
|
|
if WildCardMatch(Version, 'v*-beta*') then
|
|
|
|
Result := 'beta version'
|
|
|
|
else if WildCardMatch(Version, 'v*-rc*') then
|
|
|
|
Result := 'pre-release version'
|
|
|
|
else if WildCardMatch(Version, 'v*') then
|
|
|
|
Result := 'release version'
|
|
|
|
else if WildCardMatch(Version, 'release/v*') then
|
|
|
|
Result := 'release branch'
|
|
|
|
else if WildCardMatch(Version, 'master') then
|
|
|
|
Result := 'development branch'
|
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DownloadIDFVersionsList();
|
|
|
|
var
|
|
|
|
Url: String;
|
|
|
|
VersionFile: String;
|
|
|
|
begin
|
2020-12-16 16:40:13 +00:00
|
|
|
Url := ExpandConstant('{param:IDFVERSIONSURL|https://dl.espressif.com/dl/esp-idf/idf_versions.txt}')
|
2019-04-29 02:36:03 +00:00
|
|
|
VersionFile := ExpandConstant('{tmp}\idf_versions.txt');
|
|
|
|
if idpDownloadFile(Url, VersionFile) then
|
|
|
|
begin
|
|
|
|
Log('Downloaded ' + Url + ' to ' + VersionFile);
|
|
|
|
end else begin
|
|
|
|
Log('Download of ' + Url + ' failed, using a fallback versions list');
|
|
|
|
ExtractTemporaryFile('idf_versions.txt');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure OnIDFDownloadPagePrepare(Sender: TObject);
|
|
|
|
var
|
|
|
|
Page: TInputOptionWizardPage;
|
|
|
|
VersionFile: String;
|
|
|
|
i: Integer;
|
2020-12-16 16:40:13 +00:00
|
|
|
SuggestedIDFDirectory: String;
|
2019-04-29 02:36:03 +00:00
|
|
|
begin
|
|
|
|
Page := TInputOptionWizardPage(Sender);
|
|
|
|
Log('OnIDFDownloadPagePrepare');
|
|
|
|
if Page.CheckListBox.Items.Count > 0 then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
DownloadIDFVersionsList();
|
|
|
|
|
|
|
|
VersionFile := ExpandConstant('{tmp}\idf_versions.txt');
|
|
|
|
if not LoadStringsFromFile(VersionFile, IDFDownloadAvailableVersions) then
|
|
|
|
begin
|
|
|
|
Log('Failed to load versions from ' + VersionFile);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Log('Versions count: ' + IntToStr(GetArrayLength(IDFDownloadAvailableVersions)))
|
|
|
|
for i := 0 to GetArrayLength(IDFDownloadAvailableVersions) - 1 do
|
|
|
|
begin
|
|
|
|
Log('Version ' + IntToStr(i) + ': ' + IDFDownloadAvailableVersions[i]);
|
|
|
|
Page.Add(IDFDownloadAvailableVersions[i] + ' ('
|
|
|
|
+ GetIDFVersionDescription(IDFDownloadAvailableVersions[i]) + ')');
|
|
|
|
end;
|
|
|
|
Page.SelectedValueIndex := 0;
|
|
|
|
|
2020-12-16 16:40:13 +00:00
|
|
|
SuggestedIDFDirectory := ExpandConstant('{param:IDFDIR|' + GetSuggestedIDFDirectory() + '}');
|
|
|
|
ChoicePageSetInputText(Page, SuggestedIDFDirectory);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Validation of PATH for IDF releases which does not support special characters. }
|
|
|
|
{ Source: https://stackoverflow.com/questions/21623515/is-it-possible-to-filter-require-installation-path-to-be-ascii-in-innosetup }
|
|
|
|
function IsCharValid(Value: Char): Boolean;
|
|
|
|
begin
|
|
|
|
Result := Ord(Value) <= $007F;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function IsDirNameValid(const Value: string): Boolean;
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
for I := 1 to Length(Value) do
|
|
|
|
if not IsCharValid(Value[I]) then
|
|
|
|
Exit;
|
|
|
|
Result := True;
|
2019-04-29 02:36:03 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure OnIDFDownloadSelectionChange(Sender: TObject);
|
|
|
|
var
|
|
|
|
Page: TInputOptionWizardPage;
|
|
|
|
begin
|
|
|
|
Page := TInputOptionWizardPage(Sender);
|
|
|
|
Log('OnIDFDownloadSelectionChange index=' + IntToStr(Page.SelectedValueIndex));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function OnIDFDownloadPageValidate(Sender: TWizardPage): Boolean;
|
|
|
|
var
|
|
|
|
Page: TInputOptionWizardPage;
|
|
|
|
IDFPath: String;
|
|
|
|
begin
|
2019-07-22 06:57:21 +00:00
|
|
|
Result := False;
|
2019-04-29 02:36:03 +00:00
|
|
|
Page := TInputOptionWizardPage(Sender);
|
|
|
|
Log('OnIDFDownloadPageValidate index=' + IntToStr(Page.SelectedValueIndex));
|
|
|
|
|
|
|
|
IDFPath := ChoicePageGetInputText(Page);
|
|
|
|
if DirExists(IDFPath) and not DirIsEmpty(IDFPath) then
|
|
|
|
begin
|
|
|
|
MsgBox('Directory already exists and is not empty:' + #13#10 +
|
|
|
|
IDFPath + #13#10 + 'Please choose a different directory.', mbError, MB_OK);
|
2019-07-22 06:57:21 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Pos(' ', IDFPath) <> 0 then
|
|
|
|
begin
|
|
|
|
MsgBox('ESP-IDF build system does not support spaces in paths.' + #13#10
|
|
|
|
'Please choose a different directory.', mbError, MB_OK);
|
2019-04-29 02:36:03 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
IDFDownloadPath := IDFPath;
|
2020-12-16 16:40:13 +00:00
|
|
|
|
|
|
|
{ Use parameter /IDFVE=x to override selection in the box. }
|
|
|
|
IDFDownloadVersion := ExpandConstant('{param:IDFVERSION|}');
|
|
|
|
if (IDFDownloadVersion = '') then begin
|
|
|
|
IDFDownloadVersion := IDFDownloadAvailableVersions[Page.SelectedValueIndex];
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Following ZIP versions of IDF does not support installation on path with special characters. }
|
|
|
|
{ Issue: https://github.com/espressif/esp-idf/issues/5996 }
|
|
|
|
if ((IDFDownloadVersion = 'v4.1') or (IDFDownloadVersion = 'v4.0.2') or
|
|
|
|
(IDFDownloadVersion = 'v3.3.4')) then begin
|
|
|
|
if (not IsDirNameValid(IDFPath)) then begin
|
|
|
|
MsgBox('The installation of selected version of IDF is not supported on path with special characters.' + #13#10
|
|
|
|
'Please choose a different directory.', mbError, MB_OK);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2019-04-29 02:36:03 +00:00
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
<event('ShouldSkipPage')>
|
|
|
|
function ShouldSkipIDFDownloadPage(PageID: Integer): Boolean;
|
|
|
|
begin
|
|
|
|
if (PageID = IDFDownloadPage.ID) and not IDFDownloadRequired() then
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
<event('InitializeWizard')>
|
|
|
|
procedure CreateIDFDownloadPage();
|
|
|
|
begin
|
|
|
|
IDFDownloadPage := ChoicePageCreate(
|
|
|
|
IDFPage.ID,
|
|
|
|
'Download ESP-IDF', 'Please choose ESP-IDF version to download',
|
|
|
|
'For more information about ESP-IDF versions, see' + #13#10 +
|
|
|
|
'https://docs.espressif.com/projects/esp-idf/en/latest/versions.html',
|
|
|
|
'Choose a directory to download ESP-IDF to',
|
|
|
|
True,
|
|
|
|
@OnIDFDownloadPagePrepare,
|
|
|
|
@OnIDFDownloadSelectionChange,
|
|
|
|
@OnIDFDownloadPageValidate);
|
|
|
|
end;
|