Skip to content

Commit

Permalink
FIX: Extracting SDK Components
Browse files Browse the repository at this point in the history
In some cases, it is needed to temporary change the workdir. After which
some relative paths became inacessible.

So, the main fix is to use abs paths for the mentioned cases.
  • Loading branch information
reksar committed Sep 20, 2023
1 parent e6f03df commit c928cef
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion get-sdk.bat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ call check-components "%destination%" && (
)
echo Getting Windows SDK

set "tmp=%destination%\tmp"
for %%i in ("%destination%") do set "tmp=%%~fi\tmp"

set "archiver=%tmp%\7-zip"
call ensure-archiver "%archiver%"
Expand Down
47 changes: 26 additions & 21 deletions sdk/extract-components.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,53 @@ setlocal
set installers=%~1
set components=%~2

call which lessmsi >NUL 2>&1 || (
echo [ERR][%~n0] Requires `lessmsi`!
rem The `lessmsi` may have errors when using some complicated paths.
rem To prevent them, we need to change the workdir to %components% and then
rem use relative paths. Before doing this, we need to save the %origin_path%
rem and ensure that %installers% is an abs path.
set "origin_path=%CD%"
for %%i in ("%installers%") do set "installers=%%~fi"
if not exist "%components%" md "%components%"
cd /d "%components%"

rem Check this after cd %components%!
call check-installers "%installers%" || (
echo [ERR][%~n0] No installers found!
exit /b 1
)

rem Only used to suppress output from `lessmsi` to stdout.
set "lessmsi_log=%components%\lessmsi.log"
call which lessmsi >NUL 2>&1 || (
echo [ERR][%~n0] Executable `lessmsi` not found!
exit /b 2
)

if exist "%lessmsi_log%" (
del /q /s "%lessmsi_log%" >NUL 2>&1 && (
echo [WARN][%~n0] The old "%lessmsi_log%" has been deleted!
rem Used only to suppress output from `lessmsi` to stdout.
if exist lessmsi.log (
del /q /s lessmsi.log >NUL 2>&1 && (
echo [WARN][%~n0] The old lessmsi.log has been deleted!
) || (
echo [WARN][%~n0] Failed to delete "%lessmsi_log%"!
echo [WARN][%~n0] Failed to delete lessmsi.log!
)
)

rem Prevent path errors for `lessmsi`.
set "origin_path=%CD%"
if not exist "%components%" md "%components%"
cd /d "%components%"

echo - Extracting SDK Components

for %%i in ("%installers%\*.msi") do (
if not exist "%components%\%%~ni" (
if not exist "%%~ni" (
echo - %%~ni
lessmsi x "%%i" >> "%lessmsi_log%" || (
lessmsi x "%%i" >> lessmsi.log || (
echo [ERR][%~n0] Unable to extract SDK Component!
cd /d "%origin_path%"
exit /b 2
exit /b 3
)
) else echo - [WARN] Already exist: %%~ni
)

echo.

rem Duplicates may be created during MSI extraction.
del /q /s *.duplicate* >NUL 2>&1

cd /d "%origin_path%"

del /q /s "%lessmsi_log%" >NUL 2>&1
del /q /s lessmsi.log >NUL 2>&1
rd /q /s "%installers%" >NUL 2>&1
cd /d "%origin_path%"

endlocal
22 changes: 12 additions & 10 deletions sdk/extract-installers.bat
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
@echo off

rem --------------------------------------------------------------------------
rem Extracts the Windows SDK Installers from the [ISO] to the [INSTALLERS] dir.
rem Extracts the Windows SDK Installers from the [iso] to the [installers] dir.
rem
rem Using:
rem
rem extract-installers [ISO] [INSTALLERS]
rem extract-installers [iso] [installers]
rem --------------------------------------------------------------------------

setlocal

set iso=%~1
set installers=%~2
set files_to_extract=Installers\*.msi Installers\*.cab

call which 7z >NUL 2>&1 && (
echo|set/p=- Extracting SDK Installers ...
set files=Installers\*.msi Installers\*.cab
7z e -y -o"%installers%" "%iso%" -r %files% >NUL || (
7z e -y -o"%installers%" "%iso%" -r %files_to_extract% >NUL || (
echo FAIL
exit /b 1
)
call check-installers "%installers%" || (
echo FAIL
exit /b 1
)
echo OK
goto :END
exit /b 0
)

call extract-installers-from-drive "%iso%" "%installers%" || exit /b 1

:END
del /q /s "%iso%" >NUL 2>&1 || echo [WARN][%~n0] Unable to delete "%iso%"!
exit /b 0
call extract-installers-from-drive "%iso%" "%installers%" ^
&& exit /b 0 ^
|| exit /b 1

endlocal
3 changes: 2 additions & 1 deletion utils/destination.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@echo off

rem --------------------------------------------------------------------------
rem Sets the %destination% var and creates the associated dir if needed.
rem Sets the %destination% var without trailing backslash and creates the
rem associated dir if needed.
rem --------------------------------------------------------------------------

set destination=%~1
Expand Down
2 changes: 1 addition & 1 deletion utils/ensure-archiver.bat
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ echo.
endlocal

:SET_PATH
set "PATH=%~1;%PATH%"
set "PATH=%~f1;%PATH%"
exit /b 0
5 changes: 2 additions & 3 deletions utils/ensure-lessmsi.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ rem Third-party util for extracting *.MSI content without its installation.
rem
rem Using:
rem
rem ensure-lessmsi [DESTINATION]
rem
rem ensure-lessmsi [destination]
rem --------------------------------------------------------------------------

call which lessmsi >NUL 2>&1 && exit /b 0
Expand Down Expand Up @@ -49,5 +48,5 @@ echo.
endlocal

:SET_PATH
set "PATH=%~1;%PATH%"
set "PATH=%~f1;%PATH%"
exit /b 0

0 comments on commit c928cef

Please sign in to comment.