-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinitool-overwrite.cmd
64 lines (53 loc) · 1.03 KB
/
initool-overwrite.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@echo off
setlocal enabledelayedexpansion
for %%a in (%*) do (
if "%%a"=="-h" (
goto :help
)
if "%%a"=="--help" (
goto :help
)
)
if "%~2"=="" (
goto :error_usage
)
set "command=%~1"
set "file=%~2"
set status=0
set replace_original=1
if "%command%"=="e" (
set replace_original=0
)
if "%command%"=="exists" (
set replace_original=0
)
if "%file%"=="-" (
echo file must not be "-" 1>&2
exit /b 2
)
:create_temp
set "temp=%temp%\initool-in-place-%random%.tmp"
if exist "!temp!" goto :create_temp
if defined INITOOL (
"!INITOOL!" %* > "!temp!"
) else (
initool %* > "!temp!"
)
set status=%errorlevel%
if %status% equ 0 (
if %replace_original% equ 1 (
copy /y "!temp!" "%file%" > nul
)
)
del "%temp%"
exit /b %status%
:error_usage
echo usage: %~nx0 command file [arg ...] 1>&2
exit /b 2
:help
echo Modify the input file with initool.
echo.
echo usage: %~nx0 command file [arg ...]
echo.
echo You can give the path to initool in the environment variable "INITOOL".
exit /b