- 旧版在钩子里同步 curl,大文件在慢链路上会被钩子超时杀掉,留下半截+锁 - 改为经 ShellExecute 启动隐藏 PowerShell 后台下载(脱离钩子进程),钩子毫秒级返回 - download.ps1 用 curl 下载、原子改名、清锁;纯 ASCII 避免 PowerShell 5.1 按 GBK 误读
27 lines
1.1 KiB
Batchfile
27 lines
1.1 KiB
Batchfile
@echo off
|
|
rem ============================================================
|
|
rem Download URL (notify.exe is fetched from here on first run) -- edit as needed
|
|
set "DOWNLOAD_URL=https://git.pchuan.top/cc-tools/notify/releases/download/v1.0.0/notify.exe"
|
|
rem ============================================================
|
|
setlocal
|
|
set "BIN=%~dp0..\bin"
|
|
set "EXE=%BIN%\notify.exe"
|
|
set "LOCK=%BIN%\notify.download.lock"
|
|
|
|
rem first run: kick off a background download, do NOT block the hook
|
|
if not exist "%EXE%" call :bootstrap
|
|
|
|
if exist "%EXE%" "%EXE%" %*
|
|
endlocal
|
|
exit /b
|
|
|
|
:bootstrap
|
|
if not exist "%BIN%" mkdir "%BIN%" 2>nul
|
|
rem mkdir is atomic; success = we start the download, failure = already downloading
|
|
mkdir "%LOCK%" 2>nul
|
|
if errorlevel 1 exit /b
|
|
if exist "%EXE%" ( rmdir "%LOCK%" 2>nul & exit /b )
|
|
rem launch a detached hidden PowerShell downloader (ShellExecute breaks away from the hook)
|
|
powershell -NoProfile -WindowStyle Hidden -Command "Start-Process -WindowStyle Hidden -FilePath powershell -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File','%~dp0download.ps1','-Url','%DOWNLOAD_URL%','-Out','%EXE%','-Lock','%LOCK%')"
|
|
exit /b
|