build: prepare V1.2.2 with portable 7-Zip self-extraction
This commit is contained in:
1 parent
453d288a6c
commit
5aeddacfc9
12 files changed
+345
-10
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""Build a 7-Zip SFX wrapper around a prepared .7z release archive."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
def build_sfx(
|
||||
stub: Path,
|
||||
archive: Path,
|
||||
output: Path,
|
||||
) -> Path:
|
||||
"""Use the official 7z.sfx extractor (not the temporary installer stub).
|
||||
|
||||
Its native dialog selects a persistent destination. No installer config,
|
||||
registry modifications, temporary extraction or automatic launch is needed.
|
||||
"""
|
||||
stub = Path(stub)
|
||||
archive = Path(archive)
|
||||
output = Path(output)
|
||||
if not stub.is_file() or not archive.is_file():
|
||||
raise FileNotFoundError("SFX stub and archive must both exist")
|
||||
if output.exists():
|
||||
raise FileExistsError(output)
|
||||
with stub.open('rb') as stream:
|
||||
if stream.read(2) != b'MZ':
|
||||
raise ValueError('Expected Windows SFX executable')
|
||||
with archive.open('rb') as stream:
|
||||
if stream.read(6) != b'7z\xbc\xaf\x27\x1c':
|
||||
raise ValueError('Expected 7z archive')
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
temporary = output.with_name(f".{output.name}.{os.getpid()}.tmp")
|
||||
try:
|
||||
with temporary.open("xb") as target:
|
||||
for source in (stub, archive):
|
||||
with source.open('rb') as stream:
|
||||
shutil.copyfileobj(stream, target, 1024 * 1024)
|
||||
target.flush()
|
||||
os.fsync(target.fileno())
|
||||
os.replace(temporary, output)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
return output
|
||||
Reference in new issue
Block a user