Skip to content

Commit

Permalink
Merge pull request #301 from espressif/feat/replace_pdf_with_html_doc
Browse files Browse the repository at this point in the history
Replace pdf doc with html doc.
  • Loading branch information
dobairoland authored Jan 8, 2025
2 parents 416dbf6 + 7e28c32 commit 3347245
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
75 changes: 55 additions & 20 deletions Build-Installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,61 @@ function PrepareIdfPython {
}

function PrepareIdfDocumentation {
$FullFilePath = ".\build\$InstallerType\IDFdocumentation.pdf"
$DownloadUrl = "https://docs.espressif.com/projects/esp-idf/en/$OfflineBranch/esp32/esp-idf-en-$OfflineBranch-esp32.pdf"

if (Test-Path -Path $FullFilePath -PathType Leaf) {
"$FullFilePath found."
return
}

"Downloading: $DownloadUrl"
try {
$Request = Invoke-WebRequest $DownloadUrl -OutFile $FullFilePath -MaximumRedirection 0
[int]$StatusCode = $Request.StatusCode
}
catch {
[int]$StatusCode = $_.Exception.Response.StatusCode
}


if ($StatusCode -eq 302) {
FailBuild -Message "Failed to download documentation from $DownloadUrl. Status code: $StatusCode"
$DocumentationBasePath = ".\build\$InstallerType\docs"
$DownloadedZipName = "esp-idf-en-$OfflineBranch.zip"
$DownloadUrl = "https://docs.espressif.com/projects/esp-idf/en/$OfflineBranch/esp32/$DownloadedZipName"

if (-Not(Test-Path -Path $DocumentationBasePath -PathType Container)) {
New-Item -ItemType Directory -Path $DocumentationBasePath
}

$ZipFilePath = Join-Path -Path $DocumentationBasePath -ChildPath $DownloadedZipName
# Download the ZIP file if it doesn't already exist
if (-Not(Test-Path -Path $ZipFilePath -PathType Leaf)) {
"Downloading: $DownloadUrl"
try {
$Request = Invoke-WebRequest $DownloadUrl -OutFile $ZipFilePath -MaximumRedirection 0
[int]$StatusCode = $Request.StatusCode
}
catch {
[int]$StatusCode = $_.Exception.Response.StatusCode
}


if ($StatusCode -eq 302) {
FailBuild -Message "Failed to download documentation from $DownloadUrl. Status code: $StatusCode"
}
} else {
"Documentation ZIP file already exists: $ZipFilePath"
}

$ExtractedPath = Join-Path -Path $DocumentationBasePath -ChildPath "html"
# Extract the ZIP file if not already extracted
if (-Not(Test-Path -Path $ExtractedPath -PathType Container)) {
"Extracting documentation to: $ExtractedPath"
try {
Expand-Archive -Path $ZipFilePath -DestinationPath $ExtractedPath
} catch {
FailBuild -Message "Failed to extract documentation ZIP file at $ZipFilePath. Error: $_"
}
} else {
"Documentation already extracted to: $ExtractedPath"
}

# Create a symbolic link to the HTML index
$HtmlIndexPath = Join-Path -Path $ExtractedPath -ChildPath "index.html"
if (-Not(Test-Path -Path $HtmlIndexPath -PathType Leaf)) {
FailBuild -Message "Documentation HTML index not found in extracted documentation path: $ExtractedPath."
}
$SymLinkFilePath = ".\build\$InstallerType\IDFdocumentation.html"
if (-Not(Test-Path -Path $SymLinkFilePath -PathType Leaf)) {
"Creating symbolic link: $SymLinkFilePath -> $HtmlIndexPath"
try {
$AbsoluteHtmlIndexPath = Resolve-Path -Path $HtmlIndexPath -ErrorAction SilentlyContinue
New-Item -ItemType SymbolicLink -Path $SymLinkFilePath -Value $AbsoluteHtmlIndexPath > $null
} catch {
"ERROR: Failed to create symbolic link at $SymLinkFilePath. Error: $_"
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/InnoSetup/IdfToolsSetup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Source: "..\PowerShell\Initialize-Idf.ps1"; DestDir: "{app}";
Source: "{#BUILD}\espidf.constraints.v*.txt"; DestDir: "{app}"; Flags: skipifsourcedoesntexist;
; IDF Documentation
#if OFFLINE == 'yes'
Source: "{#BUILD}\IDFdocumentation.pdf"; DestDir: "{app}";
Source: "{#BUILD}\IDFdocumentation.html"; DestDir: "{app}";
#endif

; createallsubdirs is necessary for git repo. Otherwise empty directories disappears
Expand Down Expand Up @@ -382,7 +382,7 @@ Filename: "cmd"; Parameters: "/c start https://docs.espressif.com/projects/esp-i
#endif

#if OFFLINE == 'yes'
Filename: "cmd"; Parameters: "/c start """" ""{app}\IDFdocumentation.pdf"""; Flags: nowait postinstall; Description: {cm:PointToDocumentation}; Check: IsInstallSuccess;
Filename: "cmd"; Parameters: "/c start """" ""{app}\IDFdocumentation.html"""; Flags: nowait postinstall; Description: {cm:PointToDocumentation}; Check: IsInstallSuccess;
#endif

; WD registration checkbox is identified by 'Windows Defender' substring anywhere in its caption, not by the position index in WizardForm.TasksList.Items
Expand Down

0 comments on commit 3347245

Please sign in to comment.