|
21 | 21 | -- imports |
22 | 22 | import("core.base.option") |
23 | 23 | import("lib.detect.find_file") |
| 24 | +import("lib.detect.find_tool") |
24 | 25 | import("detect.tools.find_xz") |
25 | 26 | import("detect.tools.find_7z") |
26 | 27 | import("detect.tools.find_tar") |
@@ -331,6 +332,46 @@ function _extract_using_unzip(archivefile, outputdir, extension, opt) |
331 | 332 | return true |
332 | 333 | end |
333 | 334 |
|
| 335 | +-- extract archivefile using powershell |
| 336 | +-- powershell -ExecutionPolicy Bypass -File "D:\scripts\unzip.ps1" "archivefile" "outputdir" |
| 337 | +function _extract_using_powershell(archivefile, outputdir, extension, opt) |
| 338 | + |
| 339 | + -- find powershell |
| 340 | + local powershell = find_tool("pwsh") or find_tool("powershell") |
| 341 | + if not powershell then |
| 342 | + return false |
| 343 | + end |
| 344 | + |
| 345 | + -- get the script file |
| 346 | + local scriptfile = path.join(os.programdir(), "scripts", "unzip.ps1") |
| 347 | + |
| 348 | + -- extract to *.tar file first |
| 349 | + local outputdir_old = nil |
| 350 | + if extension:startswith(".tar.") then |
| 351 | + outputdir_old = outputdir |
| 352 | + outputdir = os.tmpfile({ramdisk = false}) .. ".tar" |
| 353 | + end |
| 354 | + |
| 355 | + -- ensure output directory |
| 356 | + if not os.isdir(outputdir) then |
| 357 | + os.mkdir(outputdir) |
| 358 | + end |
| 359 | + |
| 360 | + -- extract it |
| 361 | + local argv = {"-ExecutionPolicy", "Bypass", "-File", scriptfile, archivefile, outputdir} |
| 362 | + os.vrunv(powershell.program, argv) |
| 363 | + |
| 364 | + -- continue to extract *.tar file |
| 365 | + if outputdir_old then |
| 366 | + local tarfile = find_file("**.tar", outputdir) |
| 367 | + if tarfile and os.isfile(tarfile) then |
| 368 | + return _extract(tarfile, outputdir_old, ".tar", {_extract_using_tar, _extract_using_7z}, opt) |
| 369 | + end |
| 370 | + end |
| 371 | + return true |
| 372 | +end |
| 373 | + |
| 374 | + |
334 | 375 | -- extract archivefile using bzip2 |
335 | 376 | function _extract_using_bzip2(archivefile, outputdir, extension, opt) |
336 | 377 |
|
@@ -425,7 +466,7 @@ function main(archivefile, outputdir, opt) |
425 | 466 | -- tar/windows can not extract .bz2 ... |
426 | 467 | extractors = |
427 | 468 | { |
428 | | - [".zip"] = {_extract_using_7z, _extract_using_unzip, _extract_using_tar} |
| 469 | + [".zip"] = {_extract_using_7z, _extract_using_unzip, _extract_using_tar, _extract_using_powershell} |
429 | 470 | , [".7z"] = {_extract_using_7z} |
430 | 471 | , [".gz"] = {_extract_using_7z, _extract_using_gzip, _extract_using_tar} |
431 | 472 | , [".xz"] = {_extract_using_7z, _extract_using_xz, _extract_using_tar} |
|
0 commit comments